From 764be5035b04b2950916f30533ec006a45f60c20 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 8 Mar 2021 14:28:27 +0800 Subject: [PATCH] common/lockdep: use std::bitset for tracking follows for better readability Signed-off-by: Kefu Chai --- src/common/lockdep.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/common/lockdep.cc b/src/common/lockdep.cc index c62332c0cfc20..855a988276612 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); -- 2.39.5