Skip to contentSkip to conversation

speed up cpu_up()

PATCH Superseded Len Brown 3 participants 5 messages May 8, 2015 – May 10, 2015

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
author
#2 lore raw

PATCH v3 2/2 x86: remove 10ms delay from cpu_up() on modern processors

In reply to Len Brown

From: Len Brown <[email protected]>

Modern processor familes do not require the 10ms delay in cpu_up() to de-assert INIT. This speeds up boot and resume by 10ms per (application) processor.

---
 arch/x86/kernel/smpboot.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/x86/kernel/smpboot.c +15 -0
index 0ddc28b..3ab3df5 100644
@@ -524,6 +524,7 @@ void __inquire_remote_apic(int apicid)
  * many cores and don't require that delay.
  *
  * Cmdline "init_cpu_udelay=" is available to over-ride this delay.
+ * Modern processor families are quirked to remove the delay entirely.
  */
 #define UDELAY_10MS_DEFAULT 10000
 
@@ -537,6 +538,18 @@ static int __init cpu_init_udelay(char *str)
 }
 early_param("cpu_init_udelay", cpu_init_udelay);
 
+static void __init smp_quirk_init_udelay(void)
+{
+	/* if cmdline changed it from default, leave it alone */
+	if (init_udelay != UDELAY_10MS_DEFAULT)
+		return;
+
+	/* if modern processor, use no delay */
+	if (((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) && (boot_cpu_data.x86 == 6)) ||
+	    ((boot_cpu_data.x86_vendor == X86_VENDOR_AMD) && (boot_cpu_data.x86 >= 0xF)))
+		init_udelay = 0;
+}
+
 /*
  * Poke the other CPU in the eye via NMI to wake it up. Remember that the normal
  * INIT, INIT, STARTUP sequence will reset the chip hard for us, and this
@@ -1191,6 +1204,8 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
 		uv_system_init();
 
 	set_mtrr_aps_delayed_init();
+
+	smp_quirk_init_udelay();
 }
 
 void arch_enable_nonboot_cpus_begin(void)
Signature · 1 line
2.4.0.rc1

Len Brown

author
#0 lore raw

v3 cover speed up cpu_up()

Thanks for the feedback, here is a simplifed pair of patches.

I also like the x2apic optimization, since it addresses additional delays.
-- though we may be able to optimize those in the non-x2apic case too.

thanks,
Len Brown, Intel Open Source Technology Center

author
#1 lore raw

PATCH v3 1/2 x86: Add cmdline "cpu_init_udelay=N" to specify cpu_up() delay

From: Len Brown <[email protected]>

No change to default behavior.

Replace the hard-coded mdelay(10) in cpu_up() with a variable udelay, that is set to a defined default -- rather than a magic number.

Add a boot-time override, "cpu_init_udelay=N"

---
 Documentation/kernel-parameters.txt |  6 ++++++
 arch/x86/kernel/smpboot.c           | 23 ++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)
Documentation/kernel-parameters.txt +6 -0
index bfcb1a6..0a16309 100644
@@ -737,6 +737,12 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 	cpuidle.off=1	[CPU_IDLE]
 			disable the cpuidle sub-system
 
+	cpu_init_udelay=N
+			[X86] Delay for N microsec between assert and de-assert
+			of APIC INIT to start processors.  This delay occurs
+			on every CPU online, such as boot, and resume from suspend.
+			Default: 10000
+
 	cpcihp_generic=	[HW,PCI] Generic port I/O CompactPCI driver
 			Format:
 			<first_slot>,<last_slot>,<port>,<enum_bit>[,<debug>]
arch/x86/kernel/smpboot.c +22 -1
index febc6aa..0ddc28b 100644
@@ -517,6 +517,27 @@ void __inquire_remote_apic(int apicid)
 }
 
 /*
+ * The Multiprocessor Specification 1.4 (1997) example code suggests
+ * that there should be a 10ms delay between the BSP asserting INIT
+ * and de-asserting INIT, when starting a remote processor.
+ * But that slows boot and resume on modern processors, which include
+ * many cores and don't require that delay.
+ *
+ * Cmdline "init_cpu_udelay=" is available to over-ride this delay.
+ */
+#define UDELAY_10MS_DEFAULT 10000
+
+static unsigned int init_udelay = UDELAY_10MS_DEFAULT;
+
+static int __init cpu_init_udelay(char *str)
+{
+	get_option(&str, &init_udelay);
+
+	return 0;
+}
+early_param("cpu_init_udelay", cpu_init_udelay);
+
+/*
  * Poke the other CPU in the eye via NMI to wake it up. Remember that the normal
  * INIT, INIT, STARTUP sequence will reset the chip hard for us, and this
  * won't ... remember to clear down the APIC, etc later.
@@ -586,7 +607,7 @@ wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip)
 	pr_debug("Waiting for send to finish...\n");
 	send_status = safe_apic_wait_icr_idle();
 
-	mdelay(10);
+	udelay(init_udelay);
 
 	pr_debug("Deasserting INIT\n");
 
Signature · 1 line
2.4.0.rc1
#4 lore raw
In reply to Len Brown
Quoted 7 lines · Len Brown

Thanks for the feedback, here is a simplifed pair of patches.

I also like the x2apic optimization, since it addresses additional delays.
-- though we may be able to optimize those in the non-x2apic case too.

thanks,
Len Brown, Intel Open Source Technology Center

Could you please send it against tip:master, so that it applies cleanly to the x2apic optimization which is already applied?

Thanks,

Ingo