Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eca0cd0

Browse files
Alok KatariaH. Peter Anvin
authored andcommitted
x86: Add a synthetic TSC_RELIABLE feature bit.
Impact: Changes timebase calibration on Vmware. Use the synthetic TSC_RELIABLE bit to workaround virtualization anomalies. Virtual TSCs can be kept nearly in sync, but because the virtual TSC offset is set by software, it's not perfect. So, the TSC synchronization test can fail. Even then the TSC can be used as a clocksource since the VMware platform exports a reliable TSC to the guest for timekeeping purposes. Use this bit to check if we need to skip the TSC sync checks. Along with this also set the CONSTANT_TSC bit when on VMware, since we still want to use TSC as clocksource on VM running over hardware which has unsynchronized TSC's (opteron's), since the hypervisor will take care of providing consistent TSC to the guest. Signed-off-by: Alok N Kataria <[email protected]> Signed-off-by: Dan Hecht <[email protected]> Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 88b094f commit eca0cd0

4 files changed

Lines changed: 36 additions & 2 deletions

File tree

arch/x86/include/asm/vmware.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222

2323
extern unsigned long vmware_get_tsc_khz(void);
2424
extern int vmware_platform(void);
25+
extern void vmware_set_feature_bits(struct cpuinfo_x86 *c);
2526

2627
#endif

arch/x86/kernel/cpu/hypervisor.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,17 @@ unsigned long get_hypervisor_tsc_freq(void)
4141
return 0;
4242
}
4343

44+
static inline void __cpuinit
45+
hypervisor_set_feature_bits(struct cpuinfo_x86 *c)
46+
{
47+
if (boot_cpu_data.x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE) {
48+
vmware_set_feature_bits(c);
49+
return;
50+
}
51+
}
52+
4453
void __cpuinit init_hypervisor(struct cpuinfo_x86 *c)
4554
{
4655
detect_hypervisor_vendor(c);
56+
hypervisor_set_feature_bits(c);
4757
}
48-

arch/x86/kernel/cpu/vmware.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,21 @@ unsigned long vmware_get_tsc_khz(void)
8686
BUG_ON(!vmware_platform());
8787
return __vmware_get_tsc_khz();
8888
}
89+
90+
/*
91+
* VMware hypervisor takes care of exporting a reliable TSC to the guest.
92+
* Still, due to timing difference when running on virtual cpus, the TSC can
93+
* be marked as unstable in some cases. For example, the TSC sync check at
94+
* bootup can fail due to a marginal offset between vcpus' TSCs (though the
95+
* TSCs do not drift from each other). Also, the ACPI PM timer clocksource
96+
* is not suitable as a watchdog when running on a hypervisor because the
97+
* kernel may miss a wrap of the counter if the vcpu is descheduled for a
98+
* long time. To skip these checks at runtime we set these capability bits,
99+
* so that the kernel could just trust the hypervisor with providing a
100+
* reliable virtual TSC that is suitable for timekeeping.
101+
*/
102+
void __cpuinit vmware_set_feature_bits(struct cpuinfo_x86 *c)
103+
{
104+
set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
105+
set_cpu_cap(c, X86_FEATURE_TSC_RELIABLE);
106+
}

arch/x86/kernel/tsc_sync.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ void __cpuinit check_tsc_sync_source(int cpu)
108108
if (unsynchronized_tsc())
109109
return;
110110

111+
if (boot_cpu_has(X86_FEATURE_TSC_RELIABLE)) {
112+
printk(KERN_INFO
113+
"Skipping synchronization checks as TSC is reliable.\n");
114+
return;
115+
}
116+
111117
printk(KERN_INFO "checking TSC synchronization [CPU#%d -> CPU#%d]:",
112118
smp_processor_id(), cpu);
113119

@@ -161,7 +167,7 @@ void __cpuinit check_tsc_sync_target(void)
161167
{
162168
int cpus = 2;
163169

164-
if (unsynchronized_tsc())
170+
if (unsynchronized_tsc() || boot_cpu_has(X86_FEATURE_TSC_RELIABLE))
165171
return;
166172

167173
/*

0 commit comments

Comments
 (0)