From 01863bb6fb62ea89aa3e21e43bf4dc4f3da9cfcb Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Thu, 14 Sep 2017 09:28:34 -0400 Subject: [PATCH] lockdep: don't take lockdep_mutex twice for new lock registrations We can do it under the same mutex, which should be more efficient. Signed-off-by: Jeff Layton --- src/common/lockdep.cc | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/common/lockdep.cc b/src/common/lockdep.cc index 5e4283e289eac..1fc564c9fd167 100644 --- a/src/common/lockdep.cc +++ b/src/common/lockdep.cc @@ -163,11 +163,10 @@ int lockdep_get_free_id(void) return -1; } -int lockdep_register(const char *name) +static int _lockdep_register(const char *name) { int id; - pthread_mutex_lock(&lockdep_mutex); ceph::unordered_map::iterator p = lock_ids.find(name); if (p == lock_ids.end()) { id = lockdep_get_free_id(); @@ -191,11 +190,20 @@ int lockdep_register(const char *name) } ++lock_refs[id]; - pthread_mutex_unlock(&lockdep_mutex); return id; } +int lockdep_register(const char *name) +{ + int id; + + pthread_mutex_lock(&lockdep_mutex); + id = _lockdep_register(name); + pthread_mutex_unlock(&lockdep_mutex); + return id; +} + void lockdep_unregister(int id) { if (id < 0) { @@ -269,9 +277,10 @@ static bool does_follow(int a, int b) int lockdep_will_lock(const char *name, int id, bool force_backtrace) { pthread_t p = pthread_self(); - if (id < 0) id = lockdep_register(name); pthread_mutex_lock(&lockdep_mutex); + if (id < 0) + id = _lockdep_register(name); lockdep_dout(20) << "_will_lock " << name << " (" << id << ")" << dendl; // check dependency graph @@ -343,9 +352,10 @@ int lockdep_locked(const char *name, int id, bool force_backtrace) { pthread_t p = pthread_self(); - if (id < 0) id = lockdep_register(name); - pthread_mutex_lock(&lockdep_mutex); + if (id < 0) + id = _lockdep_register(name); + lockdep_dout(20) << "_locked " << name << dendl; if (force_backtrace || lockdep_force_backtrace()) held[p][id] = new BackTrace(BACKTRACE_SKIP); -- 2.39.5