From: Kefu Chai Date: Mon, 8 Mar 2021 06:28:27 +0000 (+0800) Subject: common/lockdep: use std::bitset for tracking follows X-Git-Tag: v17.1.0~2674^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=764be5035b04b2950916f30533ec006a45f60c20;p=ceph.git common/lockdep: use std::bitset for tracking follows for better readability Signed-off-by: Kefu Chai --- diff --git a/src/common/lockdep.cc b/src/common/lockdep.cc index c62332c0cfc2..855a98827661 100644 --- a/src/common/lockdep.cc +++ b/src/common/lockdep.cc @@ -12,6 +12,7 @@ * */ #include "lockdep.h" +#include #include "common/ceph_context.h" #include "common/dout.h" #include "common/valgrind.h" @@ -39,7 +40,7 @@ static std::map lock_names; static std::map lock_refs; static char free_ids[MAX_LOCKS/8]; // bit set = free static ceph::unordered_map > held; -static char follows[MAX_LOCKS][MAX_LOCKS/8]; // follows[a][b] means b taken after a +static std::vector> follows(MAX_LOCKS); // follows[a][b] means b taken after a static ceph::BackTrace *follows_bt[MAX_LOCKS][MAX_LOCKS]; unsigned current_maxid; int last_freed_id = -1; @@ -94,7 +95,8 @@ void lockdep_unregister_ceph_context(CephContext *cct) lock_names.clear(); lock_ids.clear(); // FIPS zeroization audit 20191115: these memsets are not security related. - memset((void*)&follows[0][0], 0, current_maxid * MAX_LOCKS/8); + std::for_each(follows.begin(), std::next(follows.begin(), current_maxid), + [](auto& follow) { follow.reset(); }); memset((void*)&follows_bt[0][0], 0, sizeof(ceph::BackTrace*) * current_maxid * MAX_LOCKS); } pthread_mutex_unlock(&lockdep_mutex); @@ -215,15 +217,14 @@ void lockdep_unregister(int id) if (--refs == 0) { if (p != lock_names.end()) { // reset dependency ordering - // FIPS zeroization audit 20191115: this memset is not security related. - memset((void*)&follows[id][0], 0, MAX_LOCKS/8); + follows[id].reset(); for (unsigned i=0; i " @@ -257,7 +258,7 @@ static bool does_follow(int a, int b) } for (unsigned i=0; i " << lock_names[i] << " (" << i << ") at:\n"; @@ -305,8 +306,7 @@ int lockdep_will_lock(const char *name, int id, bool force_backtrace, *_dout << dendl; ceph_abort(); } - } - else if (!(follows[p->first][id/8] & (1 << (id % 8)))) { + } else if (!follows[p->first].test(id)) { // new dependency // did we just create a cycle? @@ -339,7 +339,7 @@ int lockdep_will_lock(const char *name, int id, bool force_backtrace, if (force_backtrace || lockdep_force_backtrace()) { bt = new ceph::BackTrace(BACKTRACE_SKIP); } - follows[p->first][id/8] |= 1 << (id % 8); + follows[p->first].set(id); follows_bt[p->first][id] = bt; lockdep_dout(10) << lock_names[p->first] << " -> " << name << " at" << dendl; //bt->print(*_dout);