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>
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 13677b5..cf2c7f7 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -26,6 +26,7 @@
static struct dso *dsos__find(const char *name);
static struct map *map__new2(u64 start, struct dso *dso);
static void kernel_maps__insert(struct map *map);
+unsigned int symbol__priv_size;
static struct rb_root kernel_maps;
@@ -75,18 +76,17 @@
}
}
-static struct symbol *symbol__new(u64 start, u64 len, const char *name,
- unsigned int priv_size)
+static struct symbol *symbol__new(u64 start, u64 len, const char *name)
{
size_t namelen = strlen(name) + 1;
- struct symbol *self = calloc(1, priv_size + sizeof(*self) + namelen);
-
+ struct symbol *self = calloc(1, (symbol__priv_size +
+ sizeof(*self) + namelen));
if (!self)
return NULL;
- if (priv_size) {
- memset(self, 0, priv_size);
- self = ((void *)self) + priv_size;
+ if (symbol__priv_size) {
+ memset(self, 0, symbol__priv_size);
+ self = ((void *)self) + symbol__priv_size;
}
self->start = start;
self->end = len ? start + len - 1 : start;
@@ -98,9 +98,9 @@
return self;
}
-static void symbol__delete(struct symbol *self, unsigned int priv_size)
+static void symbol__delete(struct symbol *self)
{
- free(((void *)self) - priv_size);
+ free(((void *)self) - symbol__priv_size);
}
static size_t symbol__fprintf(struct symbol *self, FILE *fp)
@@ -109,7 +109,7 @@
self->start, self->end, self->name);
}
-struct dso *dso__new(const char *name, unsigned int sym_priv_size)
+struct dso *dso__new(const char *name)
{
struct dso *self = malloc(sizeof(*self) + strlen(name) + 1);
@@ -118,7 +118,6 @@
self->long_name = self->name;
self->short_name = self->name;
self->syms = RB_ROOT;
- self->sym_priv_size = sym_priv_size;
self->find_symbol = dso__find_symbol;
self->slen_calculated = 0;
self->origin = DSO__ORIG_NOT_FOUND;
@@ -136,7 +135,7 @@
pos = rb_entry(next, struct symbol, rb_node);
next = rb_next(&pos->rb_node);
rb_erase(&pos->rb_node, &self->syms);
- symbol__delete(pos, self->sym_priv_size);
+ symbol__delete(pos);
}
}
@@ -250,8 +249,7 @@
/*
* Will fix up the end later, when we have all symbols sorted.
*/
- sym = symbol__new(start, 0, symbol_name,
- kernel_map->dso->sym_priv_size);
+ sym = symbol__new(start, 0, symbol_name);
if (sym == NULL)
goto out_delete_line;
@@ -317,8 +315,7 @@
snprintf(dso_name, sizeof(dso_name), "[kernel].%d",
kernel_range++);
- dso = dso__new(dso_name,
- kernel_map->dso->sym_priv_size);
+ dso = dso__new(dso_name);
if (dso == NULL)
return -1;
@@ -336,7 +333,7 @@
if (filter && filter(map, pos)) {
delete_symbol:
rb_erase(&pos->rb_node, &kernel_map->dso->syms);
- symbol__delete(pos, kernel_map->dso->sym_priv_size);
+ symbol__delete(pos);
} else {
if (map != kernel_map) {
rb_erase(&pos->rb_node, &kernel_map->dso->syms);
@@ -417,14 +414,13 @@
if (len + 2 >= line_len)
continue;
- sym = symbol__new(start, size, line + len,
- self->sym_priv_size);
+ sym = symbol__new(start, size, line + len);
if (sym == NULL)
goto out_delete_line;
if (filter && filter(map, sym))
- symbol__delete(sym, self->sym_priv_size);
+ symbol__delete(sym);
else {
dso__insert_symbol(self, sym);
nr_syms++;
@@ -616,7 +612,7 @@
"%s@plt", elf_sym__name(&sym, symstrs));
f = symbol__new(plt_offset, shdr_plt.sh_entsize,
- sympltname, self->sym_priv_size);
+ sympltname);
if (!f)
goto out_elf_end;
@@ -634,7 +630,7 @@
"%s@plt", elf_sym__name(&sym, symstrs));
f = symbol__new(plt_offset, shdr_plt.sh_entsize,
- sympltname, self->sym_priv_size);
+ sympltname);
if (!f)
goto out_elf_end;
@@ -769,7 +765,7 @@
if (kmodule)
start += map->start + shdr.sh_offset;
- curr_dso = dso__new(dso_name, self->sym_priv_size);
+ curr_dso = dso__new(dso_name);
if (curr_dso == NULL)
goto out_elf_end;
curr_map = map__new2(start, curr_dso);
@@ -803,14 +799,13 @@
if (demangled != NULL)
elf_name = demangled;
new_symbol:
- f = symbol__new(sym.st_value, sym.st_size, elf_name,
- curr_dso->sym_priv_size);
+ f = symbol__new(sym.st_value, sym.st_size, elf_name);
free(demangled);
if (!f)
goto out_elf_end;
if (filter && filter(curr_map, f))
- symbol__delete(f, curr_dso->sym_priv_size);
+ symbol__delete(f);
else {
dso__insert_symbol(curr_dso, f);
nr++;
@@ -1141,7 +1136,7 @@
return self;
}
-static int dsos__load_modules(unsigned int sym_priv_size)
+static int dsos__load_modules(void)
{
char *line = NULL;
size_t n;
@@ -1180,7 +1175,7 @@
*sep = '\0';
snprintf(name, sizeof(name), "[%s]", line);
- dso = dso__new(name, sym_priv_size);
+ dso = dso__new(name);
if (dso == NULL)
goto out_delete_line;
@@ -1224,11 +1219,11 @@
return err;
}
-int dsos__load_kernel(const char *vmlinux, unsigned int sym_priv_size,
- symbol_filter_t filter, int use_modules)
+int dsos__load_kernel(const char *vmlinux, symbol_filter_t filter,
+ int use_modules)
{
int err = -1;
- struct dso *dso = dso__new(vmlinux, sym_priv_size);
+ struct dso *dso = dso__new(vmlinux);
if (dso == NULL)
return -1;
@@ -1240,7 +1235,7 @@
kernel_map->map_ip = kernel_map->unmap_ip = identity__map_ip;
- if (use_modules && dsos__load_modules(sym_priv_size) < 0) {
+ if (use_modules && dsos__load_modules() < 0) {
pr_warning("Failed to load list of modules in use! "
"Continuing...\n");
use_modules = 0;
@@ -1312,12 +1307,12 @@
return NULL;
}
-struct dso *dsos__findnew(const char *name, unsigned int sym_priv_size)
+struct dso *dsos__findnew(const char *name)
{
struct dso *dso = dsos__find(name);
if (!dso) {
- dso = dso__new(name, sym_priv_size);
+ dso = dso__new(name);
if (dso != NULL)
dsos__add(dso);
}
@@ -1333,13 +1328,12 @@
dso__fprintf(pos, fp);
}
-int load_kernel(unsigned int sym_priv_size, symbol_filter_t filter)
+int load_kernel(symbol_filter_t filter)
{
- if (dsos__load_kernel(vmlinux_name, sym_priv_size, filter,
- modules) <= 0)
+ if (dsos__load_kernel(vmlinux_name, filter, modules) <= 0)
return -1;
- vdso = dso__new("[vdso]", 0);
+ vdso = dso__new("[vdso]");
if (!vdso)
return -1;
@@ -1348,7 +1342,8 @@
return 0;
}
-void symbol__init(void)
+void symbol__init(unsigned int priv_size)
{
elf_version(EV_CURRENT);
+ symbol__priv_size = priv_size;
}