Skip to content

Commit

Permalink
lockdep: do not automatically collect all backtraces
Browse files Browse the repository at this point in the history
It is expensive to collect backtraces every time a lock is
checked in order to provide cycle backtraces.  The backtraces
can be forced on for specific locks or globally via the new
config option "lockdep_force_backtrace".

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit 7354d25)
  • Loading branch information
Jason Dillaman committed Jul 22, 2015
1 parent 3b6880f commit 7c66db2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/common/Mutex.h
Expand Up @@ -53,7 +53,7 @@ class Mutex {
id = lockdep_register(name.c_str());
}
void _will_lock() { // about to lock
id = lockdep_will_lock(name.c_str(), id);
id = lockdep_will_lock(name.c_str(), id, backtrace);
}
void _locked() { // just locked
id = lockdep_locked(name.c_str(), id, backtrace);
Expand Down
1 change: 1 addition & 0 deletions src/common/config_opts.h
Expand Up @@ -23,6 +23,7 @@ OPTION(num_client, OPT_INT, 1)
OPTION(monmap, OPT_STR, "")
OPTION(mon_host, OPT_STR, "")
OPTION(lockdep, OPT_BOOL, false)
OPTION(lockdep_force_backtrace, OPT_BOOL, false) // always gather current backtrace at every lock
OPTION(run_dir, OPT_STR, "/var/run/ceph") // the "/var/run/ceph" dir, created on daemon startup
OPTION(admin_socket, OPT_STR, "$run_dir/$cluster-$name.asok") // default changed by common_preinit()

Expand Down
16 changes: 13 additions & 3 deletions src/common/lockdep.cc
Expand Up @@ -56,6 +56,12 @@ static list<int> free_ids;
static ceph::unordered_map<pthread_t, map<int,BackTrace*> > held;
static BackTrace *follows[MAX_LOCKS][MAX_LOCKS]; // follows[a][b] means b taken after a

static bool lockdep_force_backtrace()
{
return (g_lockdep_ceph_ctx != NULL &&
g_lockdep_ceph_ctx->_conf->lockdep_force_backtrace);
}

/******* Functions **********/
void lockdep_register_ceph_context(CephContext *cct)
{
Expand Down Expand Up @@ -204,7 +210,7 @@ static bool does_follow(int a, int b)
return false;
}

int lockdep_will_lock(const char *name, int id)
int lockdep_will_lock(const char *name, int id, bool force_backtrace)
{
pthread_t p = pthread_self();
if (id < 0) id = lockdep_register(name);
Expand Down Expand Up @@ -234,8 +240,8 @@ int lockdep_will_lock(const char *name, int id)
// new dependency

// did we just create a cycle?
BackTrace *bt = new BackTrace(BACKTRACE_SKIP);
if (does_follow(id, p->first)) {
BackTrace *bt = new BackTrace(BACKTRACE_SKIP);
lockdep_dout(0) << "new dependency " << lock_names[p->first]
<< " (" << p->first << ") -> " << name << " (" << id << ")"
<< " creates a cycle at\n";
Expand All @@ -261,6 +267,10 @@ int lockdep_will_lock(const char *name, int id)

assert(0); // actually, we should just die here.
} else {
BackTrace *bt = NULL;
if (force_backtrace || lockdep_force_backtrace()) {
bt = new BackTrace(BACKTRACE_SKIP);
}
follows[p->first][id] = bt;
lockdep_dout(10) << lock_names[p->first] << " -> " << name << " at" << dendl;
//bt->print(*_dout);
Expand All @@ -280,7 +290,7 @@ int lockdep_locked(const char *name, int id, bool force_backtrace)

pthread_mutex_lock(&lockdep_mutex);
lockdep_dout(20) << "_locked " << name << dendl;
if (g_lockdep >= 2 || force_backtrace)
if (force_backtrace || lockdep_force_backtrace())
held[p][id] = new BackTrace(BACKTRACE_SKIP);
else
held[p][id] = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/common/lockdep.h
Expand Up @@ -23,7 +23,7 @@ extern void lockdep_register_ceph_context(CephContext *cct);
extern void lockdep_unregister_ceph_context(CephContext *cct);
extern int lockdep_register(const char *n);
extern void lockdep_unregister(int id);
extern int lockdep_will_lock(const char *n, int id);
extern int lockdep_will_lock(const char *n, int id, bool force_backtrace=false);
extern int lockdep_locked(const char *n, int id, bool force_backtrace=false);
extern int lockdep_will_unlock(const char *n, int id);
extern int lockdep_dump_locks();
Expand Down

0 comments on commit 7c66db2

Please sign in to comment.