]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/Mutex: avoid trylock on lock if instrumentation is not enabled 5640/head
authorSage Weil <sage@redhat.com>
Sun, 23 Aug 2015 18:02:59 +0000 (14:02 -0400)
committerSage Weil <sage@redhat.com>
Sun, 23 Aug 2015 18:02:59 +0000 (14:02 -0400)
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>
src/common/Mutex.cc

index cedba098128cb55238fb7a53e76ba9af5bbdf7ee..5e9b590a5395e56c7dcafc5e638f542d8a161143 100644 (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();