Re: [External] Re: [PATCH] seqlock: Use while instead of if+goto in __read_seqcount_begin

From: Peter Zijlstra
Date: Wed Apr 15 2020 - 07:44:25 EST


On Tue, Apr 14, 2020 at 08:01:06PM +0800, Muchun Song wrote:
> On Tue, Apr 14, 2020 at 7:05 PM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:

> > .... That said,
> > Will, would it make sense to use smp_cond_load_relaxed() here ?
>
> I have a similar idea. Would it make sense to use smp_cond_load_acquire()
> in raw_read_seqcount_begin()?

Not sure; I did consider it, but that rmb it has seems more natural in
the over-all ordering scheme here. I mean:

load seqcount inc seqcount
rmb wmb
// load stuff // modify stuff
rmb wmb
compare seqcount inc seqcount

is nice and symmetric, making that upper left rmb an acquire 'works' but
is just weird IMO. And I suppose you can make the lower right wmb a
store-release, which is somewhat better, but then it gets all weird when
you consider things like barrier and latch.

So best to just leave it as is I think.

Those incs do seem to be really wanting a WRITE_ONCE() though.