rwlock: avoid branches in the slow path if lockstat is disabled

This commit is contained in:
mjg 2017-11-17 02:21:24 +00:00
parent 72b0124a90
commit 3b151c9e66

View File

@ -424,11 +424,14 @@ __rw_rlock_hard(volatile uintptr_t *c, struct thread *td, uintptr_t v,
struct lock_delay_arg lda;
#endif
#ifdef KDTRACE_HOOKS
uintptr_t state;
u_int sleep_cnt = 0;
int64_t sleep_time = 0;
int64_t all_time = 0;
#endif
#if defined(KDTRACE_HOOKS) || defined(LOCK_PROFILING)
uintptr_t state;
int doing_lockprof;
#endif
if (SCHEDULER_STOPPED())
return;
@ -440,12 +443,17 @@ __rw_rlock_hard(volatile uintptr_t *c, struct thread *td, uintptr_t v,
#endif
rw = rwlock2rw(c);
#ifdef KDTRACE_HOOKS
all_time -= lockstat_nsecs(&rw->lock_object);
#endif
#ifdef KDTRACE_HOOKS
#ifdef LOCK_PROFILING
doing_lockprof = 1;
state = v;
#elif defined(KDTRACE_HOOKS)
doing_lockprof = lockstat_enabled;
if (__predict_false(doing_lockprof)) {
all_time -= lockstat_nsecs(&rw->lock_object);
state = v;
}
#endif
for (;;) {
if (__rw_rlock_try(rw, td, &v, file, line))
break;
@ -583,6 +591,10 @@ __rw_rlock_hard(volatile uintptr_t *c, struct thread *td, uintptr_t v,
__func__, rw);
v = RW_READ_VALUE(rw);
}
#if defined(KDTRACE_HOOKS) || defined(LOCK_PROFILING)
if (__predict_true(!doing_lockprof))
return;
#endif
#ifdef KDTRACE_HOOKS
all_time += lockstat_nsecs(&rw->lock_object);
if (sleep_time)