Commit e3738c69 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

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: default avatarKent Overstreet <kent.overstreet@gmail.com>
parent 2e27f656
...@@ -22,15 +22,19 @@ struct six_lock_count bch2_btree_node_lock_counts(struct btree_trans *trans, ...@@ -22,15 +22,19 @@ struct six_lock_count bch2_btree_node_lock_counts(struct btree_trans *trans,
unsigned level) unsigned level)
{ {
struct btree_path *path; 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)) if (IS_ERR_OR_NULL(b))
return ret; return ret;
trans_for_each_path(trans, path) trans_for_each_path(trans, path)
if (path != skip && path->l[level].b == b) { if (path != skip && path->l[level].b == b) {
ret.read += btree_node_read_locked(path, level); int t = btree_node_locked_type(path, level);
ret.intent += btree_node_intent_locked(path, level);
if (t != BTREE_NODE_UNLOCKED)
ret.n[t]++;
} }
return ret; return ret;
...@@ -48,7 +52,7 @@ void bch2_btree_node_unlock_write(struct btree_trans *trans, ...@@ -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) 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() - * Must drop our read locks before calling six_lock_write() -
......
...@@ -764,15 +764,19 @@ EXPORT_SYMBOL_GPL(six_lock_pcpu_alloc); ...@@ -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 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) if (!lock->readers)
ret.read += lock->state.read_lock; ret.n[SIX_LOCK_read] += lock->state.read_lock;
else { else {
int cpu; int cpu;
for_each_possible_cpu(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; return ret;
......
...@@ -206,8 +206,7 @@ void six_lock_pcpu_free(struct six_lock *); ...@@ -206,8 +206,7 @@ void six_lock_pcpu_free(struct six_lock *);
void six_lock_pcpu_alloc(struct six_lock *); void six_lock_pcpu_alloc(struct six_lock *);
struct six_lock_count { struct six_lock_count {
unsigned read; unsigned n[3];
unsigned intent;
}; };
struct six_lock_count six_lock_counts(struct six_lock *); struct six_lock_count six_lock_counts(struct six_lock *);
......
...@@ -453,11 +453,11 @@ TRACE_EVENT(btree_node_upgrade_fail, ...@@ -453,11 +453,11 @@ TRACE_EVENT(btree_node_upgrade_fail,
__entry->locked = btree_node_locked(path, level); __entry->locked = btree_node_locked(path, level);
c = bch2_btree_node_lock_counts(trans, NULL, path->l[level].b, level), c = bch2_btree_node_lock_counts(trans, NULL, path->l[level].b, level),
__entry->self_read_count = c.read; __entry->self_read_count = c.n[SIX_LOCK_read];
__entry->self_intent_count = c.intent; __entry->self_intent_count = c.n[SIX_LOCK_intent];
c = six_lock_counts(&path->l[level].b->c.lock); c = six_lock_counts(&path->l[level].b->c.lock);
__entry->read_count = c.read; __entry->read_count = c.n[SIX_LOCK_read];
__entry->intent_count = c.intent; __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", TP_printk("%s %pS btree %s pos %llu:%llu:%u, locked %u held %u:%u lock count %u:%u",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment