Skip to content

Commit

Permalink
fix(hal-x86_64): fix wrong LAPIC frequency calc (#499)
Browse files Browse the repository at this point in the history
1 Hz = 1 second. 1 ms = 1/1000 second. So we should multiply here
instead of dividing, lol.

The divide accidentally makes us consider the LAPIC frequency to be 0,
and then we just "don't ever have a timer". Whoopsie.
  • Loading branch information
hawkw committed Dec 31, 2024
1 parent 4909f6f commit 0363e82
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions hal-x86_64/src/interrupt/apic/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,24 @@ impl LocalApic {

let cpuid = CpuId::new();

if let Some(undivided_freq_khz) = cpuid.get_hypervisor_info().and_then(|hypervisor| {
if let Some(freq_khz) = cpuid.get_hypervisor_info().and_then(|hypervisor| {
tracing::trace!("CPUID contains hypervisor info");
let freq = hypervisor.apic_frequency();
tracing::trace!(hypervisor.apic_frequency = ?freq);
tracing::trace!(hypervisor.apic_frequency_khz = ?freq);
NonZeroU32::new(freq?)
}) {
// the hypervisor info CPUID leaf expresses the frequency in kHz,
// and the frequency is not divided by the target timer divisor.
let frequency_hz = undivided_freq_khz.get() / 1000 / Self::TIMER_DIVISOR;
let frequency_hz = (freq_khz.get() * 1000) / Self::TIMER_DIVISOR;
tracing::debug!(
frequency_hz,
"determined APIC frequency from CPUID hypervisor info"
);
return frequency_hz;
}

// XXX ELIZA THIS IS TSC FREQUENCY, SO IDK IF THAT'S RIGHT?
/*
if let Some(undivided_freq_hz) = cpuid.get_tsc_info().and_then(|tsc| {
tracing::trace!("CPUID contains TSC info");
let freq = tsc.nominal_frequency();
Expand All @@ -161,6 +163,7 @@ impl LocalApic {
);
return frequency_hz;
}
*/

// CPUID didn't help, so fall back to calibrating the APIC frequency
// using the PIT.
Expand Down

0 comments on commit 0363e82

Please sign in to comment.