]> www.infradead.org Git - users/dwmw2/linux.git/commit
x86/kvm: Obtain TSC frequency from CPUID if present cpuid
authorDavid Woodhouse <dwmw@amazon.co.uk>
Wed, 13 Aug 2025 09:16:59 +0000 (10:16 +0100)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Mon, 18 Aug 2025 09:49:03 +0000 (10:49 +0100)
commit75bb8c64b00b1258dc2cd3774044dfa157fb6f5a
tree496989fddeb763c596cd7cb331a05da5b3fb2703
parent6ed155f732242e74ba0a2701cd00fd5fe29ae810
x86/kvm: Obtain TSC frequency from CPUID if present

In https://lkml.org/lkml/2008/10/1/246 a proposal was made for generic
CPUID conventions across hypervisors. It was mostly shot down in flames,
but the leaf at 0x40000010 containing timing information didn't die.

It's used by XNU and FreeBSD guests under all hypervisors¹² to determine
the TSC frequency, and also exposed by the EC2 Nitro hypervisor (as
well as, presumably, VMware). FreeBSD's Bhyve is probably just about
to start exposing it too.

Use it under KVM to obtain the TSC frequency more accurately, instead
of reverse-calculating the frequency from the mul/shift values in the
KVM clock.

Before:
[    0.000020] tsc: Detected 2900.014 MHz processor

After:
[    0.000020] tsc: Detected 2900.015 MHz processor

$ cpuid -1 -l 0x40000010
CPU:
   hypervisor generic timing information (0x40000010):
      TSC frequency (Hz) = 2900015
      bus frequency (Hz) = 1000000

¹ https://github.com/apple/darwin-xnu/blob/main/osfmk/i386/cpuid.c
² https://github.com/freebsd/freebsd-src/commit/4a432614f68

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
arch/x86/include/asm/kvm_para.h
arch/x86/kernel/kvm.c
arch/x86/kernel/kvmclock.c