Hyper-V timers
v2 cover Hyper-V timers
This RFC series adds support for two Hyper-V timer services - a per-partition reference time counter, and a partition reference time enlightenment.
Vadim Rozenfeld (2):
add support for Hyper-V reference time counter
add support for Hyper-V invariant TSC
arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/include/uapi/asm/hyperv.h | 14 +++++++++++++ arch/x86/kvm/x86.c | 43 +++++++++++++++++++++++++++++++++++++- include/uapi/linux/kvm.h | 1 + 4 files changed, 59 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.1.2
RFC PATCH v2 1/2 add support for Hyper-V reference time counter
Signed-off: Peter Lieven <[email protected]>
Signed-off: Gleb Natapov <[email protected]>
Signed-off: Vadim Rozenfeld <[email protected]>
v1 -> v2
1. mark TSC page dirty as suggested by
Eric Northup <[email protected]> and Gleb
2. disable local irq when calling get_kernel_ns, as it was done by Peter Lieven <[email protected]>
3. move check for TSC page enable from second patch to this one.
--- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/include/uapi/asm/hyperv.h | 14 ++++++++++++++ arch/x86/kvm/x86.c | 39 +++++++++++++++++++++++++++++++++++++- include/uapi/linux/kvm.h | 1 + 4 files changed, 55 insertions(+), 1 deletion(-)
arch/x86/include/asm/kvm_host.h +2 -0
@@ -575,6 +575,8 @@ struct kvm_arch {/* fields used by HYPER-V emulation */ u64 hv_guest_os_id;u64 hv_hypercall; +u64 hv_ref_count; +u64 hv_tsc_page;#ifdef CONFIG_KVM_MMU_AUDIT int audit_point;
arch/x86/include/uapi/asm/hyperv.h +14 -0
@@ -136,6 +136,9 @@/* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT 0x40000020 +/* A partition's reference time stamp counter (TSC) page */ +#define HV_X64_MSR_REFERENCE_TSC 0x40000021 +/* Define the virtual APIC registers */ #define HV_X64_MSR_EOI 0x40000070#define HV_X64_MSR_ICR 0x40000071
@@ -179,6 +182,9 @@#define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_MASK \ (~((1ull << HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT) - 1)) +#define HV_X64_MSR_TSC_REFERENCE_ENABLE 0x00000001 +#define HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT 12 +#define HV_PROCESSOR_POWER_STATE_C0 0#define HV_PROCESSOR_POWER_STATE_C1 1#define HV_PROCESSOR_POWER_STATE_C2 2
@@ -191,4 +197,12 @@#define HV_STATUS_INVALID_ALIGNMENT 4#define HV_STATUS_INSUFFICIENT_BUFFERS 19 +typedef struct _HV_REFERENCE_TSC_PAGE { +__u32 TscSequence; +__u32 Rserved1; +__u64 TscScale; +__s64 TscOffset; +}HV_REFERENCE_TSC_PAGE , *PHV_REFERENCE_TSC_PAGE ; + +#endif
arch/x86/kvm/x86.c +38 -1
@@ -843,7 +843,7 @@ EXPORT_SYMBOL_GPL(kvm_rdpmc);static u32 msrs_to_save[] = {MSR_KVM_SYSTEM_TIME ,MSR_KVM_WALL_CLOCK ,MSR_KVM_SYSTEM_TIME_NEW ,MSR_KVM_WALL_CLOCK_NEW , -HV_X64_MSR_GUEST_OS_ID ,HV_X64_MSR_HYPERCALL , +HV_X64_MSR_GUEST_OS_ID ,HV_X64_MSR_HYPERCALL ,HV_X64_MSR_TIME_REF_COUNT ,HV_X64_MSR_APIC_ASSIST_PAGE ,MSR_KVM_ASYNC_PF_EN ,MSR_KVM_STEAL_TIME ,MSR_KVM_PV_EOI_EN ,MSR_IA32_SYSENTER_CS ,MSR_IA32_SYSENTER_ESP ,MSR_IA32_SYSENTER_EIP ,
@@ -1788,6 +1788,8 @@ static bool kvm_hv_msr_partition_wide(u32 msr)switch (msr) {case HV_X64_MSR_GUEST_OS_ID :case HV_X64_MSR_HYPERCALL : +case HV_X64_MSR_REFERENCE_TSC : +case HV_X64_MSR_TIME_REF_COUNT : r = true;break ; }
@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ; + } +case HV_X64_MSR_REFERENCE_TSC : { +u64 gfn; +unsigned long addr; +HV_REFERENCE_TSC_PAGE tsc_ref; + tsc_ref.TscSequence =0 ; +if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { + kvm->arch.hv_tsc_page = data; +break ; + } + gfn = data >>HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT ; + addr =gfn_to_hva (kvm, data >> +HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT ); +if (kvm_is_error_hva (addr)) +return 1 ; +if (__copy_to_user ((void __user *)addr, &tsc_ref,sizeof (tsc_ref))) +return 1 ; +mark_page_dirty (kvm, gfn); + kvm->arch.hv_tsc_page = data;break ; }default :
@@ -2253,6 +2278,17 @@ static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)case HV_X64_MSR_HYPERCALL : data = kvm->arch.hv_hypercall;break ; +case HV_X64_MSR_TIME_REF_COUNT : { +u64 now_ns; +local_irq_disable (); + now_ns =get_kernel_ns () + kvm->arch.kvmclock_offset; + data =div_u64 (now_ns - kvm->arch.hv_ref_count,100 ); +local_irq_enable (); +break ; + } +case HV_X64_MSR_REFERENCE_TSC : + data = kvm->arch.hv_tsc_page; +break ;default :vcpu_unimpl (vcpu,"Hyper-V unhandled rdmsr: 0x%x\n" , msr);return 1 ;
@@ -2566,6 +2602,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_ASSIGN_DEV_IRQ :case KVM_CAP_PCI_2_3 :#endif +case KVM_CAP_HYPERV_TIME : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :
include/uapi/linux/kvm.h +1 -0
@@ -666,6 +666,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_IRQ_MPIC 90#define KVM_CAP_PPC_RTAS 91#define KVM_CAP_IRQ_XICS 92 +#define KVM_CAP_HYPERV_TIME 93#ifdef KVM_CAP_IRQ_ROUTING
Signature · 1 line
1.8.1.2
Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Quoted 57 lines · Vadim Rozenfeld
Signed-off: Peter Lieven <[email protected]>
Signed-off: Gleb Natapov <[email protected]>
Signed-off: Vadim Rozenfeld <[email protected]>v1 -> v2
1. mark TSC page dirty as suggested by
Eric Northup <[email protected]> and Gleb
2. disable local irq when callingget_kernel_ns, as it was done by Peter Lieven <[email protected]>
3. move check for TSC page enable from second patch to this one.--- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/include/uapi/asm/hyperv.h | 14 ++++++++++++++ arch/x86/kvm/x86.c | 39 +++++++++++++++++++++++++++++++++++++- include/uapi/linux/kvm.h | 1 + 4 files changed, 55 insertions(+), 1 deletion(-)arch/x86/include/asm/kvm_host.h +2
-0@@ -575,6 +575,8 @@ struct kvm_arch {/* fields used by HYPER-V emulation */ u64 hv_guest_os_id;u64 hv_hypercall; +u64 hv_ref_count; +u64 hv_tsc_page;#ifdef CONFIG_KVM_MMU_AUDIT int audit_point;arch/x86/include/uapi/asm/hyperv.h +6
-0@@ -136,6 +136,9 @@/* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT 0x40000020 +/* A partition's reference time stamp counter (TSC) page */ +#define HV_X64_MSR_REFERENCE_TSC 0x40000021 +/* Define the virtual APIC registers */ #define HV_X64_MSR_EOI 0x40000070#define HV_X64_MSR_ICR 0x40000071@@ -179,6 +182,9 @@#define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_MASK \ (~((1ull << HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT) - 1)) +#define HV_X64_MSR_TSC_REFERENCE_ENABLE 0x00000001 +#define HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT 12 +#define HV_PROCESSOR_POWER_STATE_C0 0#define HV_PROCESSOR_POWER_STATE_C1 1#define HV_PROCESSOR_POWER_STATE_C2 2
arch/x86/include/uapi/asm/hyperv.h line 206
Quoted 10 lines
arch/x86/include/uapi/asm/hyperv.h +7
-0@@ -191,4 +197,12 @@#define HV_STATUS_INVALID_ALIGNMENT 4#define HV_STATUS_INSUFFICIENT_BUFFERS 19 +typedef struct _HV_REFERENCE_TSC_PAGE { +__u32 TscSequence; +__u32 Rserved1; +__u64 TscScale; +__s64 TscOffset; +}HV_REFERENCE_TSC_PAGE , *PHV_REFERENCE_TSC_PAGE ; +
I understand that you want to keep structure definition as close to MS docs as possible, but this breaks all the rules of Linux kernel code unfortunately. Lest define it like that:
struct hv_reference_tsc_page {
__u32 tsc_sequence;
__u32 reserved1;
__u64 tsc_scale;
__s64 tsc_offset;
};And drop typedef. If you'll look at include/linux/hyperv.h this is what Linux hyper-v guest support does.
Quoted 35 lines
arch/x86/include/uapi/asm/hyperv.h +1
-0+#endif arch/x86/kvm/x86.c +10
-1@@ -843,7 +843,7 @@ EXPORT_SYMBOL_GPL(kvm_rdpmc);static u32 msrs_to_save[] = {MSR_KVM_SYSTEM_TIME ,MSR_KVM_WALL_CLOCK ,MSR_KVM_SYSTEM_TIME_NEW ,MSR_KVM_WALL_CLOCK_NEW , -HV_X64_MSR_GUEST_OS_ID ,HV_X64_MSR_HYPERCALL , +HV_X64_MSR_GUEST_OS_ID ,HV_X64_MSR_HYPERCALL ,HV_X64_MSR_TIME_REF_COUNT ,HV_X64_MSR_APIC_ASSIST_PAGE ,MSR_KVM_ASYNC_PF_EN ,MSR_KVM_STEAL_TIME ,MSR_KVM_PV_EOI_EN ,MSR_IA32_SYSENTER_CS ,MSR_IA32_SYSENTER_ESP ,MSR_IA32_SYSENTER_EIP ,@@ -1788,6 +1788,8 @@ static bool kvm_hv_msr_partition_wide(u32 msr)switch (msr) {case HV_X64_MSR_GUEST_OS_ID :case HV_X64_MSR_HYPERCALL : +case HV_X64_MSR_REFERENCE_TSC : +case HV_X64_MSR_TIME_REF_COUNT : r = true;break ; }@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ; + } +case HV_X64_MSR_REFERENCE_TSC : { +u64 gfn;
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1848
Quoted 10 lines
arch/x86/kvm/x86.c +10
-0+unsigned long addr; +HV_REFERENCE_TSC_PAGE tsc_ref; + tsc_ref.TscSequence =0 ; +if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { + kvm->arch.hv_tsc_page = data; +break ; + } + gfn = data >>HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT ; + addr =gfn_to_hva (kvm, data >> +HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT );
addr = gfn_to_hva(kvm, gfn);
You already calculated gfn :)
Quoted 49 lines
arch/x86/kvm/x86.c +18
-0+if (kvm_is_error_hva (addr)) +return 1 ; +if (__copy_to_user ((void __user *)addr, &tsc_ref,sizeof (tsc_ref))) +return 1 ; +mark_page_dirty (kvm, gfn); + kvm->arch.hv_tsc_page = data;break ; }default :@@ -2253,6 +2278,17 @@ static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)case HV_X64_MSR_HYPERCALL : data = kvm->arch.hv_hypercall;break ; +case HV_X64_MSR_TIME_REF_COUNT : { +u64 now_ns; +local_irq_disable (); + now_ns =get_kernel_ns () + kvm->arch.kvmclock_offset; + data =div_u64 (now_ns - kvm->arch.hv_ref_count,100 ); +local_irq_enable (); +break ; + } +case HV_X64_MSR_REFERENCE_TSC : + data = kvm->arch.hv_tsc_page; +break ;default :vcpu_unimpl (vcpu,"Hyper-V unhandled rdmsr: 0x%x\n" , msr);return 1 ;@@ -2566,6 +2602,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_ASSIGN_DEV_IRQ :case KVM_CAP_PCI_2_3 :#endif +case KVM_CAP_HYPERV_TIME : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :include/uapi/linux/kvm.h +1
-0@@ -666,6 +666,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_IRQ_MPIC 90#define KVM_CAP_PPC_RTAS 91#define KVM_CAP_IRQ_XICS 92 +#define KVM_CAP_HYPERV_TIME 93#ifdef KVM_CAP_IRQ_ROUTING Signature · 1 line
1.8.1.2
--
Gleb.
Paolo Bonzini
maintainerRe: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
In reply to Vadim RozenfeldIl 19/05/2013 09:06, Vadim Rozenfeld ha scritto:
Quoted 95 lines
Signed-off: Peter Lieven <[email protected]>
Signed-off: Gleb Natapov <[email protected]>
Signed-off: Vadim Rozenfeld <[email protected]>v1 -> v2
1. mark TSC page dirty as suggested by
Eric Northup <[email protected]> and Gleb
2. disable local irq when callingget_kernel_ns, as it was done by Peter Lieven <[email protected]>
3. move check for TSC page enable from second patch to this one.--- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/include/uapi/asm/hyperv.h | 14 ++++++++++++++ arch/x86/kvm/x86.c | 39 +++++++++++++++++++++++++++++++++++++- include/uapi/linux/kvm.h | 1 + 4 files changed, 55 insertions(+), 1 deletion(-)arch/x86/include/asm/kvm_host.h +2
-0@@ -575,6 +575,8 @@ struct kvm_arch {/* fields used by HYPER-V emulation */ u64 hv_guest_os_id;u64 hv_hypercall; +u64 hv_ref_count; +u64 hv_tsc_page;#ifdef CONFIG_KVM_MMU_AUDIT int audit_point;arch/x86/include/uapi/asm/hyperv.h +14
-0@@ -136,6 +136,9 @@/* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT 0x40000020 +/* A partition's reference time stamp counter (TSC) page */ +#define HV_X64_MSR_REFERENCE_TSC 0x40000021 +/* Define the virtual APIC registers */ #define HV_X64_MSR_EOI 0x40000070#define HV_X64_MSR_ICR 0x40000071@@ -179,6 +182,9 @@#define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_MASK \ (~((1ull << HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT) - 1)) +#define HV_X64_MSR_TSC_REFERENCE_ENABLE 0x00000001 +#define HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT 12 +#define HV_PROCESSOR_POWER_STATE_C0 0#define HV_PROCESSOR_POWER_STATE_C1 1#define HV_PROCESSOR_POWER_STATE_C2 2@@ -191,4 +197,12 @@#define HV_STATUS_INVALID_ALIGNMENT 4#define HV_STATUS_INSUFFICIENT_BUFFERS 19 +typedef struct _HV_REFERENCE_TSC_PAGE { +__u32 TscSequence; +__u32 Rserved1; +__u64 TscScale; +__s64 TscOffset; +}HV_REFERENCE_TSC_PAGE , *PHV_REFERENCE_TSC_PAGE ; + +#endif arch/x86/kvm/x86.c +3
-1@@ -843,7 +843,7 @@ EXPORT_SYMBOL_GPL(kvm_rdpmc);static u32 msrs_to_save[] = {MSR_KVM_SYSTEM_TIME ,MSR_KVM_WALL_CLOCK ,MSR_KVM_SYSTEM_TIME_NEW ,MSR_KVM_WALL_CLOCK_NEW , -HV_X64_MSR_GUEST_OS_ID ,HV_X64_MSR_HYPERCALL , +HV_X64_MSR_GUEST_OS_ID ,HV_X64_MSR_HYPERCALL ,HV_X64_MSR_TIME_REF_COUNT ,HV_X64_MSR_APIC_ASSIST_PAGE ,MSR_KVM_ASYNC_PF_EN ,MSR_KVM_STEAL_TIME ,MSR_KVM_PV_EOI_EN ,MSR_IA32_SYSENTER_CS ,MSR_IA32_SYSENTER_ESP ,MSR_IA32_SYSENTER_EIP ,@@ -1788,6 +1788,8 @@ static bool kvm_hv_msr_partition_wide(u32 msr)switch (msr) {case HV_X64_MSR_GUEST_OS_ID :case HV_X64_MSR_HYPERCALL : +case HV_X64_MSR_REFERENCE_TSC : +case HV_X64_MSR_TIME_REF_COUNT : r = true;break ; }@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data;
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1841
Quoted 10 lines
arch/x86/kvm/x86.c +10
-0+local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ; + } +case HV_X64_MSR_REFERENCE_TSC : { +u64 gfn; +unsigned long addr; +HV_REFERENCE_TSC_PAGE tsc_ref; + tsc_ref.TscSequence =0 ;
Again, please explain why this is not 0xFFFFFFFF.
Paolo
Quoted 55 lines
arch/x86/kvm/x86.c +25
-0+if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { + kvm->arch.hv_tsc_page = data; +break ; + } + gfn = data >>HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT ; + addr =gfn_to_hva (kvm, data >> +HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT ); +if (kvm_is_error_hva (addr)) +return 1 ; +if (__copy_to_user ((void __user *)addr, &tsc_ref,sizeof (tsc_ref))) +return 1 ; +mark_page_dirty (kvm, gfn); + kvm->arch.hv_tsc_page = data;break ; }default :@@ -2253,6 +2278,17 @@ static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)case HV_X64_MSR_HYPERCALL : data = kvm->arch.hv_hypercall;break ; +case HV_X64_MSR_TIME_REF_COUNT : { +u64 now_ns; +local_irq_disable (); + now_ns =get_kernel_ns () + kvm->arch.kvmclock_offset; + data =div_u64 (now_ns - kvm->arch.hv_ref_count,100 ); +local_irq_enable (); +break ; + } +case HV_X64_MSR_REFERENCE_TSC : + data = kvm->arch.hv_tsc_page; +break ;default :vcpu_unimpl (vcpu,"Hyper-V unhandled rdmsr: 0x%x\n" , msr);return 1 ;@@ -2566,6 +2602,7 @@ int kvm_dev_ioctl_check_extension(long ext)case KVM_CAP_ASSIGN_DEV_IRQ :case KVM_CAP_PCI_2_3 :#endif +case KVM_CAP_HYPERV_TIME : r =1 ;break ;case KVM_CAP_COALESCED_MMIO :include/uapi/linux/kvm.h +1
-0@@ -666,6 +666,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_IRQ_MPIC 90#define KVM_CAP_PPC_RTAS 91#define KVM_CAP_IRQ_XICS 92 +#define KVM_CAP_HYPERV_TIME 93#ifdef KVM_CAP_IRQ_ROUTING
Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
In reply to Vadim RozenfeldQuoted 92 lines · Vadim Rozenfeld
Signed-off: Peter Lieven <[email protected]>
Signed-off: Gleb Natapov <[email protected]>
Signed-off: Vadim Rozenfeld <[email protected]>v1 -> v2
1. mark TSC page dirty as suggested by
Eric Northup <[email protected]> and Gleb
2. disable local irq when callingget_kernel_ns, as it was done by Peter Lieven <[email protected]>
3. move check for TSC page enable from second patch to this one.--- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/include/uapi/asm/hyperv.h | 14 ++++++++++++++ arch/x86/kvm/x86.c | 39 +++++++++++++++++++++++++++++++++++++- include/uapi/linux/kvm.h | 1 + 4 files changed, 55 insertions(+), 1 deletion(-)arch/x86/include/asm/kvm_host.h +2
-0@@ -575,6 +575,8 @@ struct kvm_arch {/* fields used by HYPER-V emulation */ u64 hv_guest_os_id;u64 hv_hypercall; +u64 hv_ref_count; +u64 hv_tsc_page;#ifdef CONFIG_KVM_MMU_AUDIT int audit_point;arch/x86/include/uapi/asm/hyperv.h +14
-0@@ -136,6 +136,9 @@/* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT 0x40000020 +/* A partition's reference time stamp counter (TSC) page */ +#define HV_X64_MSR_REFERENCE_TSC 0x40000021 +/* Define the virtual APIC registers */ #define HV_X64_MSR_EOI 0x40000070#define HV_X64_MSR_ICR 0x40000071@@ -179,6 +182,9 @@#define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_MASK \ (~((1ull << HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT) - 1)) +#define HV_X64_MSR_TSC_REFERENCE_ENABLE 0x00000001 +#define HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT 12 +#define HV_PROCESSOR_POWER_STATE_C0 0#define HV_PROCESSOR_POWER_STATE_C1 1#define HV_PROCESSOR_POWER_STATE_C2 2@@ -191,4 +197,12 @@#define HV_STATUS_INVALID_ALIGNMENT 4#define HV_STATUS_INSUFFICIENT_BUFFERS 19 +typedef struct _HV_REFERENCE_TSC_PAGE { +__u32 TscSequence; +__u32 Rserved1; +__u64 TscScale; +__s64 TscOffset; +}HV_REFERENCE_TSC_PAGE , *PHV_REFERENCE_TSC_PAGE ; + +#endif arch/x86/kvm/x86.c +3
-1@@ -843,7 +843,7 @@ EXPORT_SYMBOL_GPL(kvm_rdpmc);static u32 msrs_to_save[] = {MSR_KVM_SYSTEM_TIME ,MSR_KVM_WALL_CLOCK , MSR_KVM_SYSTEM_TIME_NEW, MSR_KVM_WALL_CLOCK_NEW, not needed. - HV_X64_MSR_GUEST_OS_ID,HV_X64_MSR_HYPERCALL , + HV_X64_MSR_GUEST_OS_ID,HV_X64_MSR_HYPERCALL ,HV_X64_MSR_TIME_REF_COUNT ,HV_X64_MSR_APIC_ASSIST_PAGE ,MSR_KVM_ASYNC_PF_EN ,MSR_KVM_STEAL_TIME ,MSR_KVM_PV_EOI_EN ,MSR_IA32_SYSENTER_CS ,MSR_IA32_SYSENTER_ESP ,MSR_IA32_SYSENTER_EIP ,@@ -1788,6 +1788,8 @@ static bool kvm_hv_msr_partition_wide(u32 msr)switch (msr) {case HV_X64_MSR_GUEST_OS_ID :case HV_X64_MSR_HYPERCALL : +case HV_X64_MSR_REFERENCE_TSC : +case HV_X64_MSR_TIME_REF_COUNT : r = true;break ; }
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1835
Quoted 7 lines
arch/x86/kvm/x86.c +4
-0@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ;
local_irq_disable/local_irq_enable not needed.
What is the reasoning behind reading this time value at msr write time?
Quoted 24 lines
arch/x86/kvm/x86.c +19
-0+ } +case HV_X64_MSR_REFERENCE_TSC : { +u64 gfn; +unsigned long addr; +HV_REFERENCE_TSC_PAGE tsc_ref; + tsc_ref.TscSequence =0 ; +if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { + kvm->arch.hv_tsc_page = data; +break ; + } + gfn = data >>HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT ; + addr =gfn_to_hva (kvm, data >> +HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT ); +if (kvm_is_error_hva (addr)) +return 1 ; +if (__copy_to_user ((void __user *)addr, &tsc_ref,sizeof (tsc_ref))) +return 1 ; +mark_page_dirty (kvm, gfn); + kvm->arch.hv_tsc_page = data;break ; }default :@@ -2253,6 +2278,17 @@ static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)case HV_X64_MSR_HYPERCALL :
arch/x86/kvm/x86.c static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) · line 2288
Quoted 10 lines
arch/x86/kvm/x86.c +8
-0data = kvm->arch.hv_hypercall;break ; +case HV_X64_MSR_TIME_REF_COUNT : { +u64 now_ns; +local_irq_disable (); + now_ns =get_kernel_ns () + kvm->arch.kvmclock_offset; + data =div_u64 (now_ns - kvm->arch.hv_ref_count,100 ); +local_irq_enable (); +break ; + }
local_irq_disable/enable not needed.
It would be nice to have a testcase to compare reference tsc versus MSR.
Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Quoted 94 lines · Marcelo Tosatti
Quoted 93 lines · Vadim Rozenfeld
Signed-off: Peter Lieven <[email protected]>
Signed-off: Gleb Natapov <[email protected]>
Signed-off: Vadim Rozenfeld <[email protected]>v1 -> v2
1. mark TSC page dirty as suggested by
Eric Northup <[email protected]> and Gleb
2. disable local irq when callingget_kernel_ns, as it was done by Peter Lieven <[email protected]>
3. move check for TSC page enable from second patch to this one.--- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/include/uapi/asm/hyperv.h | 14 ++++++++++++++ arch/x86/kvm/x86.c | 39 +++++++++++++++++++++++++++++++++++++- include/uapi/linux/kvm.h | 1 + 4 files changed, 55 insertions(+), 1 deletion(-)arch/x86/include/asm/kvm_host.h +2
-0@@ -575,6 +575,8 @@ struct kvm_arch {/* fields used by HYPER-V emulation */ u64 hv_guest_os_id;u64 hv_hypercall; +u64 hv_ref_count; +u64 hv_tsc_page;#ifdef CONFIG_KVM_MMU_AUDIT int audit_point;arch/x86/include/uapi/asm/hyperv.h +14
-0@@ -136,6 +136,9 @@/* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT 0x40000020 +/* A partition's reference time stamp counter (TSC) page */ +#define HV_X64_MSR_REFERENCE_TSC 0x40000021 +/* Define the virtual APIC registers */ #define HV_X64_MSR_EOI 0x40000070#define HV_X64_MSR_ICR 0x40000071@@ -179,6 +182,9 @@#define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_MASK \ (~((1ull << HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT) - 1)) +#define HV_X64_MSR_TSC_REFERENCE_ENABLE 0x00000001 +#define HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT 12 +#define HV_PROCESSOR_POWER_STATE_C0 0#define HV_PROCESSOR_POWER_STATE_C1 1#define HV_PROCESSOR_POWER_STATE_C2 2@@ -191,4 +197,12 @@#define HV_STATUS_INVALID_ALIGNMENT 4#define HV_STATUS_INSUFFICIENT_BUFFERS 19 +typedef struct _HV_REFERENCE_TSC_PAGE { +__u32 TscSequence; +__u32 Rserved1; +__u64 TscScale; +__s64 TscOffset; +}HV_REFERENCE_TSC_PAGE , *PHV_REFERENCE_TSC_PAGE ; + +#endif arch/x86/kvm/x86.c +3
-1@@ -843,7 +843,7 @@ EXPORT_SYMBOL_GPL(kvm_rdpmc);static u32 msrs_to_save[] = {MSR_KVM_SYSTEM_TIME ,MSR_KVM_WALL_CLOCK , MSR_KVM_SYSTEM_TIME_NEW, MSR_KVM_WALL_CLOCK_NEW, not needed. - HV_X64_MSR_GUEST_OS_ID,HV_X64_MSR_HYPERCALL , + HV_X64_MSR_GUEST_OS_ID,HV_X64_MSR_HYPERCALL ,HV_X64_MSR_TIME_REF_COUNT ,HV_X64_MSR_APIC_ASSIST_PAGE ,MSR_KVM_ASYNC_PF_EN ,MSR_KVM_STEAL_TIME ,MSR_KVM_PV_EOI_EN ,MSR_IA32_SYSENTER_CS ,MSR_IA32_SYSENTER_ESP ,MSR_IA32_SYSENTER_EIP ,@@ -1788,6 +1788,8 @@ static bool kvm_hv_msr_partition_wide(u32 msr)switch (msr) {case HV_X64_MSR_GUEST_OS_ID :case HV_X64_MSR_HYPERCALL : +case HV_X64_MSR_REFERENCE_TSC : +case HV_X64_MSR_TIME_REF_COUNT : r = true;break ; }@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))
Quoted 9 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1835
Quoted 6 lines
arch/x86/kvm/x86.c +4
-0return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ;local_irq_disable/local_irq_enable not needed.
get_kernel_ns has WARN_ON(preemptible()) so at least preempt_disable() is needed, but all callers of the function disable interrupts.
Quoted 39 lines
What is the reasoning behind reading this time value at msr write time?
Quoted 24 lines
arch/x86/kvm/x86.c +19
-0+ } +case HV_X64_MSR_REFERENCE_TSC : { +u64 gfn; +unsigned long addr; +HV_REFERENCE_TSC_PAGE tsc_ref; + tsc_ref.TscSequence =0 ; +if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { + kvm->arch.hv_tsc_page = data; +break ; + } + gfn = data >>HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT ; + addr =gfn_to_hva (kvm, data >> +HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT ); +if (kvm_is_error_hva (addr)) +return 1 ; +if (__copy_to_user ((void __user *)addr, &tsc_ref,sizeof (tsc_ref))) +return 1 ; +mark_page_dirty (kvm, gfn); + kvm->arch.hv_tsc_page = data;break ; }default :@@ -2253,6 +2278,17 @@ static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)case HV_X64_MSR_HYPERCALL :arch/x86/kvm/x86.c static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) · line 2288
Quoted 10 lines
arch/x86/kvm/x86.c +8
-0data = kvm->arch.hv_hypercall;break ; +case HV_X64_MSR_TIME_REF_COUNT : { +u64 now_ns; +local_irq_disable (); + now_ns =get_kernel_ns () + kvm->arch.kvmclock_offset; + data =div_u64 (now_ns - kvm->arch.hv_ref_count,100 ); +local_irq_enable (); +break ; + }local_irq_disable/enable not needed.
Quoted 1 line
It would be nice to have a testcase to compare reference tsc versus MSR.
--
Gleb.
Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
On Wed, May 22, 2013 at 06:28:47AM +0300, Gleb Natapov wrote
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
arch/x86/kvm/x86.c +1
-0+case HV_X64_MSR_TIME_REF_COUNT : r = true;break ; }@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))Quoted 9 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1835
Quoted 6 lines
arch/x86/kvm/x86.c +4
-0return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ;local_irq_disable/local_irq_enable not needed.
Quoted 2 lines
get_kernel_nshas WARN_ON(preemptible()) so at leastpreempt_disable()is needed, but all callers of the function disable interrupts.
OK. Its not necessary to disable interrupts (this is a left over of kvm_guest_update_time).
Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Quoted 16 lines · Marcelo Tosatti
On Wed, May 22, 2013 at 06:28:47AM +0300, Gleb Natapov wrote
Quoted 15 lines
Quoted 15 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1835
Quoted 12 lines
arch/x86/kvm/x86.c +5
-0+case HV_X64_MSR_TIME_REF_COUNT : r = true;break ; }@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ;local_irq_disable/local_irq_enable not needed.
Quoted 5 lines
Quoted 2 lines
get_kernel_nshas WARN_ON(preemptible()) so at leastpreempt_disable()is needed, but all callers of the function disable interrupts.OK. Its not necessary to disable interrupts (this is a left over of
kvm_guest_update_time).
So preempt_disable() then? Should we change other callers?
--
Gleb.
Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Quoted 17 lines · Gleb Natapov
Quoted 16 lines · Marcelo Tosatti
On Wed, May 22, 2013 at 06:28:47AM +0300, Gleb Natapov wrote
Quoted 15 lines
Quoted 15 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1835
Quoted 12 lines
arch/x86/kvm/x86.c +5
-0+case HV_X64_MSR_TIME_REF_COUNT : r = true;break ; }@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ;local_irq_disable/local_irq_enable not needed.
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
get_kernel_nshas WARN_ON(preemptible()) so at leastpreempt_disable()is needed, but all callers of the function disable interrupts.OK. Its not necessary to disable interrupts (this is a left over of
kvm_guest_update_time).So
preempt_disable()then? Should we change other callers?
Yes. Should only disable interrupts if necessary (the case in kvm_write_guest_time is necessary).
Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
In reply to Marcelo Tosatti----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Wednesday, May 22, 2013 10:46:14 AM
Subject: Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Quoted 92 lines · Vadim Rozenfeld
Signed-off: Peter Lieven <[email protected]>
Signed-off: Gleb Natapov <[email protected]>
Signed-off: Vadim Rozenfeld <[email protected]>v1 -> v2
1. mark TSC page dirty as suggested by
Eric Northup <[email protected]> and Gleb
2. disable local irq when callingget_kernel_ns, as it was done by Peter Lieven <[email protected]>
3. move check for TSC page enable from second patch to this one.--- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/include/uapi/asm/hyperv.h | 14 ++++++++++++++ arch/x86/kvm/x86.c | 39 +++++++++++++++++++++++++++++++++++++- include/uapi/linux/kvm.h | 1 + 4 files changed, 55 insertions(+), 1 deletion(-)arch/x86/include/asm/kvm_host.h +2
-0@@ -575,6 +575,8 @@ struct kvm_arch {/* fields used by HYPER-V emulation */ u64 hv_guest_os_id;u64 hv_hypercall; +u64 hv_ref_count; +u64 hv_tsc_page;#ifdef CONFIG_KVM_MMU_AUDIT int audit_point;arch/x86/include/uapi/asm/hyperv.h +14
-0@@ -136,6 +136,9 @@/* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT 0x40000020 +/* A partition's reference time stamp counter (TSC) page */ +#define HV_X64_MSR_REFERENCE_TSC 0x40000021 +/* Define the virtual APIC registers */ #define HV_X64_MSR_EOI 0x40000070#define HV_X64_MSR_ICR 0x40000071@@ -179,6 +182,9 @@#define HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_MASK \ (~((1ull << HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT) - 1)) +#define HV_X64_MSR_TSC_REFERENCE_ENABLE 0x00000001 +#define HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT 12 +#define HV_PROCESSOR_POWER_STATE_C0 0#define HV_PROCESSOR_POWER_STATE_C1 1#define HV_PROCESSOR_POWER_STATE_C2 2@@ -191,4 +197,12 @@#define HV_STATUS_INVALID_ALIGNMENT 4#define HV_STATUS_INSUFFICIENT_BUFFERS 19 +typedef struct _HV_REFERENCE_TSC_PAGE { +__u32 TscSequence; +__u32 Rserved1; +__u64 TscScale; +__s64 TscOffset; +}HV_REFERENCE_TSC_PAGE , *PHV_REFERENCE_TSC_PAGE ; + +#endif arch/x86/kvm/x86.c +3
-1@@ -843,7 +843,7 @@ EXPORT_SYMBOL_GPL(kvm_rdpmc);static u32 msrs_to_save[] = {MSR_KVM_SYSTEM_TIME ,MSR_KVM_WALL_CLOCK , MSR_KVM_SYSTEM_TIME_NEW, MSR_KVM_WALL_CLOCK_NEW, not needed. - HV_X64_MSR_GUEST_OS_ID,HV_X64_MSR_HYPERCALL , + HV_X64_MSR_GUEST_OS_ID,HV_X64_MSR_HYPERCALL ,HV_X64_MSR_TIME_REF_COUNT ,HV_X64_MSR_APIC_ASSIST_PAGE ,MSR_KVM_ASYNC_PF_EN ,MSR_KVM_STEAL_TIME ,MSR_KVM_PV_EOI_EN ,MSR_IA32_SYSENTER_CS ,MSR_IA32_SYSENTER_ESP ,MSR_IA32_SYSENTER_EIP ,@@ -1788,6 +1788,8 @@ static bool kvm_hv_msr_partition_wide(u32 msr)switch (msr) {case HV_X64_MSR_GUEST_OS_ID :case HV_X64_MSR_HYPERCALL : +case HV_X64_MSR_REFERENCE_TSC : +case HV_X64_MSR_TIME_REF_COUNT : r = true;break ; }
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1835
Quoted 7 lines
arch/x86/kvm/x86.c +4
-0@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ;
local_irq_disable/local_irq_enable not needed.
What is the reasoning behind reading this time value at msr write time? [VR] Windows writs this MSR only once, during HAL initialization. So, I decided to treat this call as a partition crate event.
Quoted 24 lines
arch/x86/kvm/x86.c +19
-0+ } +case HV_X64_MSR_REFERENCE_TSC : { +u64 gfn; +unsigned long addr; +HV_REFERENCE_TSC_PAGE tsc_ref; + tsc_ref.TscSequence =0 ; +if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { + kvm->arch.hv_tsc_page = data; +break ; + } + gfn = data >>HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT ; + addr =gfn_to_hva (kvm, data >> +HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT ); +if (kvm_is_error_hva (addr)) +return 1 ; +if (__copy_to_user ((void __user *)addr, &tsc_ref,sizeof (tsc_ref))) +return 1 ; +mark_page_dirty (kvm, gfn); + kvm->arch.hv_tsc_page = data;break ; }default :@@ -2253,6 +2278,17 @@ static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)case HV_X64_MSR_HYPERCALL :
arch/x86/kvm/x86.c static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) · line 2288
Quoted 10 lines
arch/x86/kvm/x86.c +8
-0data = kvm->arch.hv_hypercall;break ; +case HV_X64_MSR_TIME_REF_COUNT : { +u64 now_ns; +local_irq_disable (); + now_ns =get_kernel_ns () + kvm->arch.kvmclock_offset; + data =div_u64 (now_ns - kvm->arch.hv_ref_count,100 ); +local_irq_enable (); +break ; + }
local_irq_disable/enable not needed.
It would be nice to have a testcase to compare reference tsc versus MSR.
Paolo Bonzini
maintainerRe: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Il 22/05/2013 09:32, Vadim Rozenfeld ha scritto:
Quoted 11 lines
Quoted 8 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1835
Quoted 8 lines
arch/x86/kvm/x86.c +4
-0@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ;local_irq_disable/local_irq_enable not needed.
Quoted 4 lines
What is the reasoning behind reading this time value at msr write time? [VR] Windows writs this MSR only once, during HAL initialization. So, I decided to treat this call as a partition crate event.
But is it expected by Windows that the reference count starts counting up from 0 at partition creation time? If you could just use (get_kernel_ns() + kvm->arch.kvmclock_offset) / 100, it would also be simpler for migration purposes.
Paolo
Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Quoted 17 lines · Paolo Bonzini
Il 22/05/2013 09:32, Vadim Rozenfeld ha scritto:
Quoted 11 lines
Quoted 8 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1835
Quoted 8 lines
arch/x86/kvm/x86.c +4
-0@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ;local_irq_disable/local_irq_enable not needed.
Quoted 4 lines
What is the reasoning behind reading this time value at msr write time? [VR] Windows writs this MSR only once, during HAL initialization. So, I decided to treat this call as a partition crate event.
Quoted 4 lines
But is it expected by Windows that the reference count starts counting up from 0 at partition creation time? If you could just use (
get_kernel_ns()+kvm->arch.kvmclock_offset) / 100, it would also be simpler for migration purposes.
I can just report, that I have used the patch that does it that way and it works. Maybe Windows is calculating the uptime by the reference counter?
Peter
Paolo Bonzini
maintainerRe: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Il 23/05/2013 08:17, Peter Lieven ha scritto:
Quoted 19 lines · Paolo Bonzini
Quoted 18 lines
Il 22/05/2013 09:32, Vadim Rozenfeld ha scritto:
Quoted 16 lines
Quoted 9 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu · line 1836
Quoted 9 lines
arch/x86/kvm/x86.c +4
-0@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ;local_irq_disable/local_irq_enable not needed.
What is the reasoning behind reading this time value at msr write time? [VR] Windows writs this MSR only once, during HAL initialization. So, I decided to treat this call as a partition crate event.
Quoted 7 lines
Quoted 4 lines
But is it expected by Windows that the reference count starts counting up from 0 at partition creation time? If you could just use (
get_kernel_ns()+kvm->arch.kvmclock_offset) / 100, it would also be simpler for migration purposes.I can just report, that I have used the patch that does it that way and it works.
What do you mean by "that way"? :)
Paolo
Quoted 4 lines
Maybe Windows is calculating the uptime by the reference counter?
Peter
Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Quoted 25 lines · Paolo Bonzini
Il 23/05/2013 08:17, Peter Lieven ha scritto:
Quoted 24 lines · Paolo Bonzini
Quoted 22 lines
Il 22/05/2013 09:32, Vadim Rozenfeld ha scritto:
Quoted 12 lines
Quoted 9 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu · line 1836
Quoted 9 lines
arch/x86/kvm/x86.c +4
-0@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ;local_irq_disable/local_irq_enable not needed.
Quoted 4 lines
What is the reasoning behind reading this time value at msr write time? [VR] Windows writs this MSR only once, during HAL initialization. So, I decided to treat this call as a partition crate event.
But is it expected by Windows that the reference count starts counting up from 0 at partition creation time? If you could just use (
get_kernel_ns()+kvm->arch.kvmclock_offset) / 100, it would also be simpler for migration purposes.
Quoted 4 lines
Quoted 2 lines
I can just report, that I have used the patch that does it that way and it works.
What do you mean by "that way"? :)
Ups sorry… I meant the way it was implemented in the old patch (I sent a few days ago).
@@ -1426,6 +1428,21 @@ static int set_msr_hyperv_pw(struct kvm_
if (__copy_to_user((void *)addr, instructions, 4)) return 1; kvm->arch.hv_hypercall = data;
+ kvm->arch.hv_ref_count = get_kernel_ns();
+ break;
+ }
+ case HV_X64_MSR_REFERENCE_TSC: {
+ u64 gfn;
+ unsigned long addr;
+ u32 hv_tsc_sequence;
+ gfn = data >> HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
+ addr = gfn_to_hva(kvm, gfn);
+ if (kvm_is_error_hva(addr))
+ return 1;
+ hv_tsc_sequence = 0x0; //invalid
+ if (__copy_to_user((void *)addr, (void __user *) &hv_tsc_sequence, sizeof(hv_tsc_sequence)))
+ return 1;
+ kvm->arch.hv_reference_tsc = data; break; } default: @@ -1826,6 +1843,17 @@ static int get_msr_hyperv_pw(struct kvm_ case HV_X64_MSR_HYPERCALL: data = kvm->arch.hv_hypercall; break;
+ case HV_X64_MSR_TIME_REF_COUNT: {
+ u64 now_ns;
+ local_irq_disable();
+ now_ns = get_kernel_ns();
+ data = div_u64(now_ns + kvm->arch.kvmclock_offset - kvm->arch.hv_ref_count,100);
+ local_irq_enable();
+ break;
+ }
+ case HV_X64_MSR_REFERENCE_TSC:
+ data = kvm->arch.hv_reference_tsc;
+ break; default: pr_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr); return 1;
Peter
Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
In reply to Peter Lieven----- Original Message -----
From: "Peter Lieven" <[email protected]>
To: "Paolo Bonzini" <[email protected]>
Cc: "Vadim Rozenfeld" <[email protected]>, "Marcelo Tosatti" <[email protected]>, [email protected], [email protected], [email protected]
Sent: Thursday, May 23, 2013 4:17:57 PM
Subject: Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Quoted 17 lines · Paolo Bonzini
Il 22/05/2013 09:32, Vadim Rozenfeld ha scritto:
Quoted 11 lines
Quoted 8 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1835
Quoted 8 lines
arch/x86/kvm/x86.c +4
-0@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ;local_irq_disable/local_irq_enable not needed.
Quoted 4 lines
What is the reasoning behind reading this time value at msr write time? [VR] Windows writs this MSR only once, during HAL initialization. So, I decided to treat this call as a partition crate event.
Quoted 4 lines
But is it expected by Windows that the reference count starts counting up from 0 at partition creation time? If you could just use (
get_kernel_ns()+kvm->arch.kvmclock_offset) / 100, it would also be simpler for migration purposes.
I can just report, that I have used the patch that does it that way and it works. Maybe Windows is calculating the uptime by the reference counter?
[VR]
Windows use it (reference counters/iTSC/PMTimer/HPET) as a time-stamp source for (Ke)QueryPerformanceCounter function.
Peter
Paolo Bonzini
maintainerRe: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Il 23/05/2013 14:25, Vadim Rozenfeld ha scritto:
Quoted 32 lines
----- Original Message -----
From: "Peter Lieven" <[email protected]>
To: "Paolo Bonzini" <[email protected]>
Cc: "Vadim Rozenfeld" <[email protected]>, "Marcelo Tosatti" <[email protected]>, [email protected], [email protected], [email protected]
Sent: Thursday, May 23, 2013 4:17:57 PM
Subject: Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counterQuoted 17 lines · Paolo Bonzini
Il 22/05/2013 09:32, Vadim Rozenfeld ha scritto:
Quoted 11 lines
Quoted 8 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1835
Quoted 8 lines
arch/x86/kvm/x86.c +4
-0@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)if (__copy_to_user ((void __user *)addr, instructions,4 ))return 1 ; kvm->arch.hv_hypercall = data; +local_irq_disable (); + kvm->arch.hv_ref_count =get_kernel_ns (); +local_irq_enable (); +break ;local_irq_disable/local_irq_enable not needed.
Quoted 4 lines
What is the reasoning behind reading this time value at msr write time? [VR] Windows writs this MSR only once, during HAL initialization. So, I decided to treat this call as a partition crate event.
Quoted 4 lines
But is it expected by Windows that the reference count starts counting up from 0 at partition creation time? If you could just use (
get_kernel_ns()+kvm->arch.kvmclock_offset) / 100, it would also be simpler for migration purposes.
Quoted 6 lines
I can just report, that I have used the patch that does it that way and it works. Maybe Windows is calculating the uptime by the reference counter?
[VR]
Windows use it (reference counters/iTSC/PMTimer/HPET) as a time-stamp source for (Ke)QueryPerformanceCounter function.
So I would prefer to remove kvm->arch.hv_ref_count altogether.
Paolo
Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Quoted 33 lines · Paolo Bonzini
Il 23/05/2013 14:25, Vadim Rozenfeld ha scritto:
Quoted 32 lines
----- Original Message -----
From: "Peter Lieven" <[email protected]>
To: "Paolo Bonzini" <[email protected]>
Cc: "Vadim Rozenfeld" <[email protected]>, "Marcelo Tosatti" <[email protected]>, [email protected], [email protected], [email protected]
Sent: Thursday, May 23, 2013 4:17:57 PM
Subject: Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counterQuoted 21 lines · Paolo Bonzini
Il 22/05/2013 09:32, Vadim Rozenfeld ha scritto:
Quoted 11 lines
Quoted 8 lines
Review static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1835
Quoted 8 lines
(quoted diff) +4
-0@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) if (__copy_to_user((void __user *)addr, instructions, 4)) return 1; kvm->arch.hv_hypercall = data; + local_irq_disable(); + kvm->arch.hv_ref_count = get_kernel_ns(); + local_irq_enable(); + break;local_irq_disable/local_irq_enable not needed.
Quoted 4 lines
What is the reasoning behind reading this time value at msr write time? [VR] Windows writs this MSR only once, during HAL initialization. So, I decided to treat this call as a partition crate event.
But is it expected by Windows that the reference count starts counting up from 0 at partition creation time? If you could just use (
get_kernel_ns()+kvm->arch.kvmclock_offset) / 100, it would also be simpler for migration purposes.
Quoted 8 lines
Quoted 6 lines
I can just report, that I have used the patch that does it that way and it works. Maybe Windows is calculating the uptime by the reference counter?
[VR]
Windows use it (reference counters/iTSC/PMTimer/HPET) as a time-stamp source for (Ke)QueryPerformanceCounter function.So I would prefer to remove
kvm->arch.hv_ref_countaltogether.
But only if the migration support is guaranteed. And what if we have a host which lacks invariant TSC support?
Peter
Quoted 3 lines
Paolo
Paolo Bonzini
maintainerRe: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Il 23/05/2013 15:20, Peter Lieven ha scritto:
Quoted 42 lines · Paolo Bonzini
Quoted 41 lines
Il 23/05/2013 14:25, Vadim Rozenfeld ha scritto:
Quoted 40 lines
----- Original Message -----
From: "Peter Lieven" <[email protected]>
To: "Paolo Bonzini" <[email protected]>
Cc: "Vadim Rozenfeld" <[email protected]>, "Marcelo Tosatti" <[email protected]>, [email protected], [email protected], [email protected]
Sent: Thursday, May 23, 2013 4:17:57 PM
Subject: Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counterQuoted 19 lines · Paolo Bonzini
Il 22/05/2013 09:32, Vadim Rozenfeld ha scritto:
Quoted 12 lines
Quoted 9 lines
Review static int set_msr_hyperv_pw(struct · line 1836
Quoted 9 lines
(quoted diff) +4
-0@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) if (__copy_to_user((void __user *)addr, instructions, 4)) return 1; kvm->arch.hv_hypercall = data; + local_irq_disable(); + kvm->arch.hv_ref_count = get_kernel_ns(); + local_irq_enable(); + break;local_irq_disable/local_irq_enable not needed.
Quoted 5 lines
What is the reasoning behind reading this time value at msr write time?
[VR] Windows writs this MSR only once, during HAL initialization. So, I decided to treat this call as a partition crate event.Quoted 4 lines
But is it expected by Windows that the reference count starts counting up from 0 at partition creation time? If you could just use (
get_kernel_ns()+kvm->arch.kvmclock_offset) / 100, it would also be simpler for migration purposes.I can just report, that I have used the patch that does it that way and it works.
Maybe Windows is calculating the uptime by the reference counter?
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
[VR]
Windows use it (reference counters/iTSC/PMTimer/HPET) as a time-stamp source
for (Ke)QueryPerformanceCounter function.So I would prefer to remove
kvm->arch.hv_ref_countaltogether.But only if the migration support is guaranteed.
Migration support wouldn't work yet anyway, you need to recompute the scale and sequence. But that could be done by KVM_SET_CLOCK.
Quoted 1 line
And what if we have a host which lacks invariant TSC support?
Then the sequence must be set to 0 or 0xFFFFFFFF, I still haven't understood. :)
Paolo
Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Quoted 48 lines · Paolo Bonzini
Il 23/05/2013 15:20, Peter Lieven ha scritto:
Quoted 47 lines · Paolo Bonzini
Quoted 46 lines
Il 23/05/2013 14:25, Vadim Rozenfeld ha scritto:
Quoted 44 lines
----- Original Message -----
From: "Peter Lieven" <[email protected]>
To: "Paolo Bonzini" <[email protected]>
Cc: "Vadim Rozenfeld" <[email protected]>, "Marcelo Tosatti" <[email protected]>, [email protected], [email protected], [email protected]
Sent: Thursday, May 23, 2013 4:17:57 PM
Subject: Re: [RFC PATCH v2 1/2] add support for Hyper-V reference time counterQuoted 19 lines · Paolo Bonzini
Il 22/05/2013 09:32, Vadim Rozenfeld ha scritto:
Quoted 12 lines
Quoted 9 lines
Review static int set_msr_hyperv_pw(struct · line 1836
Quoted 9 lines
(quoted diff) +4
-0@@ -1827,6 +1829,29 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) if (__copy_to_user((void __user *)addr, instructions, 4)) return 1; kvm->arch.hv_hypercall = data; + local_irq_disable(); + kvm->arch.hv_ref_count = get_kernel_ns(); + local_irq_enable(); + break;local_irq_disable/local_irq_enable not needed.
Quoted 5 lines
What is the reasoning behind reading this time value at msr write time?
[VR] Windows writs this MSR only once, during HAL initialization. So, I decided to treat this call as a partition crate event.Quoted 4 lines
But is it expected by Windows that the reference count starts counting up from 0 at partition creation time? If you could just use (
get_kernel_ns()+kvm->arch.kvmclock_offset) / 100, it would also be simpler for migration purposes.I can just report, that I have used the patch that does it that way and it works.
Maybe Windows is calculating the uptime by the reference counter?[VR]
Windows use it (reference counters/iTSC/PMTimer/HPET) as a time-stamp source
for (Ke)QueryPerformanceCounter function.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
So I would prefer to remove
kvm->arch.hv_ref_countaltogether.But only if the migration support is guaranteed.
Migration support wouldn't work yet anyway, you need to recompute the scale and sequence. But that could be done by
KVM_SET_CLOCK.
hv_ref_counter does work out of the box. what I was trying to say is even it is slower than iTSC, it is significantly faster than hpet or pmtimer and I can confirm it works flawlessly with migration.
Quoted 5 lines
Quoted 2 lines
And what if we have a host which lacks invariant TSC support?
Then the sequence must be set to 0 or
0xFFFFFFFF, I still haven't understood. :)
yes, but windows does then fall back to pmtimer or hpet which is much slower then reference counter.
Peter
Paolo Bonzini
maintainerRe: [RFC PATCH v2 1/2] add support for Hyper-V reference time counter
Il 23/05/2013 15:30, Peter Lieven ha scritto:
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
So I would prefer to remove
kvm->arch.hv_ref_countaltogether.But only if the migration support is guaranteed.
Migration support wouldn't work yet anyway, you need to recompute the scale and sequence. But that could be done by
KVM_SET_CLOCK.
hv_ref_counterdoes work out of the box. what I was trying to say is even it is slower than iTSC, it is significantly faster than hpet or pmtimer and I can confirm it works flawlessly with migration.
I can't see how without a userspace patch to migrate hv_ref_count.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
And what if we have a host which lacks invariant TSC support?
Then the sequence must be set to 0 or
0xFFFFFFFF, I still haven't understood. :)yes, but windows does then fall back to pmtimer or hpet which is much slower then reference counter.
IIUC, with 0 it doesn't.
Paolo
RFC PATCH v2 2/2 add support for Hyper-V invariant TSC
In reply to Vadim RozenfeldThe following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.
--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kvm/x86.c +5 -1
@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;
@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ; + tsc_ref.TscScale = + ((10000LL <<32 ) / vcpu->arch.virtual_tsc_khz) <<32 ; + tsc_ref.TscOffset =0 ;if (__copy_to_user ((void __user *)addr, &tsc_ref,sizeof (tsc_ref)))return 1 ;mark_page_dirty (kvm, gfn);
Signature · 1 line
1.8.1.2
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 24 lines · Vadim Rozenfeld
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;
1) You want NONSTOP_TSC (see 40fb1715 commit) which matches INVARIANT TSC.
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
3) 0xFFFFFFFF is the value for invalid source of reference time?
Quoted 8 lines
arch/x86/kvm/x86.c +3
-0+ tsc_ref.TscScale = + ((10000LL <<32 ) / vcpu->arch.virtual_tsc_khz) <<32 ; + tsc_ref.TscOffset =0 ;if (__copy_to_user ((void __user *)addr, &tsc_ref,sizeof (tsc_ref)))return 1 ;mark_page_dirty (kvm, gfn);Signature · 1 line
1.8.1.2
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Wednesday, May 22, 2013 10:50:46 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 24 lines · Vadim Rozenfeld
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;
1) You want NONSTOP_TSC (see 40fb1715 commit) which matches INVARIANT TSC.
[VR]
Thank you for reviewing. Will fix it.
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
[VR]
Yes, on every VM resume, including migration. After migration we also need
to recalculate scale and adjust offset.
3) 0xFFFFFFFF is the value for invalid source of reference time?
[VR] Yes, on boot-up. In this case guest will go with PMTimer (not sure about HPET but I can check). But if we set sequence to 0xFFFFFFFF after migration - it's probably will not work.
Quoted 8 lines
arch/x86/kvm/x86.c +3
-0+ tsc_ref.TscScale = + ((10000LL <<32 ) / vcpu->arch.virtual_tsc_khz) <<32 ; + tsc_ref.TscOffset =0 ;if (__copy_to_user ((void __user *)addr, &tsc_ref,sizeof (tsc_ref)))return 1 ;mark_page_dirty (kvm, gfn);Signature · 1 line
1.8.1.2
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 43 lines · Vadim Rozenfeld
----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Wednesday, May 22, 2013 10:50:46 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSCQuoted 24 lines · Vadim Rozenfeld
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;1) You want
NONSTOP_TSC(see40fb1715commit) which matches INVARIANT TSC. [VR]
Thank you for reviewing. Will fix it.
Quoted 8 lines
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
[VR]
Yes, on every VM resume, including migration. After migration we also need
to recalculate scale and adjust offset.
3)0xFFFFFFFFis the value for invalid source of reference time?
[VR] Yes, on boot-up. In this case guest will go with PMTimer (not sure about HPET but I can check). But if we set sequence to0xFFFFFFFFafter migration - it's probably will not work.
"Reference TSC during Save and Restore and Migration
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of 0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."
Why it would not/does not work after migration?
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 55 lines · Marcelo Tosatti
Quoted 43 lines · Vadim Rozenfeld
----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Wednesday, May 22, 2013 10:50:46 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSCQuoted 24 lines · Vadim Rozenfeld
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;1) You want
NONSTOP_TSC(see40fb1715commit) which matches INVARIANT TSC. [VR]
Thank you for reviewing. Will fix it.Quoted 8 lines
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
[VR]
Yes, on every VM resume, including migration. After migration we also need
to recalculate scale and adjust offset.
3)0xFFFFFFFFis the value for invalid source of reference time?
[VR] Yes, on boot-up. In this case guest will go with PMTimer (not sure about HPET but I can check). But if we set sequence to0xFFFFFFFFafter migration - it's probably will not work."Reference TSC during Save and Restore and Migration
Quoted 10 lines
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."Why it would not/does not work after migration?
what exactly do we heed the reference TSC for? the reference counter alone works great and it seems that there is a lot of trouble and crash possibilities involved with the referece tsc.
Peter
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 63 lines · Peter Lieven
Quoted 62 lines · Marcelo Tosatti
Quoted 43 lines · Vadim Rozenfeld
----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Wednesday, May 22, 2013 10:50:46 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSCQuoted 24 lines · Vadim Rozenfeld
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;1) You want
NONSTOP_TSC(see40fb1715commit) which matches INVARIANT TSC. [VR]
Thank you for reviewing. Will fix it.Quoted 8 lines
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
[VR]
Yes, on every VM resume, including migration. After migration we also need
to recalculate scale and adjust offset.
3)0xFFFFFFFFis the value for invalid source of reference time?
[VR] Yes, on boot-up. In this case guest will go with PMTimer (not sure about HPET but I can check). But if we set sequence to0xFFFFFFFFafter migration - it's probably will not work."Reference TSC during Save and Restore and Migration
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."
Quoted 7 lines
Quoted 3 lines
Why it would not/does not work after migration?
what exactly do we heed the reference TSC for? the reference counter alone works great and it seems that there is a lot of trouble and crash possibilities involved with the referece tsc.
Reference TSC is even faster. There should be no crashed with proper implementation.
--
Gleb.
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 14 lines · Gleb Natapov
Quoted 14 lines
Quoted 13 lines
"Reference TSC during Save and Restore and Migration
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."Why it would not/does not work after migration?
Quoted 8 lines
Quoted 3 lines
what exactly do we heed the reference TSC for? the reference counter alone works great and it seems that there is a lot of trouble and crash possibilities involved with the referece tsc.
Reference TSC is even faster. There should be no crashed with proper implementation.
--
Gleb.
Lack of invariant TSC support in the host.
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 18 lines · Marcelo Tosatti
Quoted 17 lines · Gleb Natapov
Quoted 17 lines
Quoted 13 lines
"Reference TSC during Save and Restore and Migration
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."Why it would not/does not work after migration?
what exactly do we heed the reference TSC for? the reference counter alone works great and it seems that there is a lot of trouble and crash possibilities involved with the referece tsc.
Quoted 7 lines
Quoted 5 lines
Reference TSC is even faster. There should be no crashed with proper implementation.
--
Gleb.Lack of invariant TSC support in the host.
Proper implementation will disable reference TSC in this case.
--
Gleb.
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
In reply to Marcelo Tosatti----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Gleb Natapov" <[email protected]>
Cc: "Peter Lieven" <[email protected]>, "Vadim Rozenfeld" <[email protected]>, [email protected], [email protected]
Sent: Thursday, May 23, 2013 11:35:59 PM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 14 lines · Gleb Natapov
Quoted 14 lines
Quoted 13 lines
"Reference TSC during Save and Restore and Migration
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."Why it would not/does not work after migration?
Quoted 8 lines
Quoted 3 lines
what exactly do we heed the reference TSC for? the reference counter alone works great and it seems that there is a lot of trouble and crash possibilities involved with the referece tsc.
Reference TSC is even faster. There should be no crashed with proper implementation.
--
Gleb.
Lack of invariant TSC support in the host.
if there is no iTSC in the host -> set sequence to 0 and go with reference counter. It is why they both scaled to 10 MHz, and it's why reference counters is a fall-back for iTSC.
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
In reply to Peter Lieven----- Original Message -----
From: "Peter Lieven" <[email protected]>
To: "Marcelo Tosatti" <[email protected]>
Cc: "Vadim Rozenfeld" <[email protected]>, [email protected], [email protected], [email protected]
Sent: Thursday, May 23, 2013 4:18:55 PM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 55 lines · Marcelo Tosatti
Quoted 43 lines · Vadim Rozenfeld
----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Wednesday, May 22, 2013 10:50:46 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSCQuoted 24 lines · Vadim Rozenfeld
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;1) You want
NONSTOP_TSC(see40fb1715commit) which matches INVARIANT TSC. [VR]
Thank you for reviewing. Will fix it.Quoted 8 lines
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
[VR]
Yes, on every VM resume, including migration. After migration we also need
to recalculate scale and adjust offset.
3)0xFFFFFFFFis the value for invalid source of reference time?
[VR] Yes, on boot-up. In this case guest will go with PMTimer (not sure about HPET but I can check). But if we set sequence to0xFFFFFFFFafter migration - it's probably will not work."Reference TSC during Save and Restore and Migration
Quoted 10 lines
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."Why it would not/does not work after migration?
what exactly do we heed the reference TSC for? the reference counter alone works great and it seems that there is a lot of trouble and crash possibilities involved with the referece tsc.
[VR]
Because it is incredibly light and fast.
The simple test which calls QueryPerformanceCounter in a loop 10 millions times gives we the following results:
PMTimer 32269 ms HPET 38466 ms Ref Count 6499 ms iTSC 1169 ms
Vadim.
Peter
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 79 lines · Vadim Rozenfeld
----- Original Message -----
From: "Peter Lieven" <[email protected]>
To: "Marcelo Tosatti" <[email protected]>
Cc: "Vadim Rozenfeld" <[email protected]>, [email protected], [email protected], [email protected]
Sent: Thursday, May 23, 2013 4:18:55 PM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSCQuoted 55 lines · Marcelo Tosatti
Quoted 43 lines · Vadim Rozenfeld
----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Wednesday, May 22, 2013 10:50:46 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSCQuoted 24 lines · Vadim Rozenfeld
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;1) You want
NONSTOP_TSC(see40fb1715commit) which matches INVARIANT TSC. [VR]
Thank you for reviewing. Will fix it.Quoted 8 lines
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
[VR]
Yes, on every VM resume, including migration. After migration we also need
to recalculate scale and adjust offset.
3)0xFFFFFFFFis the value for invalid source of reference time?
[VR] Yes, on boot-up. In this case guest will go with PMTimer (not sure about HPET but I can check). But if we set sequence to0xFFFFFFFFafter migration - it's probably will not work."Reference TSC during Save and Restore and Migration
Quoted 10 lines
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."Why it would not/does not work after migration?
what exactly do we heed the reference TSC for? the reference counter alone works great and it seems that there is a lot of trouble and crash possibilities involved with the referece tsc.
Quoted 8 lines
[VR]
Because it is incredibly light and fast.
The simple test which calls QueryPerformanceCounter in a loop 10 millions times gives we the following results:PMTimer 32269 ms HPET 38466 ms Ref Count 6499 ms iTSC 1169 ms
is the ref_count with local_irq_disable or preempt_disable?
Peter
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 89 lines · Peter Lieven
Quoted 79 lines · Vadim Rozenfeld
----- Original Message -----
From: "Peter Lieven" <[email protected]>
To: "Marcelo Tosatti" <[email protected]>
Cc: "Vadim Rozenfeld" <[email protected]>, [email protected], [email protected], [email protected]
Sent: Thursday, May 23, 2013 4:18:55 PM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSCQuoted 55 lines · Marcelo Tosatti
Quoted 43 lines · Vadim Rozenfeld
----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Wednesday, May 22, 2013 10:50:46 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSCQuoted 24 lines · Vadim Rozenfeld
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;1) You want
NONSTOP_TSC(see40fb1715commit) which matches INVARIANT TSC. [VR]
Thank you for reviewing. Will fix it.Quoted 8 lines
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
[VR]
Yes, on every VM resume, including migration. After migration we also need
to recalculate scale and adjust offset.
3)0xFFFFFFFFis the value for invalid source of reference time?
[VR] Yes, on boot-up. In this case guest will go with PMTimer (not sure about HPET but I can check). But if we set sequence to0xFFFFFFFFafter migration - it's probably will not work."Reference TSC during Save and Restore and Migration
Quoted 10 lines
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."Why it would not/does not work after migration?
what exactly do we heed the reference TSC for? the reference counter alone works great and it seems that there is a lot of trouble and crash possibilities involved with the referece tsc.
Quoted 8 lines
[VR]
Because it is incredibly light and fast.
The simple test which calls QueryPerformanceCounter in a loop 10 millions times gives we the following results:PMTimer 32269 ms HPET 38466 ms Ref Count 6499 ms iTSC 1169 ms
Quoted 2 lines
is the
ref_countwithlocal_irq_disableorpreempt_disable?
irq disabling cannot account for such big difference.
--
Gleb.
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
In reply to Peter Lieven----- Original Message -----
From: "Peter Lieven" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: "Marcelo Tosatti" <[email protected]>, [email protected], [email protected], [email protected]
Sent: Thursday, May 23, 2013 10:44:14 PM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 79 lines · Vadim Rozenfeld
----- Original Message -----
From: "Peter Lieven" <[email protected]>
To: "Marcelo Tosatti" <[email protected]>
Cc: "Vadim Rozenfeld" <[email protected]>, [email protected], [email protected], [email protected]
Sent: Thursday, May 23, 2013 4:18:55 PM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSCQuoted 55 lines · Marcelo Tosatti
Quoted 43 lines · Vadim Rozenfeld
----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Wednesday, May 22, 2013 10:50:46 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSCQuoted 24 lines · Vadim Rozenfeld
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;1) You want
NONSTOP_TSC(see40fb1715commit) which matches INVARIANT TSC. [VR]
Thank you for reviewing. Will fix it.Quoted 8 lines
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
[VR]
Yes, on every VM resume, including migration. After migration we also need
to recalculate scale and adjust offset.
3)0xFFFFFFFFis the value for invalid source of reference time?
[VR] Yes, on boot-up. In this case guest will go with PMTimer (not sure about HPET but I can check). But if we set sequence to0xFFFFFFFFafter migration - it's probably will not work."Reference TSC during Save and Restore and Migration
Quoted 10 lines
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."Why it would not/does not work after migration?
what exactly do we heed the reference TSC for? the reference counter alone works great and it seems that there is a lot of trouble and crash possibilities involved with the referece tsc.
Quoted 8 lines
[VR]
Because it is incredibly light and fast.
The simple test which calls QueryPerformanceCounter in a loop 10 millions times gives we the following results:PMTimer 32269 ms HPET 38466 ms Ref Count 6499 ms iTSC 1169 ms
is the ref_count with local_irq_disable or preempt_disable? [VR]local_irq_disable
Peter
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
In reply to Marcelo TosattiQuoted 55 lines · Marcelo Tosatti
Quoted 43 lines · Vadim Rozenfeld
----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Wednesday, May 22, 2013 10:50:46 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSCQuoted 24 lines · Vadim Rozenfeld
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;1) You want
NONSTOP_TSC(see40fb1715commit) which matches INVARIANT TSC. [VR]
Thank you for reviewing. Will fix it.Quoted 8 lines
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
[VR]
Yes, on every VM resume, including migration. After migration we also need
to recalculate scale and adjust offset.
3)0xFFFFFFFFis the value for invalid source of reference time?
[VR] Yes, on boot-up. In this case guest will go with PMTimer (not sure about HPET but I can check). But if we set sequence to0xFFFFFFFFafter migration - it's probably will not work."Reference TSC during Save and Restore and Migration
Quoted 9 lines
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."Why it would not/does not work after migration?
Please read the whole discussion, we talked about it already. We definitely do not want to fall back to PM timer either, we want to use reference counter instead.
--
Gleb.
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 7 lines · Gleb Natapov
Quoted 7 lines
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."
Quoted 5 lines
Quoted 2 lines
Why it would not/does not work after migration?
Please read the whole discussion, we talked about it already. We definitely do not want to fall back to PM timer either, we want to use reference counter instead.
Case 1) On migration of TSC page enabled Windows guest, from invariant TSC host, to non-invariant TSC host, Windows guests fallback to PMTimer
and not to reference timer via MSR.
This is suboptimal because pmtimer emulation is excessively slow.
Is there a better option?
Case 2)
Reference timer (via MSR) support is interesting for the case of non invariant TSC host.
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 14 lines · Marcelo Tosatti
Quoted 7 lines · Gleb Natapov
Quoted 7 lines
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."Quoted 5 lines
Quoted 2 lines
Why it would not/does not work after migration?
Please read the whole discussion, we talked about it already. We definitely do not want to fall back to PM timer either, we want to use reference counter instead.
Quoted 8 lines
Case 1) On migration of TSC page enabled Windows guest, from invariant TSC host, to non-invariant TSC host, Windows guests fallback to PMTimer
and not to reference timer via MSR.This is suboptimal because pmtimer emulation is excessively slow.
Is there a better option?
If setting TscSequence to zero makes Windows fall back to the MSR this is a better option.
Quoted 3 lines
Case 2)
Reference timer (via MSR) support is interesting for the case of non invariant TSC host.
--
Gleb.
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
----- Original Message -----
From: "Gleb Natapov" <[email protected]>
To: "Marcelo Tosatti" <[email protected]>
Cc: "Vadim Rozenfeld" <[email protected]>, [email protected], [email protected]
Sent: Friday, May 24, 2013 1:31:10 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 14 lines · Marcelo Tosatti
Quoted 7 lines · Gleb Natapov
Quoted 7 lines
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."Quoted 5 lines
Quoted 2 lines
Why it would not/does not work after migration?
Please read the whole discussion, we talked about it already. We definitely do not want to fall back to PM timer either, we want to use reference counter instead.
Quoted 8 lines
Case 1) On migration of TSC page enabled Windows guest, from invariant TSC host, to non-invariant TSC host, Windows guests fallback to PMTimer
and not to reference timer via MSR.This is suboptimal because pmtimer emulation is excessively slow.
Is there a better option?
If setting TscSequence to zero makes Windows fall back to the MSR this is a better option.
+1
This is why MS has two different mechanisms:
iTSC as a primary, reference counters as a fall-back.
Quoted 3 lines
Case 2)
Reference timer (via MSR) support is interesting for the case of non invariant TSC host.
--
Gleb.
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 8 lines · Vadim Rozenfeld
Quoted 2 lines
Is there a better option?
If setting TscSequence to zero makes Windows fall back to the MSR this is a better option.
+1
This is why MS has two different mechanisms:
iTSC as a primary, reference counters as a fall-back.
Ok, is it documented that transition
iTSC valid (Sequence != 0 and != 0xFFFFFFFF) ->
iTSC not valid but ref MSR valid (Sequence = 0),
is a valid transition?
It was not obvious for me. Can you point to documentation?
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 10 lines · Marcelo Tosatti
Quoted 8 lines · Vadim Rozenfeld
Quoted 2 lines
Is there a better option?
If setting TscSequence to zero makes Windows fall back to the MSR this is a better option.
+1
This is why MS has two different mechanisms:
iTSC as a primary, reference counters as a fall-back.
Quoted 7 lines
Ok, is it documented that transition
iTSC valid (Sequence != 0 and !=
0xFFFFFFFF) ->
iTSC not valid but ref MSR valid (Sequence = 0),is a valid transition?
Yes, it's true.
Quoted 3 lines
It was not obvious for me. Can you point to documentation?
Hypervisor Functional Specification v2.0a: For Windows Server 2008 R2
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=18673
"15.4.3.3 Reference TSC during Save/Restore and Migration
To address migration scenarios to physical platforms which do not support iTSC, the TscSequence field is used. In the event a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of 0x0, which directs the guest operating system to fall back to a different clock source (the virtual PM timer)."
Now what the virtual PM timer is - if hypervisor provides PM Timer assist support (HvPartitionPropertyPmTimerAssist partition property), it will use partition reference counters to calculate PM Timer value. If partition has no HvPartitionPropertyPmTimerAssist - guest will use reference counters MSR directly.
Currently we don't support PM timer assist, so TscSequence 0x0 means fallback to reference counters.
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
In reply to Marcelo Tosatti----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Thursday, May 23, 2013 7:23:30 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 43 lines · Vadim Rozenfeld
----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Wednesday, May 22, 2013 10:50:46 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSCQuoted 24 lines · Vadim Rozenfeld
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;1) You want
NONSTOP_TSC(see40fb1715commit) which matches INVARIANT TSC. [VR]
Thank you for reviewing. Will fix it.
Quoted 8 lines
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
[VR]
Yes, on every VM resume, including migration. After migration we also need
to recalculate scale and adjust offset.
3)0xFFFFFFFFis the value for invalid source of reference time?
[VR] Yes, on boot-up. In this case guest will go with PMTimer (not sure about HPET but I can check). But if we set sequence to0xFFFFFFFFafter migration - it's probably will not work.
"Reference TSC during Save and Restore and Migration
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of 0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."
Why it would not/does not work after migration?
[VR]
Because of different frequencies, I think. Hyper-V reference counters and iTSC report performance frequency equal to 10MHz,
which is obviously is not true for PM and HPET timers. Windows calibrates timers on boot-up and you probably have no chance to do it after or during resume.
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 28 lines · Vadim Rozenfeld
Quoted 10 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 6 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;1) You want
NONSTOP_TSC(see40fb1715commit) which matches INVARIANT TSC. [VR]
Thank you for reviewing. Will fix it.Quoted 8 lines
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
[VR]
Yes, on every VM resume, including migration. After migration we also need
to recalculate scale and adjust offset.
3)0xFFFFFFFFis the value for invalid source of reference time?
[VR] Yes, on boot-up. In this case guest will go with PMTimer (not sure about HPET but I can check). But if we set sequence to0xFFFFFFFFafter migration - it's probably will not work."Reference TSC during Save and Restore and Migration
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."
Quoted 7 lines
Why it would not/does not work after migration?
[VR]
Because of different frequencies, I think. Hyper-V reference counters and iTSC report performance frequency equal to 10MHz,
which is obviously is not true for PM and HPET timers.
Windows has to convert from the native hardware clock frequency to internal system frequency, so i don't believe this is a problem.
Quoted 2 lines
Windows calibrates timers on boot-up and you probably have no chance to do it after or during resume.
It is documented as such, it has been designed to fallback to other hardware clock devices. Is there evidence for any problem on fallback?
Earlier you said:
"> What if you put 0xFFFFFFFF as a sequence? Or is this another case where
Quoted 2 lines
the spec is wrong.
it will use PMTimer (maybe HPET if you have it) if you specify it on VM's start up. But I'm not sure if it will work if you migrate from TSC or reference counter to 0xFFFFFFFF
"
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
----- Original Message -----
From: "Marcelo Tosatti" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected]
Sent: Thursday, May 23, 2013 11:47:46 PM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Quoted 28 lines · Vadim Rozenfeld
Quoted 10 lines
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 6 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;1) You want
NONSTOP_TSC(see40fb1715commit) which matches INVARIANT TSC. [VR]
Thank you for reviewing. Will fix it.Quoted 8 lines
2) TscSequence should increase?
"This field serves as a sequence number that is incremented whenever..."
[VR]
Yes, on every VM resume, including migration. After migration we also need
to recalculate scale and adjust offset.
3)0xFFFFFFFFis the value for invalid source of reference time?
[VR] Yes, on boot-up. In this case guest will go with PMTimer (not sure about HPET but I can check). But if we set sequence to0xFFFFFFFFafter migration - it's probably will not work."Reference TSC during Save and Restore and Migration
To address migration scenarios to physical platforms that do not support iTSC, the TscSequence field is used. In the event that a guest partition is migrated from an iTSC capable host to a non-iTSC capable host, the hypervisor sets TscSequence to the special value of
0xFFFFFFFF, which directs the guest operating system to fall back to a different clock source (for example, the virtual PM timer)."
Quoted 7 lines
Why it would not/does not work after migration?
[VR]
Because of different frequencies, I think. Hyper-V reference counters and iTSC report performance frequency equal to 10MHz,
which is obviously is not true for PM and HPET timers.
Windows has to convert from the native hardware clock frequency to internal system frequency, so i don't believe this is a problem.
Quoted 2 lines
Windows calibrates timers on boot-up and you probably have no chance to do it after or during resume.
It is documented as such, it has been designed to fallback to other hardware clock devices. Is there evidence for any problem on fallback?
Earlier you said:
"> What if you put 0xFFFFFFFF as a sequence? Or is this another case where
Quoted 2 lines
the spec is wrong.
it will use PMTimer (maybe HPET if you have it) if you specify it on VM's start up. But I'm not sure if it will work if you migrate from TSC or reference counter to 0xFFFFFFFF
"
On startup, not after migration, when you migrate to host w/o iTSC and/or reference counters support.
Paolo Bonzini
maintainerRe: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
In reply to Vadim RozenfeldIl 19/05/2013 09:06, Vadim Rozenfeld ha scritto:
Quoted 24 lines
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;
Thinking more of migration, could we increment whatever sequence value we found (or better, do (x|3)+2 to skip over 0 and 0xFFFFFFFF), instead of forcing it to 1?
Add HV_X64_MSR_REFERENCE_TSC to msrs_to_save, and migration should just work.
Paolo
Quoted 7 lines
arch/x86/kvm/x86.c +3
-0+ tsc_ref.TscScale = + ((10000LL <<32 ) / vcpu->arch.virtual_tsc_khz) <<32 ; + tsc_ref.TscOffset =0 ;if (__copy_to_user ((void __user *)addr, &tsc_ref,sizeof (tsc_ref)))return 1 ;mark_page_dirty (kvm, gfn);
Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
----- Original Message -----
From: "Paolo Bonzini" <[email protected]>
To: "Vadim Rozenfeld" <[email protected]>
Cc: [email protected], [email protected], [email protected], [email protected]
Sent: Friday, May 24, 2013 2:44:50 AM
Subject: Re: [RFC PATCH v2 2/2] add support for Hyper-V invariant TSC
Il 19/05/2013 09:06, Vadim Rozenfeld ha scritto:
Quoted 24 lines
The following patch allows to activate a partition reference time enlightenment that is based on the host platform's support for an Invariant Time Stamp Counter (iTSC).
NOTE: This code will survive migration due to lack of VM stop/resume handlers, when offset, scale and sequence should be readjusted.--- arch/x86/kvm/x86.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)arch/x86/kvm/x86.c +0
-1@@ -1838,7 +1838,6 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)u64 gfn;unsigned long addr;HV_REFERENCE_TSC_PAGE tsc_ref; - tsc_ref.TscSequence =0 ;if (!(data &HV_X64_MSR_TSC_REFERENCE_ENABLE )) { kvm->arch.hv_tsc_page = data;break ;
arch/x86/kvm/x86.c static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) · line 1851
Quoted 5 lines
arch/x86/kvm/x86.c +2
-0@@ -1848,6 +1847,11 @@ static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data) HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT);if (kvm_is_error_hva (addr))return 1 ; + tsc_ref.TscSequence = +boot_cpu_has (X86_FEATURE_CONSTANT_TSC ) ?1 :0 ;
Thinking more of migration, could we increment whatever sequence value we found (or better, do (x|3)+2 to skip over 0 and 0xFFFFFFFF), instead of forcing it to 1?
[VR]
Yes, it should work.
We need to keep sequence between 1 and 0xFFFFFFFF and increment it every time the VM was migrated or paused/resumed.
Add HV_X64_MSR_REFERENCE_TSC to msrs_to_save, and migration should just work.
Paolo
Quoted 7 lines
arch/x86/kvm/x86.c +3
-0+ tsc_ref.TscScale = + ((10000LL <<32 ) / vcpu->arch.virtual_tsc_khz) <<32 ; + tsc_ref.TscOffset =0 ;if (__copy_to_user ((void __user *)addr, &tsc_ref,sizeof (tsc_ref)))return 1 ;mark_page_dirty (kvm, gfn);