Skip to content

Commit 0663bd0

Browse files
dwmw2sirlucjan
authored andcommitted
x86/smpboot: Send INIT/SIPI/SIPI to secondary CPUs in parallel
When the APs can find their own APIC ID without assistance, perform the AP bringup in parallel. Register a CPUHP_BP_PARALLEL_DYN stage "x86/cpu:kick" which just calls do_boot_cpu() to deliver INIT/SIPI/SIPI to each AP in turn before the normal native_cpu_up() does the rest of the hand-holding. The APs will then take turns through the real mode code (which has its own bitlock for exclusion) until they make it to their own stack, then proceed through the first few lines of start_secondary() and execute these parts in parallel: start_secondary() -> cr4_init() -> (some 32-bit only stuff so not in the parallel cases) -> cpu_init_secondary() -> cpu_init_exception_handling() -> cpu_init() -> wait_for_master_cpu() At this point they wait for the BSP to set their bit in cpu_callout_mask (from do_wait_cpu_initialized()), and release them to continue through the rest of cpu_init() and beyond. This reduces the time taken for bringup on my 28-thread Haswell system from about 120ms to 80ms. On a socket 96-thread Skylake it takes the bringup time from 500ms to 100ms. There is more speedup to be had by doing the remaining parts in parallel too — especially notify_cpu_starting() in which the AP takes itself through all the stages from CPUHP_BRINGUP_CPU to CPUHP_ONLINE. But those require careful auditing to ensure they are reentrant, before we can go that far. [Usama Arif: fixed rebase conflict] Signed-off-by: David Woodhouse <[email protected]> Signed-off-by: Usama Arif <[email protected]>
1 parent 166de20 commit 0663bd0

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

arch/x86/kernel/smpboot.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <linux/pgtable.h>
5858
#include <linux/overflow.h>
5959
#include <linux/stackprotector.h>
60+
#include <linux/smpboot.h>
6061

6162
#include <asm/acpi.h>
6263
#include <asm/cacheinfo.h>
@@ -1325,9 +1326,12 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
13251326
{
13261327
int ret;
13271328

1328-
ret = do_cpu_up(cpu, tidle);
1329-
if (ret)
1330-
return ret;
1329+
/* If parallel AP bringup isn't enabled, perform the first steps now. */
1330+
if (!do_parallel_bringup) {
1331+
ret = do_cpu_up(cpu, tidle);
1332+
if (ret)
1333+
return ret;
1334+
}
13311335

13321336
ret = do_wait_cpu_initialized(cpu);
13331337
if (ret)
@@ -1349,6 +1353,12 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
13491353
return ret;
13501354
}
13511355

1356+
/* Bringup step one: Send INIT/SIPI to the target AP */
1357+
static int native_cpu_kick(unsigned int cpu)
1358+
{
1359+
return do_cpu_up(cpu, idle_thread_get(cpu));
1360+
}
1361+
13521362
/**
13531363
* arch_disable_smp_support() - disables SMP support for x86 at runtime
13541364
*/
@@ -1566,6 +1576,11 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)
15661576
smpboot_control = STARTUP_SECONDARY | STARTUP_APICID_CPUID_01;
15671577
}
15681578

1579+
if (do_parallel_bringup) {
1580+
cpuhp_setup_state_nocalls(CPUHP_BP_PARALLEL_DYN, "x86/cpu:kick",
1581+
native_cpu_kick, NULL);
1582+
}
1583+
15691584
snp_set_wakeup_secondary_cpu();
15701585
}
15711586

0 commit comments

Comments
 (0)