mirror of
https://github.com/ceph/ceph
synced 2025-01-20 01:51:34 +00:00
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:
parent
2d92f4cba5
commit
151c051105
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user