From f3e75e4a542479f338355abcd90e39e7e96a0118 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Thu, 31 Mar 2022 02:41:01 +0000 Subject: [PATCH 37/49] rwlock(9): Convert to membar_acquire/release. Leave an XXX comment where I suspect there might be a missing membar -- to be audited when I have more time to think! --- sys/kern/kern_rwlock.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index 14b6dd46cd42..48a82ddb12a0 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -101,12 +101,12 @@ do { \ * Memory barriers. */ #ifdef __HAVE_ATOMIC_AS_MEMBAR -#define RW_MEMBAR_ENTER() -#define RW_MEMBAR_EXIT() +#define RW_MEMBAR_ACQUIRE() +#define RW_MEMBAR_RELEASE() #define RW_MEMBAR_PRODUCER() #else -#define RW_MEMBAR_ENTER() membar_enter() -#define RW_MEMBAR_EXIT() membar_exit() +#define RW_MEMBAR_ACQUIRE() membar_acquire() +#define RW_MEMBAR_RELEASE() membar_release() #define RW_MEMBAR_PRODUCER() membar_producer() #endif @@ -344,7 +344,7 @@ rw_vector_enter(krwlock_t *rw, const krw_t op) ~RW_WRITE_WANTED); if (__predict_true(next == owner)) { /* Got it! */ - RW_MEMBAR_ENTER(); + RW_MEMBAR_ACQUIRE(); break; } @@ -396,6 +396,7 @@ rw_vector_enter(krwlock_t *rw, const krw_t op) continue; } next = rw_cas(rw, owner, owner | set_wait); + /* XXX membar? */ if (__predict_false(next != owner)) { turnstile_exit(rw); owner = next; @@ -471,7 +472,7 @@ rw_vector_exit(krwlock_t *rw) * proceed to do direct handoff if there are waiters, and if the * lock would become unowned. */ - RW_MEMBAR_EXIT(); + RW_MEMBAR_RELEASE(); for (;;) { newown = (owner - decr); if ((newown & (RW_THREAD | RW_HAS_WAITERS)) == RW_HAS_WAITERS) @@ -585,7 +586,7 @@ rw_vector_tryenter(krwlock_t *rw, const krw_t op) RW_ASSERT(rw, (op != RW_READER && RW_OWNER(rw) == curthread) || (op == RW_READER && RW_COUNT(rw) != 0)); - RW_MEMBAR_ENTER(); + RW_MEMBAR_ACQUIRE(); return 1; }