Store resolved host mapping state (host_map, host_sym, host_addr, raw_host_ip) in struct addr_location and resolve sample->host_ip against machines->host in machine__resolve(). When a guest sample cannot be symbolized in the guest machine, automatically fall back to the resolved host mapping and symbol (and clear HIST_FILTER__GUEST when perf_host or perf_guest is active), so guest code backed by host DAX or file-backed mappings symbolizes transparently without guest symbol state. Signed-off-by: Ian Rogers --- tools/perf/util/addr_location.c | 7 ++++ tools/perf/util/addr_location.h | 4 +++ tools/perf/util/event.c | 58 +++++++++++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/addr_location.c b/tools/perf/util/addr_location.c index 57e8217a00f9..ca0380260ee6 100644 --- a/tools/perf/util/addr_location.c +++ b/tools/perf/util/addr_location.c @@ -9,8 +9,12 @@ void addr_location__init(struct addr_location *al) al->thread = NULL; al->map = NULL; al->sym = NULL; + al->host_map = NULL; + al->host_sym = NULL; al->srcline = NULL; al->addr = 0; + al->host_addr = 0; + al->raw_host_ip = 0; al->level = 0; al->filtered = 0; al->cpumode = 0; @@ -28,6 +32,7 @@ void addr_location__init(struct addr_location *al) void addr_location__exit(struct addr_location *al) { map__zput(al->map); + map__zput(al->host_map); thread__zput(al->thread); } @@ -35,7 +40,9 @@ void addr_location__copy(struct addr_location *dst, struct addr_location *src) { thread__put(dst->thread); map__put(dst->map); + map__put(dst->host_map); *dst = *src; dst->thread = thread__get(src->thread); dst->map = map__get(src->map); + dst->host_map = map__get(src->host_map); } diff --git a/tools/perf/util/addr_location.h b/tools/perf/util/addr_location.h index fdc4d3f3a68b..d4148d7df998 100644 --- a/tools/perf/util/addr_location.h +++ b/tools/perf/util/addr_location.h @@ -13,8 +13,12 @@ struct addr_location { struct thread *thread; struct map *map; struct symbol *sym; + struct map *host_map; + struct symbol *host_sym; const char *srcline; u64 addr; + u64 host_addr; + u64 raw_host_ip; char level; u8 cpumode; u16 filtered; diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index ea75816d126a..96d88d88ba06 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -808,6 +808,11 @@ int machine__resolve(struct machine *machine, struct addr_location *al, struct thread *thread; struct dso *dso; + map__zput(al->host_map); + al->host_sym = NULL; + al->host_addr = 0; + al->raw_host_ip = sample->host_ip; + if (symbol_conf.guest_code && !machine__is_host(machine)) thread = machine__findnew_guest_code(machine, sample->pid); else @@ -862,6 +867,57 @@ int machine__resolve(struct machine *machine, struct addr_location *al, */ al->latency = sample->period * 1000 / al->parallelism; + if (al->map) + al->sym = map__find_symbol(al->map, al->addr); + + if (sample->host_ip) { + struct machine *host_machine = machine__is_host(machine) ? + machine : (machine->machines ? &machine->machines->host : NULL); + + if (host_machine) { + struct thread *host_thread = machine__findnew_thread(host_machine, + sample->pid, + sample->tid); + struct maps *host_maps = NULL; + bool load_host_map = false; + + if (machine__kernel_ip(host_machine, sample->host_ip)) { + host_maps = machine__kernel_maps(host_machine); + load_host_map = !symbol_conf.lazy_load_kernel_maps; + } else if (host_thread) { + host_maps = thread__maps(host_thread); + } + + if (host_maps) { + al->host_map = maps__find(host_maps, sample->host_ip); + if (al->host_map) { + if (load_host_map) + map__load(al->host_map); + al->host_addr = map__map_ip(al->host_map, + sample->host_ip); + al->host_sym = map__find_symbol(al->host_map, + al->host_addr); + } + } + thread__put(host_thread); + } + + if ((sample->cpumode == PERF_RECORD_MISC_GUEST_USER || + sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) && + !al->sym && al->host_map && (al->host_sym || !al->map)) { + map__zput(al->map); + al->map = map__get(al->host_map); + al->addr = al->host_addr; + al->sym = al->host_sym; + dso = map__dso(al->map); + if (perf_host || perf_guest) { + al->filtered &= ~(1 << HIST_FILTER__GUEST); + al->level = (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) ? + 'g' : 'u'; + } + } + } + if (al->map) { if (symbol_conf.dso_list && (!dso || !(strlist__has_entry(symbol_conf.dso_list, @@ -871,8 +927,6 @@ int machine__resolve(struct machine *machine, struct addr_location *al, dso__long_name(dso)))))) { al->filtered |= (1 << HIST_FILTER__DSO); } - - al->sym = map__find_symbol(al->map, al->addr); } else if (symbol_conf.dso_list) { al->filtered |= (1 << HIST_FILTER__DSO); } -- 2.56.1.915.g69d5ec7298-goog