KVM: hyperv: support HV_X64_MSR_TSC_FREQUENCY and HV_X64_MSR_APIC_FREQUENCY
Subsystems (4)
PATCH v2 1/1 KVM: hyperv: support HV_X64_MSR_TSC_FREQUENCY and HV_X64_MSR_APIC_FREQUENCY
It has been experimentally confirmed that supporting these two MSRs is one of the necessary conditions for nested Hyper-V to use the TSC page. Modern Windows guests are noticeably slower when they fall back to reading timestamps from the HV_X64_MSR_TIME_REF_COUNT MSR instead of using the TSC page.
The newly supported MSRs are advertised with the AccessFrequencyRegs partition privilege flag and CPUID.40000003H:EDX[8] "Support for determining timer frequencies is available" (both outside of the scope of this KVM patch).
---
v1->v2:
* HV_X64_MSR_TSC_FREQUENCY now based on vcpu->arch.virtual_tsc_khz (Radim)
* Removed both MSRs from the partition-wide list as the implementation is no longer vcpu agnostic
arch/x86/kvm/hyperv.c | 6 ++++++ arch/x86/kvm/lapic.c | 2 -- arch/x86/kvm/lapic.h | 3 +++ arch/x86/kvm/x86.c | 1 + 4 files changed, 10 insertions(+), 2 deletions(-)
arch/x86/kvm/hyperv.c +6 -0
@@ -1135,6 +1135,12 @@ static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)return stimer_get_count (vcpu_to_stimer (vcpu, timer_index), pdata); } +case HV_X64_MSR_TSC_FREQUENCY : + data = (u64 )vcpu->arch.virtual_tsc_khz *1000 ; +break ; +case HV_X64_MSR_APIC_FREQUENCY : + data =APIC_BUS_FREQUENCY ; +break ;default :vcpu_unimpl (vcpu,"Hyper-V unhandled rdmsr: 0x%x\n" , msr);return 1 ;
arch/x86/kvm/lapic.c +0 -2
@@ -54,8 +54,6 @@#define PRIu64 "u"#define PRIo64 "o" -#define APIC_BUS_CYCLE_NS 1 -/* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */ #define apic_debug(fmt, arg...)
arch/x86/kvm/lapic.h +3 -0
@@ -12,6 +12,9 @@#define KVM_APIC_SHORT_MASK 0xc0000#define KVM_APIC_DEST_MASK 0x800 +#define APIC_BUS_CYCLE_NS 1 +#define APIC_BUS_FREQUENCY (1000000000ULL / APIC_BUS_CYCLE_NS) +struct kvm_timer {struct hrtimer timer;s64 period;/* unit: ns */
arch/x86/kvm/x86.c +1 -0
@@ -986,6 +986,7 @@ static u32 emulated_msrs[] = {MSR_KVM_SYSTEM_TIME_NEW ,MSR_KVM_WALL_CLOCK_NEW ,HV_X64_MSR_GUEST_OS_ID ,HV_X64_MSR_HYPERCALL ,HV_X64_MSR_TIME_REF_COUNT ,HV_X64_MSR_REFERENCE_TSC , +HV_X64_MSR_TSC_FREQUENCY ,HV_X64_MSR_APIC_FREQUENCY ,HV_X64_MSR_CRASH_P0 ,HV_X64_MSR_CRASH_P1 ,HV_X64_MSR_CRASH_P2 ,HV_X64_MSR_CRASH_P3 ,HV_X64_MSR_CRASH_P4 ,HV_X64_MSR_CRASH_CTL , HV_X64_MSR_RESET,
Signature · 1 line
2.9.3
2017-07-26 13:32+0200, Ladi Prosek:
Quoted 11 lines
It has been experimentally confirmed that supporting these two MSRs is one of the necessary conditions for nested Hyper-V to use the TSC page. Modern Windows guests are noticeably slower when they fall back to reading timestamps from the
HV_X64_MSR_TIME_REF_COUNTMSR instead of using the TSC page.The newly supported MSRs are advertised with the AccessFrequencyRegs partition privilege flag and CPUID.40000003H:EDX[8] "Support for determining timer frequencies is available" (both outside of the scope of this KVM patch).
Quoted 7 lines
Signed-off-by Ladi Prosek <[email protected]>---
v1->v2:
*HV_X64_MSR_TSC_FREQUENCYnow based onvcpu->arch.virtual_tsc_khz(Radim)
* Removed both MSRs from the partition-wide list as the implementation is no longer vcpu agnostic
I like that we don't have to add a capability to expose this feature to the userspace,
Quoted 76 lines · Ladi Prosek
It has been experimentally confirmed that supporting these two MSRs is one of the necessary conditions for nested Hyper-V to use the TSC page. Modern Windows guests are noticeably slower when they fall back to reading timestamps from the
HV_X64_MSR_TIME_REF_COUNTMSR instead of using the TSC page.The newly supported MSRs are advertised with the AccessFrequencyRegs partition privilege flag and CPUID.40000003H:EDX[8] "Support for determining timer frequencies is available" (both outside of the scope of this KVM patch).
Signed-off-by Ladi Prosek <[email protected]>---
v1->v2:
*HV_X64_MSR_TSC_FREQUENCYnow based onvcpu->arch.virtual_tsc_khz(Radim)
* Removed both MSRs from the partition-wide list as the implementation is no longer vcpu agnosticarch/x86/kvm/hyperv.c | 6 ++++++ arch/x86/kvm/lapic.c | 2 -- arch/x86/kvm/lapic.h | 3 +++ arch/x86/kvm/x86.c | 1 + 4 files changed, 10 insertions(+), 2 deletions(-)arch/x86/kvm/hyperv.c +6
-0@@ -1135,6 +1135,12 @@ static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)return stimer_get_count (vcpu_to_stimer (vcpu, timer_index), pdata); } +case HV_X64_MSR_TSC_FREQUENCY : + data = (u64 )vcpu->arch.virtual_tsc_khz *1000 ; +break ; +case HV_X64_MSR_APIC_FREQUENCY : + data =APIC_BUS_FREQUENCY ; +break ;default :vcpu_unimpl (vcpu,"Hyper-V unhandled rdmsr: 0x%x\n" , msr);return 1 ;arch/x86/kvm/lapic.c +0
-2@@ -54,8 +54,6 @@#define PRIu64 "u"#define PRIo64 "o" -#define APIC_BUS_CYCLE_NS 1 -/* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */ #define apic_debug(fmt, arg...)arch/x86/kvm/lapic.h +3
-0@@ -12,6 +12,9 @@#define KVM_APIC_SHORT_MASK 0xc0000#define KVM_APIC_DEST_MASK 0x800 +#define APIC_BUS_CYCLE_NS 1 +#define APIC_BUS_FREQUENCY (1000000000ULL / APIC_BUS_CYCLE_NS) +struct kvm_timer {struct hrtimer timer;s64 period;/* unit: ns */ arch/x86/kvm/x86.c +0
-0
arch/x86/kvm/x86.c static u32 emulated_msrs[] = { · line 992
Quoted 7 lines
arch/x86/kvm/x86.c +1
-0@@ -986,6 +986,7 @@ static u32 emulated_msrs[] = {MSR_KVM_SYSTEM_TIME_NEW ,MSR_KVM_WALL_CLOCK_NEW ,HV_X64_MSR_GUEST_OS_ID ,HV_X64_MSR_HYPERCALL ,HV_X64_MSR_TIME_REF_COUNT ,HV_X64_MSR_REFERENCE_TSC , +HV_X64_MSR_TSC_FREQUENCY ,HV_X64_MSR_APIC_FREQUENCY ,HV_X64_MSR_CRASH_P0 ,HV_X64_MSR_CRASH_P1 ,HV_X64_MSR_CRASH_P2 ,HV_X64_MSR_CRASH_P3 ,HV_X64_MSR_CRASH_P4 ,HV_X64_MSR_CRASH_CTL , HV_X64_MSR_RESET,
Applied to kvm/queue, thanks.
Paolo