Skip to contentSkip to conversation

percpu-refcount: add ref_trace_final_put trace

PATCH New Eugene Mavick 1 participant 2 messages Jul 6 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 2/4 refcount: add ref_trace_final_put tracepoint

Add the ref_trace_final_put tracepoint to __refcount_sub_and_test(). This fires when a refcount_t reaches zero, capturing the caller address, the function name, and the refcount_t address.

---
 include/linux/refcount.h | 2 ++
 1 file changed, 2 insertions(+)
include/linux/refcount.h +2 -0
index ba7657ced281..7b1fbf326a21 100644
@@ -107,6 +107,7 @@
 #include <linux/limits.h>
 #include <linux/refcount_types.h>
 #include <linux/spinlock_types.h>
+#include <linux/ref_trace.h>
 
 struct mutex;
 
@@ -393,6 +394,7 @@ bool __refcount_sub_and_test(int i, refcount_t *r, int *oldp)
 
 	if (old > 0 && old == i) {
 		smp_acquire__after_ctrl_dep();
+		trace_ref_final_put(r);
 		return true;
 	}
 
Signature · 1 line
2.51.2
#2 lore raw

PATCH 3/4 percpu-refcount: add ref_trace_final_put trace

In reply to a message not in the archive

Add the ref_trace_final_put tracepoint to percpu_ref_put_many(). The tracepoint fires when the atomic counter reaches zero in the atomic fallback path (after percpu_ref_kill() has been called).

---
 include/linux/percpu-refcount.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/linux/percpu-refcount.h +4 -1
index d73a1c08c3e3..55543ecdf60c 100644
@@ -55,6 +55,7 @@
 #include <linux/rcupdate.h>
 #include <linux/types.h>
 #include <linux/gfp.h>
+#include <linux/ref_trace.h>
 
 struct percpu_ref;
 typedef void (percpu_ref_func_t)(struct percpu_ref *);
@@ -331,8 +332,10 @@ static inline void percpu_ref_put_many(struct percpu_ref *ref, unsigned long nr)
 
 	if (__ref_is_percpu(ref, &percpu_count))
 		this_cpu_sub(*percpu_count, nr);
-	else if (unlikely(atomic_long_sub_and_test(nr, &ref->data->count)))
+	else if (unlikely(atomic_long_sub_and_test(nr, &ref->data->count))) {
+		trace_ref_final_put(ref);
 		ref->data->release(ref);
+	}
 
 	rcu_read_unlock();
 }
Signature · 1 line
2.51.2