* [PATCH] timers/nohz: Annotate lockless accesses to got_idle_tick
@ 2026-09-20 8:54 Kunwu Chan
2026-09-29 12:21 ` Thomas Gleixner
0 siblings, 1 reply; 2+ messages in thread
From: Kunwu Chan @ 2026-09-20 8:54 UTC (permalink / raw)
To: anna-maria, frederic, mingo, tglx; +Cc: linux-kernel, paulmck, Kunwu Chan
tick_sched_do_timer(), called from the tick interrupt handler, sets
ts->got_idle_tick when a tick fires while the CPU is idle. The idle
path reads and clears it via tick_nohz_idle_got_tick() to detect
whether the tick handler has run.
The flag is accessed locklessly from hardirq and task context. A
concurrent set can be overwritten by the clear.
Use READ_ONCE() and WRITE_ONCE() to annotate the lockless accesses.
Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
kernel/time/tick-sched.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c
index 6c3fea386713..c0ab32e543b3 100644
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -269,7 +269,7 @@ static void tick_sched_do_timer(struct tick_sched *ts, ktime_t now)
}
if (tick_sched_flag_test(ts, TS_FLAG_INIDLE))
- ts->got_idle_tick = 1;
+ WRITE_ONCE(ts->got_idle_tick, 1);
}
static void tick_sched_handle(struct tick_sched *ts, struct pt_regs *regs)
@@ -1248,8 +1248,8 @@ bool tick_nohz_idle_got_tick(void)
{
struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched);
- if (ts->got_idle_tick) {
- ts->got_idle_tick = 0;
+ if (READ_ONCE(ts->got_idle_tick)) {
+ WRITE_ONCE(ts->got_idle_tick, 0);
return true;
}
return false;
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] timers/nohz: Annotate lockless accesses to got_idle_tick
2026-09-20 8:54 [PATCH] timers/nohz: Annotate lockless accesses to got_idle_tick Kunwu Chan
@ 2026-09-29 12:21 ` Thomas Gleixner
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2026-09-29 12:21 UTC (permalink / raw)
To: Kunwu Chan, anna-maria, frederic, mingo; +Cc: linux-kernel, paulmck, Kunwu Chan
On Sun, Sep 20 2026 at 16:54, Kunwu Chan wrote:
> tick_sched_do_timer(), called from the tick interrupt handler, sets
> ts->got_idle_tick when a tick fires while the CPU is idle. The idle
> path reads and clears it via tick_nohz_idle_got_tick() to detect
> whether the tick handler has run.
>
> The flag is accessed locklessly from hardirq and task context. A
> concurrent set can be overwritten by the clear.
>
> Use READ_ONCE() and WRITE_ONCE() to annotate the lockless accesses.
The following scenarios still happen:
A)
if (READ_ONCE(got_tick)) // reads true
-> interrupt
WRITE_ONCE(got_tick, true);
WRITE_ONCE(got_tick, false);
B)
if (READ_ONCE(got_tick)) // reads false
-> interrupt
WRITE_ONCE(got_tick, true);
#A is harmless because got_tick is already true and #B is harmless as
well because the got_tick read result is only a hint for the next idle
invocation.
As this is stricly per CPU the READ/WRITE_ONCE() does not change
anything in terms of ordering. So what exactly is solved by the
READ/WRITE_ONCE()?
Thanks,
tglx
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-29 12:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-20 8:54 [PATCH] timers/nohz: Annotate lockless accesses to got_idle_tick Kunwu Chan
2026-09-29 12:21 ` Thomas Gleixner
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®