Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Use atomic_t to implement thread__{get,put} refcnt

Fixing bugs in 'perf top' where the used thread unsafe 'struct thread'
refcount implementation was falling apart because we really use two
threads.

Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-hil2hol294u5ntcuof4jhmn6@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+5 -4
+3 -3
tools/perf/util/thread.c
··· 53 53 goto err_thread; 54 54 55 55 list_add(&comm->list, &thread->comm_list); 56 - 56 + atomic_set(&thread->refcnt, 0); 57 57 } 58 58 59 59 return thread; ··· 84 84 85 85 struct thread *thread__get(struct thread *thread) 86 86 { 87 - ++thread->refcnt; 87 + atomic_inc(&thread->refcnt); 88 88 return thread; 89 89 } 90 90 91 91 void thread__put(struct thread *thread) 92 92 { 93 - if (thread && --thread->refcnt == 0) { 93 + if (thread && atomic_dec_and_test(&thread->refcnt)) { 94 94 list_del_init(&thread->node); 95 95 thread__delete(thread); 96 96 }
+2 -1
tools/perf/util/thread.h
··· 1 1 #ifndef __PERF_THREAD_H 2 2 #define __PERF_THREAD_H 3 3 4 + #include <linux/atomic.h> 4 5 #include <linux/rbtree.h> 5 6 #include <linux/list.h> 6 7 #include <unistd.h> ··· 22 21 pid_t tid; 23 22 pid_t ppid; 24 23 int cpu; 25 - int refcnt; 24 + atomic_t refcnt; 26 25 char shortname[3]; 27 26 bool comm_set; 28 27 bool dead; /* if set thread has exited */