aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Gerd Zellweger <mail@gerdzellweger.com> 2019-05-06 00:00:23 -0700
committerGravatar Gerd Zellweger <mail@gerdzellweger.com> 2019-05-06 00:00:23 -0700
commitd33a20587a1406ece7f71c2cd6e767c4ad2ae39b (patch)
tree3afa828745a5e96874c042978edba37077c37a5c
parentaf776f308e97e24f4eb3d63272596a505c3debe6 (diff)
downloadrust-x86-d33a20587a1406ece7f71c2cd6e767c4ad2ae39b.tar.gz
rust-x86-d33a20587a1406ece7f71c2cd6e767c4ad2ae39b.tar.zst
rust-x86-d33a20587a1406ece7f71c2cd6e767c4ad2ae39b.zip
Implement Pointer and Debug for VAddr, PAddr.
Also formatting.
-rw-r--r--build.rs62
-rw-r--r--src/bits64/paging.rs30
-rw-r--r--src/irq.rs2
-rw-r--r--src/perfcnt/intel/description.rs5
-rw-r--r--src/perfcnt/intel/mod.rs2
5 files changed, 63 insertions, 38 deletions
diff --git a/build.rs b/build.rs
index 54a422d..5083bc4 100644
--- a/build.rs
+++ b/build.rs
@@ -228,7 +228,8 @@ mod performance_counter {
2 => {
assert!(split_parts[0] <= u8::max_value() as u64);
assert!(split_parts[1] <= u8::max_value() as u64);
- umask = Tuple::Two(split_parts[0] as u8, split_parts[1] as u8)
+ umask =
+ Tuple::Two(split_parts[0] as u8, split_parts[1] as u8)
}
_ => panic!("More than two event codes?"),
}
@@ -280,10 +281,12 @@ mod performance_counter {
"Unit" => unit = parse_null_string(value_str),
"Filter" => filter = parse_null_string(value_str),
"ExtSel" => extsel = parse_bool(value_str),
- "CollectPEBSRecord" => collect_pebs_record = Some(parse_number(value_str)),
- "ELLC" => { /* Ignored due to missing documentation. */ },
+ "CollectPEBSRecord" => {
+ collect_pebs_record = Some(parse_number(value_str))
+ }
+ "ELLC" => { /* Ignored due to missing documentation. */ }
"EVENT_STATUS" => event_status = parse_number(value_str),
- "PDIR_COUNTER" => { /* Ignored */ },
+ "PDIR_COUNTER" => { /* Ignored */ }
"Deprecated" => deprecated = parse_bool(value_str),
"FCMask" => fc_mask = parse_number(value_str) as u8,
"FILTER_VALUE" => filter_value = parse_number(value_str),
@@ -331,14 +334,17 @@ mod performance_counter {
//println!("{:?}", ipcd.event_name);
if do_insert == true {
- builder_values.insert(String::from(ipcd.event_name), String::from(format!("{:?}", ipcd)));
+ builder_values.insert(
+ String::from(ipcd.event_name),
+ String::from(format!("{:?}", ipcd)),
+ );
}
}
} else {
panic!("JSON data is not an array.");
}
}
-
+
write!(
file,
"pub const {}: phf::Map<&'static str, EventDescription<'static>> = ",
@@ -346,11 +352,13 @@ mod performance_counter {
)
.unwrap();
-
for (key, val) in builder_values.iter() {
// Stupid hack since .entry needs &str
unsafe {
- builder.entry(mem::transmute::<&str, &'static str>(key.as_str()), mem::transmute::<&str, &'static str>(val.as_str()));
+ builder.entry(
+ mem::transmute::<&str, &'static str>(key.as_str()),
+ mem::transmute::<&str, &'static str>(val.as_str()),
+ );
}
}
builder.build(file).unwrap();
@@ -404,24 +412,20 @@ mod performance_counter {
let mut data_files = HashMap::new();
for record in rdr.decode() {
- let (family_model, version, file_name, event_type): (
- String,
- String,
- String,
- String,
- ) = record.unwrap();
+ let (family_model, version, file_name, event_type): (String, String, String, String) =
+ record.unwrap();
// TODO: Parse offcore counter descriptions.
let suffix = get_file_suffix(file_name.clone());
if suffix == "core" || suffix == "uncore" {
if !data_files.contains_key(&file_name) {
- data_files.insert(
- file_name.clone(),
- vec![(family_model, version, event_type)],
- );
- }
- else {
- data_files.get_mut(&file_name).unwrap().push((family_model, version, event_type));
+ data_files.insert(file_name.clone(), vec![(family_model, version, event_type)]);
+ } else {
+ data_files.get_mut(&file_name).unwrap().push((
+ family_model,
+ version,
+ event_type,
+ ));
}
}
}
@@ -444,8 +448,7 @@ mod performance_counter {
format!("{}", variable_upper.as_str()).as_str(),
);
inserted.insert(family_model.clone(), true);
- }
- else {
+ } else {
// ignore
}
}
@@ -466,21 +469,18 @@ mod performance_counter {
let mut architectures: HashMap<String, Vec<String>> = HashMap::new();
for (file, _) in &data_files {
let path = Path::new(file.as_str());
- let (_, ref variable_upper) = make_file_name(&path);
-
+ let (_, ref variable_upper) = make_file_name(&path);
+
println!("Adding {}", variable_upper);
- architectures.entry(variable_upper.to_string())
+ architectures
+ .entry(variable_upper.to_string())
.or_insert_with(Vec::new)
.push(file.clone());
}
for (ref arch, ref files) in architectures {
println!("Processing {:?} {:?}", arch, files);
- parse_performance_counters(
- files.to_vec(),
- arch,
- &mut filewriter
- );
+ parse_performance_counters(files.to_vec(), arch, &mut filewriter);
}
}
}
diff --git a/src/bits64/paging.rs b/src/bits64/paging.rs
index f08442a..0fbbf28 100644
--- a/src/bits64/paging.rs
+++ b/src/bits64/paging.rs
@@ -17,7 +17,7 @@ macro_rules! check_flag {
/// A wrapper for a physical address.
#[repr(transparent)]
-#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
+#[derive(Copy, Clone, Eq, Ord, PartialEq, PartialOrd)]
pub struct PAddr(pub u64);
impl PAddr {
@@ -185,6 +185,12 @@ impl fmt::Display for PAddr {
}
}
+impl fmt::Debug for PAddr {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ self.0.fmt(f)
+ }
+}
+
impl fmt::LowerHex for PAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
@@ -203,9 +209,16 @@ impl fmt::UpperHex for PAddr {
}
}
+impl fmt::Pointer for PAddr {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ use core::fmt::LowerHex;
+ self.0.fmt(f)
+ }
+}
+
/// A wrapper for a virtual address.
#[repr(transparent)]
-#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
+#[derive(Copy, Clone, Eq, Ord, PartialEq, PartialOrd)]
pub struct VAddr(pub u64);
impl VAddr {
@@ -404,6 +417,12 @@ impl fmt::Display for VAddr {
}
}
+impl fmt::Debug for VAddr {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ self.0.fmt(f)
+ }
+}
+
impl fmt::LowerHex for VAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.0.fmt(f)
@@ -422,6 +441,13 @@ impl fmt::UpperHex for VAddr {
}
}
+impl fmt::Pointer for VAddr {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ use core::fmt::LowerHex;
+ self.0.fmt(f)
+ }
+}
+
/// Log2 of base page size (12 bits).
pub const BASE_PAGE_SHIFT: usize = 12;
diff --git a/src/irq.rs b/src/irq.rs
index 12534f1..97f22cb 100644
--- a/src/irq.rs
+++ b/src/irq.rs
@@ -185,7 +185,7 @@ pub static EXCEPTIONS: [InterruptDescription; 21] = [
},
];
-bitflags!{
+bitflags! {
// Taken from Intel Manual Section 4.7 Page-Fault Exceptions.
pub struct PageFaultError: u32 {
/// 0: The fault was caused by a non-present page.
diff --git a/src/perfcnt/intel/description.rs b/src/perfcnt/intel/description.rs
index d47da75..4e5e8cc 100644
--- a/src/perfcnt/intel/description.rs
+++ b/src/perfcnt/intel/description.rs
@@ -234,11 +234,10 @@ pub struct EventDescription<'a> {
/// Port Mask
pub port_mask: u8,
- /// This field maps to the Unit Mask filed in the IA32_PERFEVTSELx[15:8] MSRs.
- /// It further qualifies the event logic unit selected in the event select
+ /// This field maps to the Unit Mask filed in the IA32_PERFEVTSELx[15:8] MSRs.
+ /// It further qualifies the event logic unit selected in the event select
/// field to detect a specific micro-architectural condition.
pub umask_ext: u8,
-
}
impl<'a> EventDescription<'a> {
diff --git a/src/perfcnt/intel/mod.rs b/src/perfcnt/intel/mod.rs
index 0c072d4..51af1c8 100644
--- a/src/perfcnt/intel/mod.rs
+++ b/src/perfcnt/intel/mod.rs
@@ -5,9 +5,9 @@ pub mod events;
mod description;
pub use self::description::{Counter, EventDescription, MSRIndex, PebsType, Tuple};
+use crate::cpuid;
use core::fmt::{Error, Result, Write};
use core::str;
-use crate::cpuid;
use phf;
const MODEL_LEN: usize = 30;