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
6060toolchain-supports-zicbom := $(call cc-option-yn, -march=$(riscv-march-y ) _zicbom)
6161riscv-march-$(toolchain-supports-zicbom) := $(riscv-march-y ) _zicbom
6262
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+
6367KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y ) )
6468KBUILD_AFLAGS += -march=$(riscv-march-y )
6569
Original file line number Diff line number Diff line change 88#ifndef _ASM_RISCV_HWCAP_H
99#define _ASM_RISCV_HWCAP_H
1010
11+ #include <asm/errno.h>
1112#include <linux/bits.h>
1213#include <uapi/asm/hwcap.h>
1314
@@ -55,6 +56,7 @@ enum riscv_isa_ext_id {
5556 RISCV_ISA_EXT_SSCOFPMF = RISCV_ISA_EXT_BASE ,
5657 RISCV_ISA_EXT_SVPBMT ,
5758 RISCV_ISA_EXT_ZICBOM ,
59+ RISCV_ISA_EXT_ZIHINTPAUSE ,
5860 RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX ,
5961};
6062
@@ -65,6 +67,7 @@ enum riscv_isa_ext_id {
6567 */
6668enum riscv_isa_ext_key {
6769 RISCV_ISA_EXT_KEY_FPU , /* For 'F' and 'D' */
70+ RISCV_ISA_EXT_KEY_ZIHINTPAUSE ,
6871 RISCV_ISA_EXT_KEY_MAX ,
6972};
7073
@@ -84,6 +87,8 @@ static __always_inline int riscv_isa_ext2key(int num)
8487 return RISCV_ISA_EXT_KEY_FPU ;
8588 case RISCV_ISA_EXT_d :
8689 return RISCV_ISA_EXT_KEY_FPU ;
90+ case RISCV_ISA_EXT_ZIHINTPAUSE :
91+ return RISCV_ISA_EXT_KEY_ZIHINTPAUSE ;
8792 default :
8893 return - EINVAL ;
8994 }
Original file line number Diff line number Diff line change 44
55#ifndef __ASSEMBLY__
66
7+ #include <linux/jump_label.h>
78#include <asm/barrier.h>
9+ #include <asm/hwcap.h>
810
911static inline void cpu_relax (void )
1012{
13+ if (!static_branch_likely (& riscv_isa_ext_keys [RISCV_ISA_EXT_KEY_ZIHINTPAUSE ])) {
1114#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 ));
1518#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+ }
1631 barrier ();
1732}
1833
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ static struct riscv_isa_ext_data isa_ext_arr[] = {
9494 __RISCV_ISA_EXT_DATA (sscofpmf , RISCV_ISA_EXT_SSCOFPMF ),
9595 __RISCV_ISA_EXT_DATA (svpbmt , RISCV_ISA_EXT_SVPBMT ),
9696 __RISCV_ISA_EXT_DATA (zicbom , RISCV_ISA_EXT_ZICBOM ),
97+ __RISCV_ISA_EXT_DATA (zihintpause , RISCV_ISA_EXT_ZIHINTPAUSE ),
9798 __RISCV_ISA_EXT_DATA ("" , RISCV_ISA_EXT_MAX ),
9899};
99100
Original file line number Diff line number Diff line change @@ -202,6 +202,7 @@ void __init riscv_fill_hwcap(void)
202202 SET_ISA_EXT_MAP ("sscofpmf" , RISCV_ISA_EXT_SSCOFPMF );
203203 SET_ISA_EXT_MAP ("svpbmt" , RISCV_ISA_EXT_SVPBMT );
204204 SET_ISA_EXT_MAP ("zicbom" , RISCV_ISA_EXT_ZICBOM );
205+ SET_ISA_EXT_MAP ("zihintpause" , RISCV_ISA_EXT_ZIHINTPAUSE );
205206 }
206207#undef SET_ISA_EXT_MAP
207208 }
You can’t perform that action at this time.
0 commit comments