]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
tracing: Use refcount for trace_event_file reference counter
authorSteven Rostedt <rostedt@goodmis.org>
Fri, 26 Jul 2024 18:42:08 +0000 (14:42 -0400)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Wed, 7 Aug 2024 22:12:46 +0000 (18:12 -0400)
Instead of using an atomic counter for the trace_event_file reference
counter, use the refcount interface. It has various checks to make sure
the reference counting is correct, and will warn if it detects an error
(like refcount_inc() on '0').

Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://lore.kernel.org/20240726144208.687cce24@rorschach.local.home
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
include/linux/trace_events.h
kernel/trace/trace_events.c

index 9df3e2973626bcb4f16fd5cccb3908c31e4d7b56..fed58e54f15efeab5bfada27a8b9d590745a6272 100644 (file)
@@ -680,7 +680,7 @@ struct trace_event_file {
         * caching and such. Which is mostly OK ;-)
         */
        unsigned long           flags;
-       atomic_t                ref;    /* ref count for opened files */
+       refcount_t              ref;    /* ref count for opened files */
        atomic_t                sm_ref; /* soft-mode reference counter */
        atomic_t                tm_ref; /* trigger-mode reference counter */
 };
index f08fbaf8cad6763adbe52fa4c3651f255a43b23d..7266ec2a4eea0016de17676edb17b4d08af4fe41 100644 (file)
@@ -992,18 +992,18 @@ static void remove_subsystem(struct trace_subsystem_dir *dir)
 
 void event_file_get(struct trace_event_file *file)
 {
-       atomic_inc(&file->ref);
+       refcount_inc(&file->ref);
 }
 
 void event_file_put(struct trace_event_file *file)
 {
-       if (WARN_ON_ONCE(!atomic_read(&file->ref))) {
+       if (WARN_ON_ONCE(!refcount_read(&file->ref))) {
                if (file->flags & EVENT_FILE_FL_FREED)
                        kmem_cache_free(file_cachep, file);
                return;
        }
 
-       if (atomic_dec_and_test(&file->ref)) {
+       if (refcount_dec_and_test(&file->ref)) {
                /* Count should only go to zero when it is freed */
                if (WARN_ON_ONCE(!(file->flags & EVENT_FILE_FL_FREED)))
                        return;
@@ -3003,7 +3003,7 @@ trace_create_new_event(struct trace_event_call *call,
        atomic_set(&file->tm_ref, 0);
        INIT_LIST_HEAD(&file->triggers);
        list_add(&file->list, &tr->events);
-       event_file_get(file);
+       refcount_set(&file->ref, 1);
 
        return file;
 }