perf symbols: Load kernel maps before using
In order to use kernel maps to read object code, those maps must be adjusted to map to the dso file offset. Because lazy-initialization is used, that is not done until symbols are loaded. However the maps are first used by thread__find_addr_map() before symbols are loaded. So this patch changes thread__find_addr() to "load" kernel maps before using them. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1375875537-4509-3-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
b55ae0a976
commit
5b7ba82a75
|
@ -206,7 +206,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
|
||||||
}
|
}
|
||||||
|
|
||||||
thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
|
thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
|
||||||
event->ip.ip, &al);
|
event->ip.ip, &al, NULL);
|
||||||
|
|
||||||
if (al.map != NULL) {
|
if (al.map != NULL) {
|
||||||
if (!al.map->dso->hit) {
|
if (!al.map->dso->hit) {
|
||||||
|
|
|
@ -341,10 +341,10 @@ static void print_sample_addr(union perf_event *event,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
|
thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
|
||||||
sample->addr, &al);
|
sample->addr, &al, NULL);
|
||||||
if (!al.map)
|
if (!al.map)
|
||||||
thread__find_addr_map(thread, machine, cpumode, MAP__VARIABLE,
|
thread__find_addr_map(thread, machine, cpumode, MAP__VARIABLE,
|
||||||
sample->addr, &al);
|
sample->addr, &al, NULL);
|
||||||
|
|
||||||
al.cpu = sample->cpu;
|
al.cpu = sample->cpu;
|
||||||
al.sym = NULL;
|
al.sym = NULL;
|
||||||
|
|
|
@ -138,7 +138,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
|
||||||
pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
|
pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
|
||||||
|
|
||||||
thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION, addr,
|
thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION, addr,
|
||||||
&al);
|
&al, NULL);
|
||||||
if (!al.map || !al.map->dso) {
|
if (!al.map || !al.map->dso) {
|
||||||
pr_debug("thread__find_addr_map failed\n");
|
pr_debug("thread__find_addr_map failed\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -33,7 +33,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
|
||||||
}
|
}
|
||||||
|
|
||||||
thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
|
thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
|
||||||
event->ip.ip, &al);
|
event->ip.ip, &al, NULL);
|
||||||
|
|
||||||
if (al.map != NULL)
|
if (al.map != NULL)
|
||||||
al.map->dso->hit = 1;
|
al.map->dso->hit = 1;
|
||||||
|
|
|
@ -592,9 +592,10 @@ int perf_event__process(struct perf_tool *tool __maybe_unused,
|
||||||
void thread__find_addr_map(struct thread *self,
|
void thread__find_addr_map(struct thread *self,
|
||||||
struct machine *machine, u8 cpumode,
|
struct machine *machine, u8 cpumode,
|
||||||
enum map_type type, u64 addr,
|
enum map_type type, u64 addr,
|
||||||
struct addr_location *al)
|
struct addr_location *al, symbol_filter_t filter)
|
||||||
{
|
{
|
||||||
struct map_groups *mg = &self->mg;
|
struct map_groups *mg = &self->mg;
|
||||||
|
bool load_map = false;
|
||||||
|
|
||||||
al->thread = self;
|
al->thread = self;
|
||||||
al->addr = addr;
|
al->addr = addr;
|
||||||
|
@ -609,11 +610,13 @@ void thread__find_addr_map(struct thread *self,
|
||||||
if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
|
if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
|
||||||
al->level = 'k';
|
al->level = 'k';
|
||||||
mg = &machine->kmaps;
|
mg = &machine->kmaps;
|
||||||
|
load_map = true;
|
||||||
} else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
|
} else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
|
||||||
al->level = '.';
|
al->level = '.';
|
||||||
} else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
|
} else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
|
||||||
al->level = 'g';
|
al->level = 'g';
|
||||||
mg = &machine->kmaps;
|
mg = &machine->kmaps;
|
||||||
|
load_map = true;
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
* 'u' means guest os user space.
|
* 'u' means guest os user space.
|
||||||
|
@ -654,8 +657,15 @@ try_again:
|
||||||
mg = &machine->kmaps;
|
mg = &machine->kmaps;
|
||||||
goto try_again;
|
goto try_again;
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
|
/*
|
||||||
|
* Kernel maps might be changed when loading symbols so loading
|
||||||
|
* must be done prior to using kernel maps.
|
||||||
|
*/
|
||||||
|
if (load_map)
|
||||||
|
map__load(al->map, filter);
|
||||||
al->addr = al->map->map_ip(al->map, al->addr);
|
al->addr = al->map->map_ip(al->map, al->addr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void thread__find_addr_location(struct thread *thread, struct machine *machine,
|
void thread__find_addr_location(struct thread *thread, struct machine *machine,
|
||||||
|
@ -663,7 +673,7 @@ void thread__find_addr_location(struct thread *thread, struct machine *machine,
|
||||||
struct addr_location *al,
|
struct addr_location *al,
|
||||||
symbol_filter_t filter)
|
symbol_filter_t filter)
|
||||||
{
|
{
|
||||||
thread__find_addr_map(thread, machine, cpumode, type, addr, al);
|
thread__find_addr_map(thread, machine, cpumode, type, addr, al, filter);
|
||||||
if (al->map != NULL)
|
if (al->map != NULL)
|
||||||
al->sym = map__find_symbol(al->map, al->addr, filter);
|
al->sym = map__find_symbol(al->map, al->addr, filter);
|
||||||
else
|
else
|
||||||
|
@ -699,7 +709,7 @@ int perf_event__preprocess_sample(const union perf_event *event,
|
||||||
machine__create_kernel_maps(machine);
|
machine__create_kernel_maps(machine);
|
||||||
|
|
||||||
thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
|
thread__find_addr_map(thread, machine, cpumode, MAP__FUNCTION,
|
||||||
event->ip.ip, al);
|
event->ip.ip, al, filter);
|
||||||
dump_printf(" ...... dso: %s\n",
|
dump_printf(" ...... dso: %s\n",
|
||||||
al->map ? al->map->dso->long_name :
|
al->map ? al->map->dso->long_name :
|
||||||
al->level == 'H' ? "[hypervisor]" : "<not found>");
|
al->level == 'H' ? "[hypervisor]" : "<not found>");
|
||||||
|
|
|
@ -41,7 +41,7 @@ static inline struct map *thread__find_map(struct thread *self,
|
||||||
|
|
||||||
void thread__find_addr_map(struct thread *thread, struct machine *machine,
|
void thread__find_addr_map(struct thread *thread, struct machine *machine,
|
||||||
u8 cpumode, enum map_type type, u64 addr,
|
u8 cpumode, enum map_type type, u64 addr,
|
||||||
struct addr_location *al);
|
struct addr_location *al, symbol_filter_t filter);
|
||||||
|
|
||||||
void thread__find_addr_location(struct thread *thread, struct machine *machine,
|
void thread__find_addr_location(struct thread *thread, struct machine *machine,
|
||||||
u8 cpumode, enum map_type type, u64 addr,
|
u8 cpumode, enum map_type type, u64 addr,
|
||||||
|
|
|
@ -272,7 +272,7 @@ static struct map *find_map(unw_word_t ip, struct unwind_info *ui)
|
||||||
struct addr_location al;
|
struct addr_location al;
|
||||||
|
|
||||||
thread__find_addr_map(ui->thread, ui->machine, PERF_RECORD_MISC_USER,
|
thread__find_addr_map(ui->thread, ui->machine, PERF_RECORD_MISC_USER,
|
||||||
MAP__FUNCTION, ip, &al);
|
MAP__FUNCTION, ip, &al, NULL);
|
||||||
return al.map;
|
return al.map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ static int access_dso_mem(struct unwind_info *ui, unw_word_t addr,
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
|
|
||||||
thread__find_addr_map(ui->thread, ui->machine, PERF_RECORD_MISC_USER,
|
thread__find_addr_map(ui->thread, ui->machine, PERF_RECORD_MISC_USER,
|
||||||
MAP__FUNCTION, addr, &al);
|
MAP__FUNCTION, addr, &al, NULL);
|
||||||
if (!al.map) {
|
if (!al.map) {
|
||||||
pr_debug("unwind: no map for %lx\n", (unsigned long)addr);
|
pr_debug("unwind: no map for %lx\n", (unsigned long)addr);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue