@@ -102,6 +102,16 @@ static inline void kvm_sched_clock_init(bool stable)
sizeof(((struct pvclock_vcpu_time_info *)NULL)->system_time));
}
+static unsigned long kvm_get_tsc_khz(void)
+{
+ unsigned int __tsc_khz, crystal_khz;
+
+ if (!cpuid_get_tsc_freq(&__tsc_khz, &crystal_khz))
+ return __tsc_khz;
+
+ return pvclock_tsc_khz(this_cpu_pvti());
+}
+
static unsigned long kvm_get_cpu_khz(void)
{
unsigned int cpu_khz;
@@ -125,11 +135,6 @@ static unsigned long kvm_get_cpu_khz(void)
* poll of guests can be running and trouble each other. So we preset
* lpj here
*/
-static unsigned long kvm_get_tsc_khz(void)
-{
- return pvclock_tsc_khz(this_cpu_pvti());
-}
-
static void __init kvm_get_preset_lpj(void)
{
unsigned long khz;
When kvmclock and CPUID.0x15 are both present, use the TSC frequency from CPUID.0x15 instead of kvmclock's frequency. Barring a misconfigured setup, both sources should provide the same frequency, CPUID.0x15 is arguably a better source when using the TSC over kvmclock, and most importantly, using CPUID.0x15 will allow stuffing the local APIC timer frequency based on the core crystal frequency, i.e. will allow skipping APIC timer calibration. Signed-off-by: Sean Christopherson <seanjc@google.com> --- arch/x86/kernel/kvmclock.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)