Commit 00a192b395b0606ad0265243844b3cd68e73420a

Authored by Arnaldo Carvalho de Melo
Committed by Ingo Molnar
1 parent afb7b4f08e

perf tools: Simplify the symbol priv area mechanism

Before we were storing this in the DSO, but in fact this is a
property of the 'symbol' class, not something that will vary
among DSOs, so move it to a global variable and initialize it
using the existing symbol__init routine.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
LKML-Reference: <1256927305-4628-2-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Showing 11 changed files with 70 additions and 80 deletions Side-by-side Diff

tools/perf/builtin-annotate.c
... ... @@ -55,11 +55,11 @@
55 55  
56 56 static const char *sym_hist_filter;
57 57  
58   -static int symbol_filter(struct map *map, struct symbol *sym)
  58 +static int symbol_filter(struct map *map __used, struct symbol *sym)
59 59 {
60 60 if (sym_hist_filter == NULL ||
61 61 strcmp(sym->name, sym_hist_filter) == 0) {
62   - struct sym_priv *priv = dso__sym_priv(map->dso, sym);
  62 + struct sym_priv *priv = symbol__priv(sym);
63 63 const int size = (sizeof(*priv->hist) +
64 64 (sym->end - sym->start) * sizeof(u64));
65 65  
... ... @@ -92,7 +92,7 @@
92 92 if (!sym || !he->map)
93 93 return;
94 94  
95   - priv = dso__sym_priv(he->map->dso, sym);
  95 + priv = symbol__priv(sym);
96 96 if (!priv->hist)
97 97 return;
98 98  
... ... @@ -202,8 +202,7 @@
202 202 static int
203 203 process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
204 204 {
205   - struct map *map = map__new(&event->mmap, NULL, 0,
206   - sizeof(struct sym_priv));
  205 + struct map *map = map__new(&event->mmap, NULL, 0);
207 206 struct thread *thread = threads__findnew(event->mmap.pid);
208 207  
209 208 dump_printf("%p [%p]: PERF_RECORD_MMAP %d: [%p(%p) @ %p]: %s\n",
... ... @@ -355,7 +354,7 @@
355 354 unsigned int hits = 0;
356 355 double percent = 0.0;
357 356 const char *color;
358   - struct sym_priv *priv = dso__sym_priv(he->map->dso, sym);
  357 + struct sym_priv *priv = symbol__priv(sym);
359 358 struct sym_ext *sym_ext = priv->ext;
360 359 struct sym_hist *h = priv->hist;
361 360  
... ... @@ -422,7 +421,7 @@
422 421  
423 422 static void free_source_line(struct hist_entry *he, int len)
424 423 {
425   - struct sym_priv *priv = dso__sym_priv(he->map->dso, he->sym);
  424 + struct sym_priv *priv = symbol__priv(he->sym);
426 425 struct sym_ext *sym_ext = priv->ext;
427 426 int i;
428 427  
... ... @@ -446,7 +445,7 @@
446 445 int i;
447 446 char cmd[PATH_MAX * 2];
448 447 struct sym_ext *sym_ext;
449   - struct sym_priv *priv = dso__sym_priv(he->map->dso, sym);
  448 + struct sym_priv *priv = symbol__priv(sym);
450 449 struct sym_hist *h = priv->hist;
451 450  
452 451 if (!h->sum)
... ... @@ -589,7 +588,7 @@
589 588 if (he->sym == NULL)
590 589 continue;
591 590  
592   - priv = dso__sym_priv(he->map->dso, he->sym);
  591 + priv = symbol__priv(he->sym);
593 592 if (priv->hist == NULL)
594 593 continue;
595 594  
... ... @@ -637,7 +636,7 @@
637 636 exit(0);
638 637 }
639 638  
640   - if (load_kernel(sizeof(struct sym_priv), symbol_filter) < 0) {
  639 + if (load_kernel(symbol_filter) < 0) {
641 640 perror("failed to load kernel symbols");
642 641 return EXIT_FAILURE;
643 642 }
... ... @@ -769,7 +768,7 @@
769 768  
770 769 int cmd_annotate(int argc, const char **argv, const char *prefix __used)
771 770 {
772   - symbol__init();
  771 + symbol__init(sizeof(struct sym_priv));
773 772  
774 773 page_size = getpagesize();
775 774  
tools/perf/builtin-report.c
... ... @@ -751,7 +751,7 @@
751 751 static int
752 752 process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
753 753 {
754   - struct map *map = map__new(&event->mmap, cwd, cwdlen, 0);
  754 + struct map *map = map__new(&event->mmap, cwd, cwdlen);
755 755 struct thread *thread = threads__findnew(event->mmap.pid);
756 756  
757 757 dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n",
... ... @@ -1093,7 +1093,7 @@
1093 1093  
1094 1094 int cmd_report(int argc, const char **argv, const char *prefix __used)
1095 1095 {
1096   - symbol__init();
  1096 + symbol__init(0);
1097 1097  
1098 1098 argc = parse_options(argc, argv, options, report_usage, 0);
1099 1099  
tools/perf/builtin-sched.c
... ... @@ -1937,7 +1937,7 @@
1937 1937  
1938 1938 int cmd_sched(int argc, const char **argv, const char *prefix __used)
1939 1939 {
1940   - symbol__init();
  1940 + symbol__init(0);
1941 1941  
1942 1942 argc = parse_options(argc, argv, sched_options, sched_usage,
1943 1943 PARSE_OPT_STOP_AT_NON_OPTION);
tools/perf/builtin-timechart.c
... ... @@ -1266,7 +1266,7 @@
1266 1266  
1267 1267 int cmd_timechart(int argc, const char **argv, const char *prefix __used)
1268 1268 {
1269   - symbol__init();
  1269 + symbol__init(0);
1270 1270  
1271 1271 page_size = getpagesize();
1272 1272  
tools/perf/builtin-top.c
... ... @@ -789,7 +789,7 @@
789 789 strstr(name, "_text_end"))
790 790 return 1;
791 791  
792   - syme = dso__sym_priv(map->dso, sym);
  792 + syme = symbol__priv(sym);
793 793 syme->map = map;
794 794 pthread_mutex_init(&syme->source_lock, NULL);
795 795 if (!sym_filter_entry && sym_filter && !strcmp(name, sym_filter))
... ... @@ -807,8 +807,7 @@
807 807  
808 808 static int parse_symbols(void)
809 809 {
810   - if (dsos__load_kernel(vmlinux_name, sizeof(struct sym_entry),
811   - symbol_filter, 1) <= 0)
  810 + if (dsos__load_kernel(vmlinux_name, symbol_filter, 1) <= 0)
812 811 return -1;
813 812  
814 813 if (dump_symtab)
... ... @@ -859,7 +858,7 @@
859 858 return;
860 859 }
861 860  
862   - syme = dso__sym_priv(map->dso, sym);
  861 + syme = symbol__priv(sym);
863 862  
864 863 if (!syme->skip) {
865 864 syme->count[counter]++;
... ... @@ -878,8 +877,7 @@
878 877 struct thread *thread = threads__findnew(self->mmap.pid);
879 878  
880 879 if (thread != NULL) {
881   - struct map *map = map__new(&self->mmap, NULL, 0,
882   - sizeof(struct sym_entry));
  880 + struct map *map = map__new(&self->mmap, NULL, 0);
883 881 if (map != NULL)
884 882 thread__insert_map(thread, map);
885 883 }
... ... @@ -1176,7 +1174,7 @@
1176 1174 {
1177 1175 int counter;
1178 1176  
1179   - symbol__init();
  1177 + symbol__init(sizeof(struct sym_entry));
1180 1178  
1181 1179 page_size = sysconf(_SC_PAGE_SIZE);
1182 1180  
tools/perf/builtin-trace.c
... ... @@ -151,7 +151,7 @@
151 151  
152 152 int cmd_trace(int argc, const char **argv, const char *prefix __used)
153 153 {
154   - symbol__init();
  154 + symbol__init(0);
155 155  
156 156 argc = parse_options(argc, argv, options, annotate_usage, 0);
157 157 if (argc) {
tools/perf/util/data_map.c
... ... @@ -130,7 +130,7 @@
130 130 if (curr_handler->sample_type_check(sample_type) < 0)
131 131 exit(-1);
132 132  
133   - if (load_kernel(0, NULL) < 0) {
  133 + if (load_kernel(NULL) < 0) {
134 134 perror("failed to load kernel symbols");
135 135 return EXIT_FAILURE;
136 136 }
tools/perf/util/event.h
... ... @@ -107,8 +107,7 @@
107 107  
108 108 void map__init(struct map *self, u64 start, u64 end, u64 pgoff,
109 109 struct dso *dso);
110   -struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen,
111   - unsigned int sym_priv_size);
  110 +struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen);
112 111 struct map *map__clone(struct map *self);
113 112 int map__overlap(struct map *l, struct map *r);
114 113 size_t map__fprintf(struct map *self, FILE *fp);
tools/perf/util/map.c
... ... @@ -32,8 +32,7 @@
32 32 RB_CLEAR_NODE(&self->rb_node);
33 33 }
34 34  
35   -struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen,
36   - unsigned int sym_priv_size)
  35 +struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen)
37 36 {
38 37 struct map *self = malloc(sizeof(*self));
39 38  
... ... @@ -60,7 +59,7 @@
60 59 filename = newfilename;
61 60 }
62 61  
63   - dso = dsos__findnew(filename, sym_priv_size);
  62 + dso = dsos__findnew(filename);
64 63 if (dso == NULL)
65 64 goto out_delete;
66 65  
tools/perf/util/symbol.c
... ... @@ -26,6 +26,7 @@
26 26 static struct dso *dsos__find(const char *name);
27 27 static struct map *map__new2(u64 start, struct dso *dso);
28 28 static void kernel_maps__insert(struct map *map);
  29 +unsigned int symbol__priv_size;
29 30  
30 31 static struct rb_root kernel_maps;
31 32  
32 33  
33 34  
... ... @@ -75,18 +76,17 @@
75 76 }
76 77 }
77 78  
78   -static struct symbol *symbol__new(u64 start, u64 len, const char *name,
79   - unsigned int priv_size)
  79 +static struct symbol *symbol__new(u64 start, u64 len, const char *name)
80 80 {
81 81 size_t namelen = strlen(name) + 1;
82   - struct symbol *self = calloc(1, priv_size + sizeof(*self) + namelen);
83   -
  82 + struct symbol *self = calloc(1, (symbol__priv_size +
  83 + sizeof(*self) + namelen));
84 84 if (!self)
85 85 return NULL;
86 86  
87   - if (priv_size) {
88   - memset(self, 0, priv_size);
89   - self = ((void *)self) + priv_size;
  87 + if (symbol__priv_size) {
  88 + memset(self, 0, symbol__priv_size);
  89 + self = ((void *)self) + symbol__priv_size;
90 90 }
91 91 self->start = start;
92 92 self->end = len ? start + len - 1 : start;
93 93  
... ... @@ -98,9 +98,9 @@
98 98 return self;
99 99 }
100 100  
101   -static void symbol__delete(struct symbol *self, unsigned int priv_size)
  101 +static void symbol__delete(struct symbol *self)
102 102 {
103   - free(((void *)self) - priv_size);
  103 + free(((void *)self) - symbol__priv_size);
104 104 }
105 105  
106 106 static size_t symbol__fprintf(struct symbol *self, FILE *fp)
... ... @@ -109,7 +109,7 @@
109 109 self->start, self->end, self->name);
110 110 }
111 111  
112   -struct dso *dso__new(const char *name, unsigned int sym_priv_size)
  112 +struct dso *dso__new(const char *name)
113 113 {
114 114 struct dso *self = malloc(sizeof(*self) + strlen(name) + 1);
115 115  
... ... @@ -118,7 +118,6 @@
118 118 self->long_name = self->name;
119 119 self->short_name = self->name;
120 120 self->syms = RB_ROOT;
121   - self->sym_priv_size = sym_priv_size;
122 121 self->find_symbol = dso__find_symbol;
123 122 self->slen_calculated = 0;
124 123 self->origin = DSO__ORIG_NOT_FOUND;
... ... @@ -136,7 +135,7 @@
136 135 pos = rb_entry(next, struct symbol, rb_node);
137 136 next = rb_next(&pos->rb_node);
138 137 rb_erase(&pos->rb_node, &self->syms);
139   - symbol__delete(pos, self->sym_priv_size);
  138 + symbol__delete(pos);
140 139 }
141 140 }
142 141  
... ... @@ -250,8 +249,7 @@
250 249 /*
251 250 * Will fix up the end later, when we have all symbols sorted.
252 251 */
253   - sym = symbol__new(start, 0, symbol_name,
254   - kernel_map->dso->sym_priv_size);
  252 + sym = symbol__new(start, 0, symbol_name);
255 253  
256 254 if (sym == NULL)
257 255 goto out_delete_line;
... ... @@ -317,8 +315,7 @@
317 315 snprintf(dso_name, sizeof(dso_name), "[kernel].%d",
318 316 kernel_range++);
319 317  
320   - dso = dso__new(dso_name,
321   - kernel_map->dso->sym_priv_size);
  318 + dso = dso__new(dso_name);
322 319 if (dso == NULL)
323 320 return -1;
324 321  
... ... @@ -336,7 +333,7 @@
336 333 if (filter && filter(map, pos)) {
337 334 delete_symbol:
338 335 rb_erase(&pos->rb_node, &kernel_map->dso->syms);
339   - symbol__delete(pos, kernel_map->dso->sym_priv_size);
  336 + symbol__delete(pos);
340 337 } else {
341 338 if (map != kernel_map) {
342 339 rb_erase(&pos->rb_node, &kernel_map->dso->syms);
343 340  
... ... @@ -417,14 +414,13 @@
417 414 if (len + 2 >= line_len)
418 415 continue;
419 416  
420   - sym = symbol__new(start, size, line + len,
421   - self->sym_priv_size);
  417 + sym = symbol__new(start, size, line + len);
422 418  
423 419 if (sym == NULL)
424 420 goto out_delete_line;
425 421  
426 422 if (filter && filter(map, sym))
427   - symbol__delete(sym, self->sym_priv_size);
  423 + symbol__delete(sym);
428 424 else {
429 425 dso__insert_symbol(self, sym);
430 426 nr_syms++;
... ... @@ -616,7 +612,7 @@
616 612 "%s@plt", elf_sym__name(&sym, symstrs));
617 613  
618 614 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
619   - sympltname, self->sym_priv_size);
  615 + sympltname);
620 616 if (!f)
621 617 goto out_elf_end;
622 618  
... ... @@ -634,7 +630,7 @@
634 630 "%s@plt", elf_sym__name(&sym, symstrs));
635 631  
636 632 f = symbol__new(plt_offset, shdr_plt.sh_entsize,
637   - sympltname, self->sym_priv_size);
  633 + sympltname);
638 634 if (!f)
639 635 goto out_elf_end;
640 636  
... ... @@ -769,7 +765,7 @@
769 765 if (kmodule)
770 766 start += map->start + shdr.sh_offset;
771 767  
772   - curr_dso = dso__new(dso_name, self->sym_priv_size);
  768 + curr_dso = dso__new(dso_name);
773 769 if (curr_dso == NULL)
774 770 goto out_elf_end;
775 771 curr_map = map__new2(start, curr_dso);
776 772  
... ... @@ -803,14 +799,13 @@
803 799 if (demangled != NULL)
804 800 elf_name = demangled;
805 801 new_symbol:
806   - f = symbol__new(sym.st_value, sym.st_size, elf_name,
807   - curr_dso->sym_priv_size);
  802 + f = symbol__new(sym.st_value, sym.st_size, elf_name);
808 803 free(demangled);
809 804 if (!f)
810 805 goto out_elf_end;
811 806  
812 807 if (filter && filter(curr_map, f))
813   - symbol__delete(f, curr_dso->sym_priv_size);
  808 + symbol__delete(f);
814 809 else {
815 810 dso__insert_symbol(curr_dso, f);
816 811 nr++;
... ... @@ -1141,7 +1136,7 @@
1141 1136 return self;
1142 1137 }
1143 1138  
1144   -static int dsos__load_modules(unsigned int sym_priv_size)
  1139 +static int dsos__load_modules(void)
1145 1140 {
1146 1141 char *line = NULL;
1147 1142 size_t n;
... ... @@ -1180,7 +1175,7 @@
1180 1175 *sep = '\0';
1181 1176  
1182 1177 snprintf(name, sizeof(name), "[%s]", line);
1183   - dso = dso__new(name, sym_priv_size);
  1178 + dso = dso__new(name);
1184 1179  
1185 1180 if (dso == NULL)
1186 1181 goto out_delete_line;
1187 1182  
... ... @@ -1224,11 +1219,11 @@
1224 1219 return err;
1225 1220 }
1226 1221  
1227   -int dsos__load_kernel(const char *vmlinux, unsigned int sym_priv_size,
1228   - symbol_filter_t filter, int use_modules)
  1222 +int dsos__load_kernel(const char *vmlinux, symbol_filter_t filter,
  1223 + int use_modules)
1229 1224 {
1230 1225 int err = -1;
1231   - struct dso *dso = dso__new(vmlinux, sym_priv_size);
  1226 + struct dso *dso = dso__new(vmlinux);
1232 1227  
1233 1228 if (dso == NULL)
1234 1229 return -1;
... ... @@ -1240,7 +1235,7 @@
1240 1235  
1241 1236 kernel_map->map_ip = kernel_map->unmap_ip = identity__map_ip;
1242 1237  
1243   - if (use_modules && dsos__load_modules(sym_priv_size) < 0) {
  1238 + if (use_modules && dsos__load_modules() < 0) {
1244 1239 pr_warning("Failed to load list of modules in use! "
1245 1240 "Continuing...\n");
1246 1241 use_modules = 0;
1247 1242  
... ... @@ -1312,12 +1307,12 @@
1312 1307 return NULL;
1313 1308 }
1314 1309  
1315   -struct dso *dsos__findnew(const char *name, unsigned int sym_priv_size)
  1310 +struct dso *dsos__findnew(const char *name)
1316 1311 {
1317 1312 struct dso *dso = dsos__find(name);
1318 1313  
1319 1314 if (!dso) {
1320   - dso = dso__new(name, sym_priv_size);
  1315 + dso = dso__new(name);
1321 1316 if (dso != NULL)
1322 1317 dsos__add(dso);
1323 1318 }
1324 1319  
1325 1320  
... ... @@ -1333,13 +1328,12 @@
1333 1328 dso__fprintf(pos, fp);
1334 1329 }
1335 1330  
1336   -int load_kernel(unsigned int sym_priv_size, symbol_filter_t filter)
  1331 +int load_kernel(symbol_filter_t filter)
1337 1332 {
1338   - if (dsos__load_kernel(vmlinux_name, sym_priv_size, filter,
1339   - modules) <= 0)
  1333 + if (dsos__load_kernel(vmlinux_name, filter, modules) <= 0)
1340 1334 return -1;
1341 1335  
1342   - vdso = dso__new("[vdso]", 0);
  1336 + vdso = dso__new("[vdso]");
1343 1337 if (!vdso)
1344 1338 return -1;
1345 1339  
1346 1340  
... ... @@ -1348,8 +1342,9 @@
1348 1342 return 0;
1349 1343 }
1350 1344  
1351   -void symbol__init(void)
  1345 +void symbol__init(unsigned int priv_size)
1352 1346 {
1353 1347 elf_version(EV_CURRENT);
  1348 + symbol__priv_size = priv_size;
1354 1349 }
tools/perf/util/symbol.h
... ... @@ -39,11 +39,17 @@
39 39 char name[0];
40 40 };
41 41  
  42 +extern unsigned int symbol__priv_size;
  43 +
  44 +static inline void *symbol__priv(struct symbol *self)
  45 +{
  46 + return ((void *)self) - symbol__priv_size;
  47 +}
  48 +
42 49 struct dso {
43 50 struct list_head node;
44 51 struct rb_root syms;
45 52 struct symbol *(*find_symbol)(struct dso *, u64 ip);
46   - unsigned int sym_priv_size;
47 53 unsigned char adjust_symbols;
48 54 unsigned char slen_calculated;
49 55 bool loaded;
50 56  
51 57  
52 58  
53 59  
... ... @@ -53,28 +59,22 @@
53 59 char name[0];
54 60 };
55 61  
56   -struct dso *dso__new(const char *name, unsigned int sym_priv_size);
  62 +struct dso *dso__new(const char *name);
57 63 void dso__delete(struct dso *self);
58 64  
59   -static inline void *dso__sym_priv(struct dso *self, struct symbol *sym)
60   -{
61   - return ((void *)sym) - self->sym_priv_size;
62   -}
63   -
64 65 struct symbol *dso__find_symbol(struct dso *self, u64 ip);
65 66  
66   -int dsos__load_kernel(const char *vmlinux, unsigned int sym_priv_size,
67   - symbol_filter_t filter, int modules);
68   -struct dso *dsos__findnew(const char *name, unsigned int sym_priv_size);
  67 +int dsos__load_kernel(const char *vmlinux, symbol_filter_t filter, int modules);
  68 +struct dso *dsos__findnew(const char *name);
69 69 int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
70 70 void dsos__fprintf(FILE *fp);
71 71  
72 72 size_t dso__fprintf(struct dso *self, FILE *fp);
73 73 char dso__symtab_origin(const struct dso *self);
74 74  
75   -int load_kernel(unsigned int sym_priv_size, symbol_filter_t filter);
  75 +int load_kernel(symbol_filter_t filter);
76 76  
77   -void symbol__init(void);
  77 +void symbol__init(unsigned int priv_size);
78 78  
79 79 extern struct list_head dsos;
80 80 extern struct map *kernel_map;