Re: [patch 3/3] tick: Annotate tick_do_timer_cpu data races
From: Thomas Gleixner
Date: Tue Dec 15 2020 - 19:28:44 EST
On Tue, Dec 08 2020 at 07:03, Paul E. McKenney wrote:
> On Tue, Dec 08, 2020 at 09:11:29AM +0100, Peter Zijlstra wrote:
>> On Mon, Dec 07, 2020 at 11:44:06AM -0800, Paul E. McKenney wrote:
>>
>> > Also, in this particular case, why data_race() rather than READ_ONCE()?
>> > Do we really expect the compiler to be able to optimize this case
>> > significantly without READ_ONCE()?
There is probably not much optimization potential for the compiler if
data_race() is used vs. READ/WRITE_ONCE() in this code.
>> It's about intent and how the code reads. READ_ONCE() is something
>> completely different from data_race(). data_race() is correct here.
>
> Why?
Lemme answer that to the extent why _I_ chose data_race() - aside of my
likely confusion over our IRC conversation.
The code does not really care about the compiler trying to be clever or
not as it is designed to be tolerant of all sorts of concurrency
including competing writes. It does not care about multiple reloads
either. It neither cares about invented stores as long as these
invented stores are not storing phantasy values.
The only thing it cares about is store/load tearing, but there is no
'clever' way to use that because of the only valid transitions of
'cpunr' which comes from smp_processor_id() to TICK_DO_TIMER_NONE which
is the only constant involved or the other way round (which is
intentionally subject to competing stores).
If the compiler is free to store the 32bit value as 4 seperate bytes or
does invented stores with phantasy values, then there is surely a reason
to switch to READ/WRITE_ONCE(), but that'd be a really daft reason.
So my intent was to document that this code does not care about anything
else than what I'd consider to be plain compiler bugs.
My conclusion might be wrong as usual :)
Thanks,
tglx