From: Elliot Berman <eberman@codeaurora.org>
To: Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
Jonathan Corbet <corbet@lwn.net>
Cc: Elliot Berman <eberman@codeaurora.org>,
Trilok Soni <tsoni@codeaurora.org>,
Prasad Sodagudi <psodagud@codeaurora.org>,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org
Subject: [PATCH] smp: Add bootcpus parameter to boot subset of CPUs
Date: Thu, 22 Oct 2020 15:04:03 -0700 [thread overview]
Message-ID: <1603404243-5536-1-git-send-email-eberman@codeaurora.org> (raw)
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@codeaurora.org>
---
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
next reply other threads:[~2020-10-22 22:05 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-22 22:04 Elliot Berman [this message]
2020-10-23 7:45 ` [PATCH] smp: Add bootcpus parameter to boot subset of CPUs Peter Zijlstra
2020-10-23 21:59 ` Thomas Gleixner
2020-10-26 17:08 ` psodagud
2020-10-26 17:12 ` Peter Zijlstra
2020-10-27 17:06 ` Elliot Berman
2020-10-28 14:55 ` Qais Yousef
2020-10-28 15:15 ` Sudeep Holla
2020-10-29 21:37 ` Elliot Berman
2020-10-30 17:45 ` Sudeep Holla
2020-11-03 22:10 ` Thomas Gleixner
2020-10-26 19:04 ` Thomas Gleixner
2020-10-25 13:06 ` Qais Yousef
2020-10-28 15:55 ` Sudeep Holla
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1603404243-5536-1-git-send-email-eberman@codeaurora.org \
--to=eberman@codeaurora.org \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=psodagud@codeaurora.org \
--cc=tglx@linutronix.de \
--cc=tsoni@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).