Skip to content

Commit 47b9533

Browse files
Merge patch series "tools: Add barrier implementations for riscv"
Charlie Jenkins <[email protected]> says: Add support for riscv specific barrier implementations to the tools tree, so that fence instructions can be emitted for synchronization. * b4-shazam-merge: tools: Optimize ring buffer for riscv tools: Add riscv barrier implementation Link: https://lore.kernel.org/r/20240806-optimize_ring_buffer_read_riscv-v2-0-ca7e193ae198@rivosinc.com Signed-off-by: Palmer Dabbelt <[email protected]>
2 parents ad380f6 + aa5736d commit 47b9533

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copied from the kernel sources to tools/arch/riscv:
4+
*
5+
* Copyright (C) 2012 ARM Ltd.
6+
* Copyright (C) 2013 Regents of the University of California
7+
* Copyright (C) 2017 SiFive
8+
*/
9+
10+
#ifndef _TOOLS_LINUX_ASM_RISCV_BARRIER_H
11+
#define _TOOLS_LINUX_ASM_RISCV_BARRIER_H
12+
13+
#include <asm/fence.h>
14+
#include <linux/compiler.h>
15+
16+
/* These barriers need to enforce ordering on both devices and memory. */
17+
#define mb() RISCV_FENCE(iorw, iorw)
18+
#define rmb() RISCV_FENCE(ir, ir)
19+
#define wmb() RISCV_FENCE(ow, ow)
20+
21+
/* These barriers do not need to enforce ordering on devices, just memory. */
22+
#define smp_mb() RISCV_FENCE(rw, rw)
23+
#define smp_rmb() RISCV_FENCE(r, r)
24+
#define smp_wmb() RISCV_FENCE(w, w)
25+
26+
#define smp_store_release(p, v) \
27+
do { \
28+
RISCV_FENCE(rw, w); \
29+
WRITE_ONCE(*p, v); \
30+
} while (0)
31+
32+
#define smp_load_acquire(p) \
33+
({ \
34+
typeof(*p) ___p1 = READ_ONCE(*p); \
35+
RISCV_FENCE(r, rw); \
36+
___p1; \
37+
})
38+
39+
#endif /* _TOOLS_LINUX_ASM_RISCV_BARRIER_H */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* Copied from the kernel sources to tools/arch/riscv:
4+
*/
5+
6+
#ifndef _ASM_RISCV_FENCE_H
7+
#define _ASM_RISCV_FENCE_H
8+
9+
#define RISCV_FENCE_ASM(p, s) "\tfence " #p "," #s "\n"
10+
#define RISCV_FENCE(p, s) \
11+
({ __asm__ __volatile__ (RISCV_FENCE_ASM(p, s) : : : "memory"); })
12+
13+
#endif /* _ASM_RISCV_FENCE_H */

tools/include/asm/barrier.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "../../arch/arm64/include/asm/barrier.h"
99
#elif defined(__powerpc__)
1010
#include "../../arch/powerpc/include/asm/barrier.h"
11+
#elif defined(__riscv)
12+
#include "../../arch/riscv/include/asm/barrier.h"
1113
#elif defined(__s390__)
1214
#include "../../arch/s390/include/asm/barrier.h"
1315
#elif defined(__sh__)

tools/include/linux/ring_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static inline u64 ring_buffer_read_head(struct perf_event_mmap_page *base)
5555
* READ_ONCE() + smp_mb() pair.
5656
*/
5757
#if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) || \
58-
defined(__ia64__) || defined(__sparc__) && defined(__arch64__)
58+
defined(__ia64__) || defined(__sparc__) && defined(__arch64__) || defined(__riscv)
5959
return smp_load_acquire(&base->data_head);
6060
#else
6161
u64 head = READ_ONCE(base->data_head);

0 commit comments

Comments
 (0)