Skip to content

locking: Introduce local{,64}_try_cmpxchg

Uros Bizjak linux-alpha linux-arch linux-mips linux-perf-users linuxppc-dev lkml loongarch 2 versions – Applied

Status from this message: The following commit has been merged into the locking/core branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 14 repliesApplied
  2. v110 patches 9 repliesSuperseded

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/5locking/atomic: Add generic try_cmpxchg{,64}_local supportinclude/linux/atomic/atomic-arch-fallback.h include/linux/atomic/atomic-instrumented.h scripts/atomic/gen-atomic-fallback.sh +1 more+47 -31 reply
2/5locking/generic: Wire up local{,64}_try_cmpxchginclude/asm-generic/local.h include/asm-generic/local64.h+12 -11 reply
3/5locking/arch: Wire up local_try_cmpxchgarch/alpha/include/asm/local.h arch/loongarch/include/asm/local.h arch/mips/include/asm/local.h +2 more+54 -84 replies
4/5locking/x86: Define arch_try_cmpxchg_localarch/x86/include/asm/cmpxchg.h+6 -00 replies
5/5events: Illustrate the transition to local{,64}_try_cmpxchgarch/x86/events/core.c kernel/events/ring_buffer.c+7 -70 replies

Reviews trailers per patch

2 of 5 patches have a Reviewed-by or Acked-by.

PatchMark Rutland
1/5A-b
2/5A-b
3/5
4/5
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/5] locking: Introduce local{,64}_try_cmpxchg

Add generic and target specific support for local{,64}_try_cmpxchg and wire up support for all targets that use local_t infrastructure.

The patch enables x86 targets to emit special instruction for local_try_cmpxchg and also local64_try_cmpxchg for x86_64.

The last patch changes __perf_output_begin in events/ring_buffer to use new locking primitive and improves code from

     4b3:	48 8b 82 e8 00 00 00 	mov    0xe8(%rdx),%rax
     4ba:	48 8b b8 08 04 00 00 	mov    0x408(%rax),%rdi
     4c1:	8b 42 1c             	mov    0x1c(%rdx),%eax
     4c4:	48 8b 4a 28          	mov    0x28(%rdx),%rcx
     4c8:	85 c0                	test   %eax,%eax
     ...
     4ef:	48 89 c8             	mov    %rcx,%rax
     4f2:	48 0f b1 7a 28       	cmpxchg %rdi,0x28(%rdx)
     4f7:	48 39 c1             	cmp    %rax,%rcx
     4fa:	75 b7                	jne    4b3 <...>

to

     4b2:	48 8b 4a 28          	mov    0x28(%rdx),%rcx
     4b6:	48 8b 82 e8 00 00 00 	mov    0xe8(%rdx),%rax
     4bd:	48 8b b0 08 04 00 00 	mov    0x408(%rax),%rsi
     4c4:	8b 42 1c             	mov    0x1c(%rdx),%eax
     4c7:	85 c0                	test   %eax,%eax
     ...
     4d4:	48 89 c8             	mov    %rcx,%rax
     4d7:	48 0f b1 72 28       	cmpxchg %rsi,0x28(%rdx)
     4dc:	0f 85 d0 00 00 00    	jne    5b2 <...>
     ...
     5b2:	48 89 c1             	mov    %rax,%rcx
     5b5:	e9 fc fe ff ff       	jmp    4b6 <...>

Please note that in addition to removed compare, the load from 0x28(%rdx) gets moved out of the loop and the code is rearranged according to likely/unlikely tags in the source.
---
v2:

Implement target specific support for local_try_cmpxchg and local_cmpxchg using typed C wrappers that call their _local counterpart and provide additional checking of their input arguments.

Cc Richard Henderson <[email protected]>
Cc Ivan Kokshaysky <[email protected]>
Cc Matt Turner <[email protected]>
Cc Huacai Chen <[email protected]>
Cc WANG Xuerui <[email protected]>
Cc Thomas Bogendoerfer <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Christophe Leroy <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Dave Hansen <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Alexander Shishkin <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Ian Rogers <[email protected]>
Cc Will Deacon <[email protected]>
Cc Boqun Feng <[email protected]>
Cc Jiaxun Yang <[email protected]>
Cc Jun Yi <[email protected]>

Uros Bizjak (5):
locking/atomic: Add generic try_cmpxchg{,64}_local support locking/generic: Wire up local{,64}_try_cmpxchg locking/arch: Wire up local_try_cmpxchg locking/x86: Define arch_try_cmpxchg_local
events: Illustrate the transition to local{,64}_try_cmpxchg

 arch/alpha/include/asm/local.h              | 12 +++++++++--
 arch/loongarch/include/asm/local.h          | 13 +++++++++--
 arch/mips/include/asm/local.h               | 13 +++++++++--
 arch/powerpc/include/asm/local.h            | 11 ++++++++++
 arch/x86/events/core.c                      |  9 ++++----
 arch/x86/include/asm/cmpxchg.h              |  6 ++++++
 arch/x86/include/asm/local.h                | 13 +++++++++--
 include/asm-generic/local.h                 |  1 +
 include/asm-generic/local64.h               | 12 ++++++++++-
 include/linux/atomic/atomic-arch-fallback.h | 24 ++++++++++++++++++++-
 include/linux/atomic/atomic-instrumented.h  | 20 ++++++++++++++++-
 kernel/events/ring_buffer.c                 |  5 +++--
 scripts/atomic/gen-atomic-fallback.sh       |  4 ++++
 scripts/atomic/gen-atomic-instrumented.sh   |  2 +-
 14 files changed, 126 insertions(+), 19 deletions(-)
Signature · 1 line
2.39.2