From 07c73e384bf896225c43f65ec89cc0e0a9e03960 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Thu, 31 Mar 2022 02:39:59 +0000 Subject: [PATCH 36/49] mutex(9): Convert to membar_acquire/release. Except for setting the waiters bit -- not sure if this is actually required to be store-before-load/store. Seems unlikely -- surely we'd have seen some serious bug by now if not, because membar_enter has failed to guarantee that on x86! -- but I'm leaving it for now until I have time to think enough about it to be sure one way or another. --- sys/kern/kern_mutex.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index e94157ba77e7..57a546c5e172 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -169,10 +169,12 @@ do { \ */ #ifdef __HAVE_ATOMIC_AS_MEMBAR #define MUTEX_MEMBAR_ENTER() -#define MUTEX_MEMBAR_EXIT() +#define MUTEX_MEMBAR_ACQUIRE() +#define MUTEX_MEMBAR_RELEASE() #else #define MUTEX_MEMBAR_ENTER() membar_enter() -#define MUTEX_MEMBAR_EXIT() membar_exit() +#define MUTEX_MEMBAR_ACQUIRE() membar_acquire() +#define MUTEX_MEMBAR_RELEASE() membar_release() #endif /* @@ -238,7 +240,7 @@ MUTEX_ACQUIRE(kmutex_t *mtx, uintptr_t curthread) MUTEX_INHERITDEBUG(oldown, mtx->mtx_owner); MUTEX_INHERITDEBUG(newown, oldown); rv = MUTEX_CAS(&mtx->mtx_owner, oldown, newown); - MUTEX_MEMBAR_ENTER(); + MUTEX_MEMBAR_ACQUIRE(); return rv; } @@ -256,7 +258,7 @@ MUTEX_RELEASE(kmutex_t *mtx) { uintptr_t newown; - MUTEX_MEMBAR_EXIT(); + MUTEX_MEMBAR_RELEASE(); newown = 0; MUTEX_INHERITDEBUG(newown, mtx->mtx_owner); mtx->mtx_owner = newown;