mbox series

[PATCHv3,00/18] atomics: API cleanups

Message ID 20180618101919.51973-1-mark.rutland@arm.com
Headers show
Series atomics: API cleanups | expand

Message

Mark Rutland June 18, 2018, 10:19 a.m. UTC
This series contains a few cleanups of the atomic API, fixing
inconsistencies between atomic_* and atomic64_*, and minimizing
repetition in arch code. This is nicer for arch code, and the improved
regularity will help when generating the atomic headers in future.

Since v1 [1]:
* Add missing inc_not_zero #define for x86_32
* Remove newly redundant test op definitions for riscv
* Remove atomic_inc_not_zero_hint()
* Make inc/dec ops optional

Since v2 [2]
* Make test ops return bool
* Clean up ifdeffery for andnot opes
* Update comments for clarity
* Rebase to v4.18-rc1
* Accumulate acks
* Fix typos

The bulk of the patches reorganise things so architectures consistently
provide <atomic>_fetch_add_unless(), with atomic_fetch_add_unless()
provided as a wrapper by core code. A generic fallback is provided for
<atomic>_fetch_add_unless(), based on <atomic>_read() and
<atomic>_try_cmpxchg().

Other patches in the series add common fallbacks for:

* atomic64_inc_not_zero() 
* <atomic>_inc_and_test()
* <atomic>_dec_and_test()
* <atomic>_sub_and_test()
* <atomic>add_negative()
* <atomic>_*inc*()
* <atomic>_*dec*()

... as almost all architectures provide (near-)identical implementation
of these today. Where an architecture provides a non-trivial definition,
it is updated to provide a matching preprocessor symbol, and the
instrumented atomics are updated correspondingly.

The end result is a strongly negative diffstat, though <linux/atomic.h>
grows by a reasonable amount. We could halve this in future by
templating the various fallbacks for atomic{,64}_t with code generation.

I've pushed this out to my atomics/api-cleanup branch [3] on kernel.org.

Thanks,
Mark.

[1] https://lkml.kernel.org/r/20180523133533.1076-1-mark.rutland@arm.com
[2] https://lkml.kernel.org/r/20180529154346.3168-1-mark.rutland@arm.com
[3] git://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git atomics/api-cleanup

Mark Rutland (18):
  atomics/treewide: s/__atomic_add_unless/atomic_fetch_add_unless/
  atomics/treewide: remove redundant atomic_inc_not_zero() definitions
  atomics/treewide: remove atomic_inc_not_zero_hint()
  atomics: make conditional ops return bool
  atomics/treewide: make atomic64_inc_not_zero() optional
  atomics/treewide: make atomic_fetch_add_unless() optional
  atomics: prepare for atomic64_fetch_add_unless()
  atomics/generic: define atomic64_fetch_add_unless()
  atomics/alpha: define atomic64_fetch_add_unless()
  atomics/arc: define atomic64_fetch_add_unless()
  atomics/arm: define atomic64_fetch_add_unless()
  atomics/powerpc: define atomic64_fetch_add_unless()
  atomics/riscv: define atomic64_fetch_add_unless()
  atomics/treewide: make atomic64_fetch_add_unless() optional
  atomics/treewide: make test ops optional
  atomics/treewide: make unconditional inc/dec ops optional
  atomics/treewide: make conditional inc/dec ops optional
  atomics/treewide: clean up andnot ifdeffery

 arch/alpha/include/asm/atomic.h           |  56 ++--
 arch/arc/include/asm/atomic.h             |  86 ++-----
 arch/arm/include/asm/atomic.h             |  55 +---
 arch/arm64/include/asm/atomic.h           |  47 +---
 arch/h8300/include/asm/atomic.h           |  15 +-
 arch/hexagon/include/asm/atomic.h         |  18 +-
 arch/ia64/include/asm/atomic.h            |  81 ------
 arch/m68k/include/asm/atomic.h            |  24 +-
 arch/mips/include/asm/atomic.h            | 172 -------------
 arch/openrisc/include/asm/atomic.h        |   4 +-
 arch/parisc/include/asm/atomic.h          | 107 --------
 arch/powerpc/include/asm/atomic.h         |  52 ++--
 arch/riscv/include/asm/atomic.h           | 149 +----------
 arch/s390/include/asm/atomic.h            |  65 -----
 arch/sh/include/asm/atomic.h              |  35 ---
 arch/sparc/include/asm/atomic_32.h        |  24 +-
 arch/sparc/include/asm/atomic_64.h        |  65 +----
 arch/sparc/lib/atomic32.c                 |   4 +-
 arch/x86/include/asm/atomic.h             |  30 +--
 arch/x86/include/asm/atomic64_32.h        |  61 +----
 arch/x86/include/asm/atomic64_64.h        |  48 +---
 arch/xtensa/include/asm/atomic.h          |  98 -------
 drivers/block/rbd.c                       |   2 +-
 drivers/infiniband/core/rdma_core.c       |   2 +-
 fs/afs/rxrpc.c                            |   2 +-
 include/asm-generic/atomic-instrumented.h |  71 ++++-
 include/asm-generic/atomic.h              |  33 ---
 include/asm-generic/atomic64.h            |  15 +-
 include/linux/atomic.h                    | 415 +++++++++++++++++++++++-------
 kernel/bpf/syscall.c                      |   4 +-
 lib/atomic64.c                            |  12 +-
 net/atm/pppoatm.c                         |   2 +-
 net/rxrpc/call_object.c                   |   2 +-
 net/rxrpc/conn_object.c                   |   4 +-
 net/rxrpc/local_object.c                  |   2 +-
 net/rxrpc/peer_object.c                   |   2 +-
 36 files changed, 511 insertions(+), 1353 deletions(-)

-- 
2.11.0

Comments

Will Deacon June 18, 2018, 4:38 p.m. UTC | #1
On Mon, Jun 18, 2018 at 11:19:01AM +0100, Mark Rutland wrote:
> This series contains a few cleanups of the atomic API, fixing

> inconsistencies between atomic_* and atomic64_*, and minimizing

> repetition in arch code. This is nicer for arch code, and the improved

> regularity will help when generating the atomic headers in future.


Apart from the Alpha patch:

Reviewed-by: Will Deacon <will.deacon@arm.com>


I also tried to compare disassembly before/after, but the changes to
add_unless made that quite fiddly for anything using it as a backend.

Do you plan to move arm64 over to atomic-instrumented.h at some point?

Will
Mark Rutland June 18, 2018, 7:21 p.m. UTC | #2
On Mon, Jun 18, 2018 at 05:38:06PM +0100, Will Deacon wrote:
> On Mon, Jun 18, 2018 at 11:19:01AM +0100, Mark Rutland wrote:

> > This series contains a few cleanups of the atomic API, fixing

> > inconsistencies between atomic_* and atomic64_*, and minimizing

> > repetition in arch code. This is nicer for arch code, and the improved

> > regularity will help when generating the atomic headers in future.

> 

> Apart from the Alpha patch:

> 

> Reviewed-by: Will Deacon <will.deacon@arm.com>


Cheers! I assume that also holds with patch 7 fixes up to use s64.

> I also tried to compare disassembly before/after, but the changes to

> add_unless made that quite fiddly for anything using it as a backend.

> 

> Do you plan to move arm64 over to atomic-instrumented.h at some point?


That's the plan -- there's still a way to go with the generated atomic headers
for that to work.

Thanks,
Mark.
Mark Rutland June 19, 2018, 10:18 a.m. UTC | #3
On Mon, Jun 18, 2018 at 08:21:27PM +0100, Mark Rutland wrote:
> On Mon, Jun 18, 2018 at 05:38:06PM +0100, Will Deacon wrote:

> > On Mon, Jun 18, 2018 at 11:19:01AM +0100, Mark Rutland wrote:

> > > This series contains a few cleanups of the atomic API, fixing

> > > inconsistencies between atomic_* and atomic64_*, and minimizing

> > > repetition in arch code. This is nicer for arch code, and the improved

> > > regularity will help when generating the atomic headers in future.

> > 

> > Apart from the Alpha patch:

> > 

> > Reviewed-by: Will Deacon <will.deacon@arm.com>

> 

> Cheers! I assume that also holds with patch 7 fixes up to use s64.


I've pushed out the series with those fixes and your Reviewed-by tags.

Given the whole series has your Reviewed-By and Peter's Acked-by, I
assume that you're both happy for this to be queued?

What's your prefered way for that to happen? Should I send a v4 with
those fixes, a pull request, or are you happy to fetch that in a little
while regardless?

Thanks,
Mark.
Will Deacon June 19, 2018, 10:20 a.m. UTC | #4
On Tue, Jun 19, 2018 at 11:18:01AM +0100, Mark Rutland wrote:
> On Mon, Jun 18, 2018 at 08:21:27PM +0100, Mark Rutland wrote:

> > On Mon, Jun 18, 2018 at 05:38:06PM +0100, Will Deacon wrote:

> > > On Mon, Jun 18, 2018 at 11:19:01AM +0100, Mark Rutland wrote:

> > > > This series contains a few cleanups of the atomic API, fixing

> > > > inconsistencies between atomic_* and atomic64_*, and minimizing

> > > > repetition in arch code. This is nicer for arch code, and the improved

> > > > regularity will help when generating the atomic headers in future.

> > > 

> > > Apart from the Alpha patch:

> > > 

> > > Reviewed-by: Will Deacon <will.deacon@arm.com>

> > 

> > Cheers! I assume that also holds with patch 7 fixes up to use s64.

> 

> I've pushed out the series with those fixes and your Reviewed-by tags.

> 

> Given the whole series has your Reviewed-By and Peter's Acked-by, I

> assume that you're both happy for this to be queued?

> 

> What's your prefered way for that to happen? Should I send a v4 with

> those fixes, a pull request, or are you happy to fetch that in a little

> while regardless?


Probably best to send a v4, then Ingo can take it all via -tip. Before you
do that, can you also spell-check your commit messages please? I spotted a
bunch of silly typos, and it will save Ingo from having to fix them up if
you do it first.

Will
Mark Rutland June 19, 2018, 10:38 a.m. UTC | #5
On Tue, Jun 19, 2018 at 11:20:49AM +0100, Will Deacon wrote:
> On Tue, Jun 19, 2018 at 11:18:01AM +0100, Mark Rutland wrote:

> > On Mon, Jun 18, 2018 at 08:21:27PM +0100, Mark Rutland wrote:

> > > On Mon, Jun 18, 2018 at 05:38:06PM +0100, Will Deacon wrote:

> > > > On Mon, Jun 18, 2018 at 11:19:01AM +0100, Mark Rutland wrote:

> > > > > This series contains a few cleanups of the atomic API, fixing

> > > > > inconsistencies between atomic_* and atomic64_*, and minimizing

> > > > > repetition in arch code. This is nicer for arch code, and the improved

> > > > > regularity will help when generating the atomic headers in future.

> > > > 

> > > > Apart from the Alpha patch:

> > > > 

> > > > Reviewed-by: Will Deacon <will.deacon@arm.com>

> > > 

> > > Cheers! I assume that also holds with patch 7 fixes up to use s64.

> > 

> > I've pushed out the series with those fixes and your Reviewed-by tags.

> > 

> > Given the whole series has your Reviewed-By and Peter's Acked-by, I

> > assume that you're both happy for this to be queued?

> > 

> > What's your prefered way for that to happen? Should I send a v4 with

> > those fixes, a pull request, or are you happy to fetch that in a little

> > while regardless?

> 

> Probably best to send a v4, then Ingo can take it all via -tip.


Ok.

> Before you do that, can you also spell-check your commit messages

> please? I spotted a bunch of silly typos, and it will save Ingo from

> having to fix them up if you do it first.


Sorry about that. I've gone through those now, and fixed what I have
spotted. I'll give it another pass before I post v4, just in case. :)

Thanks,
Mark.