Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+43 -42
+1 -1
tools/perf/builtin-inject.c
··· 440 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 445 if (al.map != NULL) { 446 446 if (!al.map->dso->hit) {
+9 -10
tools/perf/builtin-script.c
··· 717 717 if (PRINT_FIELD(DSO)) { 718 718 memset(&alf, 0, sizeof(alf)); 719 719 memset(&alt, 0, sizeof(alt)); 720 - thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, from, &alf); 721 - thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, to, &alt); 720 + thread__find_map(thread, sample->cpumode, from, &alf); 721 + thread__find_map(thread, sample->cpumode, to, &alt); 722 722 } 723 723 724 724 printed += fprintf(fp, " 0x%"PRIx64, from); ··· 764 764 from = br->entries[i].from; 765 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 768 if (alf.map) 769 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 772 if (alt.map) 773 773 alt.sym = map__find_symbol(alt.map, alt.addr); 774 774 ··· 814 814 from = br->entries[i].from; 815 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 818 if (alf.map && !alf.map->dso->adjust_symbols) 819 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 822 if (alt.map && !alt.map->dso->adjust_symbols) 823 823 to = map__map_ip(alt.map, to); 824 824 ··· 882 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 886 if (!al.map || !al.map->dso) { 887 887 pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); 888 888 return 0; ··· 933 933 934 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 937 if (!al.map) 938 - thread__find_addr_map(thread, cpumode, MAP__VARIABLE, 939 - addr, &al); 938 + __thread__find_map(thread, cpumode, MAP__VARIABLE, addr, &al); 940 939 if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end) 941 940 return 0; 942 941
+2 -2
tools/perf/tests/code-reading.c
··· 236 236 237 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 240 if (!al.map || !al.map->dso) { 241 241 if (cpumode == PERF_RECORD_MISC_HYPERVISOR) { 242 242 pr_debug("Hypervisor address can not be resolved - skipping\n"); 243 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 247 return -1; 248 248 } 249 249
+3 -4
tools/perf/tests/mmap-thread-lookup.c
··· 188 188 189 189 pr_debug("looking for map %p\n", td->map); 190 190 191 - thread__find_addr_map(thread, 192 - PERF_RECORD_MISC_USER, MAP__FUNCTION, 193 - (unsigned long) (td->map + 1), &al); 191 + thread__find_map(thread, PERF_RECORD_MISC_USER, 192 + (unsigned long) (td->map + 1), &al); 194 193 195 194 thread__put(thread); 196 195 ··· 217 218 * perf_event__synthesize_threads (global) 218 219 * 219 220 * We test we can find all memory maps via: 220 - * thread__find_addr_map 221 + * thread__find_map 221 222 * 222 223 * by using all thread objects. 223 224 */
+1 -1
tools/perf/util/build-id.c
··· 47 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 52 if (al.map != NULL) 53 53 al.map->dso->hit = 1;
+1 -1
tools/perf/util/cs-etm.c
··· 269 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 274 if (!al.map || !al.map->dso) 275 275 return 0;
+9 -9
tools/perf/util/event.c
··· 1489 1489 return machine__process_event(machine, event, sample); 1490 1490 } 1491 1491 1492 - void thread__find_addr_map(struct thread *thread, u8 cpumode, 1493 - enum map_type type, u64 addr, 1494 - struct addr_location *al) 1492 + void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type, 1493 + u64 addr, struct addr_location *al) 1495 1494 { 1496 1495 struct map_groups *mg = thread->mg; 1497 1496 struct machine *machine = mg->machine; ··· 1568 1569 u8 cpumode, enum map_type type, u64 addr, 1569 1570 struct addr_location *al) 1570 1571 { 1571 - thread__find_addr_map(thread, cpumode, type, addr, al); 1572 + __thread__find_map(thread, cpumode, type, addr, al); 1572 1573 if (al->map != NULL) 1573 1574 al->sym = map__find_symbol(al->map, al->addr); 1574 1575 else ··· 1589 1590 return -1; 1590 1591 1591 1592 dump_printf(" ... thread: %s:%d\n", thread__comm_str(thread), thread->tid); 1592 - thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->ip, al); 1593 + thread__find_map(thread, sample->cpumode, sample->ip, al); 1593 1594 dump_printf(" ...... dso: %s\n", 1594 1595 al->map ? al->map->dso->long_name : 1595 1596 al->level == 'H' ? "[hypervisor]" : "<not found>"); ··· 1668 1669 void thread__resolve(struct thread *thread, struct addr_location *al, 1669 1670 struct perf_sample *sample) 1670 1671 { 1671 - thread__find_addr_map(thread, sample->cpumode, MAP__FUNCTION, sample->addr, al); 1672 - if (!al->map) 1673 - thread__find_addr_map(thread, sample->cpumode, MAP__VARIABLE, 1674 - sample->addr, al); 1672 + thread__find_map(thread, sample->cpumode, sample->addr, al); 1673 + if (!al->map) { 1674 + __thread__find_map(thread, sample->cpumode, MAP__VARIABLE, 1675 + sample->addr, al); 1676 + } 1675 1677 1676 1678 al->cpu = sample->cpu; 1677 1679 al->sym = NULL;
+1 -1
tools/perf/util/intel-bts.c
··· 335 335 if (!thread) 336 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 339 if (!al.map || !al.map->dso) 340 340 goto out_put; 341 341
+2 -2
tools/perf/util/intel-pt.c
··· 442 442 } 443 443 444 444 while (1) { 445 - thread__find_addr_map(thread, cpumode, MAP__FUNCTION, *ip, &al); 445 + thread__find_map(thread, cpumode, *ip, &al); 446 446 if (!al.map || !al.map->dso) 447 447 return -EINVAL; 448 448 ··· 596 596 if (!thread) 597 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 600 if (!al.map || !al.map->dso) 601 601 return -EINVAL; 602 602
+8 -3
tools/perf/util/thread.h
··· 92 92 93 93 struct thread *thread__main_thread(struct machine *machine, struct thread *thread); 94 94 95 - void thread__find_addr_map(struct thread *thread, 96 - u8 cpumode, enum map_type type, u64 addr, 97 - struct addr_location *al); 95 + void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type, 96 + u64 addr, 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 104 void thread__find_addr_location(struct thread *thread, 100 105 u8 cpumode, enum map_type type, u64 addr,
+3 -4
tools/perf/util/unwind-libdw.c
··· 103 103 struct addr_location al; 104 104 ssize_t size; 105 105 106 - thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, 107 - MAP__FUNCTION, addr, &al); 106 + thread__find_map(ui->thread, PERF_RECORD_MISC_USER, addr, &al); 108 107 if (!al.map) { 109 108 /* 110 109 * We've seen cases (softice) where DWARF unwinder went 111 110 * through non executable mmaps, which we need to lookup 112 111 * in MAP__VARIABLE tree. 113 112 */ 114 - thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, 115 - MAP__VARIABLE, addr, &al); 113 + __thread__find_map(ui->thread, PERF_RECORD_MISC_USER, 114 + MAP__VARIABLE, addr, &al); 116 115 } 117 116 118 117 if (!al.map) {
+3 -4
tools/perf/util/unwind-libunwind-local.c
··· 367 367 { 368 368 struct addr_location al; 369 369 370 - thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, 371 - MAP__FUNCTION, ip, &al); 370 + thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al); 372 371 if (!al.map) { 373 372 /* 374 373 * We've seen cases (softice) where DWARF unwinder went 375 374 * through non executable mmaps, which we need to lookup 376 375 * in MAP__VARIABLE tree. 377 376 */ 378 - thread__find_addr_map(ui->thread, PERF_RECORD_MISC_USER, 379 - MAP__VARIABLE, ip, &al); 377 + __thread__find_map(ui->thread, PERF_RECORD_MISC_USER, 378 + MAP__VARIABLE, ip, &al); 380 379 } 381 380 return al.map; 382 381 }