Adjust tsc calculation

Since we only want to record the time when benchmarking
This commit is contained in:
David Venhoff 2025-09-12 11:04:02 +02:00
parent 9ba2bbe8cd
commit 2732383465

View File

@ -49,8 +49,10 @@ pub fn analyze_dump(
let f_bus = cpuid!(0x16).ecx as f64 * 1_000_000.0; let f_bus = cpuid!(0x16).ecx as f64 * 1_000_000.0;
let mut current_cbr = 0u8; let mut current_cbr = 0u8;
let mut first_tsc = None::<u64>; // Records the first tsc after the ptwrite (42) message
let mut last_tsc = 0; let mut first_tsc_main = None::<u64>;
// Records the first tsc after the ptwrite (43) message
let mut first_tsc_post_run = None::<u64>;
let mut seen_cbrs = HashMap::<u8, u64>::new(); let mut seen_cbrs = HashMap::<u8, u64>::new();
@ -68,10 +70,15 @@ pub fn analyze_dump(
segments.last_mut().unwrap().1 += duration; segments.last_mut().unwrap().1 += duration;
} }
Ok(Packet::Tsc(tsc)) => { Ok(Packet::Tsc(tsc)) => {
if first_tsc.is_none() { if let [.., (Scope::Main, _)] = segments.as_slice()
first_tsc = Some(tsc.tsc()); && first_tsc_main.is_none()
{
first_tsc_main = Some(tsc.tsc());
} else if let [.., (Scope::PostRun, _)] = segments.as_slice()
&& first_tsc_post_run.is_none()
{
first_tsc_post_run = Some(tsc.tsc());
} }
last_tsc = tsc.tsc();
} }
Ok(Packet::Cbr(cbr)) => { Ok(Packet::Cbr(cbr)) => {
current_cbr = cbr.ratio(); current_cbr = cbr.ratio();
@ -104,7 +111,7 @@ pub fn analyze_dump(
.unwrap() .unwrap()
.tsc_frequency() .tsc_frequency()
.unwrap(); .unwrap();
let total_seconds_tsc = (last_tsc - first_tsc.unwrap()) as f64 / f_tsc as f64; let total_seconds_tsc = (first_tsc_post_run.unwrap() - first_tsc_main.unwrap()) as f64 / f_tsc as f64;
Ok(AnalyzeData { Ok(AnalyzeData {
packets: total, packets: total,