Skip to content

Commit

Permalink
Add membar_sync
Browse files Browse the repository at this point in the history
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 <richard.yao@alumni.stonybrook.edu>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Closes #13907
  • Loading branch information
mjguzik authored Sep 20, 2022
1 parent 62e2a28 commit 402426c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/os/freebsd/spl/sys/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/os/linux/spl/sys/vmsystm.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#define membar_consumer() smp_rmb()
#define membar_producer() smp_wmb()
#define membar_sync() smp_mb()

#define physmem zfs_totalram_pages

Expand Down
6 changes: 6 additions & 0 deletions lib/libspl/atomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 7 additions & 0 deletions lib/libspl/include/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 402426c

Please sign in to comment.