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

perf thread: Make thread__find_map() return the map

It was returning the searched map just on the addr_location passed, with
the function itself returning void.

Make it return the map so that we can make the code more compact.

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-tzlrrzdeoof4i6ktyqv1t6ks@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+28 -42
+1 -3
tools/perf/builtin-inject.c
··· 440 440 goto repipe; 441 441 } 442 442 443 - thread__find_map(thread, sample->cpumode, sample->ip, &al); 444 - 445 - if (al.map != NULL) { 443 + if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) { 446 444 if (!al.map->dso->hit) { 447 445 al.map->dso->hit = 1; 448 446 if (map__load(al.map) >= 0) {
+6 -8
tools/perf/builtin-script.c
··· 809 809 from = br->entries[i].from; 810 810 to = br->entries[i].to; 811 811 812 - thread__find_map(thread, sample->cpumode, from, &alf); 813 - if (alf.map && !alf.map->dso->adjust_symbols) 812 + if (thread__find_map(thread, sample->cpumode, from, &alf) && 813 + !alf.map->dso->adjust_symbols) 814 814 from = map__map_ip(alf.map, from); 815 815 816 - thread__find_map(thread, sample->cpumode, to, &alt); 817 - if (alt.map && !alt.map->dso->adjust_symbols) 816 + if (thread__find_map(thread, sample->cpumode, to, &alt) && 817 + !alt.map->dso->adjust_symbols) 818 818 to = map__map_ip(alt.map, to); 819 819 820 820 printed += fprintf(fp, " 0x%"PRIx64, from); ··· 877 877 return 0; 878 878 } 879 879 880 - thread__find_map(thread, *cpumode, start, &al); 881 - if (!al.map || !al.map->dso) { 880 + if (!thread__find_map(thread, *cpumode, start, &al) || !al.map->dso) { 882 881 pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end); 883 882 return 0; 884 883 } ··· 927 928 928 929 memset(&al, 0, sizeof(al)); 929 930 930 - thread__find_map(thread, cpumode, addr, &al); 931 - if (!al.map) 931 + if (!thread__find_map(thread, cpumode, addr, &al)) 932 932 __thread__find_map(thread, cpumode, MAP__VARIABLE, addr, &al); 933 933 if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end) 934 934 return 0;
+1 -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_map(thread, cpumode, addr, &al); 240 - if (!al.map || !al.map->dso) { 239 + if (!thread__find_map(thread, cpumode, addr, &al) || !al.map->dso) { 241 240 if (cpumode == PERF_RECORD_MISC_HYPERVISOR) { 242 241 pr_debug("Hypervisor address can not be resolved - skipping\n"); 243 242 return 0;
+1 -3
tools/perf/util/build-id.c
··· 47 47 return -1; 48 48 } 49 49 50 - thread__find_map(thread, sample->cpumode, sample->ip, &al); 51 - 52 - if (al.map != NULL) 50 + if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) 53 51 al.map->dso->hit = 1; 54 52 55 53 thread__put(thread);
+1 -3
tools/perf/util/cs-etm.c
··· 269 269 thread = etmq->etm->unknown_thread; 270 270 } 271 271 272 - thread__find_map(thread, cpumode, address, &al); 273 - 274 - if (!al.map || !al.map->dso) 272 + if (!thread__find_map(thread, cpumode, address, &al) || !al.map->dso) 275 273 return 0; 276 274 277 275 if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR &&
+8 -8
tools/perf/util/event.c
··· 1489 1489 return machine__process_event(machine, event, sample); 1490 1490 } 1491 1491 1492 - void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type, 1493 - u64 addr, struct addr_location *al) 1492 + struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type type, 1493 + u64 addr, struct addr_location *al) 1494 1494 { 1495 1495 struct map_groups *mg = thread->mg; 1496 1496 struct machine *machine = mg->machine; ··· 1504 1504 1505 1505 if (machine == NULL) { 1506 1506 al->map = NULL; 1507 - return; 1507 + return NULL; 1508 1508 } 1509 1509 1510 1510 if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) { ··· 1532 1532 !perf_host) 1533 1533 al->filtered |= (1 << HIST_FILTER__HOST); 1534 1534 1535 - return; 1535 + return NULL; 1536 1536 } 1537 1537 try_again: 1538 1538 al->map = map_groups__find(mg, type, al->addr); ··· 1562 1562 map__load(al->map); 1563 1563 al->addr = al->map->map_ip(al->map, al->addr); 1564 1564 } 1565 + 1566 + return al->map; 1565 1567 } 1566 1568 1567 1569 void __thread__find_symbol(struct thread *thread, u8 cpumode, 1568 1570 enum map_type type, u64 addr, 1569 1571 struct addr_location *al) 1570 1572 { 1571 - __thread__find_map(thread, cpumode, type, addr, al); 1572 - if (al->map != NULL) 1573 + if (__thread__find_map(thread, cpumode, type, addr, al)) 1573 1574 al->sym = map__find_symbol(al->map, al->addr); 1574 1575 else 1575 1576 al->sym = NULL; ··· 1669 1668 void thread__resolve(struct thread *thread, struct addr_location *al, 1670 1669 struct perf_sample *sample) 1671 1670 { 1672 - thread__find_map(thread, sample->cpumode, sample->addr, al); 1673 - if (!al->map) { 1671 + if (!thread__find_map(thread, sample->cpumode, sample->addr, al)) { 1674 1672 __thread__find_map(thread, sample->cpumode, MAP__VARIABLE, 1675 1673 sample->addr, al); 1676 1674 }
+1 -2
tools/perf/util/intel-bts.c
··· 335 335 if (!thread) 336 336 return -1; 337 337 338 - thread__find_map(thread, cpumode, ip, &al); 339 - if (!al.map || !al.map->dso) 338 + if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso) 340 339 goto out_put; 341 340 342 341 len = dso__data_read_addr(al.map->dso, al.map, machine, ip, buf,
+2 -4
tools/perf/util/intel-pt.c
··· 442 442 } 443 443 444 444 while (1) { 445 - thread__find_map(thread, cpumode, *ip, &al); 446 - if (!al.map || !al.map->dso) 445 + if (!thread__find_map(thread, cpumode, *ip, &al) || !al.map->dso) 447 446 return -EINVAL; 448 447 449 448 if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR && ··· 595 596 if (!thread) 596 597 return -EINVAL; 597 598 598 - thread__find_map(thread, cpumode, ip, &al); 599 - if (!al.map || !al.map->dso) 599 + if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso) 600 600 return -EINVAL; 601 601 602 602 offset = al.map->map_ip(al.map, ip);
+5 -5
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_map(struct thread *thread, u8 cpumode, enum map_type type, 96 - u64 addr, struct addr_location *al); 95 + struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type type, 96 + u64 addr, struct addr_location *al); 97 97 98 - static inline void thread__find_map(struct thread *thread, u8 cpumode, 99 - u64 addr, struct addr_location *al) 98 + static inline struct map *thread__find_map(struct thread *thread, u8 cpumode, 99 + u64 addr, struct addr_location *al) 100 100 { 101 - __thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al); 101 + return __thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al); 102 102 } 103 103 104 104 void __thread__find_symbol(struct thread *thread, u8 cpumode, enum map_type type,
+1 -2
tools/perf/util/unwind-libdw.c
··· 104 104 struct addr_location al; 105 105 ssize_t size; 106 106 107 - thread__find_map(ui->thread, PERF_RECORD_MISC_USER, addr, &al); 108 - if (!al.map) { 107 + if (!thread__find_map(ui->thread, PERF_RECORD_MISC_USER, addr, &al)) { 109 108 /* 110 109 * We've seen cases (softice) where DWARF unwinder went 111 110 * through non executable mmaps, which we need to lookup
+1 -2
tools/perf/util/unwind-libunwind-local.c
··· 367 367 { 368 368 struct addr_location al; 369 369 370 - thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al); 371 - if (!al.map) { 370 + if (!thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al)) { 372 371 /* 373 372 * We've seen cases (softice) where DWARF unwinder went 374 373 * through non executable mmaps, which we need to lookup