path: root/tools/perf/tests/hists_cumulate.c
diff options
authorArnaldo Carvalho de Melo <>2015-04-06 20:43:22 -0300
committerArnaldo Carvalho de Melo <>2015-05-08 16:19:27 -0300
commitb91fc39f4ad7503419dd617df78401fa36266cb3 (patch)
tree370d4454766d031be63ac06a9407055b528954da /tools/perf/tests/hists_cumulate.c
parente1ed3a5b87ed6759e16ec93f16aae83d2cc77ca2 (diff)
perf machine: Protect the machine->threads with a rwlock
In addition to using refcounts for the struct thread lifetime management, we need to protect access to machine->threads from concurrent access. That happens in 'perf top', where a thread processes events, inserting and deleting entries from that rb_tree while another thread decays hist_entries, that end up dropping references and ultimately deleting threads from the rb_tree and releasing its resources when no further hist_entry (or other data structures, like in 'perf sched') references it. So the rule is the same for refcounts + protected trees in the kernel, get the tree lock, find object, bump the refcount, drop the tree lock, return, use object, drop the refcount if no more use of it is needed, keep it if storing it in some other data structure, drop when releasing that data structure. I.e. pair "t = machine__find(new)_thread()" with a "thread__put(t)", and "perf_event__preprocess_sample(&al)" with "addr_location__put(&al)". The addr_location__put() one is because as we return references to several data structures, we may end up adding more reference counting for the other data structures and then we'll drop it at addr_location__put() time. Acked-by: David Ahern <> Cc: Adrian Hunter <> Cc: Borislav Petkov <> Cc: Don Zickus <> Cc: Frederic Weisbecker <> Cc: Jiri Olsa <> Cc: Namhyung Kim <> Cc: Stephane Eranian <> Link: Signed-off-by: Arnaldo Carvalho de Melo <>
Diffstat (limited to 'tools/perf/tests/hists_cumulate.c')
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c
index b08a95a5ca1a..620f626e5b35 100644
--- a/tools/perf/tests/hists_cumulate.c
+++ b/tools/perf/tests/hists_cumulate.c
@@ -105,8 +105,10 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
goto out;
if (hist_entry_iter__add(&iter, &al, evsel, &sample,
+ addr_location__put(&al);
goto out;
+ }
fake_samples[i].thread = al.thread;
fake_samples[i].map =;