rwlock: stop re-reading the owner when going to sleep

This commit is contained in:
Mateusz Guzik 2017-11-25 20:08:11 +00:00
parent d915a14ef0
commit 2e106e0427
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=326194

View File

@ -411,8 +411,8 @@ __rw_rlock_hard(struct rwlock *rw, struct thread *td, uintptr_t v
LOCK_FILE_LINE_ARG_DEF) LOCK_FILE_LINE_ARG_DEF)
{ {
struct turnstile *ts; struct turnstile *ts;
struct thread *owner;
#ifdef ADAPTIVE_RWLOCKS #ifdef ADAPTIVE_RWLOCKS
volatile struct thread *owner;
int spintries = 0; int spintries = 0;
int i, n; int i, n;
#endif #endif
@ -531,6 +531,8 @@ __rw_rlock_hard(struct rwlock *rw, struct thread *td, uintptr_t v
continue; continue;
} }
owner = lv_rw_wowner(v);
#ifdef ADAPTIVE_RWLOCKS #ifdef ADAPTIVE_RWLOCKS
/* /*
* The current lock owner might have started executing * 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 * chain lock. If so, drop the turnstile lock and try
* again. * again.
*/ */
if ((v & RW_LOCK_READ) == 0) { if (owner != NULL) {
owner = (struct thread *)RW_OWNER(v);
if (TD_IS_RUNNING(owner)) { if (TD_IS_RUNNING(owner)) {
turnstile_cancel(ts); turnstile_cancel(ts);
continue; continue;
@ -581,7 +582,8 @@ __rw_rlock_hard(struct rwlock *rw, struct thread *td, uintptr_t v
#ifdef KDTRACE_HOOKS #ifdef KDTRACE_HOOKS
sleep_time -= lockstat_nsecs(&rw->lock_object); sleep_time -= lockstat_nsecs(&rw->lock_object);
#endif #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 #ifdef KDTRACE_HOOKS
sleep_time += lockstat_nsecs(&rw->lock_object); sleep_time += lockstat_nsecs(&rw->lock_object);
sleep_cnt++; sleep_cnt++;
@ -850,8 +852,8 @@ __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v LOCK_FILE_LINE_ARG_DEF)
uintptr_t tid; uintptr_t tid;
struct rwlock *rw; struct rwlock *rw;
struct turnstile *ts; struct turnstile *ts;
struct thread *owner;
#ifdef ADAPTIVE_RWLOCKS #ifdef ADAPTIVE_RWLOCKS
volatile struct thread *owner;
int spintries = 0; int spintries = 0;
int i, n; int i, n;
#endif #endif
@ -981,6 +983,7 @@ __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v LOCK_FILE_LINE_ARG_DEF)
#endif #endif
ts = turnstile_trywait(&rw->lock_object); ts = turnstile_trywait(&rw->lock_object);
v = RW_READ_VALUE(rw); v = RW_READ_VALUE(rw);
owner = lv_rw_wowner(v);
#ifdef ADAPTIVE_RWLOCKS #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 * chain lock. If so, drop the turnstile lock and try
* again. * again.
*/ */
if (!(v & RW_LOCK_READ)) { if (owner != NULL) {
owner = (struct thread *)RW_OWNER(v);
if (TD_IS_RUNNING(owner)) { if (TD_IS_RUNNING(owner)) {
turnstile_cancel(ts); turnstile_cancel(ts);
continue; continue;
@ -1045,7 +1047,8 @@ __rw_wlock_hard(volatile uintptr_t *c, uintptr_t v LOCK_FILE_LINE_ARG_DEF)
#ifdef KDTRACE_HOOKS #ifdef KDTRACE_HOOKS
sleep_time -= lockstat_nsecs(&rw->lock_object); sleep_time -= lockstat_nsecs(&rw->lock_object);
#endif #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 #ifdef KDTRACE_HOOKS
sleep_time += lockstat_nsecs(&rw->lock_object); sleep_time += lockstat_nsecs(&rw->lock_object);
sleep_cnt++; sleep_cnt++;