File tree Expand file tree Collapse file tree 5 files changed +29
-3
lines changed Expand file tree Collapse file tree 5 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,10 @@ riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei
60
60
toolchain-supports-zicbom := $(call cc-option-yn, -march=$(riscv-march-y ) _zicbom)
61
61
riscv-march-$(toolchain-supports-zicbom) := $(riscv-march-y ) _zicbom
62
62
63
+ # Check if the toolchain supports Zihintpause extension
64
+ toolchain-supports-zihintpause := $(call cc-option-yn, -march=$(riscv-march-y ) _zihintpause)
65
+ riscv-march-$(toolchain-supports-zihintpause) := $(riscv-march-y ) _zihintpause
66
+
63
67
KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y ) )
64
68
KBUILD_AFLAGS += -march=$(riscv-march-y )
65
69
Original file line number Diff line number Diff line change 8
8
#ifndef _ASM_RISCV_HWCAP_H
9
9
#define _ASM_RISCV_HWCAP_H
10
10
11
+ #include <asm/errno.h>
11
12
#include <linux/bits.h>
12
13
#include <uapi/asm/hwcap.h>
13
14
@@ -55,6 +56,7 @@ enum riscv_isa_ext_id {
55
56
RISCV_ISA_EXT_SSCOFPMF = RISCV_ISA_EXT_BASE ,
56
57
RISCV_ISA_EXT_SVPBMT ,
57
58
RISCV_ISA_EXT_ZICBOM ,
59
+ RISCV_ISA_EXT_ZIHINTPAUSE ,
58
60
RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX ,
59
61
};
60
62
@@ -65,6 +67,7 @@ enum riscv_isa_ext_id {
65
67
*/
66
68
enum riscv_isa_ext_key {
67
69
RISCV_ISA_EXT_KEY_FPU , /* For 'F' and 'D' */
70
+ RISCV_ISA_EXT_KEY_ZIHINTPAUSE ,
68
71
RISCV_ISA_EXT_KEY_MAX ,
69
72
};
70
73
@@ -84,6 +87,8 @@ static __always_inline int riscv_isa_ext2key(int num)
84
87
return RISCV_ISA_EXT_KEY_FPU ;
85
88
case RISCV_ISA_EXT_d :
86
89
return RISCV_ISA_EXT_KEY_FPU ;
90
+ case RISCV_ISA_EXT_ZIHINTPAUSE :
91
+ return RISCV_ISA_EXT_KEY_ZIHINTPAUSE ;
87
92
default :
88
93
return - EINVAL ;
89
94
}
Original file line number Diff line number Diff line change 4
4
5
5
#ifndef __ASSEMBLY__
6
6
7
+ #include <linux/jump_label.h>
7
8
#include <asm/barrier.h>
9
+ #include <asm/hwcap.h>
8
10
9
11
static inline void cpu_relax (void )
10
12
{
13
+ if (!static_branch_likely (& riscv_isa_ext_keys [RISCV_ISA_EXT_KEY_ZIHINTPAUSE ])) {
11
14
#ifdef __riscv_muldiv
12
- int dummy ;
13
- /* In lieu of a halt instruction, induce a long-latency stall. */
14
- __asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy ));
15
+ int dummy ;
16
+ /* In lieu of a halt instruction, induce a long-latency stall. */
17
+ __asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy ));
15
18
#endif
19
+ } else {
20
+ /*
21
+ * Reduce instruction retirement.
22
+ * This assumes the PC changes.
23
+ */
24
+ #ifdef __riscv_zihintpause
25
+ __asm__ __volatile__ ("pause" );
26
+ #else
27
+ /* Encoding of the pause instruction */
28
+ __asm__ __volatile__ (".4byte 0x100000F" );
29
+ #endif
30
+ }
16
31
barrier ();
17
32
}
18
33
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ static struct riscv_isa_ext_data isa_ext_arr[] = {
94
94
__RISCV_ISA_EXT_DATA (sscofpmf , RISCV_ISA_EXT_SSCOFPMF ),
95
95
__RISCV_ISA_EXT_DATA (svpbmt , RISCV_ISA_EXT_SVPBMT ),
96
96
__RISCV_ISA_EXT_DATA (zicbom , RISCV_ISA_EXT_ZICBOM ),
97
+ __RISCV_ISA_EXT_DATA (zihintpause , RISCV_ISA_EXT_ZIHINTPAUSE ),
97
98
__RISCV_ISA_EXT_DATA ("" , RISCV_ISA_EXT_MAX ),
98
99
};
99
100
Original file line number Diff line number Diff line change @@ -202,6 +202,7 @@ void __init riscv_fill_hwcap(void)
202
202
SET_ISA_EXT_MAP ("sscofpmf" , RISCV_ISA_EXT_SSCOFPMF );
203
203
SET_ISA_EXT_MAP ("svpbmt" , RISCV_ISA_EXT_SVPBMT );
204
204
SET_ISA_EXT_MAP ("zicbom" , RISCV_ISA_EXT_ZICBOM );
205
+ SET_ISA_EXT_MAP ("zihintpause" , RISCV_ISA_EXT_ZIHINTPAUSE );
205
206
}
206
207
#undef SET_ISA_EXT_MAP
207
208
}
You can’t perform that action at this time.
0 commit comments