Skip to content

Commit b01141f

Browse files
committed
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 <[email protected]> Cc: David Ahern <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Wang Nan <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent ffe67c2 commit b01141f

File tree

7 files changed

+37
-16
lines changed

7 files changed

+37
-16
lines changed

tools/perf/builtin-annotate.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ static int __cmd_annotate(struct perf_annotate *ann)
204204
struct perf_evsel *pos;
205205
u64 total_nr_samples;
206206

207-
machines__set_symbol_filter(&session->machines, symbol__annotate_init);
208-
209207
if (ann->cpu_list) {
210208
ret = perf_session__cpu_bitmap(session, ann->cpu_list,
211209
ann->cpu_bitmap);
@@ -367,7 +365,10 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
367365
if (annotate.session == NULL)
368366
return -1;
369367

370-
symbol_conf.priv_size = sizeof(struct annotation);
368+
ret = symbol__annotation_init();
369+
if (ret < 0)
370+
goto out_delete;
371+
371372
symbol_conf.try_vmlinux_path = true;
372373

373374
ret = symbol__init(&annotate.session->header.env);

tools/perf/builtin-report.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,9 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
984984
* implementation.
985985
*/
986986
if (ui__has_annotation()) {
987-
symbol_conf.priv_size = sizeof(struct annotation);
988-
machines__set_symbol_filter(&session->machines,
989-
symbol__annotate_init);
987+
ret = symbol__annotation_init();
988+
if (ret < 0)
989+
goto error;
990990
/*
991991
* For searching by name on the "Browse map details".
992992
* providing it only in verbose mode not to bloat too

tools/perf/builtin-top.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
13241324
if (symbol_conf.cumulate_callchain && !callchain_param.order_set)
13251325
callchain_param.order = ORDER_CALLER;
13261326

1327-
symbol_conf.priv_size = sizeof(struct annotation);
1327+
status = symbol__annotation_init();
1328+
if (status < 0)
1329+
goto out_delete_evlist;
13281330

13291331
symbol_conf.try_vmlinux_path = (symbol_conf.vmlinux_name == NULL);
13301332
if (symbol__init(NULL) < 0)

tools/perf/util/annotate.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,6 @@ static struct ins *ins__find(const char *name)
491491
return bsearch(name, instructions, nmemb, sizeof(struct ins), ins__key_cmp);
492492
}
493493

494-
int 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-
501494
int symbol__alloc_hist(struct symbol *sym)
502495
{
503496
struct annotation *notes = symbol__annotation(sym);

tools/perf/util/annotate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ enum symbol_disassemble_errno {
177177
int symbol__strerror_disassemble(struct symbol *sym, struct map *map,
178178
int errnum, char *buf, size_t buflen);
179179

180-
int symbol__annotate_init(struct map *map, struct symbol *sym);
181180
int symbol__annotate_printf(struct symbol *sym, struct map *map,
182181
struct perf_evsel *evsel, bool full_paths,
183182
int min_pcnt, int max_lines, int context);

tools/perf/util/symbol.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <fcntl.h>
1010
#include <unistd.h>
1111
#include <inttypes.h>
12+
#include "annotate.h"
1213
#include "build-id.h"
1314
#include "util.h"
1415
#include "debug.h"
@@ -235,8 +236,13 @@ struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name)
235236
if (sym == NULL)
236237
return NULL;
237238

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+
}
239244
sym = ((void *)sym) + symbol_conf.priv_size;
245+
}
240246

241247
sym->start = start;
242248
sym->end = len ? start + len : start;
@@ -1948,6 +1954,23 @@ static bool symbol__read_kptr_restrict(void)
19481954
return value;
19491955
}
19501956

1957+
int 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+
19511974
int symbol__init(struct perf_env *env)
19521975
{
19531976
const char *symfs;

tools/perf/util/symbol.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct symbol_conf {
8888
unsigned short priv_size;
8989
unsigned short nr_events;
9090
bool try_vmlinux_path,
91+
init_annotation,
9192
force,
9293
ignore_vmlinux,
9394
ignore_vmlinux_buildid,
@@ -277,6 +278,8 @@ struct perf_env;
277278
int symbol__init(struct perf_env *env);
278279
void symbol__exit(void);
279280
void symbol__elf_init(void);
281+
int symbol__annotation_init(void);
282+
280283
struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
281284
size_t __symbol__fprintf_symname_offs(const struct symbol *sym,
282285
const struct addr_location *al,

0 commit comments

Comments
 (0)