summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2017-10-24 08:53:16 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2017-10-24 08:53:16 +0000
commit1e0f3ecacdd43839fb71c03b5797317c4cd9701d (patch)
treec77e5c406c7ed54e64aa93decc9172f43b90a409
parent7bf457912b08c92454707838773e51f0ba537965 (diff)
Use membar_enter_after_atomic(9) amd membar_exit_before_atomic(9).
Micro-optimization useful to x86 archs where the cmpxchg{q,l} instruction used by rw_enter(9) and rw_exit(9) already include an implicit memory barrier. From Mateusz Guzik, ok visa@, mikeb@, kettenis@
-rw-r--r--sys/kern/kern_rwlock.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c
index 9252413b1b3..399c352f396 100644
--- a/sys/kern/kern_rwlock.c
+++ b/sys/kern/kern_rwlock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_rwlock.c,v 1.31 2017/10/12 09:19:45 mpi Exp $ */
+/* $OpenBSD: kern_rwlock.c,v 1.32 2017/10/24 08:53:15 mpi Exp $ */
/*
* Copyright (c) 2002, 2003 Artur Grabowski <art@openbsd.org>
@@ -96,7 +96,7 @@ _rw_enter_read(struct rwlock *rwl LOCK_FL_VARS)
rw_cas(&rwl->rwl_owner, owner, owner + RWLOCK_READ_INCR)))
_rw_enter(rwl, RW_READ LOCK_FL_ARGS);
else {
- membar_enter();
+ membar_enter_after_atomic();
WITNESS_CHECKORDER(&rwl->rwl_lock_obj, LOP_NEWORDER, file, line,
NULL);
WITNESS_LOCK(&rwl->rwl_lock_obj, 0, file, line);
@@ -112,7 +112,7 @@ _rw_enter_write(struct rwlock *rwl LOCK_FL_VARS)
RW_PROC(p) | RWLOCK_WRLOCK)))
_rw_enter(rwl, RW_WRITE LOCK_FL_ARGS);
else {
- membar_enter();
+ membar_enter_after_atomic();
WITNESS_CHECKORDER(&rwl->rwl_lock_obj,
LOP_EXCLUSIVE | LOP_NEWORDER, file, line, NULL);
WITNESS_LOCK(&rwl->rwl_lock_obj, LOP_EXCLUSIVE, file, line);
@@ -126,7 +126,7 @@ _rw_exit_read(struct rwlock *rwl LOCK_FL_VARS)
rw_assert_rdlock(rwl);
- membar_exit();
+ membar_exit_before_atomic();
if (__predict_false((owner & RWLOCK_WAIT) ||
rw_cas(&rwl->rwl_owner, owner, owner - RWLOCK_READ_INCR)))
_rw_exit(rwl LOCK_FL_ARGS);
@@ -141,7 +141,7 @@ _rw_exit_write(struct rwlock *rwl LOCK_FL_VARS)
rw_assert_wrlock(rwl);
- membar_exit();
+ membar_exit_before_atomic();
if (__predict_false((owner & RWLOCK_WAIT) ||
rw_cas(&rwl->rwl_owner, owner, 0)))
_rw_exit(rwl LOCK_FL_ARGS);
@@ -261,7 +261,7 @@ retry:
if (__predict_false(rw_cas(&rwl->rwl_owner, o, o + inc)))
goto retry;
- membar_enter();
+ membar_enter_after_atomic();
/*
* If old lock had RWLOCK_WAIT and RWLOCK_WRLOCK set, it means we
@@ -295,7 +295,7 @@ _rw_exit(struct rwlock *rwl LOCK_FL_VARS)
WITNESS_UNLOCK(&rwl->rwl_lock_obj, wrlock ? LOP_EXCLUSIVE : 0,
file, line);
- membar_exit();
+ membar_exit_before_atomic();
do {
owner = rwl->rwl_owner;
if (wrlock)