]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
s390/smp: Implement raw_smp_processor_id() with inline assembly
authorHeiko Carstens <hca@linux.ibm.com>
Mon, 10 Mar 2025 09:33:40 +0000 (10:33 +0100)
committerVasily Gorbik <gor@linux.ibm.com>
Tue, 18 Mar 2025 16:13:04 +0000 (17:13 +0100)
Implement raw_smp_processor_id() with an inline assembly, which makes
use of the ALTERNATIVE macro, to read cpu_nr from lowcore. Provide an
alternative instruction with a different offset in case lowcore is
relocated.

This replaces sequences of two instructions with one instruction.

Before:
  1000b6:       a5 1e 00 00             llilh   %r1,0
  1000ba:       58 20 13 a0             l       %r2,928(%r1)

After:
  1000b6:       e3 20 03 a0 00 58       ly      %r2,928

Kernel image size change:
add/remove: 753/755 grow/shrink: 230/1510 up/down: 30538/-35832 (-5294)

Acked-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/include/asm/smp.h

index 7feca96c48c6a2e6db8c92a9496ad785cba49348..03f4d01664f8affe3c4119151afd49e227ff2144 100644 (file)
@@ -7,11 +7,29 @@
 #ifndef __ASM_SMP_H
 #define __ASM_SMP_H
 
-#include <asm/sigp.h>
-#include <asm/lowcore.h>
 #include <asm/processor.h>
+#include <asm/lowcore.h>
+#include <asm/machine.h>
+#include <asm/sigp.h>
+
+static __always_inline unsigned int raw_smp_processor_id(void)
+{
+       unsigned long lc_cpu_nr;
+       unsigned int cpu;
+
+       BUILD_BUG_ON(sizeof_field(struct lowcore, cpu_nr) != sizeof(cpu));
+       lc_cpu_nr = offsetof(struct lowcore, cpu_nr);
+       asm_inline(
+               ALTERNATIVE("   ly      %[cpu],%[offzero](%%r0)\n",
+                           "   ly      %[cpu],%[offalt](%%r0)\n",
+                           ALT_FEATURE(MFEATURE_LOWCORE))
+               : [cpu] "=d" (cpu)
+               : [offzero] "i" (lc_cpu_nr),
+                 [offalt] "i" (lc_cpu_nr + LOWCORE_ALT_ADDRESS),
+                 "m" (((struct lowcore *)0)->cpu_nr));
+       return cpu;
+}
 
-#define raw_smp_processor_id() (get_lowcore()->cpu_nr)
 #define arch_scale_cpu_capacity smp_cpu_get_capacity
 
 extern struct mutex smp_cpu_state_mutex;