Skip to content

Commit 65c07e9

Browse files
hcahcaVasily Gorbik
authored andcommitted
s390/current: Implement current with inline assembly
Implement current with an inline assembly, which makes use of the ALTERNATIVE macro, to read current 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: 100076: a5 1e 00 00 llilh %r1,0 10007a: e3 40 13 40 00 04 lg %r4,832(%r1) After: 100076: e3 10 03 40 00 04 lg %r1,832 Kernel image size change: add/remove: 3/17 grow/shrink: 166/2204 up/down: 7122/-24594 (-17472) Reviewed-by: Alexander Gordeev <[email protected]> Signed-off-by: Heiko Carstens <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]>
1 parent 430693c commit 65c07e9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

arch/s390/include/asm/current.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,25 @@
1111
#define _S390_CURRENT_H
1212

1313
#include <asm/lowcore.h>
14+
#include <asm/machine.h>
1415

1516
struct task_struct;
1617

17-
#define current ((struct task_struct *const)get_lowcore()->current_task)
18+
static __always_inline struct task_struct *get_current(void)
19+
{
20+
unsigned long ptr, lc_current;
21+
22+
lc_current = offsetof(struct lowcore, current_task);
23+
asm_inline(
24+
ALTERNATIVE(" lg %[ptr],%[offzero](%%r0)\n",
25+
" lg %[ptr],%[offalt](%%r0)\n",
26+
ALT_FEATURE(MFEATURE_LOWCORE))
27+
: [ptr] "=d" (ptr)
28+
: [offzero] "i" (lc_current),
29+
[offalt] "i" (lc_current + LOWCORE_ALT_ADDRESS));
30+
return (struct task_struct *)ptr;
31+
}
32+
33+
#define current get_current()
1834

1935
#endif /* !(_S390_CURRENT_H) */

0 commit comments

Comments
 (0)