linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pingfan Liu <kernelfans@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Pingfan Liu <kernelfans@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Steven Price <steven.price@arm.com>,
	Andi Kleen <ak@linux.intel.com>,
	Frederic Weisbecker <frederic@kernel.org>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	Mark Rutland <mark.rutland@arm.com>
Subject: [RFC 01/10] cpu/hotplug: Make __cpuhp_kick_ap() ready for async
Date: Mon, 22 Aug 2022 10:15:11 +0800	[thread overview]
Message-ID: <20220822021520.6996-2-kernelfans@gmail.com> (raw)
In-Reply-To: <20220822021520.6996-1-kernelfans@gmail.com>

At present, during the kexec reboot, the teardown of cpus can not run in
parallel. As the first step towards the parallel, it demands the
initiator to kick ap thread one by one instead of waiting for each ap
thread completion.

Change the prototype of __cpuhp_kick_ap() to cope with this demand.

Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Steven Price <steven.price@arm.com>
Cc: "Peter Zijlstra
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: Mark Rutland <mark.rutland@arm.com>
To: linux-kernel@vger.kernel.org
---
 kernel/cpu.c | 41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index bbad5e375d3b..338e1d426c7e 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -526,7 +526,7 @@ cpuhp_reset_state(int cpu, struct cpuhp_cpu_state *st,
 }
 
 /* Regular hotplug invocation of the AP hotplug thread */
-static void __cpuhp_kick_ap(struct cpuhp_cpu_state *st)
+static void __cpuhp_kick_ap(struct cpuhp_cpu_state *st, bool sync)
 {
 	if (!st->single && st->state == st->target)
 		return;
@@ -539,20 +539,22 @@ static void __cpuhp_kick_ap(struct cpuhp_cpu_state *st)
 	smp_mb();
 	st->should_run = true;
 	wake_up_process(st->thread);
-	wait_for_ap_thread(st, st->bringup);
+	if (sync)
+		wait_for_ap_thread(st, st->bringup);
 }
 
 static int cpuhp_kick_ap(int cpu, struct cpuhp_cpu_state *st,
-			 enum cpuhp_state target)
+		enum cpuhp_state target, bool sync)
 {
 	enum cpuhp_state prev_state;
 	int ret;
 
 	prev_state = cpuhp_set_state(cpu, st, target);
-	__cpuhp_kick_ap(st);
-	if ((ret = st->result)) {
+	__cpuhp_kick_ap(st, sync);
+	ret = st->result;
+	if (sync && ret) {
 		cpuhp_reset_state(cpu, st, prev_state);
-		__cpuhp_kick_ap(st);
+		__cpuhp_kick_ap(st, true);
 	}
 
 	return ret;
@@ -583,7 +585,7 @@ static int bringup_wait_for_ap(unsigned int cpu)
 	if (st->target <= CPUHP_AP_ONLINE_IDLE)
 		return 0;
 
-	return cpuhp_kick_ap(cpu, st, st->target);
+	return cpuhp_kick_ap(cpu, st, st->target, true);
 }
 
 static int bringup_cpu(unsigned int cpu)
@@ -835,7 +837,7 @@ cpuhp_invoke_ap_callback(int cpu, enum cpuhp_state state, bool bringup,
 	st->cb_state = state;
 	st->single = true;
 
-	__cpuhp_kick_ap(st);
+	__cpuhp_kick_ap(st, true);
 
 	/*
 	 * If we failed and did a partial, do a rollback.
@@ -844,7 +846,7 @@ cpuhp_invoke_ap_callback(int cpu, enum cpuhp_state state, bool bringup,
 		st->rollback = true;
 		st->bringup = !bringup;
 
-		__cpuhp_kick_ap(st);
+		__cpuhp_kick_ap(st, true);
 	}
 
 	/*
@@ -868,12 +870,29 @@ static int cpuhp_kick_ap_work(unsigned int cpu)
 	cpuhp_lock_release(true);
 
 	trace_cpuhp_enter(cpu, st->target, prev_state, cpuhp_kick_ap_work);
-	ret = cpuhp_kick_ap(cpu, st, st->target);
+	ret = cpuhp_kick_ap(cpu, st, st->target, true);
 	trace_cpuhp_exit(cpu, st->state, prev_state, ret);
 
 	return ret;
 }
 
+/* In the async case, trace is meaningless since ret value is not available */
+static int cpuhp_kick_ap_work_async(unsigned int cpu)
+{
+	struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
+	int ret;
+
+	cpuhp_lock_acquire(false);
+	cpuhp_lock_release(false);
+
+	cpuhp_lock_acquire(true);
+	cpuhp_lock_release(true);
+
+	ret = cpuhp_kick_ap(cpu, st, st->target, false);
+
+	return ret;
+}
+
 static struct smp_hotplug_thread cpuhp_threads = {
 	.store			= &cpuhp_state.thread,
 	.thread_should_run	= cpuhp_should_run,
@@ -1171,7 +1190,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
 	if (ret && st->state < prev_state) {
 		if (st->state == CPUHP_TEARDOWN_CPU) {
 			cpuhp_reset_state(cpu, st, prev_state);
-			__cpuhp_kick_ap(st);
+			__cpuhp_kick_ap(st, true);
 		} else {
 			WARN(1, "DEAD callback error for CPU%d", cpu);
 		}
-- 
2.31.1


  reply	other threads:[~2022-08-22  2:15 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-22  2:15 [RFC 00/10] arm64/riscv: Introduce fast kexec reboot Pingfan Liu
2022-08-22  2:15 ` Pingfan Liu [this message]
2022-08-22  2:15 ` [RFC 02/10] cpu/hotplug: Compile smp_shutdown_nonboot_cpus() conditioned on CONFIG_SHUTDOWN_NONBOOT_CPUS Pingfan Liu
2022-08-22  2:15 ` [RFC 03/10] cpu/hotplug: Introduce fast kexec reboot Pingfan Liu
2022-08-22  2:15 ` [RFC 04/10] cpu/hotplug: Check the capability of kexec quick reboot Pingfan Liu
2022-08-22  2:15 ` [RFC 05/10] perf/arm-dsu: Make dsu_pmu_cpu_teardown() parallel Pingfan Liu
2022-08-22  2:15 ` [RFC 06/10] rcu/hotplug: Make rcutree_dead_cpu() parallel Pingfan Liu
2022-08-22  2:45   ` Paul E. McKenney
2022-08-23  1:50     ` Pingfan Liu
2022-08-23  3:01       ` Paul E. McKenney
2022-08-24 13:53         ` Pingfan Liu
2022-08-24 16:20           ` Paul E. McKenney
2022-08-24 17:26             ` Joel Fernandes
2022-08-24 19:21               ` Paul E. McKenney
2022-08-24 22:54                 ` Joel Fernandes
2022-08-24 23:01                   ` Paul E. McKenney
2022-08-31 16:15             ` Paul E. McKenney
2022-09-05  3:53               ` Pingfan Liu
2022-09-06 18:45                 ` Paul E. McKenney
2022-08-22 18:08   ` Joel Fernandes
2022-08-23  1:56     ` Pingfan Liu
2022-08-23  3:14       ` Joel Fernandes
2022-08-24 13:38         ` Pingfan Liu
2022-08-24 13:44       ` Jason A. Donenfeld
2022-08-22  2:15 ` [RFC 07/10] lib/cpumask: Introduce cpumask_not_dying_but() Pingfan Liu
2022-08-22 14:15   ` Yury Norov
2022-08-23  7:29     ` Pingfan Liu
2022-08-22  2:15 ` [RFC 08/10] cpuhp: Replace cpumask_any_but(cpu_online_mask, cpu) Pingfan Liu
2022-08-22  2:15 ` [RFC 09/10] genirq/cpuhotplug: Ask migrate_one_irq() to migrate to a real online cpu Pingfan Liu
2022-08-22  2:15 ` [RFC 10/10] arm64: smp: Make __cpu_disable() parallel Pingfan Liu

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=20220822021520.6996-2-kernelfans@gmail.com \
    --to=kernelfans@gmail.com \
    --cc=Jason@zx2c4.com \
    --cc=ak@linux.intel.com \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=steven.price@arm.com \
    --cc=tglx@linutronix.de \
    /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).