[PATCH 3/4] stop_machine: Rearrange multi_cpu_stop state machine loop
From: Nicholas Piggin
Date: Tue Jun 25 2024 - 07:43:50 EST
More clearly separate the state-machine progress case from the
non-progress case.
Move stop_machine_yield() and rcu_momentary_dyntick_idle() calls
to the non-progress case like touch_nmi_watchdog(), rather than
always calling them, since there is no reason to yield or touch
watchdogs if the state machine progressed.
Signed-off-by: Nicholas Piggin <npiggin@xxxxxxxxx>
---
kernel/stop_machine.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
index cedb17ba158a..1e5c4702e36c 100644
--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -225,8 +225,6 @@ static int multi_cpu_stop(void *data)
/* Simple state machine */
do {
- /* Chill out and ensure we re-read multi_stop_state. */
- stop_machine_yield(cpumask);
newstate = READ_ONCE(msdata->state);
if (newstate != curstate) {
curstate = newstate;
@@ -243,15 +241,22 @@ static int multi_cpu_stop(void *data)
break;
}
ack_state(msdata);
- } else if (curstate > MULTI_STOP_PREPARE) {
- /*
- * At this stage all other CPUs we depend on must spin
- * in the same loop. Any reason for hard-lockup should
- * be detected and reported on their side.
- */
- touch_nmi_watchdog();
+
+ } else {
+ /* No state change, chill out */
+ stop_machine_yield(cpumask);
+ if (curstate > MULTI_STOP_PREPARE) {
+ /*
+ * At this stage all other CPUs we depend on
+ * must spin in the same loop. Any reason for
+ * hard-lockup should be detected and reported
+ * on their side.
+ */
+ touch_nmi_watchdog();
+ }
+ rcu_momentary_dyntick_idle();
}
- rcu_momentary_dyntick_idle();
+
} while (curstate != MULTI_STOP_EXIT);
local_irq_restore(flags);
--
2.45.1