aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-annotate.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2015-04-06 19:43:22 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-05-08 15:19:27 -0400
commitb91fc39f4ad7503419dd617df78401fa36266cb3 (patch)
tree370d4454766d031be63ac06a9407055b528954da /tools/perf/builtin-annotate.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 <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-bs9rt4n0jw3hi9f3zxyy3xln@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-annotate.c')
-rw-r--r--tools/perf/builtin-annotate.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 71bf7451c0ca..b57a027fb200 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -84,6 +84,7 @@ static int process_sample_event(struct perf_tool *tool,
84{ 84{
85 struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool); 85 struct perf_annotate *ann = container_of(tool, struct perf_annotate, tool);
86 struct addr_location al; 86 struct addr_location al;
87 int ret = 0;
87 88
88 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) { 89 if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
89 pr_warning("problem processing %d event, skipping it.\n", 90 pr_warning("problem processing %d event, skipping it.\n",
@@ -92,15 +93,16 @@ static int process_sample_event(struct perf_tool *tool,
92 } 93 }
93 94
94 if (ann->cpu_list && !test_bit(sample->cpu, ann->cpu_bitmap)) 95 if (ann->cpu_list && !test_bit(sample->cpu, ann->cpu_bitmap))
95 return 0; 96 goto out_put;
96 97
97 if (!al.filtered && perf_evsel__add_sample(evsel, sample, &al, ann)) { 98 if (!al.filtered && perf_evsel__add_sample(evsel, sample, &al, ann)) {
98 pr_warning("problem incrementing symbol count, " 99 pr_warning("problem incrementing symbol count, "
99 "skipping event\n"); 100 "skipping event\n");
100 return -1; 101 ret = -1;
101 } 102 }
102 103out_put:
103 return 0; 104 addr_location__put(&al);
105 return ret;
104} 106}
105 107
106static int hist_entry__tty_annotate(struct hist_entry *he, 108static int hist_entry__tty_annotate(struct hist_entry *he,