Skip to content

Allow inlined spinlocks again V6

Heiko Carstens linux-arch lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest9 patches 10 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9powerpc: rename __spin_try_lock() and friendsarch/powerpc/include/asm/spinlock.h+10 -101 reply
2/9sparc: rename __spin_try_lock() and friendsarch/sparc/include/asm/spinlock_32.h arch/sparc/include/asm/spinlock_64.h+20 -201 reply
3/9m68k/asm-offsets: rename pt_regs offset definesarch/m68k/include/asm/entry_mm.h arch/m68k/include/asm/entry_no.h arch/m68k/include/asm/math-emu.h +3 more+53 -561 reply
4/9m68k/asm-offsets: rename signal definesarch/m68k/include/asm/entry_mm.h arch/m68k/kernel/asm-offsets.c arch/m68k/math-emu/fp_entry.S+8 -91 reply
5/9m68k: calculate thread_info offset with asm offsetarch/m68k/include/asm/thread_info_mm.h arch/m68k/kernel/asm-offsets.c+15 -11 reply
6/9spinlock: move spinlock function bodies to header fileinclude/linux/spinlock.h include/linux/spinlock_api_smp.h kernel/spinlock.c+300 -1551 reply
7/9spinlock: allow inlined spinlocksinclude/linux/spinlock_api_smp.h kernel/spinlock.c+175 -01 reply
8/9spinlock: simplify inlininginclude/linux/spinlock.h include/linux/spinlock_api_smp.h+18 -401 reply
9/9spinlock: inline code for all locking variants on s390arch/s390/include/asm/spinlock.h+29 -01 reply

Reviews trailers per patch

8 of 9 patches have a Reviewed-by or Acked-by.

PatchDavid S. MillerArnd BergmannPeter Zijlstra
1/9A-b
2/9A-b A-b A-b
3/9A-b
4/9
5/9A-b
6/9A-b A-b A-b A-b
7/9A-b
8/9A-b
9/9A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v1 thread

Cover letter [patch 0/9] Allow inlined spinlocks again V6

This patch set allows to have inlined spinlocks again.

V2: rewritten from scratch - now also with readable code

V3: removed macro to generate out-of-line spinlock variants since that
would break ctags. As requested by Arnd Bergmann.

V4: allow architectures to specify for each lock/unlock variant if
it should be kept out-of-line or inlined.

V5: simplify ifdefs as pointed out by Linus. Fix architecture compile
breakages caused by this change.

V6: rename __spin_lock_is_small to __always_inline__spin_lock as requested
by Ingo Molnar. That way it is more consistent with the other methods used to force inlining.
Also simplify inlining by getting rid of the old variants to force inlining of the unlock functions.

This is hopefully the final version. I did again run the whole cross compiles. The patch set applies on top of latest Linus' git tree, but also applies on top of linux-next.

Ingo, I assume you don't have further objections?

Should this go in via -mm then?

---

The rationale behind this is that function calls on at least s390 are expensive.

If one considers that server kernels are usually compiled with !CONFIG_PREEMPT a simple spin_lock is just a compare and swap loop. The extra overhead for a function call is significant.
With inlined spinlocks overall cpu usage gets reduced by 1%-5% on s390. These numbers were taken with some network benchmarks. However I expect any workload that calls frequently into the kernel and which grabs a few locks to perform better.

The implementation is straight forward: move the function bodies of the locking functions to static inline functions and place them in a header file.
By default all locking code remains out-of-line. An architecture can specify

#define __always_inline__spin_lock

in arch/<whatever>/include/asm/spinlock.h to force inlining of a locking function.

defconfig cross compile tested for alpha, arm, x86, x86_64, ia64, m68k, m68knommu, mips, powerpc, powerpc64, sparc64, s390, s390x.