common/Mutex: avoid trylock on lock if instrumentation is not enabled

Benchmarks have shown that the trylock in the lock path has a high
latency cost.  Only pay the penalty if instrumentation is actually
enabled.

While we are at it, avoid the duplicate conditional check so that
the fast path is faster.

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2015-08-23 14:02:59 -04:00
parent 2d92f4cba5
commit 151c051105

View File

@ -82,21 +82,26 @@ Mutex::~Mutex() {
}
void Mutex::Lock(bool no_lockdep) {
utime_t start;
int r;
if (lockdep && g_lockdep && !no_lockdep) _will_lock();
if (TryLock()) {
goto out;
}
if (logger && cct && cct->_conf->mutex_perf_counter)
if (logger && cct && cct->_conf->mutex_perf_counter) {
utime_t start;
// instrumented mutex enabled
start = ceph_clock_now(cct);
r = pthread_mutex_lock(&_m);
if (logger && cct && cct->_conf->mutex_perf_counter)
if (TryLock()) {
goto out;
}
r = pthread_mutex_lock(&_m);
logger->tinc(l_mutex_wait,
ceph_clock_now(cct) - start);
} else {
r = pthread_mutex_lock(&_m);
}
assert(r == 0);
if (lockdep && g_lockdep) _locked();
_post_lock();