Calculate the bus frequency at runtime

The 100mHz value was guaranteed by intel for this CPU,
but this approach is more reliable
This commit is contained in:
David Venhoff 2025-09-04 18:32:58 +02:00
parent f072c0ce53
commit d14e0fe3a0

View File

@ -6,7 +6,7 @@ use std::error::Error;
use std::fs::File;
use std::path::Path;
use std::time::Duration;
use raw_cpuid::CpuId;
use raw_cpuid::{cpuid, CpuId};
#[derive(Debug)]
pub struct AnalyzeData {
@ -38,8 +38,9 @@ pub fn analyze_dump(path: impl AsRef<Path>) -> Result<AnalyzeData, Box<dyn Error
let mut segments = vec![(Scope::PreRun, Duration::ZERO)];
let mut total = 0u64;
// Lets assume 100Mhz bus frequency (TODO compute that automatically)
let f_bus = 100_000_000.0;
// cpuid(0x16):ecx returns the bus frequency in mHz (See volume 2, chapter 1.3 CPUID in the intel manual)
// Combined with the core to bus ration we can calculate the core frequency
let f_bus = cpuid!(0x16).ecx as f64 * 1_000_000.0;
let mut current_cbr = 0u8;
let mut first_tsc = None::<u64>;