Re: [PATCH] timers/nohz: Annotate lockless accesses to got_idle_tick

From: Thomas Gleixner

Date: Tue Sep 29 2026 - 08:29:36 EST


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