perf thread: Make thread__find_map() return the map
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 24 Apr 2018 14:58:56 +0000 (11:58 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 26 Apr 2018 16:47:08 +0000 (13:47 -0300)
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>
tools/perf/builtin-inject.c
tools/perf/builtin-script.c
tools/perf/tests/code-reading.c
tools/perf/util/build-id.c
tools/perf/util/cs-etm.c
tools/perf/util/event.c
tools/perf/util/intel-bts.c
tools/perf/util/intel-pt.c
tools/perf/util/thread.h
tools/perf/util/unwind-libdw.c
tools/perf/util/unwind-libunwind-local.c

index 92677d8f9eae76599ac0470bc50446db2c8c6afe..a3b346359ba00c406735d2fb7687bbc02b9db7fb 100644 (file)
@@ -440,9 +440,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,
                goto repipe;
        }
 
-       thread__find_map(thread, sample->cpumode, sample->ip, &al);
-
-       if (al.map != NULL) {
+       if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) {
                if (!al.map->dso->hit) {
                        al.map->dso->hit = 1;
                        if (map__load(al.map) >= 0) {
index ffd02faee87b1702f5227d10b1dae80538e47700..07cb083ac89ce4cd4f48a0a085263935acfb2901 100644 (file)
@@ -809,12 +809,12 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,
                from = br->entries[i].from;
                to   = br->entries[i].to;
 
-               thread__find_map(thread, sample->cpumode, from, &alf);
-               if (alf.map && !alf.map->dso->adjust_symbols)
+               if (thread__find_map(thread, sample->cpumode, from, &alf) &&
+                   !alf.map->dso->adjust_symbols)
                        from = map__map_ip(alf.map, from);
 
-               thread__find_map(thread, sample->cpumode, to, &alt);
-               if (alt.map && !alt.map->dso->adjust_symbols)
+               if (thread__find_map(thread, sample->cpumode, to, &alt) &&
+                   !alt.map->dso->adjust_symbols)
                        to = map__map_ip(alt.map, to);
 
                printed += fprintf(fp, " 0x%"PRIx64, from);
@@ -877,8 +877,7 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
                return 0;
        }
 
-       thread__find_map(thread, *cpumode, start, &al);
-       if (!al.map || !al.map->dso) {
+       if (!thread__find_map(thread, *cpumode, start, &al) || !al.map->dso) {
                pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
                return 0;
        }
@@ -928,8 +927,7 @@ static int ip__fprintf_sym(uint64_t addr, struct thread *thread,
 
        memset(&al, 0, sizeof(al));
 
-       thread__find_map(thread, cpumode, addr, &al);
-       if (!al.map)
+       if (!thread__find_map(thread, cpumode, addr, &al))
                __thread__find_map(thread, cpumode, MAP__VARIABLE, addr, &al);
        if ((*lastsym) && al.addr >= (*lastsym)->start && al.addr < (*lastsym)->end)
                return 0;
index 5b0a55499486b834ed849942b03ab1eb3598309c..afa4ce21ba7c5e31e657a66687a7379896a1672f 100644 (file)
@@ -236,8 +236,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
 
        pr_debug("Reading object code for memory address: %#"PRIx64"\n", addr);
 
-       thread__find_map(thread, cpumode, addr, &al);
-       if (!al.map || !al.map->dso) {
+       if (!thread__find_map(thread, cpumode, addr, &al) || !al.map->dso) {
                if (cpumode == PERF_RECORD_MISC_HYPERVISOR) {
                        pr_debug("Hypervisor address can not be resolved - skipping\n");
                        return 0;
index b512dc8fa6c33ef7c39e0d26a351a92369d1bea0..04b1d53e4bf9a7d3606169bbb25cdb1a5d059600 100644 (file)
@@ -47,9 +47,7 @@ int build_id__mark_dso_hit(struct perf_tool *tool __maybe_unused,
                return -1;
        }
 
-       thread__find_map(thread, sample->cpumode, sample->ip, &al);
-
-       if (al.map != NULL)
+       if (thread__find_map(thread, sample->cpumode, sample->ip, &al))
                al.map->dso->hit = 1;
 
        thread__put(thread);
index 8fe573d040b61f8e9b7857ed20ed3b0bb02df3e1..6533b1adb50b6fdecb1b58ed87fd5d4267706494 100644 (file)
@@ -269,9 +269,7 @@ static u32 cs_etm__mem_access(struct cs_etm_queue *etmq, u64 address,
                thread = etmq->etm->unknown_thread;
        }
 
-       thread__find_map(thread, cpumode, address, &al);
-
-       if (!al.map || !al.map->dso)
+       if (!thread__find_map(thread, cpumode, address, &al) || !al.map->dso)
                return 0;
 
        if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR &&
index 2d860fbeb227eb12feeb41854a288036a70670a7..48e4b252f6ff8fba7ac9fbd2dffdbb2b26aef757 100644 (file)
@@ -1489,8 +1489,8 @@ int perf_event__process(struct perf_tool *tool __maybe_unused,
        return machine__process_event(machine, event, sample);
 }
 
-void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
-                       u64 addr, struct addr_location *al)
+struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
+                              u64 addr, struct addr_location *al)
 {
        struct map_groups *mg = thread->mg;
        struct machine *machine = mg->machine;
@@ -1504,7 +1504,7 @@ void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
 
        if (machine == NULL) {
                al->map = NULL;
-               return;
+               return NULL;
        }
 
        if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
@@ -1532,7 +1532,7 @@ void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
                        !perf_host)
                        al->filtered |= (1 << HIST_FILTER__HOST);
 
-               return;
+               return NULL;
        }
 try_again:
        al->map = map_groups__find(mg, type, al->addr);
@@ -1562,14 +1562,15 @@ try_again:
                        map__load(al->map);
                al->addr = al->map->map_ip(al->map, al->addr);
        }
+
+       return al->map;
 }
 
 void __thread__find_symbol(struct thread *thread, u8 cpumode,
                           enum map_type type, u64 addr,
                           struct addr_location *al)
 {
-       __thread__find_map(thread, cpumode, type, addr, al);
-       if (al->map != NULL)
+       if (__thread__find_map(thread, cpumode, type, addr, al))
                al->sym = map__find_symbol(al->map, al->addr);
        else
                al->sym = NULL;
@@ -1668,8 +1669,7 @@ bool sample_addr_correlates_sym(struct perf_event_attr *attr)
 void thread__resolve(struct thread *thread, struct addr_location *al,
                     struct perf_sample *sample)
 {
-       thread__find_map(thread, sample->cpumode, sample->addr, al);
-       if (!al->map) {
+       if (!thread__find_map(thread, sample->cpumode, sample->addr, al)) {
                __thread__find_map(thread, sample->cpumode, MAP__VARIABLE,
                                   sample->addr, al);
        }
index ea0ce8572bf26439b94fe88bb4b464f4ac5d2ae3..7f0c83b6332bfd94ca92eac2723c700421cf119a 100644 (file)
@@ -335,8 +335,7 @@ static int intel_bts_get_next_insn(struct intel_bts_queue *btsq, u64 ip)
        if (!thread)
                return -1;
 
-       thread__find_map(thread, cpumode, ip, &al);
-       if (!al.map || !al.map->dso)
+       if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso)
                goto out_put;
 
        len = dso__data_read_addr(al.map->dso, al.map, machine, ip, buf,
index 441e681a46a0601e545bfdc8b7b114b9f5e1277f..a272b35f6c5ad5aab655fe8b23edb34e17524624 100644 (file)
@@ -442,8 +442,7 @@ static int intel_pt_walk_next_insn(struct intel_pt_insn *intel_pt_insn,
        }
 
        while (1) {
-               thread__find_map(thread, cpumode, *ip, &al);
-               if (!al.map || !al.map->dso)
+               if (!thread__find_map(thread, cpumode, *ip, &al) || !al.map->dso)
                        return -EINVAL;
 
                if (al.map->dso->data.status == DSO_DATA_STATUS_ERROR &&
@@ -596,8 +595,7 @@ static int __intel_pt_pgd_ip(uint64_t ip, void *data)
        if (!thread)
                return -EINVAL;
 
-       thread__find_map(thread, cpumode, ip, &al);
-       if (!al.map || !al.map->dso)
+       if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso)
                return -EINVAL;
 
        offset = al.map->map_ip(al.map, ip);
index b69e65c821f953ff8f36e775836812c2c0ce506a..1961e4bc1c2c5c95c2a4df00c1f194424e38e20c 100644 (file)
@@ -92,13 +92,13 @@ size_t thread__fprintf(struct thread *thread, FILE *fp);
 
 struct thread *thread__main_thread(struct machine *machine, struct thread *thread);
 
-void __thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
-                       u64 addr, struct addr_location *al);
+struct map *__thread__find_map(struct thread *thread, u8 cpumode, enum map_type type,
+                              u64 addr, struct addr_location *al);
 
-static inline void thread__find_map(struct thread *thread, u8 cpumode,
-                                   u64 addr, struct addr_location *al)
+static inline struct map *thread__find_map(struct thread *thread, u8 cpumode,
+                                          u64 addr, struct addr_location *al)
 {
-       __thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al);
+       return __thread__find_map(thread, cpumode, MAP__FUNCTION, addr, al);
 }
 
 void __thread__find_symbol(struct thread *thread, u8 cpumode, enum map_type type,
index bdc22f1864df9255c6b7d28dbe33d949ff319d6d..17401922cd42e638ec6d8eb2add7b2420137a5fc 100644 (file)
@@ -104,8 +104,7 @@ static int access_dso_mem(struct unwind_info *ui, Dwarf_Addr addr,
        struct addr_location al;
        ssize_t size;
 
-       thread__find_map(ui->thread, PERF_RECORD_MISC_USER, addr, &al);
-       if (!al.map) {
+       if (!thread__find_map(ui->thread, PERF_RECORD_MISC_USER, addr, &al)) {
                /*
                 * We've seen cases (softice) where DWARF unwinder went
                 * through non executable mmaps, which we need to lookup
index 0007c64f322046d310bceb7f81e4294535672855..4662590ef09152c998f24f479e3ab9efc316f8ac 100644 (file)
@@ -367,8 +367,7 @@ static struct map *find_map(unw_word_t ip, struct unwind_info *ui)
 {
        struct addr_location al;
 
-       thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al);
-       if (!al.map) {
+       if (!thread__find_map(ui->thread, PERF_RECORD_MISC_USER, ip, &al)) {
                /*
                 * We've seen cases (softice) where DWARF unwinder went
                 * through non executable mmaps, which we need to lookup