Skip to contentSkip to conversation

x86/vmware: avoid TSC recalibration

PATCH Applied Alexey Makhalov 3 participants 4 messages Jan 5, 2021 – Mar 28, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/vmware: avoid TSC recalibration

When TSC frequency is known (retrieved from hypervisor), we should skip TSC refined calibration by setting X86_FEATURE_TSC_KNOWN_FREQ.

---
 arch/x86/kernel/cpu/vmware.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/cpu/vmware.c +2 -0
index c6ede3b3d302..83164110ccc5 100644
@@ -378,6 +378,8 @@ static void __init vmware_set_capabilities(void)
 {
 	setup_force_cpu_cap(X86_FEATURE_CONSTANT_TSC);
 	setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE);
+	if (vmware_tsc_khz)
+		setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
 	if (vmware_hypercall_mode == CPUID_VMWARE_FEATURES_ECX_VMCALL)
 		setup_force_cpu_cap(X86_FEATURE_VMCALL);
 	else if (vmware_hypercall_mode == CPUID_VMWARE_FEATURES_ECX_VMMCALL)
Signature · 6 lines
2.11.0

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#1 lore raw
Quoted 13 lines · Alexey Makhalov

When TSC frequency is known (retrieved from hypervisor), we should skip TSC refined calibration by setting X86_FEATURE_TSC_KNOWN_FREQ.

---
 arch/x86/kernel/cpu/vmware.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/cpu/vmware.c +0 -0
index c6ede3b3d302..83164110ccc5 100644

arch/x86/kernel/cpu/vmware.c static void __init vmware_set_capabilities(void) · line 385

Quoted 8 lines
arch/x86/kernel/cpu/vmware.c +2 -0
@@ -378,6 +378,8 @@ static void __init vmware_set_capabilities(void)
 {
 	setup_force_cpu_cap(X86_FEATURE_CONSTANT_TSC);
 	setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE);
+	if (vmware_tsc_khz)
+		setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
 	if (vmware_hypercall_mode == CPUID_VMWARE_FEATURES_ECX_VMCALL)
 		setup_force_cpu_cap(X86_FEATURE_VMCALL);
 	else if (vmware_hypercall_mode == CPUID_VMWARE_FEATURES_ECX_VMMCALL)

The same trick is being used in Xen/Jailhouse/KVM code already and Hyper-V overwrites x86_platform.calibrate_tsc/x86_platform.calibrate_cpu hooks to basically achive the same goal. Should we maybe introduce a flag in 'struct hypervisor_x86' or something like that to unify all this?

Just a suggestion.

Signature · 6 lines
Vitaly

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#2 lore raw

Hi Vitaly,

I believe, it is responsibility of each guest code to set X86_FEATURE_TSC_KNOWN_FREQ cap. Regarding VMware guest, there is a case where vmware_tsc_khz is zero (not provided by hypervisor) and TSC frequency should be calculated.

Sorry for late response.

Regards,
—Alexey

Quoted 32 lines · Vitaly Kuznetsov
Quoted 13 lines · Alexey Makhalov

When TSC frequency is known (retrieved from hypervisor), we should skip TSC refined calibration by setting X86_FEATURE_TSC_KNOWN_FREQ.

---
arch/x86/kernel/cpu/vmware.c | 2 ++

1 file changed, 2 insertions(+)
arch/x86/kernel/cpu/vmware.c +0 -0
index c6ede3b3d302..83164110ccc5 100644

arch/x86/kernel/cpu/vmware.c static void __init vmware_set_capabilities(void) · line 385

Quoted 8 lines
arch/x86/kernel/cpu/vmware.c +2 -0
@@ -378,6 +378,8 @@ static void __init vmware_set_capabilities(void)
 {
 	setup_force_cpu_cap(X86_FEATURE_CONSTANT_TSC);
 	setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE);
+	if (vmware_tsc_khz)
+		setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
 	if (vmware_hypercall_mode == CPUID_VMWARE_FEATURES_ECX_VMCALL)
 		setup_force_cpu_cap(X86_FEATURE_VMCALL);
 	else if (vmware_hypercall_mode == CPUID_VMWARE_FEATURES_ECX_VMMCALL)

The same trick is being used in Xen/Jailhouse/KVM code already and Hyper-V overwrites x86_platform.calibrate_tsc/x86_platform.calibrate_cpu hooks to basically achive the same goal. Should we maybe introduce a flag in 'struct hypervisor_x86' or something like that to unify all this?

Quoted 4 lines

Just a suggestion.

Signature · 1 line
Vitaly

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#3 lore raw

[tip: x86/vmware] x86/vmware: Avoid TSC recalibration when frequency is known

In reply to Alexey Makhalov
The following commit has been merged into the x86/vmware branch of tip:

The following commit has been merged into the x86/vmware branch of tip:

Commit-ID:     0b4a285e2c65c2c9449c6eccb87298e385213e7b
Gitweb:        https://git.kernel.org/tip/0b4a285e2c65c2c9449c6eccb87298e385213e7b
Author:        Alexey Makhalov <[email protected]>
AuthorDate:    Mon, 04 Jan 2021 16:47:52 -08:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Sun, 28 Mar 2021 21:11:43 +02:00

x86/vmware: Avoid TSC recalibration when frequency is known

When the TSC frequency is known because it is retrieved from the hypervisor, skip TSC refined calibration by setting X86_FEATURE_TSC_KNOWN_FREQ.

---
 arch/x86/kernel/cpu/vmware.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kernel/cpu/vmware.c +2 -0
index c6ede3b..8316411 100644
@@ -378,6 +378,8 @@ static void __init vmware_set_capabilities(void)
 {
 	setup_force_cpu_cap(X86_FEATURE_CONSTANT_TSC);
 	setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE);
+	if (vmware_tsc_khz)
+		setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
 	if (vmware_hypercall_mode == CPUID_VMWARE_FEATURES_ECX_VMCALL)
 		setup_force_cpu_cap(X86_FEATURE_VMCALL);
 	else if (vmware_hypercall_mode == CPUID_VMWARE_FEATURES_ECX_VMMCALL)