[PATCH] x86/vmware: avoid TSC recalibration

Subsystems: the rest, vmware hypervisor interface, x86 architecture (32-bit and 64-bit)

STALE2010d LANDED

Landed in mainline as 0b4a285e2c65 on 2021-03-28.

3 messages, 2 authors, 2021-03-15 · open the first message on its own page

[PATCH] x86/vmware: avoid TSC recalibration

From: Alexey Makhalov <hidden>
Date: 2021-01-05 01:05:05

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

Signed-off-by: Alexey Makhalov <redacted>
---
 arch/x86/kernel/cpu/vmware.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
index c6ede3b3d302..83164110ccc5 100644
--- a/arch/x86/kernel/cpu/vmware.c
+++ b/arch/x86/kernel/cpu/vmware.c
@@ -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)
-- 
2.11.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH] x86/vmware: avoid TSC recalibration

From: Vitaly Kuznetsov <vkuznets@redhat.com>
Date: 2021-01-05 13:07:57

Alexey Makhalov [off-list ref] writes:
quoted hunk
When TSC frequency is known (retrieved from hypervisor), we should skip
TSC refined calibration by setting X86_FEATURE_TSC_KNOWN_FREQ.

Signed-off-by: Alexey Makhalov <redacted>
---
 arch/x86/kernel/cpu/vmware.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
index c6ede3b3d302..83164110ccc5 100644
--- a/arch/x86/kernel/cpu/vmware.c
+++ b/arch/x86/kernel/cpu/vmware.c
@@ -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.

-- 
Vitaly

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH] x86/vmware: avoid TSC recalibration

From: Alexey Makhalov <hidden>
Date: 2021-03-15 22:40:41

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
On Jan 5, 2021, at 5:06 AM, Vitaly Kuznetsov [off-list ref] wrote:

Alexey Makhalov [off-list ref] writes:
quoted
When TSC frequency is known (retrieved from hypervisor), we should skip
TSC refined calibration by setting X86_FEATURE_TSC_KNOWN_FREQ.

Signed-off-by: Alexey Makhalov <redacted>
---
arch/x86/kernel/cpu/vmware.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
index c6ede3b3d302..83164110ccc5 100644
--- a/arch/x86/kernel/cpu/vmware.c
+++ b/arch/x86/kernel/cpu/vmware.c
@@ -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.

-- 
Vitaly
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help