All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hrtimers: Update new CPU's next event in hrtimers_cpu_dying()
@ 2025-07-08 10:17 Xiongfeng Wang
  2025-07-08 12:40 ` Frederic Weisbecker
  0 siblings, 1 reply; 6+ messages in thread
From: Xiongfeng Wang @ 2025-07-08 10:17 UTC (permalink / raw)
  To: anna-maria, frederic, tglx
  Cc: linux-kernel, xiexiuqi, bobo.shaobowang, wangxiongfeng2

When testing softirq based hrtimers on an ARM32 board, with high
resolution mode and nohz are both inactive, softirq based hrtimers
failed to trigger when moved away from an offline CPU. The flowpath
is as follows.

CPU0				CPU1
				softirq based hrtimers are queued
				offline CPU1
				move hrtimers to CPU0 in hrtimers_cpu_dying()
				send IPI to CPU0 to retrigger next event
'softirq_expires_next' is KTIME_MAX
call retrigger_next_event()
highres and nohz is inactive,just return
'softirq_expires_next' is not updated
hrtimer softirq is never triggered

Some softirq based hrtimers are queued on CPU1. Then we offline CPU1.
hrtimers_cpu_dying() moves hrtimers from CPU1 to CPU0, and then it send
a IPI to CPU0 to let CPU0 call retrigger_next_event(). But high
resolution mode and nohz are both inactive. So retrigger_next_event()
just returned. 'softirq_expires_next' is never updated and remains
KTIME_MAX. So hrtimer softirq is never raised.

To fix this issue, we call hrtimer_update_next_event() in
hrtimers_cpu_dying() to update 'softirq_expires_next' for the new CPU.
It also update hardirq hrtimer's next event, but it should have no bad
effect.

Fixes: 5c0930ccaad5 ("hrtimers: Push pending hrtimers away from outgoing CPU earlier")
Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
---
 kernel/time/hrtimer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 30899a8cc52c..ff97eb36c116 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -2298,8 +2298,11 @@ int hrtimers_cpu_dying(unsigned int dying_cpu)
 	/*
 	 * The migration might have changed the first expiring softirq
 	 * timer on this CPU. Update it.
+	 * We also need to update 'softirq_expires_next' here, because it will
+	 * not be updated in retrigger_next_event() if high resolution mode
+	 * and nohz are both inactive.
 	 */
-	__hrtimer_get_next_event(new_base, HRTIMER_ACTIVE_SOFT);
+	hrtimer_update_next_event(new_base);
 	/* Tell the other CPU to retrigger the next event */
 	smp_call_function_single(ncpu, retrigger_next_event, NULL, 0);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-07-09 12:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-08 10:17 [PATCH] hrtimers: Update new CPU's next event in hrtimers_cpu_dying() Xiongfeng Wang
2025-07-08 12:40 ` Frederic Weisbecker
2025-07-08 16:23   ` 答复: " Wangshaobo (bobo)
2025-07-08 16:45     ` Wangshaobo (bobo)
2025-07-09  3:18   ` Xiongfeng Wang
2025-07-09 12:54     ` Frederic Weisbecker

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.