Skip to content

Commit

Permalink
vm: calc_ns_per_tsc: Fix invariant TSC frequency
Browse files Browse the repository at this point in the history
VMware Fusion Version 8.5.10 (7527438) returns zero for it.

Change-Id: I75c5ad9e7feff3df0887a1675b6e338182202e9f
  • Loading branch information
masamichitakagi committed Dec 2, 2019
1 parent 8f41b8e commit 4f6386b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions linux/driver/smp/arch/x86_64/smp-arch-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 4f6386b

Please sign in to comment.