summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-08-10 12:21:56 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2022-08-11 17:32:31 -0400
commit5cb7d3b0c8e4c4315a0c262069c0e1c2b387010d (patch)
treee99f5b5bcc5d02b79288d8810e8f762ffe07b9f1
parent7b8f4b0cbae07cc150197333d56bd1750c6b9391 (diff)
fixup! locking: SIX locks (shared/intent/exclusive)
-rw-r--r--include/linux/six.h7
-rw-r--r--kernel/locking/six.c20
2 files changed, 27 insertions, 0 deletions
diff --git a/include/linux/six.h b/include/linux/six.h
index 477c33eb00d7..41ddf63b7470 100644
--- a/include/linux/six.h
+++ b/include/linux/six.h
@@ -200,4 +200,11 @@ void six_lock_pcpu_free_rcu(struct six_lock *);
void six_lock_pcpu_free(struct six_lock *);
void six_lock_pcpu_alloc(struct six_lock *);
+struct six_lock_count {
+ unsigned read;
+ unsigned intent;
+};
+
+struct six_lock_count six_lock_counts(struct six_lock *);
+
#endif /* _LINUX_SIX_H */
diff --git a/kernel/locking/six.c b/kernel/locking/six.c
index fca1208720b6..5b2d92c6e91c 100644
--- a/kernel/locking/six.c
+++ b/kernel/locking/six.c
@@ -757,3 +757,23 @@ void six_lock_pcpu_alloc(struct six_lock *lock)
#endif
}
EXPORT_SYMBOL_GPL(six_lock_pcpu_alloc);
+
+/*
+ * Returns lock held counts, for both read and intent
+ */
+struct six_lock_count six_lock_counts(struct six_lock *lock)
+{
+ struct six_lock_count ret = { 0, lock->state.intent_lock };
+
+ if (!lock->readers)
+ ret.read += lock->state.read_lock;
+ else {
+ int cpu;
+
+ for_each_possible_cpu(cpu)
+ ret.read += *per_cpu_ptr(lock->readers, cpu);
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(six_lock_counts);