mtx: microoptimize lockstat handling in __mtx_lock_sleep
This saves a function call and multiple branches after the lock is acquired.
This commit is contained in:
parent
57abbcd5ad
commit
7640beb920
@ -62,7 +62,7 @@ SDT_PROBE_DEFINE1(lockstat, , , sx__downgrade, "struct sx *");
|
||||
|
||||
SDT_PROBE_DEFINE2(lockstat, , , thread__spin, "struct mtx *", "uint64_t");
|
||||
|
||||
int __read_mostly lockstat_enabled;
|
||||
volatile int __read_mostly lockstat_enabled;
|
||||
|
||||
uint64_t
|
||||
lockstat_nsecs(struct lock_object *lo)
|
||||
|
@ -446,6 +446,7 @@ __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v, uintptr_t tid, int opts,
|
||||
u_int sleep_cnt = 0;
|
||||
int64_t sleep_time = 0;
|
||||
int64_t all_time = 0;
|
||||
int doing_lockstat;
|
||||
#endif
|
||||
|
||||
if (SCHEDULER_STOPPED())
|
||||
@ -484,7 +485,9 @@ __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v, uintptr_t tid, int opts,
|
||||
"_mtx_lock_sleep: %s contested (lock=%p) at %s:%d",
|
||||
m->lock_object.lo_name, (void *)m->mtx_lock, file, line);
|
||||
#ifdef KDTRACE_HOOKS
|
||||
all_time -= lockstat_nsecs(&m->lock_object);
|
||||
doing_lockstat = lockstat_enabled;
|
||||
if (__predict_false(doing_lockstat))
|
||||
all_time -= lockstat_nsecs(&m->lock_object);
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
@ -591,15 +594,17 @@ __mtx_lock_sleep(volatile uintptr_t *c, uintptr_t v, uintptr_t tid, int opts,
|
||||
#endif
|
||||
v = MTX_READ_VALUE(m);
|
||||
}
|
||||
#ifdef KDTRACE_HOOKS
|
||||
all_time += lockstat_nsecs(&m->lock_object);
|
||||
#endif
|
||||
#ifdef KTR
|
||||
if (cont_logged) {
|
||||
CTR4(KTR_CONTENTION,
|
||||
"contention end: %s acquired by %p at %s:%d",
|
||||
m->lock_object.lo_name, (void *)tid, file, line);
|
||||
}
|
||||
#endif
|
||||
#ifdef KDTRACE_HOOKS
|
||||
if (__predict_true(!doing_lockstat))
|
||||
return;
|
||||
all_time += lockstat_nsecs(&m->lock_object);
|
||||
#endif
|
||||
LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(adaptive__acquire, m, contested,
|
||||
waittime, file, line);
|
||||
|
@ -68,7 +68,7 @@ SDT_PROBE_DECLARE(lockstat, , , thread__spin);
|
||||
#define LOCKSTAT_WRITER 0
|
||||
#define LOCKSTAT_READER 1
|
||||
|
||||
extern int lockstat_enabled;
|
||||
extern volatile int lockstat_enabled;
|
||||
|
||||
#ifdef KDTRACE_HOOKS
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user