]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
s390/preempt: Optimize preempt_count()
authorHeiko Carstens <hca@linux.ibm.com>
Tue, 13 Jan 2026 19:43:57 +0000 (20:43 +0100)
committerHeiko Carstens <hca@linux.ibm.com>
Sat, 17 Jan 2026 14:52:49 +0000 (15:52 +0100)
commit6cce3609a1e0dedeef9b4bfdc87d0d4692f691d7
tree8438c3f467298edb74df26cebffd81b9dfc99414
parent12ea976f955cefb06eeae4c9e5eb48d08038ccb2
s390/preempt: Optimize preempt_count()

Provide an inline assembly using alternatives to avoid the need of
a base register when reading preempt_count() from lowcore. Use the
LLGT instruction, which reads only the least significant 31 bits of
preempt_count. This masks out the encoded PREEMPT_NEED_RESCHED bit.

Generated code is changed from

000000000046e5d0 <vfree>:
  46e5d0:       c0 04 00 00 00 00       jgnop   46e5d0 <vfree>
  46e5d6:       a7 39 00 00             lghi    %r3,0
  46e5da:       58 10 33 a8             l       %r1,936(%r3)
  46e5de:       c0 1b 00 ff ff 00       nilf    %r1,16776960
  46e5e4:       a7 74 00 11             jne     46e606 <vfree+0x36>

to something like this:

000000000046e5d0 <vfree>:
  46e5d0:       c0 04 00 00 00 00       jgnop   46e5d0 <vfree>
  46e5d6:       e3 10 03 a8 00 17       llgt    %r1,936
  46e5dc:       ec 41 28 b7 00 55       risbgz  %r4,%r1,40,55
  46e5e2:       a7 74 00 0f             jne     46e600 <vfree+0x30>

Overall savings are only 82 bytes according to bloat-o-meter. This
is because of different inlining decisions, and there aren't many
preempt_count() users in the kernel.

Reviewed-by: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/include/asm/preempt.h