six locks: Simplify six_lock_counts()

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2023-02-15 18:29:16 -05:00
parent 70f0b0fd7e
commit 0cc1bc84d6

View file

@ -830,19 +830,12 @@ struct six_lock_count six_lock_counts(struct six_lock *lock)
{
struct six_lock_count ret;
ret.n[SIX_LOCK_read] = 0;
ret.n[SIX_LOCK_read] = !lock->readers
? lock->state.read_lock
: pcpu_read_count(lock);
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.n[SIX_LOCK_read] += lock->state.read_lock;
else {
int cpu;
for_each_possible_cpu(cpu)
ret.n[SIX_LOCK_read] += *per_cpu_ptr(lock->readers, cpu);
}
return ret;
}
EXPORT_SYMBOL_GPL(six_lock_counts);