From: Jeff Layton Date: Thu, 14 Sep 2017 13:28:34 +0000 (-0400) Subject: lockdep: don't take lockdep_mutex twice for new lock registrations X-Git-Tag: v13.0.1~856^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=01863bb6fb62ea89aa3e21e43bf4dc4f3da9cfcb;p=ceph.git 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 --- diff --git a/src/common/lockdep.cc b/src/common/lockdep.cc index 5e4283e289e..1fc564c9fd1 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);