Re: [PATCH] seqlock: Use WRITE_ONCE() when updating sequence

From: Waiman Long
Date: Wed Dec 18 2024 - 15:09:33 EST



On 12/18/24 1:52 PM, Paul E. McKenney wrote:
If the compiler really uses the variable as a scratch storage, it will be a
problem if the variable can be accessed concurrently from multiple CPUs. It
is a new compiler optimization strategy that I am aware before. In that
case, we may really need a way to mark these variables as not suitable for
such advanced optimization.
These markings already exist, namely, the "volatile" keyword, READ_ONCE(),
WRITE_ONCE(), and hopefully soon INC_ONCE(). These last three use
volatile accesses internally.

The scratch-storage possibility exists only just before a normal
C-language store, not before volatile accesses. So a compiler is
forbidden from doing that scratch-value-store trick before a volatile
store.

I am aware of that in READ_ONCE() and WRITE_ONCE() and I am looking forward to have a INC_ONCE() and maybe DEC_ONCE() soon.

Cheers,
Longman