Re: [RFC PATCH v3] locking/atomic: Implement atomic{,64,_long}_{fetch_,}{andnot_or}{,_relaxed,_acquire,_release}()

From: Will Deacon
Date: Thu Jul 29 2021 - 05:56:06 EST


On Thu, Jul 29, 2021 at 05:30:03PM +0800, Rui Wang wrote:
> This patch introduce a new atomic primitive andnot_or:
>
> * atomic_andnot_or
> * atomic_fetch_andnot_or
> * atomic_fetch_andnot_or_relaxed
> * atomic_fetch_andnot_or_acquire
> * atomic_fetch_andnot_or_release
> * atomic64_andnot_or
> * atomic64_fetch_andnot_or
> * atomic64_fetch_andnot_or_relaxed
> * atomic64_fetch_andnot_or_acquire
> * atomic64_fetch_andnot_or_release
> * atomic_long_andnot_or
> * atomic_long_fetch_andnot_or
> * atomic_long_fetch_andnot_or_relaxed
> * atomic_long_fetch_andnot_or_acquire
> * atomic_long_fetch_andnot_or_release
>
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
> Signed-off-by: Rui Wang <wangrui@xxxxxxxxxxx>
> ---
> include/asm-generic/atomic-instrumented.h | 72 +++++-
> include/asm-generic/atomic-long.h | 62 ++++-
> include/linux/atomic-arch-fallback.h | 262 +++++++++++++++++++++-
> lib/atomic64_test.c | 92 ++++----
> scripts/atomic/atomics.tbl | 1 +
> scripts/atomic/fallbacks/andnot_or | 25 +++
> 6 files changed, 471 insertions(+), 43 deletions(-)
> create mode 100755 scripts/atomic/fallbacks/andnot_or

Please see my other comments on the other patches you posted:

https://lore.kernel.org/r/20210729093923.GD21151@willie-the-truck

Overall, I'm not thrilled to bits by extending the atomics API with
operations that cannot be implemented efficiently on any (?) architectures
and are only used by the qspinlock slowpath on machines with more than 16K
CPUs.

I also think we're lacking documentation justifying when you would use this
new primitive over e.g. a sub-word WRITE_ONCE() on architectures that
support those, especially for the non-returning variants.

Will