From 402426c7d81f410fa088c3bd893d4941a97d8332 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Wed, 21 Sep 2022 00:32:44 +0200 Subject: [PATCH] Add membar_sync Provides the missing full barrier variant to the membar primitive set. While not used right now, this is probably going to change down the road. Name taken from Solaris, to follow the existing routines. Reviewed-by: Richard Yao Reviewed-by: Brian Behlendorf Signed-off-by: Mateusz Guzik Closes #13907 --- include/os/freebsd/spl/sys/atomic.h | 1 + include/os/linux/spl/sys/vmsystm.h | 1 + lib/libspl/atomic.c | 6 ++++++ lib/libspl/include/atomic.h | 7 +++++++ 4 files changed, 15 insertions(+) diff --git a/include/os/freebsd/spl/sys/atomic.h b/include/os/freebsd/spl/sys/atomic.h index 01b13fc9af..8b9cec15c5 100644 --- a/include/os/freebsd/spl/sys/atomic.h +++ b/include/os/freebsd/spl/sys/atomic.h @@ -59,6 +59,7 @@ extern uint64_t atomic_cas_64(volatile uint64_t *target, uint64_t cmp, #define membar_consumer() atomic_thread_fence_acq() #define membar_producer() atomic_thread_fence_rel() +#define membar_sync() atomic_thread_fence_seq_cst() static __inline uint32_t atomic_add_32_nv(volatile uint32_t *target, int32_t delta) diff --git a/include/os/linux/spl/sys/vmsystm.h b/include/os/linux/spl/sys/vmsystm.h index fcd61e818f..c6d99fb318 100644 --- a/include/os/linux/spl/sys/vmsystm.h +++ b/include/os/linux/spl/sys/vmsystm.h @@ -46,6 +46,7 @@ #define membar_consumer() smp_rmb() #define membar_producer() smp_wmb() +#define membar_sync() smp_mb() #define physmem zfs_totalram_pages diff --git a/lib/libspl/atomic.c b/lib/libspl/atomic.c index ba14b113f5..8cc350710b 100644 --- a/lib/libspl/atomic.c +++ b/lib/libspl/atomic.c @@ -381,6 +381,12 @@ membar_exit(void) __atomic_thread_fence(__ATOMIC_SEQ_CST); } +void +membar_sync(void) +{ + __atomic_thread_fence(__ATOMIC_SEQ_CST); +} + void membar_producer(void) { diff --git a/lib/libspl/include/atomic.h b/lib/libspl/include/atomic.h index 1249d42b60..4ebdbbda98 100644 --- a/lib/libspl/include/atomic.h +++ b/lib/libspl/include/atomic.h @@ -313,6 +313,13 @@ extern void membar_enter(void); */ extern void membar_exit(void); +/* + * Make all stores and loads emitted prior to the the barrier complete before + * crossing it, while also making sure stores and loads emitted after the + * barrier only start being executed after crossing it. + */ +extern void membar_sync(void); + /* * Arrange that all stores issued before this point in the code reach * global visibility before any stores that follow; useful in producer