Skip to content

Commit 1d50c77

Browse files
xiaobo55xavpatel
authored andcommitted
tools: riscv: Add header file vdso/processor.h
Borrow the cpu_relax() definitions from kernel's arch/riscv/include/asm/vdso/processor.h to tools/ for riscv. Signed-off-by: Haibo Xu <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Signed-off-by: Anup Patel <[email protected]>
1 parent a69459d commit 1d50c77

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
#ifndef __ASM_VDSO_PROCESSOR_H
3+
#define __ASM_VDSO_PROCESSOR_H
4+
5+
#ifndef __ASSEMBLY__
6+
7+
#include <asm-generic/barrier.h>
8+
9+
static inline void cpu_relax(void)
10+
{
11+
#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+
#endif
16+
17+
#ifdef CONFIG_TOOLCHAIN_HAS_ZIHINTPAUSE
18+
/*
19+
* Reduce instruction retirement.
20+
* This assumes the PC changes.
21+
*/
22+
__asm__ __volatile__ ("pause");
23+
#else
24+
/* Encoding of the pause instruction */
25+
__asm__ __volatile__ (".4byte 0x100000F");
26+
#endif
27+
barrier();
28+
}
29+
30+
#endif /* __ASSEMBLY__ */
31+
32+
#endif /* __ASM_VDSO_PROCESSOR_H */

0 commit comments

Comments
 (0)