aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Gerd Zellweger <mail@gerdzellweger.com> 2017-02-17 17:37:21 +0100
committerGravatar Gerd Zellweger <mail@gerdzellweger.com> 2017-02-17 17:37:21 +0100
commit54e5ce4811c5275eaff01e10d3899ccf2abc45f9 (patch)
tree848ffbcdb192567d99629e44434d58680eeb50cd
parent4ea243fcde12460d5e0dd8d1407d2ea2671aca7a (diff)
downloadrust-x86-54e5ce4811c5275eaff01e10d3899ccf2abc45f9.tar.gz
rust-x86-54e5ce4811c5275eaff01e10d3899ccf2abc45f9.tar.zst
rust-x86-54e5ce4811c5275eaff01e10d3899ccf2abc45f9.zip
Make lifetime for event description explicit.
Signed-off-by: Gerd Zellweger <mail@gerdzellweger.com>
-rw-r--r--build.rs206
-rw-r--r--src/shared/perfcnt/intel/description.rs73
-rw-r--r--src/shared/perfcnt/intel/mod.rs4
3 files changed, 144 insertions, 139 deletions
diff --git a/build.rs b/build.rs
index ac37ff7..f1f00c8 100644
--- a/build.rs
+++ b/build.rs
@@ -23,7 +23,8 @@ mod performance_counter {
use self::serde_json::Value;
- include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/shared/perfcnt/intel/description.rs"));
+ include!(concat!(env!("CARGO_MANIFEST_DIR"),
+ "/src/shared/perfcnt/intel/description.rs"));
/// HACK: We need to convert parsed strings to static because we're reusing
/// the struct definition which declare strings as static in the generated code.
@@ -49,42 +50,44 @@ mod performance_counter {
assert!(x.starts_with("0x"));
match u64::from_str_radix(&x[2..], 16) {
Ok(u) => u,
- Err(e) => panic!("{}: Can not parse {}", e, x)
+ Err(e) => panic!("{}: Can not parse {}", e, x),
}
- }).collect()
+ })
+ .collect()
}
fn parse_number(value_str: &str) -> u64 {
if value_str.len() > 2 && value_str[..2].starts_with("0x") {
match u64::from_str_radix(&value_str[2..], 16) {
Ok(u) => u,
- Err(e) => panic!("{}: Can not parse {}", e, value_str)
+ Err(e) => panic!("{}: Can not parse {}", e, value_str),
}
- }
- else {
+ } else {
match u64::from_str_radix(&value_str, 10) {
Ok(u) => u,
- Err(e) => panic!("{}: Can not parse {}", e, value_str)
+ Err(e) => panic!("{}: Can not parse {}", e, value_str),
}
}
}
fn parse_counter_values(value_str: &str) -> u64 {
- value_str.split(",").map(|x| x.trim())
+ value_str.split(",")
+ .map(|x| x.trim())
.filter(|x| x.len() > 0)
- .map(|x| {
- match u64::from_str_radix(&x, 10) {
- Ok(u) => u,
- Err(e) => panic!("{}: Can not parse {} in {}", e, x, value_str)
- }
- }).fold(0, |acc, c| { assert!(c < 8); acc | 1 << c })
+ .map(|x| match u64::from_str_radix(&x, 10) {
+ Ok(u) => u,
+ Err(e) => panic!("{}: Can not parse {} in {}", e, x, value_str),
+ })
+ .fold(0, |acc, c| {
+ assert!(c < 8);
+ acc | 1 << c
+ })
}
fn parse_null_string(value_str: &str) -> Option<&str> {
if value_str != "null" {
Some(value_str)
- }
- else {
+ } else {
None
}
}
@@ -94,13 +97,11 @@ mod performance_counter {
let mask: u64 = parse_counter_values(&value_str["fixed counter".len()..]);
assert!(mask <= u8::max_value() as u64);
Counter::Fixed(mask as u8)
- }
- else if value_str.to_lowercase().starts_with("fixed") {
+ } else if value_str.to_lowercase().starts_with("fixed") {
let mask: u64 = parse_counter_values(&value_str["fixed".len()..]);
assert!(mask <= u8::max_value() as u64);
Counter::Fixed(mask as u8)
- }
- else {
+ } else {
let mask: u64 = parse_counter_values(value_str);
assert!(mask <= u8::max_value() as u64);
Counter::Programmable(mask as u8)
@@ -169,7 +170,8 @@ mod performance_counter {
//println!("key = {} value = {}", key, value.as_string().unwrap());
let value_string = value.as_string().unwrap();
let value_str = string_to_static_str(value_string).trim();
- let split_str_parts: Vec<&str> = value_string.split(",").map(|x| x.trim()).collect();
+ let split_str_parts: Vec<&str> =
+ value_string.split(",").map(|x| x.trim()).collect();
match key.as_str() {
"EventName" => {
@@ -177,8 +179,7 @@ mod performance_counter {
all_events.insert(value_str, 0);
assert!(all_events.contains_key(value_str));
do_insert = true;
- }
- else {
+ } else {
do_insert = false;
println!("WARN: Key {} already exists.", value_str);
}
@@ -190,66 +191,62 @@ mod performance_counter {
1 => {
assert!(split_parts[0] <= u8::max_value() as u64);
event_code = Tuple::One(split_parts[0] as u8)
- },
+ }
2 => {
assert!(split_parts[0] <= u8::max_value() as u64);
assert!(split_parts[1] <= u8::max_value() as u64);
- event_code = Tuple::Two(split_parts[0] as u8, split_parts[1] as u8)
- },
- _ => panic!("More than two event codes?")
+ event_code = Tuple::Two(split_parts[0] as u8,
+ split_parts[1] as u8)
+ }
+ _ => panic!("More than two event codes?"),
}
- },
+ }
"UMask" => {
let split_parts: Vec<u64> = parse_hex_numbers(split_str_parts);
match split_parts.len() {
1 => {
assert!(split_parts[0] <= u8::max_value() as u64);
umask = Tuple::One(split_parts[0] as u8)
- },
+ }
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)
- },
- _ => panic!("More than two event codes?")
+ }
+ _ => panic!("More than two event codes?"),
}
- },
+ }
"BriefDescription" => brief_description = value_str,
"PublicDescription" => {
if brief_description != value_str && value_str != "tbd" {
public_description = Some(value_str);
- }
- else {
+ } else {
public_description = None;
}
- },
+ }
"Counter" => counter = parse_counters(value_str),
"CounterHTOff" => counter_ht_off = Some(parse_counters(value_str)),
"PEBScounters" => pebs_counters = Some(parse_counters(value_str)),
"SampleAfterValue" => sample_after_value = parse_number(value_str),
"MSRIndex" => {
- let split_parts: Vec<u64> = value_str
- .split(",")
+ let split_parts: Vec<u64> = value_str.split(",")
.map(|x| x.trim())
.map(|x| parse_number(x))
.collect();
- println!("{:?}", split_parts);
-
- msr_index = match split_parts.len() {
- 1 => {
- if split_parts[0] != 0 {
- MSRIndex::One(split_parts[0])
- }
- else {
- MSRIndex::None
- }
- },
- 2 => {
- MSRIndex::Two(split_parts[0], split_parts[1])
- },
- _ => panic!("More than two MSR indexes?")
+ println!("{:?}", split_parts);
+
+ msr_index = match split_parts.len() {
+ 1 => {
+ if split_parts[0] != 0 {
+ MSRIndex::One(split_parts[0])
+ } else {
+ MSRIndex::None
+ }
}
- },
+ 2 => MSRIndex::Two(split_parts[0], split_parts[1]),
+ _ => panic!("More than two MSR indexes?"),
+ }
+ }
"MSRValue" => msr_value = parse_number(value_str),
"TakenAlone" => taken_alone = parse_bool(value_str),
"CounterMask" => counter_mask = parse_number(value_str) as u8,
@@ -266,52 +263,52 @@ mod performance_counter {
"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. */ },
+ "ELLC" => { /* Ignored due to missing documentation. */ }
_ => panic!("Unknown member: {} in file {}", key, input),
};
}
- let ipcd = EventDescription::new(
- event_code,
- umask,
- event_name,
- brief_description,
- public_description,
- counter,
- counter_ht_off,
- pebs_counters,
- sample_after_value,
- msr_index,
- msr_value,
- taken_alone,
- counter_mask,
- invert,
- any_thread,
- edge_detect,
- pebs,
- precise_store,
- collect_pebs_record,
- data_la,
- l1_hit_indication,
- errata,
- offcore,
- unit,
- filter,
- extsel
- );
+ let ipcd = EventDescription::new(event_code,
+ umask,
+ event_name,
+ brief_description,
+ public_description,
+ counter,
+ counter_ht_off,
+ pebs_counters,
+ sample_after_value,
+ msr_index,
+ msr_value,
+ taken_alone,
+ counter_mask,
+ invert,
+ any_thread,
+ edge_detect,
+ pebs,
+ precise_store,
+ collect_pebs_record,
+ data_la,
+ l1_hit_indication,
+ errata,
+ offcore,
+ unit,
+ filter,
+ extsel);
//println!("{:?}", ipcd.event_name);
if do_insert == true {
builder.entry(ipcd.event_name, format!("{:?}", ipcd).as_str());
}
}
- }
- else {
+ } else {
panic!("JSON data is not an array.");
}
- write!(file, "pub const {}: phf::Map<&'static str, EventDescription> = ", variable).unwrap();
+ write!(file,
+ "pub const {}: phf::Map<&'static str, EventDescription<'static>> = ",
+ variable)
+ .unwrap();
builder.build(file).unwrap();
write!(file, ";\n").unwrap();
}
@@ -341,17 +338,13 @@ mod performance_counter {
pub fn get_file_suffix(file_name: String) -> &'static str {
if file_name.contains("_core_") {
"core"
- }
- else if file_name.contains("_uncore_") {
+ } else if file_name.contains("_uncore_") {
"uncore"
- }
- else if file_name.contains("_matrix_") {
+ } else if file_name.contains("_matrix_") {
"matrix"
- }
- else if file_name.contains("_FP_ARITH_INST_") {
+ } else if file_name.contains("_FP_ARITH_INST_") {
"fparith"
- }
- else {
+ } else {
panic!("Unknown suffix {}", file_name);
}
}
@@ -365,12 +358,14 @@ mod performance_counter {
// Parse CSV
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.
if !data_files.contains_key(&file_name) {
let suffix = get_file_suffix(file_name.clone());
if suffix == "core" || suffix == "uncore" {
- data_files.insert(file_name.clone(), (family_model + "-" + suffix, version, event_type));
+ data_files.insert(file_name.clone(),
+ (family_model + "-" + suffix, version, event_type));
}
}
}
@@ -384,10 +379,15 @@ mod performance_counter {
let (ref family_model, _, _): (String, String, String) = *data;
let path = Path::new(file.as_str());
let (_, ref variable_upper) = make_file_name(&path);
- builder.entry(family_model.as_str(), format!("{}", variable_upper.as_str()).as_str());
+ builder.entry(family_model.as_str(),
+ format!("{}", variable_upper.as_str()).as_str());
}
- write!(&mut filewriter, "pub static {}: phf::Map<&'static str, phf::Map<&'static str, EventDescription>> = ", "COUNTER_MAP").unwrap();
+ write!(&mut filewriter,
+ "pub static {}: phf::Map<&'static str, phf::Map<&'static str, \
+ EventDescription<'static>>> = ",
+ "COUNTER_MAP")
+ .unwrap();
builder.build(&mut filewriter).unwrap();
write!(&mut filewriter, ";\n").unwrap();
@@ -395,13 +395,19 @@ mod performance_counter {
for (file, data) in &data_files {
let suffix = get_file_suffix(file.clone());
if suffix == "core" || suffix == "uncore" {
- let (ref family_model, ref version, ref event_type): (String, String, String) = *data;
- println!("Processing {:?} {} {} {}", file, family_model, version, event_type);
+ let (ref family_model, ref version, ref event_type): (String, String, String) =
+ *data;
+ println!("Processing {:?} {} {} {}",
+ file,
+ family_model,
+ version,
+ event_type);
let path = Path::new(file.as_str());
let (_, ref variable_upper) = make_file_name(&path);
parse_performance_counters(format!("x86data/perfmon_data{}", file).as_str(),
- variable_upper, &mut filewriter);
+ variable_upper,
+ &mut filewriter);
}
}
}
diff --git a/src/shared/perfcnt/intel/description.rs b/src/shared/perfcnt/intel/description.rs
index b316f88..5e1b66f 100644
--- a/src/shared/perfcnt/intel/description.rs
+++ b/src/shared/perfcnt/intel/description.rs
@@ -71,7 +71,7 @@ impl fmt::Debug for Counter {
}
#[derive(Debug)]
-pub struct EventDescription {
+pub struct EventDescription<'a> {
/// This field maps to the Event Select field in the IA32_PERFEVTSELx[7:0]MSRs.
///
/// The set of values for this field is defined architecturally.
@@ -86,13 +86,13 @@ pub struct EventDescription {
pub umask: Tuple,
/// It is a string of characters to identify the programming of an event.
- pub event_name: &'static str,
+ pub event_name: &'a str,
/// This field contains a description of what is being counted by a particular event.
- pub brief_description: &'static str,
+ pub brief_description: &'a str,
/// In some cases, this field will contain a more detailed description of what is counted by an event.
- pub public_description: Option<&'static str>,
+ pub public_description: Option<&'a str>,
/// This field lists the fixed (PERF_FIXED_CTRX) or programmable (IA32_PMCX)
/// counters that can be used to count the event.
@@ -204,48 +204,47 @@ pub struct EventDescription {
///
/// * SandyBridge:
/// https://www-ssl.intel.com/content/dam/www/public/us/en/documents/specification-updates/2nd-gen-core-family-mobile-specification-update.pdf
- pub errata: Option<&'static str>,
+ pub errata: Option<&'a str>,
/// There is only 1 file for core and offcore events in this format.
/// This field is set to 1 for offcore events and 0 for core events.
pub offcore: bool,
- pub unit: Option<&'static str>,
+ pub unit: Option<&'a str>,
- pub filter: Option<&'static str>,
+ pub filter: Option<&'a str>,
pub extsel: bool,
}
-impl EventDescription {
- #[allow(dead_code)]
- fn new(event_code: Tuple,
- umask: Tuple,
- event_name: &'static str,
- brief_description: &'static str,
- public_description: Option<&'static str>,
- counter: Counter,
- counter_ht_off: Option<Counter>,
- pebs_counters: Option<Counter>,
- sample_after_value: u64,
- msr_index: MSRIndex,
- msr_value: u64,
- taken_alone: bool,
- counter_mask: u8,
- invert: bool,
- any_thread: bool,
- edge_detect: bool,
- pebs: PebsType,
- precise_store: bool,
- collect_pebs_record: Option<u64>,
- data_la: bool,
- l1_hit_indication: bool,
- errata: Option<&'static str>,
- offcore: bool,
- unit: Option<&'static str>,
- filter: Option<&'static str>,
- extsel: bool)
- -> EventDescription {
+impl<'a> EventDescription<'a> {
+ pub fn new(event_code: Tuple,
+ umask: Tuple,
+ event_name: &'a str,
+ brief_description: &'a str,
+ public_description: Option<&'a str>,
+ counter: Counter,
+ counter_ht_off: Option<Counter>,
+ pebs_counters: Option<Counter>,
+ sample_after_value: u64,
+ msr_index: MSRIndex,
+ msr_value: u64,
+ taken_alone: bool,
+ counter_mask: u8,
+ invert: bool,
+ any_thread: bool,
+ edge_detect: bool,
+ pebs: PebsType,
+ precise_store: bool,
+ collect_pebs_record: Option<u64>,
+ data_la: bool,
+ l1_hit_indication: bool,
+ errata: Option<&'a str>,
+ offcore: bool,
+ unit: Option<&'a str>,
+ filter: Option<&'a str>,
+ extsel: bool)
+ -> EventDescription<'a> {
EventDescription {
event_code: event_code,
@@ -278,7 +277,7 @@ impl EventDescription {
}
}
-impl fmt::Display for EventDescription {
+impl<'a> fmt::Display for EventDescription<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.event_name)
}
diff --git a/src/shared/perfcnt/intel/mod.rs b/src/shared/perfcnt/intel/mod.rs
index 13602f7..f038055 100644
--- a/src/shared/perfcnt/intel/mod.rs
+++ b/src/shared/perfcnt/intel/mod.rs
@@ -60,12 +60,12 @@ macro_rules! get_counters {
}
/// Return all core performance counters for the running micro-architecture.
-pub fn core_counters() -> Option<&'static phf::Map<&'static str, EventDescription>> {
+pub fn core_counters() -> Option<&'static phf::Map<&'static str, EventDescription<'static>>> {
get_counters!("{}-{}-{:X}{:X}-core")
}
/// Return all uncore performance counters for the running micro-architecture.
-pub fn uncore_counters() -> Option<&'static phf::Map<&'static str, EventDescription>> {
+pub fn uncore_counters() -> Option<&'static phf::Map<&'static str, EventDescription<'static>>> {
get_counters!("{}-{}-{:X}{:X}-uncore")
}