From ca1ac8aec85e356377e554e6ad28142ff2e65c6e Mon Sep 17 00:00:00 2001 From: iximeow Date: Tue, 4 Jul 2023 14:51:07 -0700 Subject: try reporting max cpu freq, but this is going to be messy --- src/ci_runner.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/ci_runner.rs') diff --git a/src/ci_runner.rs b/src/ci_runner.rs index 3e7dd42..63dc74e 100644 --- a/src/ci_runner.rs +++ b/src/ci_runner.rs @@ -545,6 +545,27 @@ mod host_info { .to_string() } + /// try finding core `cpu`'s max frequency in khz. we'll assume this is the actual speed a + /// build would run at.. fingers crossed. + fn try_finding_cpu_freq(cpu: u32) -> Result { + if let Ok(freq_str) = std::fs::read_to_string("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq") { + Ok(freq_str.trim().parse().unwrap()) + } else { + // so cpufreq probably isn't around, maybe /proc/cpuinfo's mhz figure is present? + let cpu_lines: Vec = std::fs::read_to_string("/proc/cpuinfo").unwrap().split("\n").map(|line| line.to_string()).collect(); + let cpu_mhzes: Vec<&String> = cpu_lines.iter().filter(|line| line.starts_with("cpu MHz")).collect(); + match cpu_mhzes.get(cpu as usize) { + Some(mhz) => { + let mhz: f64 = cpu_mhzes[cpu as usize].trim().parse().unwrap(); + Ok((mhz * 1000.0) as u64) + }, + None => { + panic!("could not get cpu freq either from cpufreq or /proc/cpuinfo?"); + } + } + } + } + // we'll have to deploy one of a few techniques, because x86/x86_64 is internally // consistent, but aarch64 is different. who knows what other CPUs think. match std::env::consts::ARCH { @@ -557,8 +578,9 @@ mod host_info { let family = find_line(&cpu_lines, "cpu family"); let model = find_line(&cpu_lines, "model\t"); let microcode = find_line(&cpu_lines, "microcode"); + let max_freq = try_finding_cpu_freq(0).unwrap(); - CpuInfo { model_name, microcode, cores, vendor_id, family, model } + CpuInfo { model_name, microcode, cores, vendor_id, family, model, max_freq } } "aarch64" => { let cpu_lines: Vec = std::fs::read_to_string("/proc/cpuinfo").unwrap().split("\n").map(|line| line.to_string()).collect(); @@ -588,8 +610,9 @@ mod host_info { let family = find_line(&cpu_lines, "CPU architecture"); let model = find_line(&cpu_lines, "CPU part"); let microcode = String::new(); + let max_freq = std::fs::read_to_string("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq").unwrap().trim().parse().unwrap(); - CpuInfo { model_name, microcode, cores, vendor_id: vendor_name, family, model } + CpuInfo { model_name, microcode, cores, vendor_id: vendor_name, family, model, max_freq } } other => { panic!("dunno how to find cpu info for {}, panik", other); -- cgit v1.1