Skip to content

Commit 0b1d60d

Browse files
smaeulpalmer-dabbelt
authored andcommitted
riscv: Fix build with CONFIG_CC_OPTIMIZE_FOR_SIZE=y
commit 8eb060e ("arch/riscv: add Zihintpause support") broke building with CONFIG_CC_OPTIMIZE_FOR_SIZE enabled (gcc 11.1.0): CC arch/riscv/kernel/vdso/vgettimeofday.o In file included from <command-line>: ./arch/riscv/include/asm/jump_label.h: In function 'cpu_relax': ././include/linux/compiler_types.h:285:33: warning: 'asm' operand 0 probably does not match constraints 285 | #define asm_volatile_goto(x...) asm goto(x) | ^~~ ./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto' 41 | asm_volatile_goto( | ^~~~~~~~~~~~~~~~~ ././include/linux/compiler_types.h:285:33: error: impossible constraint in 'asm' 285 | #define asm_volatile_goto(x...) asm goto(x) | ^~~ ./arch/riscv/include/asm/jump_label.h:41:9: note: in expansion of macro 'asm_volatile_goto' 41 | asm_volatile_goto( | ^~~~~~~~~~~~~~~~~ make[1]: *** [scripts/Makefile.build:249: arch/riscv/kernel/vdso/vgettimeofday.o] Error 1 make: *** [arch/riscv/Makefile:128: vdso_prepare] Error 2 Having a static branch in cpu_relax() is problematic because that function is widely inlined, including in some quite complex functions like in the VDSO. A quick measurement shows this static branch is responsible by itself for around 40% of the jump table. Drop the static branch, which ends up being the same number of instructions anyway. If Zihintpause is supported, we trade the nop from the static branch for a div. If Zihintpause is unsupported, we trade the jump from the static branch for (what gets interpreted as) a nop. Fixes: 8eb060e ("arch/riscv: add Zihintpause support") Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 8eb060e commit 0b1d60d

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

arch/riscv/include/asm/hwcap.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ enum riscv_isa_ext_id {
6767
*/
6868
enum riscv_isa_ext_key {
6969
RISCV_ISA_EXT_KEY_FPU, /* For 'F' and 'D' */
70-
RISCV_ISA_EXT_KEY_ZIHINTPAUSE,
7170
RISCV_ISA_EXT_KEY_MAX,
7271
};
7372

@@ -87,8 +86,6 @@ static __always_inline int riscv_isa_ext2key(int num)
8786
return RISCV_ISA_EXT_KEY_FPU;
8887
case RISCV_ISA_EXT_d:
8988
return RISCV_ISA_EXT_KEY_FPU;
90-
case RISCV_ISA_EXT_ZIHINTPAUSE:
91-
return RISCV_ISA_EXT_KEY_ZIHINTPAUSE;
9289
default:
9390
return -EINVAL;
9491
}

arch/riscv/include/asm/vdso/processor.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,25 @@
44

55
#ifndef __ASSEMBLY__
66

7-
#include <linux/jump_label.h>
87
#include <asm/barrier.h>
9-
#include <asm/hwcap.h>
108

119
static inline void cpu_relax(void)
1210
{
13-
if (!static_branch_likely(&riscv_isa_ext_keys[RISCV_ISA_EXT_KEY_ZIHINTPAUSE])) {
1411
#ifdef __riscv_muldiv
15-
int dummy;
16-
/* In lieu of a halt instruction, induce a long-latency stall. */
17-
__asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy));
12+
int dummy;
13+
/* In lieu of a halt instruction, induce a long-latency stall. */
14+
__asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy));
1815
#endif
19-
} else {
20-
/*
21-
* Reduce instruction retirement.
22-
* This assumes the PC changes.
23-
*/
16+
/*
17+
* Reduce instruction retirement.
18+
* This assumes the PC changes.
19+
*/
2420
#ifdef __riscv_zihintpause
25-
__asm__ __volatile__ ("pause");
21+
__asm__ __volatile__ ("pause");
2622
#else
27-
/* Encoding of the pause instruction */
28-
__asm__ __volatile__ (".4byte 0x100000F");
23+
/* Encoding of the pause instruction */
24+
__asm__ __volatile__ (".4byte 0x100000F");
2925
#endif
30-
}
3126
barrier();
3227
}
3328

0 commit comments

Comments
 (0)