From 2f2f65ade84433e8fc7c77c4716a73144f83421c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 2 Aug 2026 18:29:10 +0200 Subject: [PATCH 1/2] fix(x86_64/processor): read TSC frequency from FDT only on Uhyve --- src/arch/x86_64/kernel/processor.rs | 33 +++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/arch/x86_64/kernel/processor.rs b/src/arch/x86_64/kernel/processor.rs index 460c6713d8..ac0776aeb4 100644 --- a/src/arch/x86_64/kernel/processor.rs +++ b/src/arch/x86_64/kernel/processor.rs @@ -8,7 +8,6 @@ use core::arch::x86_64::{ }; use core::fmt; use core::hint::spin_loop; -use core::num::NonZero; use core::sync::atomic::{AtomicU64, Ordering}; use hermit_sync::Lazy; @@ -351,20 +350,28 @@ impl CpuFrequency { } fn detect_from_fdt(&mut self) -> Result<(), ()> { - fn mhz_from_fdt() -> Option> { - let khz = env::fdt()? - .find_node("/hermit,tsc")? - .property("khz")? - .as_usize()?; - let khz = u32::try_from(khz).ok()?; - let mhz = u16::try_from(khz / 1000).ok()?; - NonZero::new(mhz) - } + #[cfg(feature = "uhyve")] + { + use core::num::NonZero; + + fn mhz_from_fdt() -> Option> { + let khz = env::fdt()? + .find_node("/hermit,tsc")? + .property("khz")? + .as_usize()?; + let khz = u32::try_from(khz).ok()?; + let mhz = u16::try_from(khz / 1000).ok()?; + NonZero::new(mhz) + } - let mhz = mhz_from_fdt().ok_or(())?; - self.set_detected_cpu_frequency(mhz.get(), CpuFrequencySources::Fdt)?; + let mhz = mhz_from_fdt().ok_or(())?; + self.set_detected_cpu_frequency(mhz.get(), CpuFrequencySources::Fdt)?; - Ok(()) + Ok(()) + } + + #[cfg(not(feature = "uhyve"))] + Err(()) } fn detect_from_hypervisor(&mut self) -> Result<(), ()> { From dee78ed85834759278186810d78ef2aaacbc0e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 2 Aug 2026 18:53:54 +0200 Subject: [PATCH 2/2] feat(x86_64/uhyve): drop support for non-FDT TSC frequencies --- src/arch/x86_64/kernel/processor.rs | 17 ----------------- src/env.rs | 11 ----------- 2 files changed, 28 deletions(-) diff --git a/src/arch/x86_64/kernel/processor.rs b/src/arch/x86_64/kernel/processor.rs index ac0776aeb4..ae0656f35f 100644 --- a/src/arch/x86_64/kernel/processor.rs +++ b/src/arch/x86_64/kernel/processor.rs @@ -374,22 +374,6 @@ impl CpuFrequency { Err(()) } - fn detect_from_hypervisor(&mut self) -> Result<(), ()> { - #[cfg(feature = "uhyve")] - { - let cpu_freq = env::uhyve_cpu_freq().ok_or(())?.get(); - let mhz = cpu_freq / 1000; - - self.set_detected_cpu_frequency( - mhz.try_into().unwrap(), - CpuFrequencySources::Hypervisor, - ) - } - - #[cfg(not(feature = "uhyve"))] - Err(()) - } - extern "x86-interrupt" fn measure_frequency_timer_handler( _stack_frame: interrupts::ExceptionStackFrame, ) { @@ -484,7 +468,6 @@ impl CpuFrequency { .or_else(|_e| self.detect_from_cpuid(&cpuid)) .or_else(|_e| self.detect_from_cpuid_tsc_info(&cpuid)) .or_else(|_e| self.detect_from_cpuid_hypervisor_info(&cpuid)) - .or_else(|_e| self.detect_from_hypervisor()) .or_else(|_e| self.detect_from_cmdline()) .or_else(|_e| self.detect_from_cpuid_brand_string(&cpuid)) .or_else(|_e| self.measure_frequency()) diff --git a/src/env.rs b/src/env.rs index 963cd5f592..835baed36b 100644 --- a/src/env.rs +++ b/src/env.rs @@ -79,17 +79,6 @@ pub fn uhyve_num_cpus() -> Option> { } } -#[cfg_attr(not(target_arch = "x86_64"), expect(dead_code))] -#[cfg(feature = "uhyve")] -pub fn uhyve_cpu_freq() -> Option> { - use hermit_entry::boot_info::PlatformInfo; - - match boot_info().platform_info { - PlatformInfo::Uhyve { cpu_freq, .. } => Some(NonZero::new(cpu_freq?.get()).unwrap()), - _ => None, - } -} - pub fn is_uefi() -> bool { fdt().is_some_and(|fdt| fdt.root().compatible().first() == "hermit,uefi") }