[azure][PATCH 2/2] x86/hyperv: Read TSC frequency from a synthetic MSR
Marcelo Henrique Cerri
marcelo.cerri at canonical.com
Thu Sep 7 19:06:52 UTC 2017
From: Vitaly Kuznetsov <vkuznets at redhat.com>
BugLink: http://bugs.launchpad.net/bugs/1715489
It was found that SMI_TRESHOLD of 50000 is not enough for Hyper-V
guests in nested environment and falling back to counting jiffies
is not an option for Gen2 guests as they don't have PIT. As Hyper-V
provides TSC frequency in a synthetic MSR we can just use this information
instead of doing a error prone calibration.
Reported-and-tested-by: Ladi Prosek <lprosek at redhat.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets at redhat.com>
Signed-off-by: Thomas Gleixner <tglx at linutronix.de>
Cc: Stephen Hemminger <sthemmin at microsoft.com>
Cc: Haiyang Zhang <haiyangz at microsoft.com>
Cc: Jork Loeser <jloeser at microsoft.com>
Cc: devel at linuxdriverproject.org
Cc: "K. Y. Srinivasan" <kys at microsoft.com>
Link: http://lkml.kernel.org/r/20170622100730.18112-3-vkuznets@redhat.com
(cherry picked from commit 71c2a2d0a81f096a2932fccb39a500116fece554)
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri at canonical.com>
---
arch/x86/kernel/cpu/mshyperv.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 884fa7c9f192..42664f944cbc 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -161,6 +161,15 @@ static int hv_nmi_unknown(unsigned int val, struct pt_regs *regs)
}
#endif
+static unsigned long hv_get_tsc_khz(void)
+{
+ unsigned long freq;
+
+ rdmsrl(HV_X64_MSR_TSC_FREQUENCY, freq);
+
+ return freq / 1000;
+}
+
static void __init ms_hyperv_init_platform(void)
{
int hv_host_info_eax;
@@ -199,6 +208,12 @@ static void __init ms_hyperv_init_platform(void)
hv_host_info_edx >> 24, hv_host_info_edx & 0xFFFFFF);
}
+ if (ms_hyperv.features & HV_X64_ACCESS_FREQUENCY_MSRS &&
+ ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {
+ x86_platform.calibrate_tsc = hv_get_tsc_khz;
+ x86_platform.calibrate_cpu = hv_get_tsc_khz;
+ }
+
#ifdef CONFIG_X86_LOCAL_APIC
if (ms_hyperv.features & HV_X64_ACCESS_FREQUENCY_MSRS &&
ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {
--
2.7.4
More information about the kernel-team
mailing list