aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2017-11-25 20:08:11 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2017-11-25 20:08:11 +0000
commit2e106e0427f1a2b32c90a2bfdf7ebbb880f65d70 (patch)
tree04215befe372265d2ecceee0892b181434274a16
parentd915a14ef094c8dfc1a5aee70e135abfec01d0f1 (diff)
downloadsrc-2e106e0427f1a2b32c90a2bfdf7ebbb880f65d70.tar.gz
src-2e106e0427f1a2b32c90a2bfdf7ebbb880f65d70.zip
rwlock: stop re-reading the owner when going to sleep
Notes
Notes: svn path=/head/; revision=326194
-rw-r--r--sys/kern/kern_rwlock.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c
index b54d1c2bf94d..c0bc0c7510b2 100644
--- a/sys/kern/kern_rwlock.c
+++ b/sys/kern/kern_rwlock.c
@@ -411,8 +411,8 @@ __rw_rlock_hard(struct rwlock *rw, struct thread *td, uintptr_t v
LOCK_FILE_LINE_ARG_DEF)
{
struct turnstile *ts;
+ struct thread *owner;
#ifdef ADAPTIVE_RWLOCKS
- volatile struct thread *owner;
int spintries = 0;
int i, n;
#endif
@@ -531,6 +531,8 @@ __rw_rlock_hard(struct rwlock *rw, struct thread *td, uintptr_t v
continue;
}
+ owner = lv_rw_wowner(v);
+
#ifdef ADAPTIVE_RWLOCKS
/*
* The current lock owner might have started executing
@@ -539,8 +541,7 @@ __rw_rlock_hard(struct rwlock *rw, struct thread *td, uintptr_t v
* chain lock. If so, drop the turnstile lock and try
* again.
*/
- if ((v & RW_LOCK_READ) == 0) {
- owner = (struct thread *)RW_OWNER(v);
+ if (owner != NULL) {
if (TD_IS_RUNNING(owner)) {
turnstile_cancel(ts);
continue;
@@ -581,7 +582,8 @@ __rw_rlock_hard(struct rwlock *rw, struct thread *td, uintptr_t v
#ifdef KDTRACE_HOOKS
sleep_time -= lockstat_nsecs(&rw->lock_object);
#endif
- turnstile_wait(ts, rw_owner(rw), TS_SHARED_QUEUE);
+ MPASS(owner == rw_owner(rw));
+ turnstile_wait(ts, owner, TS_SHARED_QUEUE);
#ifdef KDTRACE_HOOKS
sleep_time += lockstat_nsecs(&rw->lock_object);
sleep_cnt++;
@@ -850,8 +852,8 @@ __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v LOCK_FILE_LINE_ARG_DEF)
uintptr_t tid;
struct rwlock *rw;
struct turnstile *ts;
+ struct thread *owner;
#ifdef ADAPTIVE_RWLOCKS
- volatile struct thread *owner;
int spintries = 0;
int i, n;
#endif
@@ -981,6 +983,7 @@ __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v LOCK_FILE_LINE_ARG_DEF)
#endif
ts = turnstile_trywait(&rw->lock_object);
v = RW_READ_VALUE(rw);
+ owner = lv_rw_wowner(v);
#ifdef ADAPTIVE_RWLOCKS
/*
@@ -990,8 +993,7 @@ __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v LOCK_FILE_LINE_ARG_DEF)
* chain lock. If so, drop the turnstile lock and try
* again.
*/
- if (!(v & RW_LOCK_READ)) {
- owner = (struct thread *)RW_OWNER(v);
+ if (owner != NULL) {
if (TD_IS_RUNNING(owner)) {
turnstile_cancel(ts);
continue;
@@ -1045,7 +1047,8 @@ __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v LOCK_FILE_LINE_ARG_DEF)
#ifdef KDTRACE_HOOKS
sleep_time -= lockstat_nsecs(&rw->lock_object);
#endif
- turnstile_wait(ts, rw_owner(rw), TS_EXCLUSIVE_QUEUE);
+ MPASS(owner == rw_owner(rw));
+ turnstile_wait(ts, owner, TS_EXCLUSIVE_QUEUE);
#ifdef KDTRACE_HOOKS
sleep_time += lockstat_nsecs(&rw->lock_object);
sleep_cnt++;