From: Sage Weil Date: Sun, 23 Aug 2015 18:02:59 +0000 (-0400) Subject: common/Mutex: avoid trylock on lock if instrumentation is not enabled X-Git-Tag: v9.1.0~278^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=151c0511050c196003d0737858e0bf3ea9b665a4;p=ceph.git 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 --- diff --git a/src/common/Mutex.cc b/src/common/Mutex.cc index cedba098128c..5e9b590a5395 100644 --- a/src/common/Mutex.cc +++ b/src/common/Mutex.cc @@ -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();