From: Dou Liyang <douly.fnst@cn.fujitsu.com>
To: <linux-kernel@vger.kernel.org>, <x86@kernel.org>,
<linux-acpi@vger.kernel.org>, <linux-doc@vger.kernel.org>
Cc: <tglx@linutronix.de>, <mingo@redhat.com>, <corbet@lwn.net>,
<rjw@rjwysocki.net>, <lenb@kernel.org>, <hpa@zytor.com>,
<peterz@infradead.org>, Dou Liyang <douly.fnst@cn.fujitsu.com>
Subject: [PATCH 3/5] x86/smpboot: Make the check code more clear in prefill_possible_map()
Date: Tue, 20 Mar 2018 19:04:30 +0800 [thread overview]
Message-ID: <20180320110432.28127-4-douly.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <20180320110432.28127-1-douly.fnst@cn.fujitsu.com>
In prefill_possible_map(), Kernel need to get the number of possible CPUs
to reset cpu_possible_map. The number is related to the options:
-nosmp, maxcpus, possible_cpus, nr_cpus
... which need to be checked.
Currentlly, the check code mixed these options together in confusion and
hard to follow.
Isolate them, and check them linearly.
No functionary change, Prepare for cutting the number of possible CPUs
Signed-off-by: Dou Liyang <douly.fnst@cn.fujitsu.com>
---
Situations:
setup_possible_cpus == -1 | setup_max_cpus == 0 | CONFIG_HOTPLUG_CPU == y |
yes | yes | yes |
no | no | no |
Test cases:
Cases | the number of possible cpus
| (the same with or w/o this patch)
case 1: no | no | no | --> min (setup_possible_cpus, nr_cpu_ids, setup_max_cpus)
case 2: no | no | yes| --> min (setup_possible_cpus, nr_cpu_ids)
case 3: no | yes | no | --> 1
case 4: no | yes | yes| --> 1
case 5: yes | no | no | --> min (num_processors, nr_cpu_ids, setup_max_cpus)
case 6: yes | no | yes| --> min (num_processors + disabled_cpus, nr_cpu_ids)
case 7: yes | yes | no | --> 1
case 8: yes | yes | yes| --> 1
arch/x86/kernel/smpboot.c | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index ff99e2b6fc54..2fdda8567bf9 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1334,7 +1334,7 @@ early_param("possible_cpus", _setup_possible_cpus);
* We do this because additional CPUs waste a lot of memory.
* -AK
*/
-__init void prefill_possible_map(void)
+void __init prefill_possible_map(void)
{
int i, possible;
@@ -1356,18 +1356,22 @@ __init void prefill_possible_map(void)
num_processors = 1;
}
- i = setup_max_cpus ?: 1;
+ /* The SMP kernel could be acted as an UP kernel via nosmp/maxcpus=0 */
+ if (!setup_max_cpus) {
+ possible = 1;
+ total_cpus = num_processors + disabled_cpus;
+ goto set_cpu_possible_mask;
+ }
+
+ /* Possible CPUs could be overwrited via possible_cpus= */
if (setup_possible_cpus == -1) {
possible = num_processors;
#ifdef CONFIG_HOTPLUG_CPU
- if (setup_max_cpus)
- possible += disabled_cpus;
-#else
- if (possible > i)
- possible = i;
+ possible += disabled_cpus;
#endif
- } else
+ } else {
possible = setup_possible_cpus;
+ }
total_cpus = max_t(int, possible, num_processors + disabled_cpus);
@@ -1378,15 +1382,16 @@ __init void prefill_possible_map(void)
possible = nr_cpu_ids;
}
-#ifdef CONFIG_HOTPLUG_CPU
- if (!setup_max_cpus)
-#endif
- if (possible > i) {
+#ifndef CONFIG_HOTPLUG_CPU
+ /* Possible CPUs could be reduced via max_cpus= */
+ if (possible > setup_max_cpus) {
pr_warn("%d Processors exceeds max_cpus limit of %u\n",
possible, setup_max_cpus);
- possible = i;
+ possible = setup_max_cpus;
}
+#endif
+set_cpu_possible_mask:
nr_cpu_ids = possible;
pr_info("Allowing %d CPUs, %d hotplug CPUs\n",
--
2.14.3
next prev parent reply other threads:[~2018-03-20 11:07 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-20 11:04 [PATCH 0/5] x86/cpu_hotplug: one bug fix and four cleanup Dou Liyang
2018-03-20 11:04 ` [PATCH 1/5] x86/smpboot: Add the missing description of possible_cpus Dou Liyang
2018-03-20 12:37 ` Peter Zijlstra
2018-03-21 5:33 ` Dou Liyang
2018-03-21 9:08 ` Peter Zijlstra
2018-03-21 9:34 ` Dou Liyang
2018-03-21 9:41 ` Dou Liyang
2018-03-21 9:41 ` Thomas Gleixner
2018-03-20 11:04 ` [PATCH 2/5] x86/cpu_hotplug: Update the link of cpu_hotplug.rst Dou Liyang
2018-03-20 11:04 ` Dou Liyang [this message]
2018-03-20 12:39 ` [PATCH 3/5] x86/smpboot: Make the check code more clear in prefill_possible_map() Peter Zijlstra
2018-03-21 5:38 ` Dou Liyang
2018-03-20 11:04 ` [PATCH 4/5] acpi/processor: Fix the return value of acpi_processor_ids_walk() Dou Liyang
2018-05-19 15:06 ` Thomas Gleixner
2018-05-22 1:47 ` Dou Liyang
2018-05-23 1:34 ` Dou Liyang
2018-05-23 8:08 ` Rafael J. Wysocki
2018-03-20 11:04 ` [PATCH 5/5] acpi/processor: Make the acpi_duplicate_processor_id() static Dou Liyang
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=20180320110432.28127-4-douly.fnst@cn.fujitsu.com \
--to=douly.fnst@cn.fujitsu.com \
--cc=corbet@lwn.net \
--cc=hpa@zytor.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rjw@rjwysocki.net \
--cc=tglx@linutronix.de \
--cc=x86@kernel.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
all inboxes | Powered by JetHome®