Re: [PATCH v2] tools/memory-model: Add extra ordering for locks and remove it for ordinary release/acquire
From: Paul E. McKenney
Date: Tue Jul 17 2018 - 15:40:43 EST
On Tue, Jul 17, 2018 at 11:49:41AM -0700, Linus Torvalds wrote:
> On Tue, Jul 17, 2018 at 11:44 AM Linus Torvalds
> <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> >
> > (a) lwsync is a memory barrier for all the "easy" cases (ie
> > load->store, load->load, and store->load).
>
> That last one should have been "store->store", of course.
Heh! I autocorrected without noticing.
> So 'lwsync' gives smp_rmb(), smp_wmb(), and smp_load_acquire()
> semantics (which are the usual "no barrier needed at all" suspects for
> things like x86).
Yes.
> What lwsync lacks is store->load ordering. So:
>
> > (b) lwsync is *not* a memory barrier for the store->load case.
>
> BUT, this is where isync comes in:
>
> > (c) isync *is* (when in that *sequence*) a memory barrier for a
> > store->load case (and has to be: loads inside a spinlocked region MUST
> > NOT be done earlier than stores outside of it!).
>
> which is why I think that a spinlock implementation that uses isync
> would give us the semantics we want, without the use of the crazy
> expensive 'sync' that Michael tested (and which apparently gets
> horrible 10% scheduler performance regressions at least on some
> powerpc CPU's).
Again, although isync orders the store -instruction- -execution- against
later loads, it does nothing to flush the store buffer. So the prior
stores will not necessarily appear to be ordered from the viewpoint of
other CPUs not holding the lock.
Again, if those other CPUs are holding the lock, they see all memory
accesses from all prior critical sections for that lock, as required.
Thanx, Paul