[PATCH] smp: Add bootcpus parameter to boot subset of CPUs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In a heterogeneous multiprocessor system, specifying the 'maxcpus'
parameter on kernel command line does not provide sufficient control
over which CPUs are brought online at kernel boot time, since CPUs may
have nonuniform performance characteristics. Thus, add bootcpus kernel
parameter to control which CPUs should be brought online during kernel
boot. When both maxcpus and bootcpus is set, the more restrictive of the
two are booted.

Signed-off-by: Elliot Berman <eberman@xxxxxxxxxxxxxx>
---
 Documentation/admin-guide/kernel-parameters.txt |  8 +++++++
 include/linux/cpu.h                             |  2 +-
 kernel/cpu.c                                    |  4 ++--
 kernel/smp.c                                    | 28 +++++++++++++++++++++++--
 4 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 65d047f..ea31af3 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -449,6 +449,14 @@
 
 			See Documentation/admin-guide/bootconfig.rst
 
+	bootcpus=	[SMP]  List of processors that an SMP kernel
+			will bring up during bootup. Similar to maxcpus, except
+			as a cpu list as described above. The more restrictive
+			of maxcpus and bootcpus applies. If bootcpus=1-3 and
+			maxcpus=2, only processors 1 and 2 are booted. As with
+			maxcpus, you can bring up other plugged cpu by executing
+			"echo 1 > /sys/devices/system/cpu/cpuX/online"
+
 	bert_disable	[ACPI]
 			Disable BERT OS support on buggy BIOSes.
 
diff --git a/include/linux/cpu.h b/include/linux/cpu.h
index 8aa84c0..4146f71 100644
--- a/include/linux/cpu.h
+++ b/include/linux/cpu.h
@@ -95,7 +95,7 @@ void notify_cpu_starting(unsigned int cpu);
 extern void cpu_maps_update_begin(void);
 extern void cpu_maps_update_done(void);
 int bringup_hibernate_cpu(unsigned int sleep_cpu);
-void bringup_nonboot_cpus(unsigned int setup_max_cpus);
+void bringup_nonboot_cpus(unsigned int setup_max_cpus, cpumask_var_t boot_cpus);
 
 #else	/* CONFIG_SMP */
 #define cpuhp_tasks_frozen	0
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 6ff2578..71f626b 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1328,14 +1328,14 @@ int bringup_hibernate_cpu(unsigned int sleep_cpu)
 	return 0;
 }
 
-void bringup_nonboot_cpus(unsigned int setup_max_cpus)
+void bringup_nonboot_cpus(unsigned int setup_max_cpus, cpumask_var_t boot_cpus)
 {
 	unsigned int cpu;
 
 	for_each_present_cpu(cpu) {
 		if (num_online_cpus() >= setup_max_cpus)
 			break;
-		if (!cpu_online(cpu))
+		if (!cpu_online(cpu) && cpumask_test_cpu(cpu, boot_cpus))
 			cpu_up(cpu, CPUHP_ONLINE);
 	}
 }
diff --git a/kernel/smp.c b/kernel/smp.c
index 4d17501..727e003 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -738,7 +738,7 @@ EXPORT_SYMBOL(smp_call_function);
 /* Setup configured maximum number of CPUs to activate */
 unsigned int setup_max_cpus = NR_CPUS;
 EXPORT_SYMBOL(setup_max_cpus);
-
+static cpumask_var_t boot_cpus;
 
 /*
  * Setup routine for controlling SMP activation
@@ -787,6 +787,27 @@ static int __init maxcpus(char *str)
 
 early_param("maxcpus", maxcpus);
 
+static int __init bootcpus(char *str)
+{
+	alloc_bootmem_cpumask_var(&boot_cpus);
+	if (cpulist_parse(str, boot_cpus) < 0) {
+		pr_warn("incorrect bootcpus mask\n");
+		return -EINVAL;
+	}
+	cpumask_set_cpu(smp_processor_id(), boot_cpus);
+	return 0;
+}
+
+early_param("bootcpus", bootcpus);
+
+static void __init boot_cpus_init(void)
+{
+	if (!cpumask_available(boot_cpus))
+		zalloc_cpumask_var(&boot_cpus, GFP_NOWAIT);
+	if (cpumask_empty(boot_cpus))
+		cpumask_setall(boot_cpus);
+}
+
 /* Setup number of possible processor ids */
 unsigned int nr_cpu_ids __read_mostly = NR_CPUS;
 EXPORT_SYMBOL(nr_cpu_ids);
@@ -804,10 +825,13 @@ void __init smp_init(void)
 
 	idle_threads_init();
 	cpuhp_threads_init();
+	boot_cpus_init();
 
 	pr_info("Bringing up secondary CPUs ...\n");
 
-	bringup_nonboot_cpus(setup_max_cpus);
+	bringup_nonboot_cpus(setup_max_cpus, boot_cpus);
+
+	free_bootmem_cpumask_var(boot_cpus);
 
 	num_nodes = num_online_nodes();
 	num_cpus  = num_online_cpus();
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux