Unverified Commit 56b7ca42 authored by Stefan Lankes's avatar Stefan Lankes Committed by GitHub
Browse files

fix interpretation of hypervisor_info (#73)

- frequency is delivered in KHz (and not Hz)
- fix conversion to MhZ
parent b9a09ede
......@@ -17,6 +17,7 @@ use crate::x86::cpuid::*;
use crate::x86::msr::*;
use core::arch::x86_64::__rdtscp as rdtscp;
use core::arch::x86_64::_rdtsc as rdtsc;
use core::convert::TryInto;
use core::sync::atomic::spin_loop_hint;
use core::{fmt, u32};
......@@ -279,9 +280,11 @@ impl CpuFrequency {
}
unsafe fn detect_from_cpuid_hypervisor_info(&mut self, cpuid: &CpuId) -> Result<(), ()> {
const KHZ_TO_HZ: u64 = 1000;
const MHZ_TO_HZ: u64 = 1000000;
let hypervisor_info = cpuid.get_hypervisor_info().ok_or(())?;
let freq = hypervisor_info.tsc_frequency().ok_or(())?;
let mhz = (freq / 1000000u32) as u16;
let freq = hypervisor_info.tsc_frequency().ok_or(())? as u64 * KHZ_TO_HZ;
let mhz: u16 = (freq / MHZ_TO_HZ).try_into().unwrap();
self.set_detected_cpu_frequency(mhz, CpuFrequencySources::HypervisorTscInfo)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment