RE: [PATCH 1/1] X86: Hyper-V: Get the local APIC timer frequency from the hypervisor
> -Original Message- > From: Jan Beulich [mailto:jbeul...@suse.com] > Sent: Tuesday, August 27, 2013 12:26 AM > To: KY Srinivasan > Cc: o...@aepfle.de; a...@canonical.com; x...@kernel.org; > de...@linuxdriverproject.org; gre...@linuxfoundation.org; > jasow...@redhat.com; linux-kernel@vger.kernel.org; h...@zytor.com > Subject: Re: [PATCH 1/1] X86: Hyper-V: Get the local APIC timer frequency from > the hypervisor > > >>> On 27.08.13 at 01:42, "K. Y. Srinivasan" wrote: > > Hyper-V supports a mechanism for retrieving the local API frequency. > > "APIC"? > > > @@ -27,6 +27,13 @@ > > #define HV_X64_MSR_VP_RUNTIME_AVAILABLE(1 << 0) > > /* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/ > > #define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE(1 << 1) > > + > > +/* Local APIC timer frequency MSR (HV_X64_MSR_APIC_FREQUENCY) is > available */ > > +#define HV_X64_MSR_APIC_FREQUENCY_AVAILABLE (1 << 11) > > + > > +/* TSC frequency MSR (HV_X64_MSR_TSC_FREQUENCY) is available */ > > +#define HV_X64_MSR_TSC_FREQUENCY_AVAILABLE (1 << 11) > > Are these two really the same bit? If so, why two different names? > > > @@ -136,6 +143,12 @@ > > /* MSR used to read the per-partition time reference counter */ > > #define HV_X64_MSR_TIME_REF_COUNT 0x4020 > > > > +/* MSR used to retrive the TSC frequency */ > > +#define HV_X64_MSR_TSC_FREQUENCY 0x4022 > > + > > +/* MSR used to retrive the local APIC timer frequency */ > > +#define HV_X64_MSR_APIC_FREQUENCY 0x4023 > > "retrieve" (twice)? > > > @@ -76,6 +77,22 @@ static void __init ms_hyperv_init_platform(void) > > printk(KERN_INFO "HyperV: features 0x%x, hints 0x%x\n", > >ms_hyperv.features, ms_hyperv.hints); > > > > + if (ms_hyperv.features & HV_X64_MSR_APIC_FREQUENCY_AVAILABLE) { > > + /* > > +* There is no need to calibrate APIC timer frequency; > > +* nor is there a need to calibrate timer. > > +*/ > > + legacy_pic = _legacy_pic; > > This clearly disables more than just the calibration, so the comment > may be misleading to future readers. > > > + > > + /* > > +* Get the APIC frequency. > > +*/ > > + rdmsrl(HV_X64_MSR_APIC_FREQUENCY, > lapic_timer_frequency); > > + lapic_timer_frequency /= HZ; > > Is this safe? I.e. are the high 32 bits of the MSR guaranteed to > be zero, now and forever? > > > + printk(KERN_INFO "HyperV: LAPIC Timer Frequency: 0x%x\n", > > + lapic_timer_frequency); > > As a minor note, I generally recommend using %#x as being one > byte shorter than the spelled out 0x%x. > > Jan Thanks Jan. I will fix the issues you have pointed out and resubmit the patch. Regards, K. Y -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/1] X86: Hyper-V: Get the local APIC timer frequency from the hypervisor
>>> On 27.08.13 at 01:42, "K. Y. Srinivasan" wrote: > Hyper-V supports a mechanism for retrieving the local API frequency. "APIC"? > @@ -27,6 +27,13 @@ > #define HV_X64_MSR_VP_RUNTIME_AVAILABLE (1 << 0) > /* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/ > #define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE (1 << 1) > + > +/* Local APIC timer frequency MSR (HV_X64_MSR_APIC_FREQUENCY) is available */ > +#define HV_X64_MSR_APIC_FREQUENCY_AVAILABLE (1 << 11) > + > +/* TSC frequency MSR (HV_X64_MSR_TSC_FREQUENCY) is available */ > +#define HV_X64_MSR_TSC_FREQUENCY_AVAILABLE (1 << 11) Are these two really the same bit? If so, why two different names? > @@ -136,6 +143,12 @@ > /* MSR used to read the per-partition time reference counter */ > #define HV_X64_MSR_TIME_REF_COUNT0x4020 > > +/* MSR used to retrive the TSC frequency */ > +#define HV_X64_MSR_TSC_FREQUENCY 0x4022 > + > +/* MSR used to retrive the local APIC timer frequency */ > +#define HV_X64_MSR_APIC_FREQUENCY0x4023 "retrieve" (twice)? > @@ -76,6 +77,22 @@ static void __init ms_hyperv_init_platform(void) > printk(KERN_INFO "HyperV: features 0x%x, hints 0x%x\n", > ms_hyperv.features, ms_hyperv.hints); > > + if (ms_hyperv.features & HV_X64_MSR_APIC_FREQUENCY_AVAILABLE) { > + /* > + * There is no need to calibrate APIC timer frequency; > + * nor is there a need to calibrate timer. > + */ > + legacy_pic = _legacy_pic; This clearly disables more than just the calibration, so the comment may be misleading to future readers. > + > + /* > + * Get the APIC frequency. > + */ > + rdmsrl(HV_X64_MSR_APIC_FREQUENCY, lapic_timer_frequency); > + lapic_timer_frequency /= HZ; Is this safe? I.e. are the high 32 bits of the MSR guaranteed to be zero, now and forever? > + printk(KERN_INFO "HyperV: LAPIC Timer Frequency: 0x%x\n", > + lapic_timer_frequency); As a minor note, I generally recommend using %#x as being one byte shorter than the spelled out 0x%x. Jan -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/1] X86: Hyper-V: Get the local APIC timer frequency from the hypervisor
On 27.08.13 at 01:42, K. Y. Srinivasan k...@microsoft.com wrote: Hyper-V supports a mechanism for retrieving the local API frequency. APIC? @@ -27,6 +27,13 @@ #define HV_X64_MSR_VP_RUNTIME_AVAILABLE (1 0) /* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/ #define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE (1 1) + +/* Local APIC timer frequency MSR (HV_X64_MSR_APIC_FREQUENCY) is available */ +#define HV_X64_MSR_APIC_FREQUENCY_AVAILABLE (1 11) + +/* TSC frequency MSR (HV_X64_MSR_TSC_FREQUENCY) is available */ +#define HV_X64_MSR_TSC_FREQUENCY_AVAILABLE (1 11) Are these two really the same bit? If so, why two different names? @@ -136,6 +143,12 @@ /* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT0x4020 +/* MSR used to retrive the TSC frequency */ +#define HV_X64_MSR_TSC_FREQUENCY 0x4022 + +/* MSR used to retrive the local APIC timer frequency */ +#define HV_X64_MSR_APIC_FREQUENCY0x4023 retrieve (twice)? @@ -76,6 +77,22 @@ static void __init ms_hyperv_init_platform(void) printk(KERN_INFO HyperV: features 0x%x, hints 0x%x\n, ms_hyperv.features, ms_hyperv.hints); + if (ms_hyperv.features HV_X64_MSR_APIC_FREQUENCY_AVAILABLE) { + /* + * There is no need to calibrate APIC timer frequency; + * nor is there a need to calibrate timer. + */ + legacy_pic = null_legacy_pic; This clearly disables more than just the calibration, so the comment may be misleading to future readers. + + /* + * Get the APIC frequency. + */ + rdmsrl(HV_X64_MSR_APIC_FREQUENCY, lapic_timer_frequency); + lapic_timer_frequency /= HZ; Is this safe? I.e. are the high 32 bits of the MSR guaranteed to be zero, now and forever? + printk(KERN_INFO HyperV: LAPIC Timer Frequency: 0x%x\n, + lapic_timer_frequency); As a minor note, I generally recommend using %#x as being one byte shorter than the spelled out 0x%x. Jan -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
RE: [PATCH 1/1] X86: Hyper-V: Get the local APIC timer frequency from the hypervisor
-Original Message- From: Jan Beulich [mailto:jbeul...@suse.com] Sent: Tuesday, August 27, 2013 12:26 AM To: KY Srinivasan Cc: o...@aepfle.de; a...@canonical.com; x...@kernel.org; de...@linuxdriverproject.org; gre...@linuxfoundation.org; jasow...@redhat.com; linux-kernel@vger.kernel.org; h...@zytor.com Subject: Re: [PATCH 1/1] X86: Hyper-V: Get the local APIC timer frequency from the hypervisor On 27.08.13 at 01:42, K. Y. Srinivasan k...@microsoft.com wrote: Hyper-V supports a mechanism for retrieving the local API frequency. APIC? @@ -27,6 +27,13 @@ #define HV_X64_MSR_VP_RUNTIME_AVAILABLE(1 0) /* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/ #define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE(1 1) + +/* Local APIC timer frequency MSR (HV_X64_MSR_APIC_FREQUENCY) is available */ +#define HV_X64_MSR_APIC_FREQUENCY_AVAILABLE (1 11) + +/* TSC frequency MSR (HV_X64_MSR_TSC_FREQUENCY) is available */ +#define HV_X64_MSR_TSC_FREQUENCY_AVAILABLE (1 11) Are these two really the same bit? If so, why two different names? @@ -136,6 +143,12 @@ /* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT 0x4020 +/* MSR used to retrive the TSC frequency */ +#define HV_X64_MSR_TSC_FREQUENCY 0x4022 + +/* MSR used to retrive the local APIC timer frequency */ +#define HV_X64_MSR_APIC_FREQUENCY 0x4023 retrieve (twice)? @@ -76,6 +77,22 @@ static void __init ms_hyperv_init_platform(void) printk(KERN_INFO HyperV: features 0x%x, hints 0x%x\n, ms_hyperv.features, ms_hyperv.hints); + if (ms_hyperv.features HV_X64_MSR_APIC_FREQUENCY_AVAILABLE) { + /* +* There is no need to calibrate APIC timer frequency; +* nor is there a need to calibrate timer. +*/ + legacy_pic = null_legacy_pic; This clearly disables more than just the calibration, so the comment may be misleading to future readers. + + /* +* Get the APIC frequency. +*/ + rdmsrl(HV_X64_MSR_APIC_FREQUENCY, lapic_timer_frequency); + lapic_timer_frequency /= HZ; Is this safe? I.e. are the high 32 bits of the MSR guaranteed to be zero, now and forever? + printk(KERN_INFO HyperV: LAPIC Timer Frequency: 0x%x\n, + lapic_timer_frequency); As a minor note, I generally recommend using %#x as being one byte shorter than the spelled out 0x%x. Jan Thanks Jan. I will fix the issues you have pointed out and resubmit the patch. Regards, K. Y -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 1/1] X86: Hyper-V: Get the local APIC timer frequency from the hypervisor
Hyper-V supports a mechanism for retrieving the local API frequency.Use this and bypass the calibration code in the kernel. This would allow us to boot the Linux kernel as a "modern VM" on Hyper-V where many of the legacy devices (such as PIT) are not emulated. I would like to thank Olaf Hering , Jan Beulich and H. Peter Anvin for their help in this effort. Signed-off-by: K. Y. Srinivasan --- arch/x86/include/uapi/asm/hyperv.h | 13 + arch/x86/kernel/cpu/mshyperv.c | 17 + 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h index b80420b..df3d680 100644 --- a/arch/x86/include/uapi/asm/hyperv.h +++ b/arch/x86/include/uapi/asm/hyperv.h @@ -27,6 +27,13 @@ #define HV_X64_MSR_VP_RUNTIME_AVAILABLE(1 << 0) /* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/ #define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE(1 << 1) + +/* Local APIC timer frequency MSR (HV_X64_MSR_APIC_FREQUENCY) is available */ +#define HV_X64_MSR_APIC_FREQUENCY_AVAILABLE (1 << 11) + +/* TSC frequency MSR (HV_X64_MSR_TSC_FREQUENCY) is available */ +#define HV_X64_MSR_TSC_FREQUENCY_AVAILABLE (1 << 11) + /* * Basic SynIC MSRs (HV_X64_MSR_SCONTROL through HV_X64_MSR_EOM * and HV_X64_MSR_SINT0 through HV_X64_MSR_SINT15) available @@ -136,6 +143,12 @@ /* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT 0x4020 +/* MSR used to retrive the TSC frequency */ +#define HV_X64_MSR_TSC_FREQUENCY 0x4022 + +/* MSR used to retrive the local APIC timer frequency */ +#define HV_X64_MSR_APIC_FREQUENCY 0x4023 + /* Define the virtual APIC registers */ #define HV_X64_MSR_EOI 0x4070 #define HV_X64_MSR_ICR 0x4071 diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 71a39f3..0593fd9 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -23,6 +23,7 @@ #include #include #include +#include struct ms_hyperv_info ms_hyperv; EXPORT_SYMBOL_GPL(ms_hyperv); @@ -76,6 +77,22 @@ static void __init ms_hyperv_init_platform(void) printk(KERN_INFO "HyperV: features 0x%x, hints 0x%x\n", ms_hyperv.features, ms_hyperv.hints); + if (ms_hyperv.features & HV_X64_MSR_APIC_FREQUENCY_AVAILABLE) { + /* +* There is no need to calibrate APIC timer frequency; +* nor is there a need to calibrate timer. +*/ + legacy_pic = _legacy_pic; + + /* +* Get the APIC frequency. +*/ + rdmsrl(HV_X64_MSR_APIC_FREQUENCY, lapic_timer_frequency); + lapic_timer_frequency /= HZ; + printk(KERN_INFO "HyperV: LAPIC Timer Frequency: 0x%x\n", + lapic_timer_frequency); + } + if (ms_hyperv.features & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE) clocksource_register_hz(_cs, NSEC_PER_SEC/100); } -- 1.7.4.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 1/1] X86: Hyper-V: Get the local APIC timer frequency from the hypervisor
Hyper-V supports a mechanism for retrieving the local API frequency.Use this and bypass the calibration code in the kernel. This would allow us to boot the Linux kernel as a modern VM on Hyper-V where many of the legacy devices (such as PIT) are not emulated. I would like to thank Olaf Hering o...@aepfle.de, Jan Beulich jbeul...@suse.com and H. Peter Anvin h.peter.an...@intel.com for their help in this effort. Signed-off-by: K. Y. Srinivasan k...@microsoft.com --- arch/x86/include/uapi/asm/hyperv.h | 13 + arch/x86/kernel/cpu/mshyperv.c | 17 + 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/arch/x86/include/uapi/asm/hyperv.h b/arch/x86/include/uapi/asm/hyperv.h index b80420b..df3d680 100644 --- a/arch/x86/include/uapi/asm/hyperv.h +++ b/arch/x86/include/uapi/asm/hyperv.h @@ -27,6 +27,13 @@ #define HV_X64_MSR_VP_RUNTIME_AVAILABLE(1 0) /* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/ #define HV_X64_MSR_TIME_REF_COUNT_AVAILABLE(1 1) + +/* Local APIC timer frequency MSR (HV_X64_MSR_APIC_FREQUENCY) is available */ +#define HV_X64_MSR_APIC_FREQUENCY_AVAILABLE (1 11) + +/* TSC frequency MSR (HV_X64_MSR_TSC_FREQUENCY) is available */ +#define HV_X64_MSR_TSC_FREQUENCY_AVAILABLE (1 11) + /* * Basic SynIC MSRs (HV_X64_MSR_SCONTROL through HV_X64_MSR_EOM * and HV_X64_MSR_SINT0 through HV_X64_MSR_SINT15) available @@ -136,6 +143,12 @@ /* MSR used to read the per-partition time reference counter */ #define HV_X64_MSR_TIME_REF_COUNT 0x4020 +/* MSR used to retrive the TSC frequency */ +#define HV_X64_MSR_TSC_FREQUENCY 0x4022 + +/* MSR used to retrive the local APIC timer frequency */ +#define HV_X64_MSR_APIC_FREQUENCY 0x4023 + /* Define the virtual APIC registers */ #define HV_X64_MSR_EOI 0x4070 #define HV_X64_MSR_ICR 0x4071 diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 71a39f3..0593fd9 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -23,6 +23,7 @@ #include asm/desc.h #include asm/idle.h #include asm/irq_regs.h +#include asm/i8259.h struct ms_hyperv_info ms_hyperv; EXPORT_SYMBOL_GPL(ms_hyperv); @@ -76,6 +77,22 @@ static void __init ms_hyperv_init_platform(void) printk(KERN_INFO HyperV: features 0x%x, hints 0x%x\n, ms_hyperv.features, ms_hyperv.hints); + if (ms_hyperv.features HV_X64_MSR_APIC_FREQUENCY_AVAILABLE) { + /* +* There is no need to calibrate APIC timer frequency; +* nor is there a need to calibrate timer. +*/ + legacy_pic = null_legacy_pic; + + /* +* Get the APIC frequency. +*/ + rdmsrl(HV_X64_MSR_APIC_FREQUENCY, lapic_timer_frequency); + lapic_timer_frequency /= HZ; + printk(KERN_INFO HyperV: LAPIC Timer Frequency: 0x%x\n, + lapic_timer_frequency); + } + if (ms_hyperv.features HV_X64_MSR_TIME_REF_COUNT_AVAILABLE) clocksource_register_hz(hyperv_cs, NSEC_PER_SEC/100); } -- 1.7.4.1 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/