Linux-HyperV List
 help / color / mirror / Atom feed
* [PATCH] x86/hyperv: Pass on the lpj value from host to guest
@ 2023-02-06 20:49 Stanislav Kinsburskii
  2023-02-07 23:24 ` Nuno Das Neves
  2023-02-14 16:19 ` Michael Kelley (LINUX)
  0 siblings, 2 replies; 7+ messages in thread
From: Stanislav Kinsburskii @ 2023-02-06 20:49 UTC (permalink / raw)
  Cc: Stanislav Kinsburskiy, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
	Dexuan Cui, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, linux-hyperv, linux-kernel

From: Stanislav Kinsburskiy <stanislav.kinsburskiy@gmail.com>

And have it preset.
This change allows to significantly reduce time to bring up guest SMP
configuration as well as make sure the guest won't get inaccurate
calibration results due to "noisy neighbour" situation.

Below are the numbers for 16 VCPU guest before the patch (~1300 msec)

[    0.562938] x86: Booting SMP configuration:
...
[    1.859447] smp: Brought up 1 node, 16 CPUs

and after the patch (~130 msec):

[    0.445079] x86: Booting SMP configuration:
...
[    0.575035] smp: Brought up 1 node, 16 CPUs

This change is inspired by commit 0293615f3fb9 ("x86: KVM guest: use
paravirt function to calculate cpu khz").

Signed-off-by: Stanislav Kinsburskiy <stanislav.kinsburskiy@gmail.com>
CC: "K. Y. Srinivasan" <kys@microsoft.com>
CC: Haiyang Zhang <haiyangz@microsoft.com>
CC: Wei Liu <wei.liu@kernel.org>
CC: Dexuan Cui <decui@microsoft.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: Borislav Petkov <bp@alien8.de>
CC: Dave Hansen <dave.hansen@linux.intel.com>
CC: x86@kernel.org
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: linux-hyperv@vger.kernel.org
CC: linux-kernel@vger.kernel.org
---
 arch/x86/kernel/cpu/mshyperv.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index dedec2f23ad1..0282b2e96cc2 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -320,6 +320,21 @@ static void __init hv_smp_prepare_cpus(unsigned int max_cpus)
 }
 #endif
 
+static void __init __maybe_unused hv_preset_lpj(void)
+{
+	unsigned long khz;
+	u64 lpj;
+
+	if (!x86_platform.calibrate_tsc)
+		return;
+
+	khz = x86_platform.calibrate_tsc();
+
+	lpj = ((u64)khz * 1000);
+	do_div(lpj, HZ);
+	preset_lpj = lpj;
+}
+
 static void __init ms_hyperv_init_platform(void)
 {
 	int hv_max_functions_eax;
@@ -521,6 +536,12 @@ static void __init ms_hyperv_init_platform(void)
 
 	/* Register Hyper-V specific clocksource */
 	hv_init_clocksource();
+
+	/*
+	 * Preset lpj to make calibrate_delay a no-op, which is turn helps to
+	 * speed up secondary cores initialization.
+	 */
+	hv_preset_lpj();
 #endif
 	/*
 	 * TSC should be marked as unstable only after Hyper-V



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-02-21 18:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-06 20:49 [PATCH] x86/hyperv: Pass on the lpj value from host to guest Stanislav Kinsburskii
2023-02-07 23:24 ` Nuno Das Neves
2023-02-13 15:54   ` Wei Liu
2023-02-14 16:19 ` Michael Kelley (LINUX)
2023-02-16 19:41   ` Stanislav Kinsburskii
2023-02-17  2:34     ` Michael Kelley (LINUX)
2023-02-17 22:07       ` Stanislav Kinsburskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox