diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-04-24 09:49:50 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-04-26 12:47:06 -0400 |
commit | f07a2d32b521a54635c8efeb0a3180b0afcf780a (patch) | |
tree | 45a1067acbe63042868ffd6ad920b657c2ed7f51 | |
parent | e94b861a231501e73d786970ed5a1fb3ea643906 (diff) |
perf thread: Introduce thread__find_map()
Out of thread__find_add_map(..., MAP__FUNCTION, ...), idea here is to
continue removing references to MAP__{FUNCTION,VARIABLE} ahead of
getting both types of symbols in the same rbtree, as various places do
two lookups, looking first at MAP__FUNCTION, then at MAP__VARIABLE.
So thread__find_map() will eventually do just that, and 'struct symbol'
will have the symbol type, for code that cares about that.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-q27xee34l4izpfau49w103s6@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-inject.c | 2 | ||||
-rw-r--r-- | tools/perf/builtin-script.c | 19 | ||||
-rw-r--r-- | tools/perf/tests/code-reading.c | 4 | ||||
-rw-r--r-- | tools/perf/tests/mmap-thread-lookup.c | 7 | ||||
-rw-r--r-- | tools/perf/util/build-id.c | 2 | ||||
-rw-r--r-- | tools/perf/util/cs-etm.c | 2 | ||||
-rw-r--r-- | tools/perf/util/event.c | 18 | ||||
-rw-r--r-- | tools/perf/util/intel-bts.c | 2 | ||||
-rw-r--r-- | tools/perf/util/intel-pt.c | 4 | ||||
-rw-r--r-- | tools/perf/util/thread.h | 11 | ||||
-rw-r--r-- | tools/perf/util/unwind-libdw.c | 7 | ||||
-rw-r--r-- | tools/perf/util/unwind-libunwind-local.c | 7 |
12 files changed, 43 insertions, 42 deletions
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 40fe919bbcf3..92677d8f9eae 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c | |||
@@ -440,7 +440,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool, | |||
440 | goto repipe; | 440 | goto repipe; |
441 | } | 441 | } |
442 | 442 | ||
443 | thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, &al); | 443 | thread__find_map(thread, sample->cpumode, sample->ip, &al); |
444 | 444 | ||
445 | if (al.map != NULL) { | 445 | if (al.map != NULL) { |
446 | if (!al.map->dso->hit) { | 446 | if (!al.map->dso->hit) { |
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index e0a9845b6cbc..5ec1c73bbfaf 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c | |||
@@ -717,8 +717,8 @@ static int perf_sample__fprintf_brstack(struct perf_sample *sample, | |||
717 | if (PRINT_FIELD(DSO)) { | 717 | if (PRINT_FIELD(DSO)) { |
718 | memset(&alf, 0, sizeof(alf)); | 718 | memset(&alf, 0, sizeof(alf)); |
719 | memset(&alt, 0, sizeof(alt)); | 719 | memset(&alt, 0, sizeof(alt)); |
720 | thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, from, &alf); | 720 | thread__find_map(thread, sample->cpumode, from, &alf); |
721 | thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt); | 721 | thread__find_map(thread, sample->cpumode, to, &alt); |
722 | } | 722 | } |
723 | 723 | ||
724 | printed += fprintf(fp, " 0x%"PRIx64, from); | 724 | printed += fprintf(fp, " 0x%"PRIx64, from); |
@@ -764,11 +764,11 @@ static int perf_sample__fprintf_brstacksym(struct perf_sample *sample, | |||
764 | from = br->entries[i].from; | 764 | from = br->entries[i].from; |
765 | to = br->entries[i].to; | 765 | to = br->entries[i].to; |
766 | 766 | ||
767 | thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, from, &alf); | 767 | thread__find_map(thread, sample->cpumode, from, &alf); |
768 | if (alf.map) | 768 | if (alf.map) |
769 | alf.sym = map__find_symbol(alf.map, alf.addr); | 769 | alf.sym = map__find_symbol(alf.map, alf.addr); |
770 | 770 | ||
771 | thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt); | 771 | thread__find_map(thread, sample->cpumode, to, &alt); |
772 | if (alt.map) | 772 | if (alt.map) |
773 | alt.sym = map__find_symbol(alt.map, alt.addr); | 773 | alt.sym = map__find_symbol(alt.map, alt.addr); |
774 | 774 | ||
@@ -814,11 +814,11 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample, | |||
814 | from = br->entries[i].from; | 814 | from = br->entries[i].from; |
815 | to = br->entries[i].to; | 815 | to = br->entries[i].to; |
816 | 816 | ||
817 | thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, from, &alf); | 817 | thread__find_map(thread, sample->cpumode, from, &alf); |
818 | if (alf.map && !alf.map->dso->adjust_symbols) | 818 | if (alf.map && !alf.map->dso->adjust_symbols) |
819 | from = map__map_ip(alf.map, from); | 819 | from = map__map_ip(alf.map, from); |
820 | 820 | ||
821 | thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt); | 821 | thread__find_map(thread, sample->cpumode, to, &alt); |
822 | if (alt.map && !alt.map->dso->adjust_symbols) | 822 | if (alt.map && !alt.map->dso->adjust_symbols) |
823 | to = map__map_ip(alt.map, to); | 823 | to = map__map_ip(alt.map, to); |
824 | 824 | ||
@@ -882,7 +882,7 @@ static int grab_bb(u8 *buffer, u64 start, u64 end, | |||
882 | return 0; | 882 | return 0; |
883 | } | 883 | } |
884 | 884 | ||
885 | thread__find_addr_map(thread, *cpumode, MAP__FUNCTION, start, &al); | 885 | thread__find_map(thread, *cpumode, start, &al); |
886 | if (!al.map || !al.map->dso) { | 886 | if (!al.map || !al.map->dso) { |
887 | pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); | 887 | pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); |
888 | return 0; | 888 | return 0; |
@@ -933,10 +933,9 @@ static int ip__fprintf_sym(uint64_t addr, struct thread *thread, | |||
933 | 933 | ||
934 | memset(&al, 0, sizeof(al)); | 934 | memset(&al, 0, sizeof(al)); |
935 | 935 | ||
936 | thread__find_addr_map(thread, cpumode, MAP__FUNCTION, addr, &al); | 936 | thread__find_map(thread, cpumode, addr, &al); |
937 | if (!al.map) | 937 | if (!al.map) |
938 | thread__find_addr_map(thread, cpumode, MAP__VARIABLE, | 938 | __thread__find_map(thread, cpumode, MAP__VARIABLE, addr, &al); |
939 | addr, &al); | ||
940 | if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end) | 939 | if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end) |
941 | return 0; | 940 | return 0; |
942 | 941 | ||
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index 99936352df4f..5b0a55499486 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c | |||
@@ -236,14 +236,14 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode, | |||
236 | 236 | ||
237 | pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr); | 237 | pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr); |
238 | 238 | ||
239 | thread__find_addr_map(thread, cpumode, MAP__FUNCTION, addr, &al); | 239 | thread__find_map(thread, cpumode, addr, &al); |
240 | if (!al.map || !al.map->dso) { | 240 | if (!al.map || !al.map->dso) { |
241 | if (cpumode == PERF_RECORD_MISC_HYPERVISOR) { | 241 | if (cpumode == PERF_RECORD_MISC_HYPERVISOR) { |
242 | pr_debug("Hypervisor address can not be resolved - skipping\n"); | 242 | pr_debug("Hypervisor address can not be resolved - skipping\n"); |
243 | return 0; | 243 | return 0; |
244 | } | 244 | } |
245 | 245 | ||
246 | pr_debug("thread__find_addr_map failed\n"); | 246 | pr_debug("thread__find_map failed\n"); |
247 | return -1; | 247 | return -1; |
248 | } | 248 | } |
249 | 249 | ||
diff --git a/tools/perf/tests/mmap-thread-lookup.c b/tools/perf/tests/mmap-thread-lookup.c index 868d82b501f4..b1af2499a3c9 100644 --- a/tools/perf/tests/mmap-thread-lookup.c +++ b/tools/perf/tests/mmap-thread-lookup.c | |||
@@ -188,9 +188,8 @@ static int mmap_events(synth_cb synth) | |||
188 | 188 | ||
189 | pr_debug("looking for map %p\n", td->map); | 189 | pr_debug("looking for map %p\n", td->map); |
190 | 190 | ||
191 | thread__find_addr_map(thread, | 191 | thread__find_map(thread, PERF_RECORD_MISC_USER, |
192 | PERF_RECORD_MISC_USER, MAP__FUNCTION, | 192 | (unsigned long) (td->map + 1), &al); |
193 | (unsigned long) (td->map + 1), &al); | ||
194 | 193 | ||
195 | thread__put(thread); | 194 | thread__put(thread); |
196 | 195 | ||
@@ -218,7 +217,7 @@ static int mmap_events(synth_cb synth) | |||
218 | * perf_event__synthesize_threads (global) | 217 | * perf_event__synthesize_threads (global) |
219 | * | 218 | * |
220 | * We test we can find all memory maps via: | 219 | * We test we can find all memory maps via: |
221 | * thread__find_addr_map | 220 | * thread__find_map |
222 | * | 221 | * |
223 | * by using all thread objects. | 222 | * by using all thread objects. |
224 | */ | 223 | */ |
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 537eadd81914..b512dc8fa6c3 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c | |||
@@ -47,7 +47,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused, | |||
47 | return -1; | 47 | return -1; |
48 | } | 48 | } |
49 | 49 | ||
50 | thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, &al); | 50 | thread__find_map(thread, sample->cpumode, sample->ip, &al); |
51 | 51 | ||
52 | if (al.map != NULL) | 52 | if (al.map != NULL) |
53 | al.map->dso->hit = 1; | 53 | al.map->dso->hit = 1; |
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 40020b1ca54f..8fe573d040b6 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c | |||
@@ -269,7 +269,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address, | |||
269 | thread = etmq->etm->unknown_thread; | 269 | thread = etmq->etm->unknown_thread; |
270 | } | 270 | } |
271 | 271 | ||
272 | thread__find_addr_map(thread, cpumode, MAP__FUNCTION, address, &al); | 272 | thread__find_map(thread, cpumode, address, &al); |
273 | 273 | ||
274 | if (!al.map || !al.map->dso) | 274 | if (!al.map || !al.map->dso) |
275 | return 0; | 275 | return 0; |
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 98ff3a6a3d50..baa97d0b6114 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
@@ -1489,9 +1489,8 @@ int perf_event__process(struct perf_tool *tool __maybe_unused, | |||
1489 | return machine__process_event(machine, event, sample); | 1489 | return machine__process_event(machine, event, sample); |
1490 | } | 1490 | } |
1491 | 1491 | ||
1492 | void thread__find_addr_map(struct thread *thread, u8 cpumode, | 1492 | void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type, |
1493 | enum map_type type, u64 addr, | 1493 | u64 addr, struct addr_location *al) |
1494 | struct addr_location *al) | ||
1495 | { | 1494 | { |
1496 | struct map_groups *mg = thread->mg; | 1495 | struct map_groups *mg = thread->mg; |
1497 | struct machine *machine = mg->machine; | 1496 | struct machine *machine = mg->machine; |
@@ -1569,7 +1568,7 @@ void thread__find_addr_location(struct thread *thread, | |||
1569 | u8 cpumode, enum map_type type, u64 addr, | 1568 | u8 cpumode, enum map_type type, u64 addr, |
1570 | struct addr_location *al) | 1569 | struct addr_location *al) |
1571 | { | 1570 | { |
1572 | thread__find_addr_map(thread, cpumode, type, addr, al); | 1571 | __thread__find_map(thread, cpumode, type, addr, al); |
1573 | if (al->map != NULL) | 1572 | if (al->map != NULL) |
1574 | al->sym = map__find_symbol(al->map, al->addr); | 1573 | al->sym = map__find_symbol(al->map, al->addr); |
1575 | else | 1574 | else |
@@ -1590,7 +1589,7 @@ int machine__resolve(struct machine *machine, struct addr_location *al, | |||
1590 | return -1; | 1589 | return -1; |
1591 | 1590 | ||
1592 | dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid); | 1591 | dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid); |
1593 | thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, al); | 1592 | thread__find_map(thread, sample->cpumode, sample->ip, al); |
1594 | dump_printf(" ...... dso: %s\n", | 1593 | dump_printf(" ...... dso: %s\n", |
1595 | al->map ? al->map->dso->long_name : | 1594 | al->map ? al->map->dso->long_name : |
1596 | al->level == 'H' ? "[hypervisor]" : "<not found>"); | 1595 | al->level == 'H' ? "[hypervisor]" : "<not found>"); |
@@ -1669,10 +1668,11 @@ bool sample_addr_correlates_sym(struct perf_event_attr *attr) | |||
1669 | void thread__resolve(struct thread *thread, struct addr_location *al, | 1668 | void thread__resolve(struct thread *thread, struct addr_location *al, |
1670 | struct perf_sample *sample) | 1669 | struct perf_sample *sample) |
1671 | { | 1670 | { |
1672 | thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->addr, al); | 1671 | thread__find_map(thread, sample->cpumode, sample->addr, al); |
1673 | if (!al->map) | 1672 | if (!al->map) { |
1674 | thread__find_addr_map(thread, sample->cpumode, MAP__VARIABLE, | 1673 | __thread__find_map(thread, sample->cpumode, MAP__VARIABLE, |
1675 | sample->addr, al); | 1674 | sample->addr, al); |
1675 | } | ||
1676 | 1676 | ||
1677 | al->cpu = sample->cpu; | 1677 | al->cpu = sample->cpu; |
1678 | al->sym = NULL; | 1678 | al->sym = NULL; |
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c index 72db2744876d..ea0ce8572bf2 100644 --- a/tools/perf/util/intel-bts.c +++ b/tools/perf/util/intel-bts.c | |||
@@ -335,7 +335,7 @@ static int intel_bts_get_next_insn(struct intel_bts_queue *btsq, u64 ip) | |||
335 | if (!thread) | 335 | if (!thread) |
336 | return -1; | 336 | return -1; |
337 | 337 | ||
338 | thread__find_addr_map(thread, cpumode, MAP__FUNCTION, ip, &al); | 338 | thread__find_map(thread, cpumode, ip, &al); |
339 | if (!al.map || !al.map->dso) | 339 | if (!al.map || !al.map->dso) |
340 | goto out_put; | 340 | goto out_put; |
341 | 341 | ||
diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index 0effaff57020..441e681a46a0 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c | |||
@@ -442,7 +442,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn, | |||
442 | } | 442 | } |
443 | 443 | ||
444 | while (1) { | 444 | while (1) { |
445 | thread__find_addr_map(thread, cpumode, MAP__FUNCTION, *ip, &al); | 445 | thread__find_map(thread, cpumode, *ip, &al); |
446 | if (!al.map || !al.map->dso) | 446 | if (!al.map || !al.map->dso) |
447 | return -EINVAL; | 447 | return -EINVAL; |
448 | 448 | ||
@@ -596,7 +596,7 @@ static int __intel_pt_pgd_ip(uint64_t ip, void *data) | |||
596 | if (!thread) | 596 | if (!thread) |
597 | return -EINVAL; | 597 | return -EINVAL; |
598 | 598 | ||
599 | thread__find_addr_map(thread, cpumode, MAP__FUNCTION, ip, &al); | 599 | thread__find_map(thread, cpumode, ip, &al); |
600 | if (!al.map || !al.map->dso) | 600 | if (!al.map || !al.map->dso) |
601 | return -EINVAL; | 601 | return -EINVAL; |
602 | 602 | ||
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 14d44c3235b8..52c788f955de 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h | |||
@@ -92,9 +92,14 @@ size_t thread__fprintf(struct thread *thread, FILE *fp); | |||
92 | 92 | ||
93 | struct thread *thread__main_thread(struct machine *machine, struct thread *thread); | 93 | struct thread *thread__main_thread(struct machine *machine, struct thread *thread); |
94 | 94 | ||
95 | void thread__find_addr_map(struct thread *thread, | 95 | void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type, |
96 | u8 cpumode, enum map_type type, u64 addr, | 96 | u64 addr, struct addr_location *al); |
97 | struct addr_location *al); | 97 | |
98 | static inline void thread__find_map(struct thread *thread, u8 cpumode, | ||
99 | u64 addr, struct addr_location *al) | ||
100 | { | ||
101 | __thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al); | ||
102 | } | ||
98 | 103 | ||
99 | void thread__find_addr_location(struct thread *thread, | 104 | void thread__find_addr_location(struct thread *thread, |
100 | u8 cpumode, enum map_type type, u64 addr, | 105 | u8 cpumode, enum map_type type, u64 addr, |
diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c index 7bdd239c795c..1ce8744649b5 100644 --- a/tools/perf/util/unwind-libdw.c +++ b/tools/perf/util/unwind-libdw.c | |||
@@ -103,16 +103,15 @@ static int access_dso_mem(struct unwind_info *ui, Dwarf_Addr addr, | |||
103 | struct addr_location al; | 103 | struct addr_location al; |
104 | ssize_t size; | 104 | ssize_t size; |
105 | 105 | ||
106 | thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, | 106 | thread__find_map(ui->thread, PERF_RECORD_MISC_USER, addr, &al); |
107 | MAP__FUNCTION, addr, &al); | ||
108 | if (!al.map) { | 107 | if (!al.map) { |
109 | /* | 108 | /* |
110 | * We've seen cases (softice) where DWARF unwinder went | 109 | * We've seen cases (softice) where DWARF unwinder went |
111 | * through non executable mmaps, which we need to lookup | 110 | * through non executable mmaps, which we need to lookup |
112 | * in MAP__VARIABLE tree. | 111 | * in MAP__VARIABLE tree. |
113 | */ | 112 | */ |
114 | thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, | 113 | __thread__find_map(ui->thread, PERF_RECORD_MISC_USER, |
115 | MAP__VARIABLE, addr, &al); | 114 | MAP__VARIABLE, addr, &al); |
116 | } | 115 | } |
117 | 116 | ||
118 | if (!al.map) { | 117 | if (!al.map) { |
diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c index af873044d33a..33afca5c04f6 100644 --- a/tools/perf/util/unwind-libunwind-local.c +++ b/tools/perf/util/unwind-libunwind-local.c | |||
@@ -367,16 +367,15 @@ static struct map *find_map(unw_word_t ip, struct unwind_info *ui) | |||
367 | { | 367 | { |
368 | struct addr_location al; | 368 | struct addr_location al; |
369 | 369 | ||
370 | thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, | 370 | thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al); |
371 | MAP__FUNCTION, ip, &al); | ||
372 | if (!al.map) { | 371 | if (!al.map) { |
373 | /* | 372 | /* |
374 | * We've seen cases (softice) where DWARF unwinder went | 373 | * We've seen cases (softice) where DWARF unwinder went |
375 | * through non executable mmaps, which we need to lookup | 374 | * through non executable mmaps, which we need to lookup |
376 | * in MAP__VARIABLE tree. | 375 | * in MAP__VARIABLE tree. |
377 | */ | 376 | */ |
378 | thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, | 377 | __thread__find_map(ui->thread, PERF_RECORD_MISC_USER, |
379 | MAP__VARIABLE, ip, &al); | 378 | MAP__VARIABLE, ip, &al); |
380 | } | 379 | } |
381 | return al.map; | 380 | return al.map; |
382 | } | 381 | } |