Skip to content

Commit cf7df37

Browse files
Robin Holttorvalds
Robin Holt
authored andcommitted
reboot: rigrate shutdown/reboot to boot cpu
We recently noticed that reboot of a 1024 cpu machine takes approx 16 minutes of just stopping the cpus. The slowdown was tracked to commit f96972f ("kernel/sys.c: call disable_nonboot_cpus() in kernel_restart()"). The current implementation does all the work of hot removing the cpus before halting the system. We are switching to just migrating to the boot cpu and then continuing with shutdown/reboot. This also has the effect of not breaking x86's command line parameter for specifying the reboot cpu. Note, this code was shamelessly copied from arch/x86/kernel/reboot.c with bits removed pertaining to the reboot_cpu command line parameter. Signed-off-by: Robin Holt <[email protected]> Tested-by: Shawn Guo <[email protected]> Cc: "Srivatsa S. Bhat" <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Russ Anderson <[email protected]> Cc: Robin Holt <[email protected]> Cc: Russell King <[email protected]> Cc: Guan Xuetao <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 16e53db commit cf7df37

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

kernel/sys.c

+26-3
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,29 @@ int unregister_reboot_notifier(struct notifier_block *nb)
362362
}
363363
EXPORT_SYMBOL(unregister_reboot_notifier);
364364

365+
/* Add backwards compatibility for stable trees. */
366+
#ifndef PF_NO_SETAFFINITY
367+
#define PF_NO_SETAFFINITY PF_THREAD_BOUND
368+
#endif
369+
370+
static void migrate_to_reboot_cpu(void)
371+
{
372+
/* The boot cpu is always logical cpu 0 */
373+
int cpu = 0;
374+
375+
cpu_hotplug_disable();
376+
377+
/* Make certain the cpu I'm about to reboot on is online */
378+
if (!cpu_online(cpu))
379+
cpu = cpumask_first(cpu_online_mask);
380+
381+
/* Prevent races with other tasks migrating this task */
382+
current->flags |= PF_NO_SETAFFINITY;
383+
384+
/* Make certain I only run on the appropriate processor */
385+
set_cpus_allowed_ptr(current, cpumask_of(cpu));
386+
}
387+
365388
/**
366389
* kernel_restart - reboot the system
367390
* @cmd: pointer to buffer containing command to execute for restart
@@ -373,7 +396,7 @@ EXPORT_SYMBOL(unregister_reboot_notifier);
373396
void kernel_restart(char *cmd)
374397
{
375398
kernel_restart_prepare(cmd);
376-
disable_nonboot_cpus();
399+
migrate_to_reboot_cpu();
377400
syscore_shutdown();
378401
if (!cmd)
379402
printk(KERN_EMERG "Restarting system.\n");
@@ -400,7 +423,7 @@ static void kernel_shutdown_prepare(enum system_states state)
400423
void kernel_halt(void)
401424
{
402425
kernel_shutdown_prepare(SYSTEM_HALT);
403-
disable_nonboot_cpus();
426+
migrate_to_reboot_cpu();
404427
syscore_shutdown();
405428
printk(KERN_EMERG "System halted.\n");
406429
kmsg_dump(KMSG_DUMP_HALT);
@@ -419,7 +442,7 @@ void kernel_power_off(void)
419442
kernel_shutdown_prepare(SYSTEM_POWER_OFF);
420443
if (pm_power_off_prepare)
421444
pm_power_off_prepare();
422-
disable_nonboot_cpus();
445+
migrate_to_reboot_cpu();
423446
syscore_shutdown();
424447
printk(KERN_EMERG "Power down.\n");
425448
kmsg_dump(KMSG_DUMP_POWEROFF);

0 commit comments

Comments
 (0)