Commit 628ada0c authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Ingo Molnar

perf annotate: Defer allocating sym_priv->hist array

Because symbol->end is not fixed up at symbol_filter time, only
after all symbols for a DSO are loaded, and that, for asm
symbols, may be bogus, causing segfaults when hits happen in
these symbols.
Reported-by: default avatarDavid Miller <davem@davemloft.net>
Reported-by: default avatarAnton Blanchard <anton@samba.org>
Acked-by: default avatarDavid Miller <davem@davemloft.net>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: <stable@kernel.org> # for .33.x. Does not apply cleanly, needs backport.
LKML-Reference: <20100225155740.GB8553@ghostprotocols.net>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 3846df2e
...@@ -53,32 +53,20 @@ struct sym_priv { ...@@ -53,32 +53,20 @@ struct sym_priv {
static const char *sym_hist_filter; static const char *sym_hist_filter;
static int symbol_filter(struct map *map __used, struct symbol *sym) static int sym__alloc_hist(struct symbol *self)
{ {
if (sym_hist_filter == NULL || struct sym_priv *priv = symbol__priv(self);
strcmp(sym->name, sym_hist_filter) == 0) { const int size = (sizeof(*priv->hist) +
struct sym_priv *priv = symbol__priv(sym); (self->end - self->start) * sizeof(u64));
const int size = (sizeof(*priv->hist) +
(sym->end - sym->start) * sizeof(u64));
priv->hist = malloc(size); priv->hist = zalloc(size);
if (priv->hist) return priv->hist == NULL ? -1 : 0;
memset(priv->hist, 0, size);
return 0;
}
/*
* FIXME: We should really filter it out, as we don't want to go thru symbols
* we're not interested, and if a DSO ends up with no symbols, delete it too,
* but right now the kernel loading routines in symbol.c bail out if no symbols
* are found, fix it later.
*/
return 0;
} }
/* /*
* collect histogram counts * collect histogram counts
*/ */
static void hist_hit(struct hist_entry *he, u64 ip) static int annotate__hist_hit(struct hist_entry *he, u64 ip)
{ {
unsigned int sym_size, offset; unsigned int sym_size, offset;
struct symbol *sym = he->sym; struct symbol *sym = he->sym;
...@@ -88,11 +76,11 @@ static void hist_hit(struct hist_entry *he, u64 ip) ...@@ -88,11 +76,11 @@ static void hist_hit(struct hist_entry *he, u64 ip)
he->count++; he->count++;
if (!sym || !he->map) if (!sym || !he->map)
return; return 0;
priv = symbol__priv(sym); priv = symbol__priv(sym);
if (!priv->hist) if (priv->hist == NULL && sym__alloc_hist(sym) < 0)
return; return -ENOMEM;
sym_size = sym->end - sym->start; sym_size = sym->end - sym->start;
offset = ip - sym->start; offset = ip - sym->start;
...@@ -100,7 +88,7 @@ static void hist_hit(struct hist_entry *he, u64 ip) ...@@ -100,7 +88,7 @@ static void hist_hit(struct hist_entry *he, u64 ip)
pr_debug3("%s: ip=%#Lx\n", __func__, he->map->unmap_ip(he->map, ip)); pr_debug3("%s: ip=%#Lx\n", __func__, he->map->unmap_ip(he->map, ip));
if (offset >= sym_size) if (offset >= sym_size)
return; return 0;
h = priv->hist; h = priv->hist;
h->sum++; h->sum++;
...@@ -108,18 +96,31 @@ static void hist_hit(struct hist_entry *he, u64 ip) ...@@ -108,18 +96,31 @@ static void hist_hit(struct hist_entry *he, u64 ip)
pr_debug3("%#Lx %s: count++ [ip: %#Lx, %#Lx] => %Ld\n", he->sym->start, pr_debug3("%#Lx %s: count++ [ip: %#Lx, %#Lx] => %Ld\n", he->sym->start,
he->sym->name, ip, ip - he->sym->start, h->ip[offset]); he->sym->name, ip, ip - he->sym->start, h->ip[offset]);
return 0;
} }
static int perf_session__add_hist_entry(struct perf_session *self, static int perf_session__add_hist_entry(struct perf_session *self,
struct addr_location *al, u64 count) struct addr_location *al, u64 count)
{ {
bool hit; bool hit;
struct hist_entry *he = __perf_session__add_hist_entry(self, al, NULL, struct hist_entry *he;
count, &hit);
if (sym_hist_filter != NULL &&
(al->sym == NULL || strcmp(sym_hist_filter, al->sym->name) != 0)) {
/* We're only interested in a symbol named sym_hist_filter */
if (al->sym != NULL) {
rb_erase(&al->sym->rb_node,
&al->map->dso->symbols[al->map->type]);
symbol__delete(al->sym);
}
return 0;
}
he = __perf_session__add_hist_entry(self, al, NULL, count, &hit);
if (he == NULL) if (he == NULL)
return -ENOMEM; return -ENOMEM;
hist_hit(he, al->addr);
return 0; return annotate__hist_hit(he, al->addr);
} }
static int process_sample_event(event_t *event, struct perf_session *session) static int process_sample_event(event_t *event, struct perf_session *session)
...@@ -129,7 +130,7 @@ static int process_sample_event(event_t *event, struct perf_session *session) ...@@ -129,7 +130,7 @@ static int process_sample_event(event_t *event, struct perf_session *session)
dump_printf("(IP, %d): %d: %#Lx\n", event->header.misc, dump_printf("(IP, %d): %d: %#Lx\n", event->header.misc,
event->ip.pid, event->ip.ip); event->ip.pid, event->ip.ip);
if (event__preprocess_sample(event, session, &al, symbol_filter) < 0) { if (event__preprocess_sample(event, session, &al, NULL) < 0) {
pr_warning("problem processing %d event, skipping it.\n", pr_warning("problem processing %d event, skipping it.\n",
event->header.type); event->header.type);
return -1; return -1;
......
...@@ -144,7 +144,7 @@ static struct symbol *symbol__new(u64 start, u64 len, const char *name) ...@@ -144,7 +144,7 @@ static struct symbol *symbol__new(u64 start, u64 len, const char *name)
return self; return self;
} }
static void symbol__delete(struct symbol *self) void symbol__delete(struct symbol *self)
{ {
free(((void *)self) - symbol_conf.priv_size); free(((void *)self) - symbol_conf.priv_size);
} }
......
...@@ -51,6 +51,8 @@ struct symbol { ...@@ -51,6 +51,8 @@ struct symbol {
char name[0]; char name[0];
}; };
void symbol__delete(struct symbol *self);
struct strlist; struct strlist;
struct symbol_conf { struct symbol_conf {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment