From: Thomas Gleixner <tglx@linutronix.de>
To: Usama Arif <usama.arif@bytedance.com>,
dwmw2@infradead.org, kim.phillips@amd.com, brgerst@gmail.com
Cc: piotrgorski@cachyos.org, oleksandr@natalenko.name,
arjan@linux.intel.com, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, hpa@zytor.com, x86@kernel.org,
pbonzini@redhat.com, paulmck@kernel.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
rcu@vger.kernel.org, mimoja@mimoja.de, hewenliang4@huawei.com,
thomas.lendacky@amd.com, seanjc@google.com,
pmenzel@molgen.mpg.de, fam.zheng@bytedance.com,
punit.agrawal@bytedance.com, simon.evans@bytedance.com,
liangma@liangbit.com, gpiccoli@igalia.com,
David Woodhouse <dwmw@amazon.co.uk>,
Usama Arif <usama.arif@bytedance.com>
Subject: Re: [PATCH v16 3/8] cpu/hotplug: Add dynamic parallel bringup states before CPUHP_BRINGUP_CPU
Date: Fri, 24 Mar 2023 00:05:32 +0100 [thread overview]
Message-ID: <871qlf83wj.ffs@tglx> (raw)
In-Reply-To: <874jqb8588.ffs@tglx>
On Thu, Mar 23 2023 at 23:36, Thomas Gleixner wrote:
> On Tue, Mar 21 2023 at 19:40, Usama Arif wrote:
>> void bringup_nonboot_cpus(unsigned int setup_max_cpus)
>> {
>> + unsigned int n = setup_max_cpus - num_online_cpus();
>> unsigned int cpu;
>>
>> + /*
>> + * An architecture may have registered parallel pre-bringup states to
>> + * which each CPU may be brought in parallel. For each such state,
>> + * bring N CPUs to it in turn before the final round of bringing them
>> + * online.
>> + */
>> + if (n > 0) {
>> + enum cpuhp_state st = CPUHP_BP_PARALLEL_DYN;
>> +
>> + while (st <= CPUHP_BP_PARALLEL_DYN_END && cpuhp_hp_states[st].name) {
>
>
> There is no point in special casing this. All architectures can invoke
> the CPUHP_BP_* states before CPUHP_BRINGUP_CPU for each to be brought up
> CPU first. So this can be made unconditional and common exercised
> code.
Bah. There is. We discussed that before. Architectures need to opt in to
make sure that there are no implicit dependencies on the full
serialization.
Still the rest can be simplified as below.
Thanks,
tglx
---
--- a/include/linux/cpuhotplug.h
+++ b/include/linux/cpuhotplug.h
@@ -133,6 +133,20 @@ enum cpuhp_state {
CPUHP_MIPS_SOC_PREPARE,
CPUHP_BP_PREPARE_DYN,
CPUHP_BP_PREPARE_DYN_END = CPUHP_BP_PREPARE_DYN + 20,
+ /*
+ * This is an optional state if the architecture supports parallel
+ * startup. It's used to send the startup IPI so that the APs can
+ * run in parallel through the low level startup code instead of
+ * sending the IPIs one by one in CPUHP_BRINGUP_CPU. This avoids
+ * waiting for the AP to react and shortens the serialized bringup.
+ */
+ CPUHP_BP_PARALLEL_STARTUP,
+
+ /*
+ * Fully per AP serialized bringup from here on. If the
+ * architecture does no register the CPUHP_BP_PARALLEL_STARTUP
+ * state, this step sends the startup IPI first.
+ */
CPUHP_BRINGUP_CPU,
/*
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1504,13 +1504,45 @@ int bringup_hibernate_cpu(unsigned int s
void bringup_nonboot_cpus(unsigned int setup_max_cpus)
{
- unsigned int cpu;
+ unsigned int cpu, n = 1;
+ /*
+ * On architectures which have setup the CPUHP_BP_PARALLEL_STARTUP
+ * state, this invokes all BP prepare states and the parallel
+ * startup state sends the startup IPI to each of the to be onlined
+ * APs. This avoids waiting for each AP to respond to the startup
+ * IPI in CPUHP_BRINGUP_CPU. The APs proceed through the low level
+ * bringup code and then wait for the control CPU to release them
+ * one by one for the final onlining procedure in the loop below.
+ *
+ * For architectures which do not support parallel bringup all
+ * states are fully serialized in the loop below.
+ */
+ if (!cpuhp_step_empty(true, CPUHP_BP_PARALLEL_STARTUP) {
+ for_each_present_cpu(cpu) {
+ if (n++ >= setup_max_cpus)
+ break;
+ cpu_up(cpu, CPUHP_BP_PARALLEL_STARTUP);
+ }
+ }
+
+ /* Do the per CPU serialized bringup to ONLINE state */
for_each_present_cpu(cpu) {
if (num_online_cpus() >= setup_max_cpus)
break;
- if (!cpu_online(cpu))
- cpu_up(cpu, CPUHP_ONLINE);
+
+ if (!cpu_online(cpu)) {
+ struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
+ int ret = cpu_up(cpu, CPUHP_ONLINE);
+
+ /*
+ * Due to the above preparation loop a failed online attempt
+ * might have only rolled back to CPUHP_BP_PARALLEL_STARTUP. Do the
+ * remaining cleanups. NOOP for the non parallel case.
+ */
+ if (ret && can_rollback_cpu(st))
+ WARN_ON(cpuhp_invoke_callback_range(false, cpu, st, CPUHP_OFFLINE));
+ }
}
}
next prev parent reply other threads:[~2023-03-23 23:05 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 19:40 [PATCH v16 0/8] Parallel CPU bringup for x86_64 Usama Arif
2023-03-21 19:40 ` [PATCH v16 1/8] cpu/hotplug: Move idle_thread_get() to <linux/smpboot.h> Usama Arif
2023-03-21 19:40 ` [PATCH v16 2/8] cpu/hotplug: Reset task stack state in _cpu_up() Usama Arif
2023-03-22 11:06 ` Mark Rutland
2023-03-21 19:40 ` [PATCH v16 3/8] cpu/hotplug: Add dynamic parallel bringup states before CPUHP_BRINGUP_CPU Usama Arif
2023-03-23 22:36 ` Thomas Gleixner
2023-03-23 22:49 ` David Woodhouse
2023-03-23 23:48 ` Thomas Gleixner
2023-03-24 0:06 ` David Woodhouse
2023-03-23 23:05 ` Thomas Gleixner [this message]
2023-03-23 23:12 ` David Woodhouse
2023-03-24 1:16 ` Thomas Gleixner
2023-03-24 9:31 ` David Woodhouse
2023-03-24 13:57 ` Thomas Gleixner
2023-03-24 15:33 ` David Woodhouse
2023-03-24 14:07 ` Thomas Gleixner
2023-03-24 9:46 ` Thomas Gleixner
2023-03-24 10:00 ` David Woodhouse
2023-03-27 18:48 ` David Woodhouse
2023-03-21 19:40 ` [PATCH v16 4/8] x86/smpboot: Split up native_cpu_up into separate phases and document them Usama Arif
2023-03-21 19:40 ` [PATCH v16 5/8] x86/smpboot: Support parallel startup of secondary CPUs Usama Arif
2023-03-21 19:40 ` [PATCH v16 6/8] x86/smpboot: Send INIT/SIPI/SIPI to secondary CPUs in parallel Usama Arif
2023-03-21 19:40 ` [PATCH v16 7/8] x86/smpboot: Serialize topology updates for secondary bringup Usama Arif
2023-03-21 19:40 ` [PATCH v16 8/8] x86/smpboot: Allow parallel bringup for SEV-ES Usama Arif
2023-03-22 22:47 ` Borislav Petkov
2023-03-23 8:32 ` David Woodhouse
2023-03-23 8:51 ` Borislav Petkov
2023-03-23 9:04 ` David Woodhouse
2023-03-23 14:23 ` Brian Gerst
2023-03-27 17:47 ` Borislav Petkov
2023-03-27 18:14 ` David Woodhouse
2023-03-27 19:14 ` Tom Lendacky
2023-03-27 19:32 ` Borislav Petkov
2023-03-23 13:16 ` Tom Lendacky
[not found] ` <751f572f940220775054dc09324b20b929d7d66d.camel@amazon.co.uk>
2023-03-23 18:28 ` Tom Lendacky
2023-03-23 22:13 ` Borislav Petkov
2023-03-23 22:30 ` [EXTERNAL][PATCH " David Woodhouse
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=871qlf83wj.ffs@tglx \
--to=tglx@linutronix.de \
--cc=arjan@linux.intel.com \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=dave.hansen@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=dwmw@amazon.co.uk \
--cc=fam.zheng@bytedance.com \
--cc=gpiccoli@igalia.com \
--cc=hewenliang4@huawei.com \
--cc=hpa@zytor.com \
--cc=kim.phillips@amd.com \
--cc=kvm@vger.kernel.org \
--cc=liangma@liangbit.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mimoja@mimoja.de \
--cc=mingo@redhat.com \
--cc=oleksandr@natalenko.name \
--cc=paulmck@kernel.org \
--cc=pbonzini@redhat.com \
--cc=piotrgorski@cachyos.org \
--cc=pmenzel@molgen.mpg.de \
--cc=punit.agrawal@bytedance.com \
--cc=rcu@vger.kernel.org \
--cc=seanjc@google.com \
--cc=simon.evans@bytedance.com \
--cc=thomas.lendacky@amd.com \
--cc=usama.arif@bytedance.com \
--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