six locks: Improve six_lock_count

six_lock_count now counts up whether a write lock held, and this patch
now also correctly counts six_lock->intent_lock_recurse.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2022-08-21 23:08:53 -04:00 committed by Kent Overstreet
parent 2e27f6567b
commit e3738c6909
4 changed files with 20 additions and 13 deletions

View File

@ -22,15 +22,19 @@ struct six_lock_count bch2_btree_node_lock_counts(struct btree_trans *trans,
unsigned level)
{
struct btree_path *path;
struct six_lock_count ret = { 0, 0 };
struct six_lock_count ret;
memset(&ret, 0, sizeof(ret));
if (IS_ERR_OR_NULL(b))
return ret;
trans_for_each_path(trans, path)
if (path != skip && path->l[level].b == b) {
ret.read += btree_node_read_locked(path, level);
ret.intent += btree_node_intent_locked(path, level);
int t = btree_node_locked_type(path, level);
if (t != BTREE_NODE_UNLOCKED)
ret.n[t]++;
}
return ret;
@ -48,7 +52,7 @@ void bch2_btree_node_unlock_write(struct btree_trans *trans,
void __bch2_btree_node_lock_write(struct btree_trans *trans, struct btree *b)
{
int readers = bch2_btree_node_lock_counts(trans, NULL, b, b->c.level).read;
int readers = bch2_btree_node_lock_counts(trans, NULL, b, b->c.level).n[SIX_LOCK_read];
/*
* Must drop our read locks before calling six_lock_write() -

View File

@ -764,15 +764,19 @@ EXPORT_SYMBOL_GPL(six_lock_pcpu_alloc);
*/
struct six_lock_count six_lock_counts(struct six_lock *lock)
{
struct six_lock_count ret = { 0, lock->state.intent_lock };
struct six_lock_count ret;
ret.n[SIX_LOCK_read] = 0;
ret.n[SIX_LOCK_intent] = lock->state.intent_lock + lock->intent_lock_recurse;
ret.n[SIX_LOCK_write] = lock->state.seq & 1;
if (!lock->readers)
ret.read += lock->state.read_lock;
ret.n[SIX_LOCK_read] += lock->state.read_lock;
else {
int cpu;
for_each_possible_cpu(cpu)
ret.read += *per_cpu_ptr(lock->readers, cpu);
ret.n[SIX_LOCK_read] += *per_cpu_ptr(lock->readers, cpu);
}
return ret;

View File

@ -206,8 +206,7 @@ void six_lock_pcpu_free(struct six_lock *);
void six_lock_pcpu_alloc(struct six_lock *);
struct six_lock_count {
unsigned read;
unsigned intent;
unsigned n[3];
};
struct six_lock_count six_lock_counts(struct six_lock *);

View File

@ -453,11 +453,11 @@ TRACE_EVENT(btree_node_upgrade_fail,
__entry->locked = btree_node_locked(path, level);
c = bch2_btree_node_lock_counts(trans, NULL, path->l[level].b, level),
__entry->self_read_count = c.read;
__entry->self_intent_count = c.intent;
__entry->self_read_count = c.n[SIX_LOCK_read];
__entry->self_intent_count = c.n[SIX_LOCK_intent];
c = six_lock_counts(&path->l[level].b->c.lock);
__entry->read_count = c.read;
__entry->intent_count = c.intent;
__entry->read_count = c.n[SIX_LOCK_read];
__entry->intent_count = c.n[SIX_LOCK_read];
),
TP_printk("%s %pS btree %s pos %llu:%llu:%u, locked %u held %u:%u lock count %u:%u",