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

From: Peter Zijlstra
Date: Wed Dec 18 2024 - 11:23:55 EST


On Wed, Dec 18, 2024 at 07:43:41AM -0800, Paul E. McKenney wrote:
> On Wed, Dec 18, 2024 at 11:30:00AM +0100, Peter Zijlstra wrote:
> > On Tue, Dec 17, 2024 at 03:17:36PM -0800, Daniel Xu wrote:


> > > @@ -405,7 +405,7 @@ do { \
> > > static inline void do_raw_write_seqcount_begin(seqcount_t *s)
> > > {
> > > kcsan_nestable_atomic_begin();
> > > - s->sequence++;
> > > + WRITE_ONCE(s->sequence, READ_ONCE(s->sequence) + 1);
> > > smp_wmb();
> > > }
> >
> > This results in significantly worse code-gen, it will change an inc to
> > memory with a load,inc,store.
>
> Isn't that code-generation bug in the process of being fixed?

Last time I looked the compiler wasn't allowed to touch it because of
all the volatile going around. Did anything change?

> And, either way, given the likely cache miss, should we really care?

Yeah, extra register pressure too.