* [PATCH 0/2] tools: Add barrier implementations for riscv
@ 2024-07-29 20:50 Charlie Jenkins
2024-07-29 20:50 ` [PATCH 1/2] tools: Add riscv barrier implementation Charlie Jenkins
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Charlie Jenkins @ 2024-07-29 20:50 UTC (permalink / raw)
To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Andrea Parri
Cc: linux-kernel, linux-riscv, Charlie Jenkins
Add support for riscv specific barrier implementations to the tools
tree, so that fence instructions can be emitted for synchronization.
Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
---
Charlie Jenkins (2):
tools: Add riscv barrier implementation
tools: Optimize ring buffer for riscv
tools/arch/riscv/include/asm/barrier.h | 39 ++++++++++++++++++++++++++++++++++
tools/arch/riscv/include/asm/fence.h | 13 ++++++++++++
tools/include/asm/barrier.h | 2 ++
tools/include/linux/ring_buffer.h | 2 +-
4 files changed, 55 insertions(+), 1 deletion(-)
---
base-commit: 0c3836482481200ead7b416ca80c68a29cfdaabd
change-id: 20240725-optimize_ring_buffer_read_riscv-228491c4eb6e
--
- Charlie
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/2] tools: Add riscv barrier implementation 2024-07-29 20:50 [PATCH 0/2] tools: Add barrier implementations for riscv Charlie Jenkins @ 2024-07-29 20:50 ` Charlie Jenkins 2024-07-30 8:59 ` Clément Léger 2024-07-29 20:50 ` [PATCH 2/2] tools: Optimize ring buffer for riscv Charlie Jenkins 2024-07-30 9:18 ` [PATCH 0/2] tools: Add barrier implementations " Andrea Parri 2 siblings, 1 reply; 6+ messages in thread From: Charlie Jenkins @ 2024-07-29 20:50 UTC (permalink / raw) To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Andrea Parri Cc: linux-kernel, linux-riscv, Charlie Jenkins Many of the other architectures use their custom barrier implmentations. Use the barrier code from the kernel sources to optimize barriers in tools. Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> --- tools/arch/riscv/include/asm/barrier.h | 39 ++++++++++++++++++++++++++++++++++ tools/arch/riscv/include/asm/fence.h | 13 ++++++++++++ tools/include/asm/barrier.h | 2 ++ 3 files changed, 54 insertions(+) diff --git a/tools/arch/riscv/include/asm/barrier.h b/tools/arch/riscv/include/asm/barrier.h new file mode 100644 index 000000000000..6997f197086d --- /dev/null +++ b/tools/arch/riscv/include/asm/barrier.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copied from the kernel sources to tools/arch/riscv: + * + * Copyright (C) 2012 ARM Ltd. + * Copyright (C) 2013 Regents of the University of California + * Copyright (C) 2017 SiFive + */ + +#ifndef _TOOLS_LINUX_ASM_RISCV_BARRIER_H +#define _TOOLS_LINUX_ASM_RISCV_BARRIER_H + +#include <asm/fence.h> +#include <linux/compiler.h> + +/* These barriers need to enforce ordering on both devices and memory. */ +#define mb() RISCV_FENCE(iorw, iorw) +#define rmb() RISCV_FENCE(ir, ir) +#define wmb() RISCV_FENCE(ow, ow) + +/* These barriers do not need to enforce ordering on devices, just memory. */ +#define smp_mb() RISCV_FENCE(rw, rw) +#define smp_rmb() RISCV_FENCE(r, r) +#define smp_wmb() RISCV_FENCE(w, w) + +#define smp_store_release(p, v) \ +do { \ + RISCV_FENCE(rw, w); \ + WRITE_ONCE(*p, v); \ +} while (0) + +#define smp_load_acquire(p) \ +({ \ + typeof(*p) ___p1 = READ_ONCE(*p); \ + RISCV_FENCE(r, rw); \ + ___p1; \ +}) + +#endif /* _TOOLS_LINUX_ASM_RISCV_BARRIER_H */ diff --git a/tools/arch/riscv/include/asm/fence.h b/tools/arch/riscv/include/asm/fence.h new file mode 100644 index 000000000000..37860e86771d --- /dev/null +++ b/tools/arch/riscv/include/asm/fence.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copied from the kernel sources to tools/arch/riscv: + */ + +#ifndef _ASM_RISCV_FENCE_H +#define _ASM_RISCV_FENCE_H + +#define RISCV_FENCE_ASM(p, s) "\tfence " #p "," #s "\n" +#define RISCV_FENCE(p, s) \ + ({ __asm__ __volatile__ (RISCV_FENCE_ASM(p, s) : : : "memory"); }) + +#endif /* _ASM_RISCV_FENCE_H */ diff --git a/tools/include/asm/barrier.h b/tools/include/asm/barrier.h index 8d378c57cb01..0c21678ac5e6 100644 --- a/tools/include/asm/barrier.h +++ b/tools/include/asm/barrier.h @@ -8,6 +8,8 @@ #include "../../arch/arm64/include/asm/barrier.h" #elif defined(__powerpc__) #include "../../arch/powerpc/include/asm/barrier.h" +#elif defined(__riscv) +#include "../../arch/riscv/include/asm/barrier.h" #elif defined(__s390__) #include "../../arch/s390/include/asm/barrier.h" #elif defined(__sh__) -- 2.44.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] tools: Add riscv barrier implementation 2024-07-29 20:50 ` [PATCH 1/2] tools: Add riscv barrier implementation Charlie Jenkins @ 2024-07-30 8:59 ` Clément Léger 2024-08-01 1:10 ` Charlie Jenkins 0 siblings, 1 reply; 6+ messages in thread From: Clément Léger @ 2024-07-30 8:59 UTC (permalink / raw) To: Charlie Jenkins, Paul Walmsley, Palmer Dabbelt, Albert Ou, Andrea Parri Cc: linux-kernel, linux-riscv On 29/07/2024 22:50, Charlie Jenkins wrote: > Many of the other architectures use their custom barrier implmentations. Hi Charlie, Typo: implmentations -> implementations > Use the barrier code from the kernel sources to optimize barriers in > tools. > > Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> > --- > tools/arch/riscv/include/asm/barrier.h | 39 ++++++++++++++++++++++++++++++++++ > tools/arch/riscv/include/asm/fence.h | 13 ++++++++++++ > tools/include/asm/barrier.h | 2 ++ > 3 files changed, 54 insertions(+) > > diff --git a/tools/arch/riscv/include/asm/barrier.h b/tools/arch/riscv/include/asm/barrier.h > new file mode 100644 > index 000000000000..6997f197086d > --- /dev/null > +++ b/tools/arch/riscv/include/asm/barrier.h > @@ -0,0 +1,39 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Copied from the kernel sources to tools/arch/riscv: > + * > + * Copyright (C) 2012 ARM Ltd. > + * Copyright (C) 2013 Regents of the University of California > + * Copyright (C) 2017 SiFive > + */ > + > +#ifndef _TOOLS_LINUX_ASM_RISCV_BARRIER_H > +#define _TOOLS_LINUX_ASM_RISCV_BARRIER_H > + > +#include <asm/fence.h> > +#include <linux/compiler.h> > + > +/* These barriers need to enforce ordering on both devices and memory. */ > +#define mb() RISCV_FENCE(iorw, iorw) > +#define rmb() RISCV_FENCE(ir, ir) > +#define wmb() RISCV_FENCE(ow, ow) > + > +/* These barriers do not need to enforce ordering on devices, just memory. */ > +#define smp_mb() RISCV_FENCE(rw, rw) > +#define smp_rmb() RISCV_FENCE(r, r) > +#define smp_wmb() RISCV_FENCE(w, w) > + > +#define smp_store_release(p, v) \ > +do { \ > + RISCV_FENCE(rw, w); \ > + WRITE_ONCE(*p, v); \ > +} while (0) > + > +#define smp_load_acquire(p) \ > +({ \ > + typeof(*p) ___p1 = READ_ONCE(*p); \ > + RISCV_FENCE(r, rw); \ > + ___p1; \ > +}) > + > +#endif /* _TOOLS_LINUX_ASM_RISCV_BARRIER_H */ > diff --git a/tools/arch/riscv/include/asm/fence.h b/tools/arch/riscv/include/asm/fence.h > new file mode 100644 > index 000000000000..37860e86771d > --- /dev/null > +++ b/tools/arch/riscv/include/asm/fence.h > @@ -0,0 +1,13 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Copied from the kernel sources to tools/arch/riscv: > + */ > + > +#ifndef _ASM_RISCV_FENCE_H > +#define _ASM_RISCV_FENCE_H > + > +#define RISCV_FENCE_ASM(p, s) "\tfence " #p "," #s "\n" > +#define RISCV_FENCE(p, s) \ > + ({ __asm__ __volatile__ (RISCV_FENCE_ASM(p, s) : : : "memory"); }) > + > +#endif /* _ASM_RISCV_FENCE_H */ > diff --git a/tools/include/asm/barrier.h b/tools/include/asm/barrier.h > index 8d378c57cb01..0c21678ac5e6 100644 > --- a/tools/include/asm/barrier.h > +++ b/tools/include/asm/barrier.h > @@ -8,6 +8,8 @@ > #include "../../arch/arm64/include/asm/barrier.h" > #elif defined(__powerpc__) > #include "../../arch/powerpc/include/asm/barrier.h" > +#elif defined(__riscv) > +#include "../../arch/riscv/include/asm/barrier.h" > #elif defined(__s390__) > #include "../../arch/s390/include/asm/barrier.h" > #elif defined(__sh__) > Can not really tell for that part except it seems ok to me as well. Andrea might be a better candidate to add its Rb. Thanks, Clément ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] tools: Add riscv barrier implementation 2024-07-30 8:59 ` Clément Léger @ 2024-08-01 1:10 ` Charlie Jenkins 0 siblings, 0 replies; 6+ messages in thread From: Charlie Jenkins @ 2024-08-01 1:10 UTC (permalink / raw) To: Clément Léger Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, Andrea Parri, linux-kernel, linux-riscv On Tue, Jul 30, 2024 at 10:59:52AM +0200, Clément Léger wrote: > > > On 29/07/2024 22:50, Charlie Jenkins wrote: > > Many of the other architectures use their custom barrier implmentations. > > Hi Charlie, > > Typo: implmentations -> implementations Thank you! I will fix that. - Charlie > > > Use the barrier code from the kernel sources to optimize barriers in > > tools. > > > > Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> > > --- > > tools/arch/riscv/include/asm/barrier.h | 39 ++++++++++++++++++++++++++++++++++ > > tools/arch/riscv/include/asm/fence.h | 13 ++++++++++++ > > tools/include/asm/barrier.h | 2 ++ > > 3 files changed, 54 insertions(+) > > > > diff --git a/tools/arch/riscv/include/asm/barrier.h b/tools/arch/riscv/include/asm/barrier.h > > new file mode 100644 > > index 000000000000..6997f197086d > > --- /dev/null > > +++ b/tools/arch/riscv/include/asm/barrier.h > > @@ -0,0 +1,39 @@ > > +/* SPDX-License-Identifier: GPL-2.0-only */ > > +/* > > + * Copied from the kernel sources to tools/arch/riscv: > > + * > > + * Copyright (C) 2012 ARM Ltd. > > + * Copyright (C) 2013 Regents of the University of California > > + * Copyright (C) 2017 SiFive > > + */ > > + > > +#ifndef _TOOLS_LINUX_ASM_RISCV_BARRIER_H > > +#define _TOOLS_LINUX_ASM_RISCV_BARRIER_H > > + > > +#include <asm/fence.h> > > +#include <linux/compiler.h> > > + > > +/* These barriers need to enforce ordering on both devices and memory. */ > > +#define mb() RISCV_FENCE(iorw, iorw) > > +#define rmb() RISCV_FENCE(ir, ir) > > +#define wmb() RISCV_FENCE(ow, ow) > > + > > +/* These barriers do not need to enforce ordering on devices, just memory. */ > > +#define smp_mb() RISCV_FENCE(rw, rw) > > +#define smp_rmb() RISCV_FENCE(r, r) > > +#define smp_wmb() RISCV_FENCE(w, w) > > + > > +#define smp_store_release(p, v) \ > > +do { \ > > + RISCV_FENCE(rw, w); \ > > + WRITE_ONCE(*p, v); \ > > +} while (0) > > + > > +#define smp_load_acquire(p) \ > > +({ \ > > + typeof(*p) ___p1 = READ_ONCE(*p); \ > > + RISCV_FENCE(r, rw); \ > > + ___p1; \ > > +}) > > + > > +#endif /* _TOOLS_LINUX_ASM_RISCV_BARRIER_H */ > > diff --git a/tools/arch/riscv/include/asm/fence.h b/tools/arch/riscv/include/asm/fence.h > > new file mode 100644 > > index 000000000000..37860e86771d > > --- /dev/null > > +++ b/tools/arch/riscv/include/asm/fence.h > > @@ -0,0 +1,13 @@ > > +/* SPDX-License-Identifier: GPL-2.0-only */ > > +/* > > + * Copied from the kernel sources to tools/arch/riscv: > > + */ > > + > > +#ifndef _ASM_RISCV_FENCE_H > > +#define _ASM_RISCV_FENCE_H > > + > > +#define RISCV_FENCE_ASM(p, s) "\tfence " #p "," #s "\n" > > +#define RISCV_FENCE(p, s) \ > > + ({ __asm__ __volatile__ (RISCV_FENCE_ASM(p, s) : : : "memory"); }) > > + > > +#endif /* _ASM_RISCV_FENCE_H */ > > diff --git a/tools/include/asm/barrier.h b/tools/include/asm/barrier.h > > index 8d378c57cb01..0c21678ac5e6 100644 > > --- a/tools/include/asm/barrier.h > > +++ b/tools/include/asm/barrier.h > > @@ -8,6 +8,8 @@ > > #include "../../arch/arm64/include/asm/barrier.h" > > #elif defined(__powerpc__) > > #include "../../arch/powerpc/include/asm/barrier.h" > > +#elif defined(__riscv) > > +#include "../../arch/riscv/include/asm/barrier.h" > > #elif defined(__s390__) > > #include "../../arch/s390/include/asm/barrier.h" > > #elif defined(__sh__) > > > > Can not really tell for that part except it seems ok to me as well. > Andrea might be a better candidate to add its Rb. > > Thanks, > > Clément ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] tools: Optimize ring buffer for riscv 2024-07-29 20:50 [PATCH 0/2] tools: Add barrier implementations for riscv Charlie Jenkins 2024-07-29 20:50 ` [PATCH 1/2] tools: Add riscv barrier implementation Charlie Jenkins @ 2024-07-29 20:50 ` Charlie Jenkins 2024-07-30 9:18 ` [PATCH 0/2] tools: Add barrier implementations " Andrea Parri 2 siblings, 0 replies; 6+ messages in thread From: Charlie Jenkins @ 2024-07-29 20:50 UTC (permalink / raw) To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Andrea Parri Cc: linux-kernel, linux-riscv, Charlie Jenkins Now that riscv supports optimized barriers, use them in the ring buffer. Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> --- tools/include/linux/ring_buffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/include/linux/ring_buffer.h b/tools/include/linux/ring_buffer.h index 6c02617377c2..a74c397359c7 100644 --- a/tools/include/linux/ring_buffer.h +++ b/tools/include/linux/ring_buffer.h @@ -55,7 +55,7 @@ static inline u64 ring_buffer_read_head(struct perf_event_mmap_page *base) * READ_ONCE() + smp_mb() pair. */ #if defined(__x86_64__) || defined(__aarch64__) || defined(__powerpc64__) || \ - defined(__ia64__) || defined(__sparc__) && defined(__arch64__) + defined(__ia64__) || defined(__sparc__) && defined(__arch64__) || defined(__riscv) return smp_load_acquire(&base->data_head); #else u64 head = READ_ONCE(base->data_head); -- 2.44.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] tools: Add barrier implementations for riscv 2024-07-29 20:50 [PATCH 0/2] tools: Add barrier implementations for riscv Charlie Jenkins 2024-07-29 20:50 ` [PATCH 1/2] tools: Add riscv barrier implementation Charlie Jenkins 2024-07-29 20:50 ` [PATCH 2/2] tools: Optimize ring buffer for riscv Charlie Jenkins @ 2024-07-30 9:18 ` Andrea Parri 2 siblings, 0 replies; 6+ messages in thread From: Andrea Parri @ 2024-07-30 9:18 UTC (permalink / raw) To: Charlie Jenkins Cc: Paul Walmsley, Palmer Dabbelt, Albert Ou, linux-kernel, linux-riscv On Mon, Jul 29, 2024 at 01:50:34PM -0700, Charlie Jenkins wrote: > Add support for riscv specific barrier implementations to the tools > tree, so that fence instructions can be emitted for synchronization. > > Signed-off-by: Charlie Jenkins <charlie@rivosinc.com> > --- > Charlie Jenkins (2): > tools: Add riscv barrier implementation > tools: Optimize ring buffer for riscv LGTM. For the series, Reviewed-by: Andrea Parri <parri.andrea@gmail.com> Andrea ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-08-01 1:10 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-07-29 20:50 [PATCH 0/2] tools: Add barrier implementations for riscv Charlie Jenkins 2024-07-29 20:50 ` [PATCH 1/2] tools: Add riscv barrier implementation Charlie Jenkins 2024-07-30 8:59 ` Clément Léger 2024-08-01 1:10 ` Charlie Jenkins 2024-07-29 20:50 ` [PATCH 2/2] tools: Optimize ring buffer for riscv Charlie Jenkins 2024-07-30 9:18 ` [PATCH 0/2] tools: Add barrier implementations " Andrea Parri
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox