Re: [RFC][PATCH 5/7] x86: convert arch_futex_atomic_op_inuser() to user_access_begin/user_access_end()
From: Al Viro
Date: Thu Mar 26 2020 - 22:42:33 EST
On Tue, Mar 24, 2020 at 01:57:19PM -0700, Linus Torvalds wrote:
> On Tue, Mar 24, 2020 at 1:45 PM Al Viro <viro@xxxxxxxxxxxxxxxxxx> wrote:
> >
> > OK... BTW, I'd been trying to recall the reasons for the way
> > __futex_atomic_op2() loop is done; ISTR some discussion along
> > the lines of cacheline ping-pong prevention, but I'd been unable
> > to reconstruct enough details to find it and I'm not sure it
> > hadn't been about some other code ;-/
>
> No, that doesn't look like any cacheline advantage I can think of -
> quite the reverse.
>
> I suspect it's just lazy code, with the reload being unnecessary. Or
> it might be written that way because you avoid an extra variable.
>
> In fact, from a cacheline optimization standpoint, there are
> advantages to not doing the load even on the initial run: if you know
> a certain value is particularly likely, there are advantages to just
> _assuming_ that value, rather than loading it. So no initial load at
> all, and just initialize the first value to the likely case.
>
> That can avoid an unnecessary "load for shared ownership" cacheline
> state transition (since the cmpxchg will want to turn it into an
> exclusive modified cacheline anyway).
>
> But I don't think that optimization is likely the case here, and
> you're right, the loop would be better written with the initial load
> outside the loop.
OK, updated branch is in the same place; changes: __futex_atomic_op{1,2}
turned into unsafe_atomic_op{1,2}, with "goto on error" folded into those.
And pointless reload removed from cmpxchg loop in unsafe_atomic_op2().
Diffstat:
arch/alpha/include/asm/futex.h | 5 +-
arch/arc/include/asm/futex.h | 5 +-
arch/arm/include/asm/futex.h | 5 +-
arch/arm64/include/asm/futex.h | 5 +-
arch/hexagon/include/asm/futex.h | 5 +-
arch/ia64/include/asm/futex.h | 5 +-
arch/microblaze/include/asm/futex.h | 5 +-
arch/mips/include/asm/futex.h | 5 +-
arch/nds32/include/asm/futex.h | 6 +--
arch/openrisc/include/asm/futex.h | 5 +-
arch/parisc/include/asm/futex.h | 2 -
arch/powerpc/include/asm/futex.h | 5 +-
arch/riscv/include/asm/futex.h | 5 +-
arch/s390/include/asm/futex.h | 2 -
arch/sh/include/asm/futex.h | 4 --
arch/sparc/include/asm/futex_64.h | 4 --
arch/x86/include/asm/futex.h | 97 ++++++++++++++++++++++++-------------
arch/x86/include/asm/uaccess.h | 93 -----------------------------------
arch/xtensa/include/asm/futex.h | 5 +-
include/asm-generic/futex.h | 2 -
kernel/futex.c | 5 +-
tools/objtool/check.c | 1 +
22 files changed, 93 insertions(+), 183 deletions(-)
Sorry about the fuckup when sending that patchset ;-/ It ended up cc'd to
x86 list instead of the futex one; Message-Id of the beginning of the
thread is <20200327022836.881203-1-viro@xxxxxxxxxxxxxxxxxx>.