From: Colin Patrick McCabe Date: Mon, 14 Feb 2011 11:30:55 +0000 (-0800) Subject: lockdep: balance dout and dendl, fix whitespace X-Git-Tag: v0.25~122^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=97809ee3549da733c3372bb5ba5134e039c2808e;p=ceph.git lockdep: balance dout and dendl, fix whitespace Make lockdep use dendl the same way as the other code. This is in preparation for making lockdep use normal dout() rather than an unlocked version. Signed-off-by: Colin McCabe --- diff --git a/src/common/lockdep.cc b/src/common/lockdep.cc index c7d0b53ec1bf0..61ee8507e30bd 100644 --- a/src/common/lockdep.cc +++ b/src/common/lockdep.cc @@ -12,6 +12,8 @@ #undef dout #define dout(l) if (l<=g_conf.debug_lockdep) *_dout << g_clock.now() << " " << std::hex << pthread_self() << std::dec << " lockdep: " +#undef dendl +#define dendl std::endl // global int g_lockdep = 0; @@ -37,7 +39,7 @@ map lock_names; int last_id = 0; hash_map > held; -BackTrace *follows[MAX_LOCKS][MAX_LOCKS]; // follows[a][b] means b taken after a +BackTrace *follows[MAX_LOCKS][MAX_LOCKS]; // follows[a][b] means b taken after a #define BACKTRACE_SKIP 3 @@ -50,13 +52,14 @@ int lockdep_dump_locks() for (hash_map >::iterator p = held.begin(); p != held.end(); p++) { - dout(0) << "--- thread " << p->first << " ---" << std::endl; + dout(0) << "--- thread " << p->first << " ---" << dendl; for (map::iterator q = p->second.begin(); q != p->second.end(); q++) { - dout(0) << " * " << lock_names[q->first] << std::endl; + dout(0) << " * " << lock_names[q->first] << "\n"; if (q->second) q->second->print(*_dout); + *_dout << dendl; } } @@ -75,17 +78,17 @@ int lockdep_register(const char *name) for (int i=0; i::iterator p = lock_ids.find(name); if (p == lock_ids.end()) { assert(last_id < MAX_LOCKS); id = last_id++; lock_ids[name] = id; lock_names[id] = name; - dout(10) << "registered '" << name << "' as " << id << std::endl; + dout(10) << "registered '" << name << "' as " << id << dendl; } else { id = p->second; - dout(20) << "had '" << name << "' as " << id << std::endl; + dout(20) << "had '" << name << "' as " << id << dendl; } pthread_mutex_unlock(&lockdep_mutex); @@ -98,20 +101,22 @@ int lockdep_register(const char *name) static bool does_follow(int a, int b) { if (follows[a][b]) { - *_dout << std::endl; - dout(0) << "------------------------------------" << std::endl; - dout(0) << "existing dependency " << lock_names[a] << " (" << a << ") -> " << lock_names[b] << " (" << b << ") at: " << std::endl; + dout(0) << "\n"; + *_dout << "------------------------------------" << "\n"; + *_dout << "existing dependency " << lock_names[a] << " (" << a << ") -> " + << lock_names[b] << " (" << b << ") at:\n"; follows[a][b]->print(*_dout); - *_dout << std::endl; + *_dout << dendl; return true; } for (int i=0; i " << lock_names[i] << " (" << i << ") at:" << std::endl; + dout(0) << "existing intermediate dependency " << lock_names[a] + << " (" << a << ") -> " << lock_names[i] << " (" << i << ") at:\n"; follows[a][i]->print(*_dout); - *_dout << std::endl; + *_dout << dendl; return true; } } @@ -125,7 +130,7 @@ int lockdep_will_lock(const char *name, int id) if (id < 0) id = lockdep_register(name); pthread_mutex_lock(&lockdep_mutex); - dout(20) << "_will_lock " << name << " (" << id << ")" << std::endl; + dout(20) << "_will_lock " << name << " (" << id << ")" << dendl; // check dependency graph map &m = held[p]; @@ -133,43 +138,42 @@ int lockdep_will_lock(const char *name, int id) p != m.end(); p++) { if (p->first == id) { - *_dout << std::endl; - dout(0) << "recursive lock of " << name << " (" << id << ")" << std::endl; + dout(0) << "\n"; + *_dout << "recursive lock of " << name << " (" << id << ")\n"; BackTrace *bt = new BackTrace(BACKTRACE_SKIP); bt->print(*_dout); if (p->second) { - *_dout << std::endl; - dout(0) << "previously locked at" << std::endl; + *_dout << "\npreviously locked at\n"; p->second->print(*_dout); } - *_dout << std::endl; + *_dout << dendl; assert(0); } else if (!follows[p->first][id]) { - // new dependency - + // new dependency + // did we just create a cycle? BackTrace *bt = new BackTrace(BACKTRACE_SKIP); if (does_follow(id, p->first)) { - dout(0) << "new dependency " << lock_names[p->first] << " (" << p->first << ") -> " << name << " (" << id << ")" - << " creates a cycle at" - << std::endl; + dout(0) << "new dependency " << lock_names[p->first] + << " (" << p->first << ") -> " << name << " (" << id << ")" + << " creates a cycle at\n"; bt->print(*_dout); - *_dout << std::endl; + *_dout << dendl; - dout(0) << "btw, i am holding these locks:" << std::endl; + dout(0) << "btw, i am holding these locks:" << dendl; for (map::iterator q = m.begin(); q != m.end(); q++) { - dout(0) << " " << lock_names[q->first] << " (" << q->first << ")" << std::endl; + dout(0) << " " << lock_names[q->first] << " (" << q->first << ")" << dendl; if (q->second) { + dout(0) << " "; q->second->print(*_dout); - *_dout << std::endl; + *_dout << dendl; } } - *_dout << std::endl; - *_dout << std::endl; + dout(0) << "\n" << dendl; // don't add this dependency, or we'll get aMutex. cycle in the graph, and // does_follow() won't terminate. @@ -177,7 +181,7 @@ int lockdep_will_lock(const char *name, int id) assert(0); // actually, we should just die here. } else { follows[p->first][id] = bt; - dout(10) << lock_names[p->first] << " -> " << name << " at" << std::endl; + dout(10) << lock_names[p->first] << " -> " << name << " at" << dendl; //bt->print(*_dout); } } @@ -194,7 +198,7 @@ int lockdep_locked(const char *name, int id, bool force_backtrace) if (id < 0) id = lockdep_register(name); pthread_mutex_lock(&lockdep_mutex); - dout(20) << "_locked " << name << std::endl; + dout(20) << "_locked " << name << dendl; if (g_lockdep >= 2 || force_backtrace) held[p][id] = new BackTrace(BACKTRACE_SKIP); else @@ -206,7 +210,7 @@ int lockdep_locked(const char *name, int id, bool force_backtrace) int lockdep_will_unlock(const char *name, int id) { pthread_t p = pthread_self(); - + if (id < 0) { //id = lockdep_register(name); assert(id == -1); @@ -214,7 +218,7 @@ int lockdep_will_unlock(const char *name, int id) } pthread_mutex_lock(&lockdep_mutex); - dout(20) << "_will_unlock " << name << std::endl; + dout(20) << "_will_unlock " << name << dendl; // don't assert.. lockdep may be enabled at any point in time //assert(held.count(p));