Re: [PATCH 1/1] Fix: trace sched switch start/stop racy updates
From: Mathieu Desnoyers
Date: Sat Aug 17 2019 - 11:03:02 EST
----- On Aug 17, 2019, at 4:44 AM, Linus Torvalds torvalds@xxxxxxxxxxxxxxxxxxxx wrote:
>
> But I'm seeing a lot of WRITE_ONCE(x, constantvalue) kind of things
> and don't seem to find a lot of reason to think that they are any
> inherently better than "x = constantvalue".
If the only states that "x" can take is 1 or 0, then indeed there seems
to be no point in using a WRITE_ONCE() when paired with a READ_ONCE()
other than for documentation purposes.
However, if the state of "x" can be any pointer value, or a reference
count value, then not using "WRITE_ONCE()" to store a constant leaves
the compiler free to perform that store in more than one memory access.
Based on [1], section "Store tearing", there are situations where this
happens on x86 in the wild today when storing 64-bit constants: the
compiler is then free to decide to use two 32-bit immediate store
instructions.
Thanks,
Mathieu
[1] https://lwn.net/Articles/793253/
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com