summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/symbol.c
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2023-03-20 22:22:34 +0100
committerArnaldo Carvalho de Melo <acme@redhat.com>2023-04-04 20:45:38 +0200
commit5ab6d715c32f6249415bcd1972bae7e6c03636f0 (patch)
tree394ea751300b775feaa8922680314e69a34acdde /tools/perf/util/symbol.c
parentperf maps: Remove rb_node from struct map (diff)
downloadlinux-5ab6d715c32f6249415bcd1972bae7e6c03636f0.tar.xz
linux-5ab6d715c32f6249415bcd1972bae7e6c03636f0.zip
perf maps: Add functions to access maps
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>
Diffstat (limited to 'tools/perf/util/symbol.c')
-rw-r--r--tools/perf/util/symbol.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index e7a8ae290c57..316b63fb5691 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -275,7 +275,7 @@ void maps__fixup_end(struct maps *maps)
{
struct map_rb_node *prev = NULL, *curr;
- down_write(&maps->lock);
+ down_write(maps__lock(maps));
maps__for_each_entry(maps, curr) {
if (prev != NULL && !prev->map->end)
@@ -291,7 +291,7 @@ void maps__fixup_end(struct maps *maps)
if (curr && !curr->map->end)
curr->map->end = ~0ULL;
- up_write(&maps->lock);
+ up_write(maps__lock(maps));
}
struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const char *name)
@@ -844,7 +844,7 @@ static int maps__split_kallsyms(struct maps *kmaps, struct dso *dso, u64 delta,
if (!kmaps)
return -1;
- machine = kmaps->machine;
+ machine = maps__machine(kmaps);
x86_64 = machine__is(machine, "x86_64");
@@ -968,7 +968,7 @@ discard_symbol:
if (curr_map != initial_map &&
dso->kernel == DSO_SPACE__KERNEL_GUEST &&
- machine__is_default_guest(kmaps->machine)) {
+ machine__is_default_guest(maps__machine(kmaps))) {
dso__set_loaded(curr_map->dso);
}
@@ -1365,7 +1365,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
if (!kmaps)
return -EINVAL;
- machine = kmaps->machine;
+ machine = maps__machine(kmaps);
/* This function requires that the map is the kernel map */
if (!__map__is_kernel(map))
@@ -1894,7 +1894,7 @@ int dso__load(struct dso *dso, struct map *map)
else if (dso->kernel == DSO_SPACE__KERNEL_GUEST)
ret = dso__load_guest_kernel_sym(dso, map);
- machine = map__kmaps(map)->machine;
+ machine = maps__machine(map__kmaps(map));
if (machine__is(machine, "x86_64"))
machine__map_x86_64_entry_trampolines(machine, dso);
goto out;
@@ -2059,32 +2059,32 @@ static int map__strcmp_name(const void *name, const void *b)
void __maps__sort_by_name(struct maps *maps)
{
- qsort(maps->maps_by_name, maps->nr_maps, sizeof(struct map *), map__strcmp);
+ qsort(maps__maps_by_name(maps), maps__nr_maps(maps), sizeof(struct map *), map__strcmp);
}
static int map__groups__sort_by_name_from_rbtree(struct maps *maps)
{
struct map_rb_node *rb_node;
- struct map **maps_by_name = realloc(maps->maps_by_name,
- maps->nr_maps * sizeof(struct map *));
+ struct map **maps_by_name = realloc(maps__maps_by_name(maps),
+ maps__nr_maps(maps) * sizeof(struct map *));
int i = 0;
if (maps_by_name == NULL)
return -1;
- up_read(&maps->lock);
- down_write(&maps->lock);
+ up_read(maps__lock(maps));
+ down_write(maps__lock(maps));
maps->maps_by_name = maps_by_name;
- maps->nr_maps_allocated = maps->nr_maps;
+ maps->nr_maps_allocated = maps__nr_maps(maps);
maps__for_each_entry(maps, rb_node)
maps_by_name[i++] = rb_node->map;
__maps__sort_by_name(maps);
- up_write(&maps->lock);
- down_read(&maps->lock);
+ up_write(maps__lock(maps));
+ down_read(maps__lock(maps));
return 0;
}
@@ -2093,11 +2093,12 @@ static struct map *__maps__find_by_name(struct maps *maps, const char *name)
{
struct map **mapp;
- if (maps->maps_by_name == NULL &&
+ if (maps__maps_by_name(maps) == NULL &&
map__groups__sort_by_name_from_rbtree(maps))
return NULL;
- mapp = bsearch(name, maps->maps_by_name, maps->nr_maps, sizeof(*mapp), map__strcmp_name);
+ mapp = bsearch(name, maps__maps_by_name(maps), maps__nr_maps(maps),
+ sizeof(*mapp), map__strcmp_name);
if (mapp)
return *mapp;
return NULL;
@@ -2108,9 +2109,10 @@ struct map *maps__find_by_name(struct maps *maps, const char *name)
struct map_rb_node *rb_node;
struct map *map;
- down_read(&maps->lock);
+ down_read(maps__lock(maps));
- if (maps->last_search_by_name && strcmp(maps->last_search_by_name->dso->short_name, name) == 0) {
+ if (maps->last_search_by_name &&
+ strcmp(maps->last_search_by_name->dso->short_name, name) == 0) {
map = maps->last_search_by_name;
goto out_unlock;
}
@@ -2120,7 +2122,7 @@ struct map *maps__find_by_name(struct maps *maps, const char *name)
* made.
*/
map = __maps__find_by_name(maps, name);
- if (map || maps->maps_by_name != NULL)
+ if (map || maps__maps_by_name(maps) != NULL)
goto out_unlock;
/* Fallback to traversing the rbtree... */
@@ -2134,7 +2136,7 @@ struct map *maps__find_by_name(struct maps *maps, const char *name)
map = NULL;
out_unlock:
- up_read(&maps->lock);
+ up_read(maps__lock(maps));
return map;
}
@@ -2386,7 +2388,7 @@ static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map)
{
int err;
const char *kallsyms_filename;
- struct machine *machine = map__kmaps(map)->machine;
+ struct machine *machine = maps__machine(map__kmaps(map));
char path[PATH_MAX];
if (machine->kallsyms_filename) {