Re: [GIT pull] locking/urgent for v5.15-rc2

From: Peter Zijlstra
Date: Mon Sep 20 2021 - 07:27:35 EST


On Sun, Sep 19, 2021 at 01:10:45PM -0700, Linus Torvalds wrote:
> On Sun, Sep 19, 2021 at 11:28 AM Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:
> >
> >
> > - atomic_add(READER_BIAS - bias, &rwb->readers);
> > + /*
> > + * _release() is needed in case that reader is in fast path, pairing
> > + * with atomic_try_cmpxchg() in rwbase_read_trylock(), provides RELEASE
> > + */
> > + (void)atomic_add_return_release(READER_BIAS - bias, &rwb->readers);
>
> Ugh. This really needs fixing.
>
> atomic_add() is already much more than release-ordered on x86, and
> atomic_add_return_release() is much more expensive on some uarchs.

Is that XADD really more expensive? I don't think I've ever seen that.
Anyway, sure, we can go create atomic_{add,sub}_release() and replace
the few occurences we have of this (a quick grep shows this is the 3rd
such).