Skip to contentSkip to conversation

x86/hyperv: Set X86_FEATURE_TSC_KNOWN_FREQ when Hyper-V provides frequency

PATCH Applied [email protected] 4 participants 5 messages Jun 6, 2024 – Aug 23, 2024

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

PATCH 1/1 x86/hyperv: Set X86_FEATURE_TSC_KNOWN_FREQ when Hyper-V provides frequency

From: Michael Kelley <[email protected]>

A Linux guest on Hyper-V gets the TSC frequency from a synthetic MSR, if available. In this case, set X86_FEATURE_TSC_KNOWN_FREQ so that Linux doesn't unnecessarily do refined TSC calibration when setting up the TSC clocksource.

With this change, a message such as this is no longer output during boot when the TSC is used as the clocksource:

[    1.115141] tsc: Refined TSC clocksource calibration: 2918.408 MHz

Furthermore, the guest and host will have exactly the same view of the TSC frequency, which is important for features such as the TSC deadline timer that are emulated by the Hyper-V host.

---
 arch/x86/kernel/cpu/mshyperv.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/kernel/cpu/mshyperv.c +1 -0
index e0fd57a8ba84..c3e38eaf6d2f 100644
@@ -424,6 +424,7 @@ static void __init ms_hyperv_init_platform(void)
 	    ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {
 		x86_platform.calibrate_tsc = hv_get_tsc_khz;
 		x86_platform.calibrate_cpu = hv_get_tsc_khz;
+		setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
 	}
 
 	if (ms_hyperv.priv_high & HV_ISOLATION) {
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 26 lines · On 6/5/2024 7:55 PM, [email protected] wrote:

From: Michael Kelley <[email protected]>

A Linux guest on Hyper-V gets the TSC frequency from a synthetic MSR, if available. In this case, set X86_FEATURE_TSC_KNOWN_FREQ so that Linux doesn't unnecessarily do refined TSC calibration when setting up the TSC clocksource.

With this change, a message such as this is no longer output during boot when the TSC is used as the clocksource:

[    1.115141] tsc: Refined TSC clocksource calibration: 2918.408 MHz

Furthermore, the guest and host will have exactly the same view of the TSC frequency, which is important for features such as the TSC deadline timer that are emulated by the Hyper-V host.

---
  arch/x86/kernel/cpu/mshyperv.c | 1 +
  1 file changed, 1 insertion(+)
arch/x86/kernel/cpu/mshyperv.c +0 -0
index e0fd57a8ba84..c3e38eaf6d2f 100644

arch/x86/kernel/cpu/mshyperv.c static void __init ms_hyperv_init_platform(void) · line 430

Quoted 7 lines
arch/x86/kernel/cpu/mshyperv.c +1 -0
@@ -424,6 +424,7 @@ static void __init ms_hyperv_init_platform(void)
  	    ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {
  		x86_platform.calibrate_tsc = hv_get_tsc_khz;
  		x86_platform.calibrate_cpu = hv_get_tsc_khz;
+		setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
  	}
 
  	if (ms_hyperv.priv_high & HV_ISOLATION) {

LGTM

Signature · 2 lines
Thank you,
Roman
maintainer Applied
#2 lore raw
Quoted 38 lines · Roman Kisel
Quoted 26 lines · On 6/5/2024 7:55 PM, [email protected] wrote:

From: Michael Kelley <[email protected]>

A Linux guest on Hyper-V gets the TSC frequency from a synthetic MSR, if available. In this case, set X86_FEATURE_TSC_KNOWN_FREQ so that Linux doesn't unnecessarily do refined TSC calibration when setting up the TSC clocksource.

With this change, a message such as this is no longer output during boot when the TSC is used as the clocksource:

[    1.115141] tsc: Refined TSC clocksource calibration: 2918.408 MHz

Furthermore, the guest and host will have exactly the same view of the TSC frequency, which is important for features such as the TSC deadline timer that are emulated by the Hyper-V host.

---
  arch/x86/kernel/cpu/mshyperv.c | 1 +
  1 file changed, 1 insertion(+)
arch/x86/kernel/cpu/mshyperv.c +0 -0
index e0fd57a8ba84..c3e38eaf6d2f 100644

arch/x86/kernel/cpu/mshyperv.c static void __init ms_hyperv_init_platform(void) · line 429

Quoted 6 lines
arch/x86/kernel/cpu/mshyperv.c +1 -0
@@ -424,6 +424,7 @@ static void __init ms_hyperv_init_platform(void)
  	    ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {
  		x86_platform.calibrate_tsc = hv_get_tsc_khz;
  		x86_platform.calibrate_cpu = hv_get_tsc_khz;
+		setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
  	}
  	if (ms_hyperv.priv_high & HV_ISOLATION) {

LGTM

Quoted 1 line

Applied to hyperv-fixes. Thanks!

#3 lore raw

From: Wei Liu <[email protected]> Sent: Friday, August 2, 2024 4:50 PM

Quoted 40 lines · Roman Kisel
Quoted 38 lines · On 6/5/2024 7:55 PM, [email protected] wrote:
Quoted 26 lines

From: Michael Kelley <[email protected]>

A Linux guest on Hyper-V gets the TSC frequency from a synthetic MSR, if available. In this case, set X86_FEATURE_TSC_KNOWN_FREQ so that Linux doesn't unnecessarily do refined TSC calibration when setting up the TSC clocksource.

With this change, a message such as this is no longer output during boot when the TSC is used as the clocksource:

[    1.115141] tsc: Refined TSC clocksource calibration: 2918.408 MHz

Furthermore, the guest and host will have exactly the same view of the TSC frequency, which is important for features such as the TSC deadline timer that are emulated by the Hyper-V host.

---
  arch/x86/kernel/cpu/mshyperv.c | 1 +
  1 file changed, 1 insertion(+)
arch/x86/kernel/cpu/mshyperv.c +0 -0
index e0fd57a8ba84..c3e38eaf6d2f 100644

arch/x86/kernel/cpu/mshyperv.c static void __init ms_hyperv_init_platform(void) · line 429

Quoted 6 lines
arch/x86/kernel/cpu/mshyperv.c +1 -0
@@ -424,6 +424,7 @@ static void __init ms_hyperv_init_platform(void)
  	    ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {
  		x86_platform.calibrate_tsc = hv_get_tsc_khz;
  		x86_platform.calibrate_cpu = hv_get_tsc_khz;
+		setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
  	}
  	if (ms_hyperv.priv_high & HV_ISOLATION) {

LGTM

Quoted 3 lines
Quoted 1 line

Applied to hyperv-fixes. Thanks!

Wei --

hyperv-fixes isn't showing this patch, or any of the others that your emails said you applied last Friday. Hence the patches aren't in linux-next either. Did something go awry?

Michael

maintainer
#4 lore raw
Quoted 43 lines · Michael Kelley

From: Wei Liu <[email protected]> Sent: Friday, August 2, 2024 4:50 PM

Quoted 42 lines · Roman Kisel
Quoted 39 lines · On 6/5/2024 7:55 PM, [email protected] wrote:
Quoted 26 lines

From: Michael Kelley <[email protected]>

A Linux guest on Hyper-V gets the TSC frequency from a synthetic MSR, if available. In this case, set X86_FEATURE_TSC_KNOWN_FREQ so that Linux doesn't unnecessarily do refined TSC calibration when setting up the TSC clocksource.

With this change, a message such as this is no longer output during boot when the TSC is used as the clocksource:

[    1.115141] tsc: Refined TSC clocksource calibration: 2918.408 MHz

Furthermore, the guest and host will have exactly the same view of the TSC frequency, which is important for features such as the TSC deadline timer that are emulated by the Hyper-V host.

---
  arch/x86/kernel/cpu/mshyperv.c | 1 +
  1 file changed, 1 insertion(+)
arch/x86/kernel/cpu/mshyperv.c +0 -0
index e0fd57a8ba84..c3e38eaf6d2f 100644

arch/x86/kernel/cpu/mshyperv.c static void __init ms_hyperv_init_platform(void) · line 429

Quoted 6 lines
arch/x86/kernel/cpu/mshyperv.c +1 -0
@@ -424,6 +424,7 @@ static void __init ms_hyperv_init_platform(void)
  	    ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {
  		x86_platform.calibrate_tsc = hv_get_tsc_khz;
  		x86_platform.calibrate_cpu = hv_get_tsc_khz;
+		setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
  	}
  	if (ms_hyperv.priv_high & HV_ISOLATION) {

LGTM

Quoted 7 lines
Quoted 1 line

Applied to hyperv-fixes. Thanks!

Wei --

hyperv-fixes isn't showing this patch, or any of the others that your emails said you applied last Friday. Hence the patches aren't in linux-next either. Did something go awry?

The push was not successful. They should show up now.

Sorry for the delay.

Thanks,
Wei.

Quoted 2 lines

Michael