Skip to content

Commit

Permalink
lockdep: don't take lockdep_mutex twice for new lock registrations
Browse files Browse the repository at this point in the history
We can do it under the same mutex, which should be more efficient.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
  • Loading branch information
jtlayton committed Sep 16, 2017
1 parent e057b67 commit 01863bb
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/common/lockdep.cc
Expand Up @@ -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<std::string, int>::iterator p = lock_ids.find(name);
if (p == lock_ids.end()) {
id = lockdep_get_free_id();
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 01863bb

Please sign in to comment.