[PATCH 4/4] stop_machine: Add a delay between multi_cpu_stop touching watchdogs
From: Nicholas Piggin
Date: Tue Jun 25 2024 - 07:44:03 EST
If a lot of CPUs call rcu_momentary_dyntick_idle() in a tight loop,
this can cause contention that could slow other CPUs reaching
multi_cpu_stop. Add a 10ms delay between patting the various dogs.
Signed-off-by: Nicholas Piggin <npiggin@xxxxxxxxx>
---
kernel/stop_machine.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
index 1e5c4702e36c..626199b572c6 100644
--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -243,8 +243,18 @@ static int multi_cpu_stop(void *data)
ack_state(msdata);
} else {
- /* No state change, chill out */
- stop_machine_yield(cpumask);
+ /*
+ * No state change, chill out. Delay here to prevent
+ * the watchdogs and RCU being hit too hard by lots
+ * of CPUs, which can cause contention and slowdowns.
+ */
+ unsigned long t = jiffies + msecs_to_jiffies(10);
+
+ while (time_before(jiffies, t)) {
+ if (READ_ONCE(msdata->state) != curstate)
+ break;
+ stop_machine_yield(cpumask);
+ }
if (curstate > MULTI_STOP_PREPARE) {
/*
* At this stage all other CPUs we depend on
--
2.45.1