summaryrefslogtreecommitdiff
path: root/tools/perf/util/map.c
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2023-03-20 14:22:35 -0700
committerArnaldo Carvalho de Melo <acme@redhat.com>2023-04-04 16:41:57 -0300
commit63df0e4bc368adbd12ed70ed4789d8d52d65661d (patch)
tree8d023dd3ba21bc4306f672aa2c0b5c8b7866959e /tools/perf/util/map.c
parent5ab6d715c32f6249415bcd1972bae7e6c03636f0 (diff)
perf map: Add accessor for dso
Later changes will add reference count checking for struct map, with dso being the most frequently accessed variable. Add an accessor so that the reference count check is only necessary in one place. Additional changes: - add a dso variable to avoid repeated map__dso calls. - in builtin-mem.c dump_raw_samples, code only partially tested for dso == NULL. Make the possibility of NULL consistent. - in thread.c thread__memcpy fix use of spaces and use tabs. Committer notes: Did missing conversions on these files: tools/perf/arch/powerpc/util/skip-callchain-idx.c tools/perf/arch/powerpc/util/sym-handling.c tools/perf/ui/browsers/hists.c tools/perf/ui/gtk/annotate.c tools/perf/util/cs-etm.c tools/perf/util/thread.c tools/perf/util/unwind-libunwind-local.c tools/perf/util/unwind-libunwind.c 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>
Diffstat (limited to 'tools/perf/util/map.c')
-rw-r--r--tools/perf/util/map.c96
1 files changed, 60 insertions, 36 deletions
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index a99dbde656a2..90062af6675a 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -232,7 +232,7 @@ struct map *map__new2(u64 start, struct dso *dso)
bool __map__is_kernel(const struct map *map)
{
- if (!map->dso->kernel)
+ if (!map__dso(map)->kernel)
return false;
return machine__kernel_map(maps__machine(map__kmaps((struct map *)map))) == map;
}
@@ -247,8 +247,9 @@ bool __map__is_extra_kernel_map(const struct map *map)
bool __map__is_bpf_prog(const struct map *map)
{
const char *name;
+ struct dso *dso = map__dso(map);
- if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
+ if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
return true;
/*
@@ -256,15 +257,16 @@ bool __map__is_bpf_prog(const struct map *map)
* type of DSO_BINARY_TYPE__BPF_PROG_INFO. In such cases, we can
* guess the type based on name.
*/
- name = map->dso->short_name;
+ name = dso->short_name;
return name && (strstr(name, "bpf_prog_") == name);
}
bool __map__is_bpf_image(const struct map *map)
{
const char *name;
+ struct dso *dso = map__dso(map);
- if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
+ if (dso->binary_type == DSO_BINARY_TYPE__BPF_IMAGE)
return true;
/*
@@ -272,18 +274,20 @@ bool __map__is_bpf_image(const struct map *map)
* type of DSO_BINARY_TYPE__BPF_IMAGE. In such cases, we can
* guess the type based on name.
*/
- name = map->dso->short_name;
+ name = dso->short_name;
return name && is_bpf_image(name);
}
bool __map__is_ool(const struct map *map)
{
- return map->dso && map->dso->binary_type == DSO_BINARY_TYPE__OOL;
+ const struct dso *dso = map__dso(map);
+
+ return dso && dso->binary_type == DSO_BINARY_TYPE__OOL;
}
bool map__has_symbols(const struct map *map)
{
- return dso__has_symbols(map->dso);
+ return dso__has_symbols(map__dso(map));
}
static void map__exit(struct map *map)
@@ -306,18 +310,23 @@ void map__put(struct map *map)
void map__fixup_start(struct map *map)
{
- struct rb_root_cached *symbols = &map->dso->symbols;
+ struct dso *dso = map__dso(map);
+ struct rb_root_cached *symbols = &dso->symbols;
struct rb_node *nd = rb_first_cached(symbols);
+
if (nd != NULL) {
struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
+
map->start = sym->start;
}
}
void map__fixup_end(struct map *map)
{
- struct rb_root_cached *symbols = &map->dso->symbols;
+ struct dso *dso = map__dso(map);
+ struct rb_root_cached *symbols = &dso->symbols;
struct rb_node *nd = rb_last(&symbols->rb_root);
+
if (nd != NULL) {
struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
map->end = sym->end;
@@ -328,18 +337,19 @@ void map__fixup_end(struct map *map)
int map__load(struct map *map)
{
- const char *name = map->dso->long_name;
+ struct dso *dso = map__dso(map);
+ const char *name = dso->long_name;
int nr;
- if (dso__loaded(map->dso))
+ if (dso__loaded(dso))
return 0;
- nr = dso__load(map->dso, map);
+ nr = dso__load(dso, map);
if (nr < 0) {
- if (map->dso->has_build_id) {
+ if (dso->has_build_id) {
char sbuild_id[SBUILD_ID_SIZE];
- build_id__sprintf(&map->dso->bid, sbuild_id);
+ build_id__sprintf(&dso->bid, sbuild_id);
pr_debug("%s with build id %s not found", name, sbuild_id);
} else
pr_debug("Failed to open %s", name);
@@ -371,32 +381,36 @@ struct symbol *map__find_symbol(struct map *map, u64 addr)
if (map__load(map) < 0)
return NULL;
- return dso__find_symbol(map->dso, addr);
+ return dso__find_symbol(map__dso(map), addr);
}
struct symbol *map__find_symbol_by_name(struct map *map, const char *name)
{
+ struct dso *dso;
+
if (map__load(map) < 0)
return NULL;
- if (!dso__sorted_by_name(map->dso))
- dso__sort_by_name(map->dso);
+ dso = map__dso(map);
+ if (!dso__sorted_by_name(dso))
+ dso__sort_by_name(dso);
- return dso__find_symbol_by_name(map->dso, name);
+ return dso__find_symbol_by_name(dso, name);
}
struct map *map__clone(struct map *from)
{
size_t size = sizeof(struct map);
struct map *map;
+ struct dso *dso = map__dso(from);
- if (from->dso && from->dso->kernel)
+ if (dso && dso->kernel)
size += sizeof(struct kmap);
map = memdup(from, size);
if (map != NULL) {
refcount_set(&map->refcnt, 1);
- dso__get(map->dso);
+ dso__get(dso);
}
return map;
@@ -404,20 +418,23 @@ struct map *map__clone(struct map *from)
size_t map__fprintf(struct map *map, FILE *fp)
{
+ const struct dso *dso = map__dso(map);
+
return fprintf(fp, " %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s\n",
- map->start, map->end, map->pgoff, map->dso->name);
+ map->start, map->end, map->pgoff, dso->name);
}
size_t map__fprintf_dsoname(struct map *map, FILE *fp)
{
char buf[symbol_conf.pad_output_len_dso + 1];
const char *dsoname = "[unknown]";
+ const struct dso *dso = map ? map__dso(map) : NULL;
- if (map && map->dso) {
- if (symbol_conf.show_kernel_path && map->dso->long_name)
- dsoname = map->dso->long_name;
+ if (dso) {
+ if (symbol_conf.show_kernel_path && dso->long_name)
+ dsoname = dso->long_name;
else
- dsoname = map->dso->name;
+ dsoname = dso->name;
}
if (symbol_conf.pad_output_len_dso) {
@@ -432,15 +449,17 @@ char *map__srcline(struct map *map, u64 addr, struct symbol *sym)
{
if (map == NULL)
return SRCLINE_UNKNOWN;
- return get_srcline(map->dso, map__rip_2objdump(map, addr), sym, true, true, addr);
+
+ return get_srcline(map__dso(map), map__rip_2objdump(map, addr), sym, true, true, addr);
}
int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
FILE *fp)
{
+ const struct dso *dso = map ? map__dso(map) : NULL;
int ret = 0;
- if (map && map->dso) {
+ if (dso) {
char *srcline = map__srcline(map, addr, NULL);
if (strncmp(srcline, SRCLINE_UNKNOWN, strlen(SRCLINE_UNKNOWN)) != 0)
ret = fprintf(fp, "%s%s", prefix, srcline);
@@ -469,6 +488,7 @@ void srccode_state_free(struct srccode_state *state)
u64 map__rip_2objdump(struct map *map, u64 rip)
{
struct kmap *kmap = __map__kmap(map);
+ const struct dso *dso = map__dso(map);
/*
* vmlinux does not have program headers for PTI entry trampolines and
@@ -486,18 +506,18 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
}
}
- if (!map->dso->adjust_symbols)
+ if (!dso->adjust_symbols)
return rip;
- if (map->dso->rel)
+ if (dso->rel)
return rip - map->pgoff;
/*
* kernel modules also have DSO_TYPE_USER in dso->kernel,
* but all kernel modules are ET_REL, so won't get here.
*/
- if (map->dso->kernel == DSO_SPACE__USER)
- return rip + map->dso->text_offset;
+ if (dso->kernel == DSO_SPACE__USER)
+ return rip + dso->text_offset;
return map->unmap_ip(map, rip) - map->reloc;
}
@@ -516,18 +536,20 @@ u64 map__rip_2objdump(struct map *map, u64 rip)
*/
u64 map__objdump_2mem(struct map *map, u64 ip)
{
- if (!map->dso->adjust_symbols)
+ const struct dso *dso = map__dso(map);
+
+ if (!dso->adjust_symbols)
return map->unmap_ip(map, ip);
- if (map->dso->rel)
+ if (dso->rel)
return map->unmap_ip(map, ip + map->pgoff);
/*
* kernel modules also have DSO_TYPE_USER in dso->kernel,
* but all kernel modules are ET_REL, so won't get here.
*/
- if (map->dso->kernel == DSO_SPACE__USER)
- return map->unmap_ip(map, ip - map->dso->text_offset);
+ if (dso->kernel == DSO_SPACE__USER)
+ return map->unmap_ip(map, ip - dso->text_offset);
return ip + map->reloc;
}
@@ -541,7 +563,9 @@ bool map__contains_symbol(const struct map *map, const struct symbol *sym)
struct kmap *__map__kmap(struct map *map)
{
- if (!map->dso || !map->dso->kernel)
+ const struct dso *dso = map__dso(map);
+
+ if (!dso || !dso->kernel)
return NULL;
return (struct kmap *)(map + 1);
}