Skip to content

Commit

Permalink
perf maps: Add functions to access maps
Browse files Browse the repository at this point in the history
Introduce functions to access struct maps. These functions reduce the
number of places reference counting is necessary. While tidying APIs do
some small const-ification, in particlar to unwind_libunwind_ops.

Committer notes:

Fixed up tools/perf/util/unwind-libunwind.c:

-               return ops->get_entries(cb, arg, thread, data, max_stack);
+               return ops->get_entries(cb, arg, thread, data, max_stack, best_effort);

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Miaoqian Lin <linmq006@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
Cc: Song Liu <song@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Yury Norov <yury.norov@gmail.com>
Link: https://lore.kernel.org/r/20230320212248.1175731-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Ian Rogers authored and Arnaldo Carvalho de Melo committed Apr 4, 2023
1 parent ff583dc commit 5ab6d71
Show file tree
Hide file tree
Showing 20 changed files with 175 additions and 111 deletions.
7 changes: 4 additions & 3 deletions tools/perf/scripts/python/Perf-Trace-Util/Context.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ static PyObject *perf_sample_insn(PyObject *obj, PyObject *args)
if (!c)
return NULL;

if (c->sample->ip && !c->sample->insn_len &&
c->al->thread->maps && c->al->thread->maps->machine)
script_fetch_insn(c->sample, c->al->thread, c->al->thread->maps->machine);
if (c->sample->ip && !c->sample->insn_len && c->al->thread->maps) {
struct machine *machine = maps__machine(c->al->thread->maps);

script_fetch_insn(c->sample, c->al->thread, machine);
}
if (!c->sample->insn_len)
Py_RETURN_NONE; /* N.B. This is a return statement */

Expand Down
2 changes: 1 addition & 1 deletion tools/perf/tests/code-reading.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
len = al.map->end - addr;

/* Read the object code using perf */
ret_len = dso__data_read_offset(al.map->dso, thread->maps->machine,
ret_len = dso__data_read_offset(al.map->dso, maps__machine(thread->maps),
al.addr, buf1, len);
if (ret_len != len) {
pr_debug("dso__data_read_offset failed\n");
Expand Down
3 changes: 2 additions & 1 deletion tools/perf/ui/browsers/hists.c
Original file line number Diff line number Diff line change
Expand Up @@ -3139,7 +3139,8 @@ static int evsel__hists_browse(struct evsel *evsel, int nr_events, const char *h
continue;
case 'k':
if (browser->selection != NULL)
hists_browser__zoom_map(browser, browser->selection->maps->machine->vmlinux_map);
hists_browser__zoom_map(browser,
maps__machine(browser->selection->maps)->vmlinux_map);
continue;
case 'V':
verbose = (verbose + 1) % 4;
Expand Down
9 changes: 5 additions & 4 deletions tools/perf/util/callchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,8 @@ int hist_entry__append_callchain(struct hist_entry *he, struct perf_sample *samp
int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *node,
bool hide_unresolved)
{
struct machine *machine = maps__machine(node->ms.maps);

al->maps = node->ms.maps;
al->map = node->ms.map;
al->sym = node->ms.sym;
Expand All @@ -1124,17 +1126,16 @@ int fill_callchain_info(struct addr_location *al, struct callchain_cursor_node *
if (al->map == NULL)
goto out;
}

if (al->maps == machine__kernel_maps(al->maps->machine)) {
if (machine__is_host(al->maps->machine)) {
if (al->maps == machine__kernel_maps(machine)) {
if (machine__is_host(machine)) {
al->cpumode = PERF_RECORD_MISC_KERNEL;
al->level = 'k';
} else {
al->cpumode = PERF_RECORD_MISC_GUEST_KERNEL;
al->level = 'g';
}
} else {
if (machine__is_host(al->maps->machine)) {
if (machine__is_host(machine)) {
al->cpumode = PERF_RECORD_MISC_USER;
al->level = '.';
} else if (perf_guest) {
Expand Down
12 changes: 7 additions & 5 deletions tools/perf/util/db-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static int db_ids_from_al(struct db_export *dbe, struct addr_location *al,
if (al->map) {
struct dso *dso = al->map->dso;

err = db_export__dso(dbe, dso, al->maps->machine);
err = db_export__dso(dbe, dso, maps__machine(al->maps));
if (err)
return err;
*dso_db_id = dso->db_id;
Expand Down Expand Up @@ -354,19 +354,21 @@ int db_export__sample(struct db_export *dbe, union perf_event *event,
};
struct thread *main_thread;
struct comm *comm = NULL;
struct machine *machine;
int err;

err = db_export__evsel(dbe, evsel);
if (err)
return err;

err = db_export__machine(dbe, al->maps->machine);
machine = maps__machine(al->maps);
err = db_export__machine(dbe, machine);
if (err)
return err;

main_thread = thread__main_thread(al->maps->machine, thread);
main_thread = thread__main_thread(machine, thread);

err = db_export__threads(dbe, thread, main_thread, al->maps->machine, &comm);
err = db_export__threads(dbe, thread, main_thread, machine, &comm);
if (err)
goto out_put;

Expand All @@ -380,7 +382,7 @@ int db_export__sample(struct db_export *dbe, union perf_event *event,
goto out_put;

if (dbe->cpr) {
struct call_path *cp = call_path_from_sample(dbe, al->maps->machine,
struct call_path *cp = call_path_from_sample(dbe, machine,
thread, sample,
evsel);
if (cp) {
Expand Down
8 changes: 6 additions & 2 deletions tools/perf/util/dlfilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,12 @@ static const __u8 *dlfilter__insn(void *ctx, __u32 *len)
if (!al->thread && machine__resolve(d->machine, al, d->sample) < 0)
return NULL;

if (al->thread->maps && al->thread->maps->machine)
script_fetch_insn(d->sample, al->thread, al->thread->maps->machine);
if (al->thread->maps) {
struct machine *machine = maps__machine(al->thread->maps);

if (machine)
script_fetch_insn(d->sample, al->thread, machine);
}
}

if (!d->sample->insn_len)
Expand Down
4 changes: 2 additions & 2 deletions tools/perf/util/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
struct addr_location *al)
{
struct maps *maps = thread->maps;
struct machine *machine = maps->machine;
struct machine *machine = maps__machine(maps);
bool load_map = false;

al->maps = maps;
Expand Down Expand Up @@ -637,7 +637,7 @@ struct map *thread__find_map_fb(struct thread *thread, u8 cpumode, u64 addr,
struct addr_location *al)
{
struct map *map = thread__find_map(thread, cpumode, addr, al);
struct machine *machine = thread->maps->machine;
struct machine *machine = maps__machine(thread->maps);
u8 addr_cpumode = machine__addr_cpumode(machine, cpumode, addr);

if (map || addr_cpumode == cpumode)
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)

if (h->cgroup) {
const char *cgrp_name = "unknown";
struct cgroup *cgrp = cgroup__find(h->ms.maps->machine->env,
struct cgroup *cgrp = cgroup__find(maps__machine(h->ms.maps)->env,
h->cgroup);
if (cgrp != NULL)
cgrp_name = cgrp->name;
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/util/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -2847,7 +2847,7 @@ static int find_prev_cpumode(struct ip_callchain *chain, struct thread *thread,
static u64 get_leaf_frame_caller(struct perf_sample *sample,
struct thread *thread, int usr_idx)
{
if (machine__normalized_is(thread->maps->machine, "arm64"))
if (machine__normalized_is(maps__machine(thread->maps), "arm64"))
return get_leaf_frame_caller_aarch64(sample, thread, usr_idx);
else
return 0;
Expand Down
14 changes: 9 additions & 5 deletions tools/perf/util/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ bool __map__is_kernel(const struct map *map)
{
if (!map->dso->kernel)
return false;
return machine__kernel_map(map__kmaps((struct map *)map)->machine) == map;
return machine__kernel_map(maps__machine(map__kmaps((struct map *)map))) == map;
}

bool __map__is_extra_kernel_map(const struct map *map)
Expand Down Expand Up @@ -475,11 +475,15 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
* kcore may not either. However the trampoline object code is on the
* main kernel map, so just use that instead.
*/
if (kmap && is_entry_trampoline(kmap->name) && kmap->kmaps && kmap->kmaps->machine) {
struct map *kernel_map = machine__kernel_map(kmap->kmaps->machine);
if (kmap && is_entry_trampoline(kmap->name) && kmap->kmaps) {
struct machine *machine = maps__machine(kmap->kmaps);

if (kernel_map)
map = kernel_map;
if (machine) {
struct map *kernel_map = machine__kernel_map(machine);

if (kernel_map)
map = kernel_map;
}
}

if (!map->dso->adjust_symbols)
Expand Down
Loading

0 comments on commit 5ab6d71

Please sign in to comment.