From 4f6386b050cbfc01191e21abbfe47966e3719558 Mon Sep 17 00:00:00 2001 From: Masamichi Takagi Date: Mon, 21 Oct 2019 14:14:37 +0900 Subject: [PATCH] vm: calc_ns_per_tsc: Fix invariant TSC frequency VMware Fusion Version 8.5.10 (7527438) returns zero for it. Change-Id: I75c5ad9e7feff3df0887a1675b6e338182202e9f --- .../driver/smp/arch/x86_64/smp-arch-driver.c | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/linux/driver/smp/arch/x86_64/smp-arch-driver.c b/linux/driver/smp/arch/x86_64/smp-arch-driver.c index 49934a5c..35bdd5a1 100644 --- a/linux/driver/smp/arch/x86_64/smp-arch-driver.c +++ b/linux/driver/smp/arch/x86_64/smp-arch-driver.c @@ -362,18 +362,27 @@ unsigned long calc_ns_per_tsc(void) asm volatile("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a" (op)); - if (edx & (1 << 8)) { - /* Invariant TSC supported */ - /* ratio (100MHz) */ - rdmsrl(MSR_PLATFORM_INFO, msr); - ratio = (msr >> 8) & 0xFF; - - ret = 10000 / ratio; + /* Is Invariant TSC supported? */ + if (!(edx & (1 << 8))) { + goto not_found; } - else { - ret = 1000000000L / tsc_khz; + + rdmsrl(MSR_PLATFORM_INFO, msr); + ratio = (msr >> 8) & 0xFF; + + /* Zero is returned for some virtual machines */ + if (ratio == 0) { + goto not_found; } + /* Unit of ratio is 100MHz */ + ret = 10000 / ratio; + + goto out; + +not_found: + ret = 1000000000L / tsc_khz; +out: return ret; }