Skip to content

Commit fa8be59

Browse files
hcahcaVasily Gorbik
authored andcommitted
s390/percpu: Provide arch_raw_cpu_ptr()
Provide an s390 specific arch_raw_cpu_ptr() implementation which avoids the detour over get_lowcore() to get the lowcore pointer. The inline assembly is implemented with an alternative so that relocated lowcore (percpu offset is at a different address) is handled correctly. This turns code like this 102f78: a7 39 00 00 lghi %r3,0 102f7c: e3 20 33 b8 00 08 ag %r2,952(%r3) which adds the percpu offset to register r2 into a single instruction 102f7c: e3 20 33 b8 00 08 ag %r2,952(%r0) and also avoids the need of a base register, thus reducing register pressure. With defconfig bloat-o-meter -t provides this result: add/remove: 12/26 grow/shrink: 183/3391 up/down: 14880/-41950 (-27070) Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent 7bbf701 commit fa8be59

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

arch/s390/include/asm/percpu.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@
1212
*/
1313
#define __my_cpu_offset get_lowcore()->percpu_offset
1414

15+
#define arch_raw_cpu_ptr(_ptr) \
16+
({ \
17+
unsigned long lc_percpu, tcp_ptr__; \
18+
\
19+
tcp_ptr__ = (__force unsigned long)(_ptr); \
20+
lc_percpu = offsetof(struct lowcore, percpu_offset); \
21+
asm_inline volatile( \
22+
ALTERNATIVE("ag %[__ptr__],%[offzero](%%r0)\n", \
23+
"ag %[__ptr__],%[offalt](%%r0)\n", \
24+
ALT_FEATURE(MFEATURE_LOWCORE)) \
25+
: [__ptr__] "+d" (tcp_ptr__) \
26+
: [offzero] "i" (lc_percpu), \
27+
[offalt] "i" (lc_percpu + LOWCORE_ALT_ADDRESS), \
28+
"m" (((struct lowcore *)0)->percpu_offset) \
29+
: "cc"); \
30+
(TYPEOF_UNQUAL(*(_ptr)) __force __kernel *)tcp_ptr__; \
31+
})
32+
1533
/*
1634
* We use a compare-and-swap loop since that uses less cpu cycles than
1735
* disabling and enabling interrupts like the generic variant would do.

0 commit comments

Comments
 (0)