mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Price <steven.price@arm.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Vincent Donnefort <vincent.donnefort@arm.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: Steven Price <steven.price@arm.com>,
	linux-kernel@vger.kernel.org, Baokun Li <libaokun1@huawei.com>,
	Dongli Zhang <dongli.zhang@oracle.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Valentin Schneider <valentin.schneider@arm.com>,
	Yuan ZhaoXiong <yuanzhaoxiong@baidu.com>,
	YueHaibing <yuehaibing@huawei.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>
Subject: [PATCH v3 2/2] cpu/hotplug: Initialise all cpuhp_cpu_state structs earlier
Date: Mon, 11 Apr 2022 16:22:33 +0100	[thread overview]
Message-ID: <20220411152233.474129-3-steven.price@arm.com> (raw)
In-Reply-To: <20220411152233.474129-1-steven.price@arm.com>

Rather than waiting until a CPU is first brought online, do the
initialisation of the cpuhp_cpu_state structure for each CPU during the
__init phase. This saves a (small) amount of non-__init memory and
avoids potential confusion about when the cpuhp_cpu_state struct is
valid.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Steven Price <steven.price@arm.com>
---
 kernel/cpu.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index 5601216eb51b..65903cb10a55 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -715,14 +715,6 @@ static int cpuhp_up_callbacks(unsigned int cpu, struct cpuhp_cpu_state *st,
 /*
  * The cpu hotplug threads manage the bringup and teardown of the cpus
  */
-static void cpuhp_create(unsigned int cpu)
-{
-	struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
-
-	init_completion(&st->done_up);
-	init_completion(&st->done_down);
-}
-
 static int cpuhp_should_run(unsigned int cpu)
 {
 	struct cpuhp_cpu_state *st = this_cpu_ptr(&cpuhp_state);
@@ -882,15 +874,27 @@ static int cpuhp_kick_ap_work(unsigned int cpu)
 
 static struct smp_hotplug_thread cpuhp_threads = {
 	.store			= &cpuhp_state.thread,
-	.create			= &cpuhp_create,
 	.thread_should_run	= cpuhp_should_run,
 	.thread_fn		= cpuhp_thread_fun,
 	.thread_comm		= "cpuhp/%u",
 	.selfparking		= true,
 };
 
+static __init void cpuhp_init_state(void)
+{
+	struct cpuhp_cpu_state *st;
+	int cpu;
+
+	for_each_possible_cpu(cpu) {
+		st = per_cpu_ptr(&cpuhp_state, cpu);
+		init_completion(&st->done_up);
+		init_completion(&st->done_down);
+	}
+}
+
 void __init cpuhp_threads_init(void)
 {
+	cpuhp_init_state();
 	BUG_ON(smpboot_register_percpu_thread(&cpuhp_threads));
 	kthread_unpark(this_cpu_read(cpuhp_state.thread));
 }
-- 
2.25.1


  parent reply	other threads:[~2022-04-11 15:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-11 15:22 [PATCH v3 0/2] cpu/hotplug: Fix cpuhp_cpu_state used before init Steven Price
2022-04-11 15:22 ` [PATCH v3 1/2] cpu/hotplug: Remove the 'cpu' member of cpuhp_cpu_state Steven Price
2022-04-13 19:25   ` [tip: smp/urgent] " tip-bot2 for Steven Price
2022-04-13 19:32   ` [tip: smp/core] " tip-bot2 for Steven Price
2022-04-11 15:22 ` Steven Price [this message]
2022-04-13 19:32   ` [tip: smp/core] cpu/hotplug: Initialise all cpuhp_cpu_state structs earlier tip-bot2 for Steven Price

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=20220411152233.474129-3-steven.price@arm.com \
    --to=steven.price@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=dongli.zhang@oracle.com \
    --cc=libaokun1@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=valentin.schneider@arm.com \
    --cc=vincent.donnefort@arm.com \
    --cc=yuanzhaoxiong@baidu.com \
    --cc=yuehaibing@huawei.com \
    /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®