Skip to contentSkip to conversation

Shutdown from reboot_cpuid without stopping other cpus.

PATCH In review Robin Holt 2 participants 7 messages Apr 16, 2013 – Apr 17, 2013

Subsystems (2)
lore
Share & tools
lore

Robin Holt

author
#0 lore raw

cover Shutdown from reboot_cpuid without stopping other cpus.

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.

The current implementation does all the work of hot removing the cpus before halting the system. We are switching to just migrating to the reboot_cpuid and then continuing with shutdown/reboot.

The patch set is broken into four parts. The first is planned for the stable release. The others move the halt/shutdown/reboot related functions to their own kernel/reboot.c file and then introduce the kernel boot parameter.

Changes since -v3.
- Added a tested-by for the original reporter.
- Fix compile failure found by Joe Perches.
- Integrated comments by Joe Perches.

author
#1 lore raw

PATCH 2/4 Move shutdown/reboot related functions to kernel/reboot.c other cpus.

This patch is preparatory. It moves reboot related syscall, etc functions from kernel/sys.c to kernel/reboot.c.

To: Ingo Molnar <[email protected]>
To: Russ Anderson <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Linux Kernel Mailing List <[email protected]>
Cc: Michel Lespinasse <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Robin Holt <[email protected]>
Cc: "[email protected]" <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: the arch/x86 maintainers <[email protected]>
Cc: Thomas Gleixner <[email protected]>

---

Changes since -v2
- Add #include to allow building with CONFIG_HIBERNATE

 kernel/Makefile |   2 +-
 kernel/reboot.c | 329 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 kernel/sys.c    | 315 -----------------------------------------------------
 3 files changed, 330 insertions(+), 316 deletions(-)
 create mode 100644 kernel/reboot.c
kernel/Makefile +1 -1
index bbde5f1..5c2cef7 100644
@@ -9,7 +9,7 @@ obj-y     = fork.o exec_domain.o panic.o printk.o \
 	    rcupdate.o extable.o params.o posix-timers.o \
 	    kthread.o wait.o sys_ni.o posix-cpu-timers.o mutex.o \
 	    hrtimer.o rwsem.o nsproxy.o srcu.o semaphore.o \
-	    notifier.o ksysfs.o cred.o \
+	    notifier.o ksysfs.o cred.o reboot.o \
 	    async.o range.o groups.o lglock.o smpboot.o
 
 ifdef CONFIG_FUNCTION_TRACER
kernel/reboot.c new file +329 -0

329 lines not on this page · raw message

kernel/sys.c +0 -315

324 lines not on this page · raw message

Signature · 1 line
1.8.1.2
author
#2 lore raw

PATCH 3/4 checkpatch.pl the new kernel/reboot.c file.

In reply to Robin Holt

I did allow the remaining 81 character line behind. It did not seem like it was worth changing. Otherwise, it now passes checkpatch.pl.

To: Ingo Molnar <[email protected]>
To: Russ Anderson <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Linux Kernel Mailing List <[email protected]>
Cc: Michel Lespinasse <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Robin Holt <[email protected]>
Cc: "[email protected]" <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: the arch/x86 maintainers <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Joe Perches <[email protected]>

---

Changes since -v3:
- Integrated feedback from Joe Perches.

 kernel/reboot.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
kernel/reboot.c +14 -14
index 907ab48..8cfef20 100644
@@ -1,9 +1,11 @@
 /*
- *  linux/kernel/sys.c
+ *  linux/kernel/reboot.c
  *
  *  Copyright (C) 2013  Linus Torvalds
  */
 
+#define pr_fmt(fmt)	"reboot: " fmt
+
 #include <linux/export.h>
 #include <linux/kexec.h>
 #include <linux/kmod.h>
@@ -97,9 +99,9 @@ void kernel_restart(char *cmd)
 	migrate_to_reboot_cpu();
 	syscore_shutdown();
 	if (!cmd)
-		printk(KERN_EMERG "Restarting system.\n");
+		pr_emerg("Restarting system\n");
 	else
-		printk(KERN_EMERG "Restarting system with command '%s'.\n", cmd);
+		pr_emerg("Restarting system with command '%s'\n", cmd);
 	kmsg_dump(KMSG_DUMP_RESTART);
 	machine_restart(cmd);
 }
@@ -108,7 +110,7 @@ EXPORT_SYMBOL_GPL(kernel_restart);
 static void kernel_shutdown_prepare(enum system_states state)
 {
 	blocking_notifier_call_chain(&reboot_notifier_list,
-		(state == SYSTEM_HALT)?SYS_HALT:SYS_POWER_OFF, NULL);
+		(state == SYSTEM_HALT) ? SYS_HALT : SYS_POWER_OFF, NULL);
 	system_state = state;
 	usermodehelper_disable();
 	device_shutdown();
@@ -123,11 +125,10 @@ void kernel_halt(void)
 	kernel_shutdown_prepare(SYSTEM_HALT);
 	migrate_to_reboot_cpu();
 	syscore_shutdown();
-	printk(KERN_EMERG "System halted.\n");
+	pr_emerg("System halted\n");
 	kmsg_dump(KMSG_DUMP_HALT);
 	machine_halt();
 }
-
 EXPORT_SYMBOL_GPL(kernel_halt);
 
 /**
@@ -142,7 +143,7 @@ void kernel_power_off(void)
 		pm_power_off_prepare();
 	migrate_to_reboot_cpu();
 	syscore_shutdown();
-	printk(KERN_EMERG "Power down.\n");
+	pr_emerg("Power down\n");
 	kmsg_dump(KMSG_DUMP_POWEROFF);
 	machine_power_off();
 }
@@ -171,10 +172,10 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
 
 	/* For safety, we require "magic" arguments. */
 	if (magic1 != LINUX_REBOOT_MAGIC1 ||
-	    (magic2 != LINUX_REBOOT_MAGIC2 &&
-	                magic2 != LINUX_REBOOT_MAGIC2A &&
+			(magic2 != LINUX_REBOOT_MAGIC2 &&
+			magic2 != LINUX_REBOOT_MAGIC2A &&
 			magic2 != LINUX_REBOOT_MAGIC2B &&
-	                magic2 != LINUX_REBOOT_MAGIC2C))
+			magic2 != LINUX_REBOOT_MAGIC2C))
 		return -EINVAL;
 
 	/*
@@ -283,14 +284,13 @@ static int __orderly_poweroff(bool force)
 		ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);
 		argv_free(argv);
 	} else {
-		printk(KERN_WARNING "%s failed to allocate memory for \"%s\"\n",
-					 __func__, poweroff_cmd);
+		pr_warn("%s failed to allocate memory for \"%s\"\n",
+						__func__, poweroff_cmd);
 		ret = -ENOMEM;
 	}
 
 	if (ret && force) {
-		printk(KERN_WARNING "Failed to start orderly shutdown: "
-					"forcing the issue\n");
+		pr_warn("Failed to start orderly shutdown: forcing the issue\n");
 		/*
 		 * I guess this should try to kick off some daemon to sync and
 		 * poweroff asap.  Or not even bother syncing if we're doing an
Signature · 1 line
1.8.1.2
author
#3 lore raw

PATCH 4/4 Make reboot_cpuid a kernel parameter. other cpus.

In reply to Robin Holt

Moving the reboot=s<##> parameter for x86 to a kernel parameter proper. I did not find any other arch that was specifying the reboot cpu.

I left a compatibility mode in there. The new parameter always takes precedence. I also fixed up the current code to support up to cpuid's up to the current max of 4096.

To: Ingo Molnar <[email protected]>
To: Russ Anderson <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Linux Kernel Mailing List <[email protected]>
Cc: Michel Lespinasse <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Robin Holt <[email protected]>
Cc: "[email protected]" <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: the arch/x86 maintainers <[email protected]>
Cc: Thomas Gleixner <[email protected]>

---

Changes since -v3
- Added a reboot=s#### compatibility mode for x86.

 Documentation/kernel-parameters.txt |  2 ++
 arch/x86/kernel/reboot.c            | 39 +++++++++++++------------------------
 kernel/reboot.c                     |  8 +++++++-
 3 files changed, 22 insertions(+), 27 deletions(-)
Documentation/kernel-parameters.txt +2 -0
index 4609e81..11ebb48 100644
@@ -2597,6 +2597,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			Format: <reboot_mode>[,<reboot_mode2>[,...]]
 			See arch/*/kernel/reboot.c or arch/*/kernel/process.c
 
+	reboot_cpuid=	[KNL] cpuid to use for reboot/halt, etc operations.
+
 	relax_domain_level=
 			[KNL, SMP] Set scheduler's default relax_domain_level.
 			See Documentation/cgroups/cpusets.txt.
arch/x86/kernel/reboot.c +13 -26
index 76fa1e9..cdcf28f 100644
@@ -49,10 +49,6 @@ int reboot_force;
  */
 static int reboot_default = 1;
 
-#ifdef CONFIG_SMP
-static int reboot_cpu = -1;
-#endif
-
 /*
  * This is set if we need to go through the 'emergency' path.
  * When machine_emergency_restart() is called, we may be on
@@ -63,6 +59,8 @@ static int reboot_emergency;
 /* This is set by the PCI code if either type 1 or type 2 PCI is detected */
 bool port_cf9_safe = false;
 
+extern int reboot_cpuid;
+
 /*
  * reboot=b[ios] | s[mp] | t[riple] | k[bd] | e[fi] [, [w]arm | [c]old] | p[ci]
  * warm   Don't set the cold reboot flag
@@ -97,10 +95,14 @@ static int __init reboot_setup(char *str)
 
 #ifdef CONFIG_SMP
 		case 's':
-			if (isdigit(*(str+1))) {
-				reboot_cpu = (int) (*(str+1) - '0');
-				if (isdigit(*(str+2)))
-					reboot_cpu = reboot_cpu*10 + (int)(*(str+2) - '0');
+			if (reboot_cpuid < 0) {
+				int coffset;
+
+				reboot_cpuid = 0;
+				for (coffset = 1; isdigit(*(str + coffset)); coffset++) {
+					reboot_cpuid *= 10;
+					reboot_cpuid += (int)(*(str+2) - '0');
+				}
 			}
 			/*
 			 * We will leave sorting out the final value
@@ -615,25 +617,10 @@ void native_machine_shutdown(void)
 	/* Stop the cpus and apics */
 #ifdef CONFIG_SMP
 
-	/* The boot cpu is always logical cpu 0 */
-	int reboot_cpu_id = 0;
-
-	/* See if there has been given a command line override */
-	if ((reboot_cpu != -1) && (reboot_cpu < nr_cpu_ids) &&
-		cpu_online(reboot_cpu))
-		reboot_cpu_id = reboot_cpu;
-
-	/* Make certain the cpu I'm about to reboot on is online */
-	if (!cpu_online(reboot_cpu_id))
-		reboot_cpu_id = smp_processor_id();
-
-	/* Make certain I only run on the appropriate processor */
-	set_cpus_allowed_ptr(current, cpumask_of(reboot_cpu_id));
-
 	/*
-	 * O.K Now that I'm on the appropriate processor, stop all of the
-	 * others. Also disable the local irq to not receive the per-cpu
-	 * timer interrupt which may trigger scheduler's load balance.
+	 * Stop all of the others. Also disable the local irq to
+	 * not receive the per-cpu timer interrupt which may trigger
+	 * scheduler's load balance.
 	 */
 	local_irq_disable();
 	stop_other_cpus();
kernel/reboot.c +7 -1
index 8cfef20..b2ef798 100644
@@ -10,6 +10,7 @@
 #include <linux/kexec.h>
 #include <linux/kmod.h>
 #include <linux/kmsg_dump.h>
+#include <linux/moduleparam.h>
 #include <linux/reboot.h>
 #include <linux/suspend.h>
 #include <linux/syscalls.h>
@@ -69,13 +70,18 @@ int unregister_reboot_notifier(struct notifier_block *nb)
 }
 EXPORT_SYMBOL(unregister_reboot_notifier);
 
+int reboot_cpuid = -1;
+core_param(reboot_cpuid, reboot_cpuid, int, 0644);
+
 void migrate_to_reboot_cpu(void)
 {
 	/* The boot cpu is always logical cpu 0 */
-	int reboot_cpu_id = 0;
+	int reboot_cpu_id = reboot_cpuid;
 
 	/* Make certain the cpu I'm about to reboot on is online */
 	if (!cpu_online(reboot_cpu_id))
+		reboot_cpu_id = 0;
+	if (!cpu_online(reboot_cpu_id))
 		reboot_cpu_id = smp_processor_id();
 
 	/* Prevent races with other tasks migrating this task. */
Signature · 1 line
1.8.1.2
#4 lore raw

Re: [Patch -v4 4/4] Make reboot_cpuid a kernel parameter. other cpus.

Why not just support the existing syntax everywhere?

Quoted 162 lines · Robin Holt

Moving the reboot=s<##> parameter for x86 to a kernel parameter proper. I did not find any other arch that was specifying the reboot cpu.

I left a compatibility mode in there. The new parameter always takes precedence. I also fixed up the current code to support up to cpuid's up to the current max of 4096.

To: Ingo Molnar <[email protected]>
To: Russ Anderson <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Linux Kernel Mailing List <[email protected]>
Cc: Michel Lespinasse <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Robin Holt <[email protected]>
Cc: "[email protected]" <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: the arch/x86 maintainers <[email protected]>
Cc: Thomas Gleixner <[email protected]>

---

Changes since -v3
- Added a reboot=s#### compatibility mode for x86.

Documentation/kernel-parameters.txt | 2 ++
arch/x86/kernel/reboot.c | 39
+++++++++++++------------------------
kernel/reboot.c | 8 +++++++-

3 files changed, 22 insertions(+), 27 deletions(-)
Documentation/kernel-parameters.txt +0 -0
index 4609e81..11ebb48 100644
@@ -2597,6 +2597,8 @@ bytes respectively. Such letter suffixes can also

be entirely omitted.

			Format: <reboot_mode>[,<reboot_mode2>[,...]]
			See arch/*/kernel/reboot.c or arch/*/kernel/process.c
Documentation/kernel-parameters.txt +2 -0
+	reboot_cpuid=	[KNL] cpuid to use for reboot/halt, etc operations.
+

relax_domain_level=
[KNL, SMP] Set scheduler's default relax_domain_level. See Documentation/cgroups/cpusets.txt.

arch/x86/kernel/reboot.c +0 -4
index 76fa1e9..cdcf28f 100644
@@ -49,10 +49,6 @@ int reboot_force;
 */
 static int reboot_default = 1;
 
-#ifdef CONFIG_SMP
-static int reboot_cpu = -1;
-#endif
-
 /*
 * This is set if we need to go through the 'emergency' path.
 * When machine_emergency_restart() is called, we may be on
@@ -63,6 +59,8 @@ static int reboot_emergency;
 /* This is set by the PCI code if either type 1 or type 2 PCI is

detected */
bool port_cf9_safe = false;

arch/x86/kernel/reboot.c +2 -0
+extern int reboot_cpuid;
+

/*
* reboot=b[ios] | s[mp] | t[riple] | k[bd] | e[fi] [, [w]arm | [c]old] | p[ci]
* warm Don't set the cold reboot flag

arch/x86/kernel/reboot.c +11 -22
@@ -97,10 +95,14 @@ static int __init reboot_setup(char *str)
 
 #ifdef CONFIG_SMP
 		case 's':
-			if (isdigit(*(str+1))) {
-				reboot_cpu = (int) (*(str+1) - '0');
-				if (isdigit(*(str+2)))
-					reboot_cpu = reboot_cpu*10 + (int)(*(str+2) - '0');
+			if (reboot_cpuid < 0) {
+				int coffset;
+
+				reboot_cpuid = 0;
+				for (coffset = 1; isdigit(*(str + coffset)); coffset++) {
+					reboot_cpuid *= 10;
+					reboot_cpuid += (int)(*(str+2) - '0');
+				}
 			}
 			/*
 			 * We will leave sorting out the final value
@@ -615,25 +617,10 @@ void native_machine_shutdown(void)
 	/* Stop the cpus and apics */
 #ifdef CONFIG_SMP
 
-	/* The boot cpu is always logical cpu 0 */
-	int reboot_cpu_id = 0;
-
-	/* See if there has been given a command line override */
-	if ((reboot_cpu != -1) && (reboot_cpu < nr_cpu_ids) &&
-		cpu_online(reboot_cpu))
-		reboot_cpu_id = reboot_cpu;
-
-	/* Make certain the cpu I'm about to reboot on is online */
-	if (!cpu_online(reboot_cpu_id))
-		reboot_cpu_id = smp_processor_id();
-
-	/* Make certain I only run on the appropriate processor */
-	set_cpus_allowed_ptr(current, cpumask_of(reboot_cpu_id));
-
 	/*
-	 * O.K Now that I'm on the appropriate processor, stop all of the
-	 * others. Also disable the local irq to not receive the per-cpu
-	 * timer interrupt which may trigger scheduler's load balance.
+	 * Stop all of the others. Also disable the local irq to
+	 * not receive the per-cpu timer interrupt which may trigger
+	 * scheduler's load balance.
 	 */
 	local_irq_disable();
 	stop_other_cpus();
kernel/reboot.c +7 -1
index 8cfef20..b2ef798 100644
@@ -10,6 +10,7 @@
 #include <linux/kexec.h>
 #include <linux/kmod.h>
 #include <linux/kmsg_dump.h>
+#include <linux/moduleparam.h>
 #include <linux/reboot.h>
 #include <linux/suspend.h>
 #include <linux/syscalls.h>
@@ -69,13 +70,18 @@ int unregister_reboot_notifier(struct
 notifier_block *nb)
 }
 EXPORT_SYMBOL(unregister_reboot_notifier);
 
+int reboot_cpuid = -1;
+core_param(reboot_cpuid, reboot_cpuid, int, 0644);
+
 void migrate_to_reboot_cpu(void)
 {
 	/* The boot cpu is always logical cpu 0 */
-	int reboot_cpu_id = 0;
+	int reboot_cpu_id = reboot_cpuid;
 
 	/* Make certain the cpu I'm about to reboot on is online */
 	if (!cpu_online(reboot_cpu_id))
+		reboot_cpu_id = 0;
+	if (!cpu_online(reboot_cpu_id))
 		reboot_cpu_id = smp_processor_id();
 
	/* Prevent races with other tasks migrating this task. */
Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
author
#5 lore raw

Re: [Patch -v4 4/4] Make reboot_cpuid a kernel parameter. other cpus.

Quoted 1 line · H. Peter Anvin

Why not just support the existing syntax everywhere?

I have not given it much consideration, but IIRC, the other arches that were using reboot= were only looking for an 'h' or something like that.

I will consider making the syntax parse reboot=s#### when I get to the office.

Robin

Quoted 168 lines
Quoted 162 lines · Robin Holt

Moving the reboot=s<##> parameter for x86 to a kernel parameter proper. I did not find any other arch that was specifying the reboot cpu.

I left a compatibility mode in there. The new parameter always takes precedence. I also fixed up the current code to support up to cpuid's up to the current max of 4096.

To: Ingo Molnar <[email protected]>
To: Russ Anderson <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Linux Kernel Mailing List <[email protected]>
Cc: Michel Lespinasse <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Robin Holt <[email protected]>
Cc: "[email protected]" <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: the arch/x86 maintainers <[email protected]>
Cc: Thomas Gleixner <[email protected]>

---

Changes since -v3
- Added a reboot=s#### compatibility mode for x86.

Documentation/kernel-parameters.txt | 2 ++
arch/x86/kernel/reboot.c | 39
+++++++++++++------------------------
kernel/reboot.c | 8 +++++++-

3 files changed, 22 insertions(+), 27 deletions(-)
Documentation/kernel-parameters.txt +0 -0
index 4609e81..11ebb48 100644
@@ -2597,6 +2597,8 @@ bytes respectively. Such letter suffixes can also

be entirely omitted.

			Format: <reboot_mode>[,<reboot_mode2>[,...]]
			See arch/*/kernel/reboot.c or arch/*/kernel/process.c
Documentation/kernel-parameters.txt +2 -0
+	reboot_cpuid=	[KNL] cpuid to use for reboot/halt, etc operations.
+

relax_domain_level=
[KNL, SMP] Set scheduler's default relax_domain_level. See Documentation/cgroups/cpusets.txt.

arch/x86/kernel/reboot.c +0 -4
index 76fa1e9..cdcf28f 100644
@@ -49,10 +49,6 @@ int reboot_force;
 */
 static int reboot_default = 1;
 
-#ifdef CONFIG_SMP
-static int reboot_cpu = -1;
-#endif
-
 /*
 * This is set if we need to go through the 'emergency' path.
 * When machine_emergency_restart() is called, we may be on
@@ -63,6 +59,8 @@ static int reboot_emergency;
 /* This is set by the PCI code if either type 1 or type 2 PCI is

detected */
bool port_cf9_safe = false;

arch/x86/kernel/reboot.c +2 -0
+extern int reboot_cpuid;
+

/*
* reboot=b[ios] | s[mp] | t[riple] | k[bd] | e[fi] [, [w]arm | [c]old] | p[ci]
* warm Don't set the cold reboot flag

arch/x86/kernel/reboot.c +11 -22
@@ -97,10 +95,14 @@ static int __init reboot_setup(char *str)
 
 #ifdef CONFIG_SMP
 		case 's':
-			if (isdigit(*(str+1))) {
-				reboot_cpu = (int) (*(str+1) - '0');
-				if (isdigit(*(str+2)))
-					reboot_cpu = reboot_cpu*10 + (int)(*(str+2) - '0');
+			if (reboot_cpuid < 0) {
+				int coffset;
+
+				reboot_cpuid = 0;
+				for (coffset = 1; isdigit(*(str + coffset)); coffset++) {
+					reboot_cpuid *= 10;
+					reboot_cpuid += (int)(*(str+2) - '0');
+				}
 			}
 			/*
 			 * We will leave sorting out the final value
@@ -615,25 +617,10 @@ void native_machine_shutdown(void)
 	/* Stop the cpus and apics */
 #ifdef CONFIG_SMP
 
-	/* The boot cpu is always logical cpu 0 */
-	int reboot_cpu_id = 0;
-
-	/* See if there has been given a command line override */
-	if ((reboot_cpu != -1) && (reboot_cpu < nr_cpu_ids) &&
-		cpu_online(reboot_cpu))
-		reboot_cpu_id = reboot_cpu;
-
-	/* Make certain the cpu I'm about to reboot on is online */
-	if (!cpu_online(reboot_cpu_id))
-		reboot_cpu_id = smp_processor_id();
-
-	/* Make certain I only run on the appropriate processor */
-	set_cpus_allowed_ptr(current, cpumask_of(reboot_cpu_id));
-
 	/*
-	 * O.K Now that I'm on the appropriate processor, stop all of the
-	 * others. Also disable the local irq to not receive the per-cpu
-	 * timer interrupt which may trigger scheduler's load balance.
+	 * Stop all of the others. Also disable the local irq to
+	 * not receive the per-cpu timer interrupt which may trigger
+	 * scheduler's load balance.
 	 */
 	local_irq_disable();
 	stop_other_cpus();
kernel/reboot.c +7 -1
index 8cfef20..b2ef798 100644
@@ -10,6 +10,7 @@
 #include <linux/kexec.h>
 #include <linux/kmod.h>
 #include <linux/kmsg_dump.h>
+#include <linux/moduleparam.h>
 #include <linux/reboot.h>
 #include <linux/suspend.h>
 #include <linux/syscalls.h>
@@ -69,13 +70,18 @@ int unregister_reboot_notifier(struct
 notifier_block *nb)
 }
 EXPORT_SYMBOL(unregister_reboot_notifier);
 
+int reboot_cpuid = -1;
+core_param(reboot_cpuid, reboot_cpuid, int, 0644);
+
 void migrate_to_reboot_cpu(void)
 {
 	/* The boot cpu is always logical cpu 0 */
-	int reboot_cpu_id = 0;
+	int reboot_cpu_id = reboot_cpuid;
 
 	/* Make certain the cpu I'm about to reboot on is online */
 	if (!cpu_online(reboot_cpu_id))
+		reboot_cpu_id = 0;
+	if (!cpu_online(reboot_cpu_id))
 		reboot_cpu_id = smp_processor_id();
 
	/* Prevent races with other tasks migrating this task. */
Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
author
#6 lore raw

Re: [Patch -v4 4/4] Make reboot_cpuid a kernel parameter. other cpus.

Quoted 8 lines · Robin Holt
Quoted 1 line · H. Peter Anvin

Why not just support the existing syntax everywhere?

I have not given it much consideration, but IIRC, the other arches that were using reboot= were only looking for an 'h' or something like that.

I will consider making the syntax parse reboot=s#### when I get to the office.

Yesterday was rather disruptive and I did not get to this. I have given it some thought this morning.

Generally speaking, I don't like the feel of this for two reasons. First, having two different places that are parsing reboot=<reboot_mode> and its related difficulty in documenting it. Second, we lose the /sys/ file.

Some background. First, arm. It already has a reboot=<c>. That <c> gets passed to the reboot sub-arch function. It looks like it is ignored, but I am very uncertain of that as it is passed into an assembly routine.

Second unicore. It parses as reboot=<c>. That <c> gets ignored.

Now the meat of my question. The Documentation/kernel-parameters.txt file indicates reboot= is handled by the arch and are of the format <reboot-mode>[,<reboot-mode>[,...]].

I suppose we could have both an arch and generic kernel handler for __setup("reboot=",...) where the generic kernel one just handles the s###, but that seems really different from how everything else is done. I could not find one instance where a both an arch and the kernel proper both parsed the same command-line parameter.

I did not spend the time to see if having two __setup() declarations would work.

Additionally, the __setup("... mechanism loses the nice feature the core_param gives us in that there is a /sys/ file now available which allows us to easily change that setting on the running system.

Are you really sure you want me to do more than I already have. This really feels _VERY_ wrong to me. Maybe I misunderstood your direction.

Thanks,
Robin