aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2016-08-25 15:09:21 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-08-30 09:56:34 -0400
commitb01141f4f59ce56e5ed177a1fc70b3ba4d676aca (patch)
treea4d7be51790bb2e80b09100588029b51bbe33179
parentffe67c2fabf128122b30fbf0ac498928e171b0b3 (diff)
perf annotate: Initialize the priv are in symbol__new()
We need to initializa some fields (right now just a mutex) when we allocate the per symbol annotation struct, so do it at the symbol constructor instead of (ab)using the filter mechanism for that. This way we remove one of the few cases we have for that symbol filter, which will eventually led to removing it. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-cvz34avlz1lez888lob95390@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-annotate.c7
-rw-r--r--tools/perf/builtin-report.c6
-rw-r--r--tools/perf/builtin-top.c4
-rw-r--r--tools/perf/util/annotate.c7
-rw-r--r--tools/perf/util/annotate.h1
-rw-r--r--tools/perf/util/symbol.c25
-rw-r--r--tools/perf/util/symbol.h3
7 files changed, 37 insertions, 16 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 9c1034d81b4f..f07b23011b22 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -204,8 +204,6 @@ static int __cmd_annotate(struct perf_annotate *ann)
204 struct perf_evsel *pos; 204 struct perf_evsel *pos;
205 u64 total_nr_samples; 205 u64 total_nr_samples;
206 206
207 machines__set_symbol_filter(&session->machines, symbol__annotate_init);
208
209 if (ann->cpu_list) { 207 if (ann->cpu_list) {
210 ret = perf_session__cpu_bitmap(session, ann->cpu_list, 208 ret = perf_session__cpu_bitmap(session, ann->cpu_list,
211 ann->cpu_bitmap); 209 ann->cpu_bitmap);
@@ -367,7 +365,10 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
367 if (annotate.session == NULL) 365 if (annotate.session == NULL)
368 return -1; 366 return -1;
369 367
370 symbol_conf.priv_size = sizeof(struct annotation); 368 ret = symbol__annotation_init();
369 if (ret < 0)
370 goto out_delete;
371
371 symbol_conf.try_vmlinux_path = true; 372 symbol_conf.try_vmlinux_path = true;
372 373
373 ret = symbol__init(&annotate.session->header.env); 374 ret = symbol__init(&annotate.session->header.env);
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index b9e046baa5fc..1a07c4cdf6ed 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -984,9 +984,9 @@ repeat:
984 * implementation. 984 * implementation.
985 */ 985 */
986 if (ui__has_annotation()) { 986 if (ui__has_annotation()) {
987 symbol_conf.priv_size = sizeof(struct annotation); 987 ret = symbol__annotation_init();
988 machines__set_symbol_filter(&session->machines, 988 if (ret < 0)
989 symbol__annotate_init); 989 goto error;
990 /* 990 /*
991 * For searching by name on the "Browse map details". 991 * For searching by name on the "Browse map details".
992 * providing it only in verbose mode not to bloat too 992 * providing it only in verbose mode not to bloat too
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index a3223aa22213..e8ca8dc88af9 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1324,7 +1324,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
1324 if (symbol_conf.cumulate_callchain && !callchain_param.order_set) 1324 if (symbol_conf.cumulate_callchain && !callchain_param.order_set)
1325 callchain_param.order = ORDER_CALLER; 1325 callchain_param.order = ORDER_CALLER;
1326 1326
1327 symbol_conf.priv_size = sizeof(struct annotation); 1327 status = symbol__annotation_init();
1328 if (status < 0)
1329 goto out_delete_evlist;
1328 1330
1329 symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL); 1331 symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
1330 if (symbol__init(NULL) < 0) 1332 if (symbol__init(NULL) < 0)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 25a9259a6a6e..1b59e3129216 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -491,13 +491,6 @@ static struct ins *ins__find(const char *name)
491 return bsearch(name, instructions, nmemb, sizeof(struct ins), ins__key_cmp); 491 return bsearch(name, instructions, nmemb, sizeof(struct ins), ins__key_cmp);
492} 492}
493 493
494int symbol__annotate_init(struct map *map __maybe_unused, struct symbol *sym)
495{
496 struct annotation *notes = symbol__annotation(sym);
497 pthread_mutex_init(&notes->lock, NULL);
498 return 0;
499}
500
501int symbol__alloc_hist(struct symbol *sym) 494int symbol__alloc_hist(struct symbol *sym)
502{ 495{
503 struct annotation *notes = symbol__annotation(sym); 496 struct annotation *notes = symbol__annotation(sym);
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index f67ccb027561..e96f4daed9b9 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -177,7 +177,6 @@ enum symbol_disassemble_errno {
177int symbol__strerror_disassemble(struct symbol *sym, struct map *map, 177int symbol__strerror_disassemble(struct symbol *sym, struct map *map,
178 int errnum, char *buf, size_t buflen); 178 int errnum, char *buf, size_t buflen);
179 179
180int symbol__annotate_init(struct map *map, struct symbol *sym);
181int symbol__annotate_printf(struct symbol *sym, struct map *map, 180int symbol__annotate_printf(struct symbol *sym, struct map *map,
182 struct perf_evsel *evsel, bool full_paths, 181 struct perf_evsel *evsel, bool full_paths,
183 int min_pcnt, int max_lines, int context); 182 int min_pcnt, int max_lines, int context);
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 37e8d20ae03e..863d69c45b8a 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -9,6 +9,7 @@
9#include <fcntl.h> 9#include <fcntl.h>
10#include <unistd.h> 10#include <unistd.h>
11#include <inttypes.h> 11#include <inttypes.h>
12#include "annotate.h"
12#include "build-id.h" 13#include "build-id.h"
13#include "util.h" 14#include "util.h"
14#include "debug.h" 15#include "debug.h"
@@ -235,8 +236,13 @@ struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name)
235 if (sym == NULL) 236 if (sym == NULL)
236 return NULL; 237 return NULL;
237 238
238 if (symbol_conf.priv_size) 239 if (symbol_conf.priv_size) {
240 if (symbol_conf.init_annotation) {
241 struct annotation *notes = (void *)sym;
242 pthread_mutex_init(&notes->lock, NULL);
243 }
239 sym = ((void *)sym) + symbol_conf.priv_size; 244 sym = ((void *)sym) + symbol_conf.priv_size;
245 }
240 246
241 sym->start = start; 247 sym->start = start;
242 sym->end = len ? start + len : start; 248 sym->end = len ? start + len : start;
@@ -1948,6 +1954,23 @@ static bool symbol__read_kptr_restrict(void)
1948 return value; 1954 return value;
1949} 1955}
1950 1956
1957int symbol__annotation_init(void)
1958{
1959 if (symbol_conf.initialized) {
1960 pr_err("Annotation needs to be init before symbol__init()\n");
1961 return -1;
1962 }
1963
1964 if (symbol_conf.init_annotation) {
1965 pr_warning("Annotation being initialized multiple times\n");
1966 return 0;
1967 }
1968
1969 symbol_conf.priv_size += sizeof(struct annotation);
1970 symbol_conf.init_annotation = true;
1971 return 0;
1972}
1973
1951int symbol__init(struct perf_env *env) 1974int symbol__init(struct perf_env *env)
1952{ 1975{
1953 const char *symfs; 1976 const char *symfs;
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 699f7cbcfe72..f6c54d3756da 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -88,6 +88,7 @@ struct symbol_conf {
88 unsigned short priv_size; 88 unsigned short priv_size;
89 unsigned short nr_events; 89 unsigned short nr_events;
90 bool try_vmlinux_path, 90 bool try_vmlinux_path,
91 init_annotation,
91 force, 92 force,
92 ignore_vmlinux, 93 ignore_vmlinux,
93 ignore_vmlinux_buildid, 94 ignore_vmlinux_buildid,
@@ -277,6 +278,8 @@ struct perf_env;
277int symbol__init(struct perf_env *env); 278int symbol__init(struct perf_env *env);
278void symbol__exit(void); 279void symbol__exit(void);
279void symbol__elf_init(void); 280void symbol__elf_init(void);
281int symbol__annotation_init(void);
282
280struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name); 283struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
281size_t __symbol__fprintf_symname_offs(const struct symbol *sym, 284size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
282 const struct addr_location *al, 285 const struct addr_location *al,