summaryrefslogtreecommitdiffstats
path: root/tools/perf/tests
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2024-05-04 23:38:01 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2024-05-06 20:28:49 +0200
commitee756ef7491eafd70f390343a1d90930af125a51 (patch)
treeac5e5aa5fed83cbc7db80a77e67b2045b14122de /tools/perf/tests
parentperf dsos: Switch hand crafted code to bsearch() (diff)
downloadlinux-ee756ef7491eafd70f390343a1d90930af125a51.tar.xz
linux-ee756ef7491eafd70f390343a1d90930af125a51.zip
perf dso: Add reference count checking and accessor functions
Add reference count checking to struct dso, this can help with implementing correct reference counting discipline. To avoid RC_CHK_ACCESS everywhere, add accessor functions for the variables in struct dso. The majority of the change is mechanical in nature and not easy to split up. Committer testing: 'perf test' up to this patch shows no regressions. But: util/symbol.c: In function ‘dso__load_bfd_symbols’: util/symbol.c:1683:9: error: too few arguments to function ‘dso__set_adjust_symbols’ 1683 | dso__set_adjust_symbols(dso); | ^~~~~~~~~~~~~~~~~~~~~~~ In file included from util/symbol.c:21: util/dso.h:268:20: note: declared here 268 | static inline void dso__set_adjust_symbols(struct dso *dso, bool val) | ^~~~~~~~~~~~~~~~~~~~~~~ make[6]: *** [/home/acme/git/perf-tools-next/tools/build/Makefile.build:106: /tmp/tmp.ZWHbQftdN6/util/symbol.o] Error 1 MKDIR /tmp/tmp.ZWHbQftdN6/tests/workloads/ make[6]: *** Waiting for unfinished jobs.... This was updated: - symbols__fixup_end(&dso->symbols, false); - symbols__fixup_duplicate(&dso->symbols); - dso->adjust_symbols = 1; + symbols__fixup_end(dso__symbols(dso), false); + symbols__fixup_duplicate(dso__symbols(dso)); + dso__set_adjust_symbols(dso); But not build tested with BUILD_NONDISTRO and libbfd devel files installed (binutils-devel on fedora). Add the missing argument: symbols__fixup_end(dso__symbols(dso), false); symbols__fixup_duplicate(dso__symbols(dso)); - dso__set_adjust_symbols(dso); + dso__set_adjust_symbols(dso, true); Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Ben Gainey <ben.gainey@arm.com> Cc: Changbin Du <changbin.du@huawei.com> Cc: Chengen Du <chengen.du@canonical.com> Cc: Colin Ian King <colin.i.king@gmail.com> Cc: Dima Kogan <dima@secretsauce.net> Cc: Ilkka Koskinen <ilkka@os.amperecomputing.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: K Prateek Nayak <kprateek.nayak@amd.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linux.dev> Cc: Li Dong <lidong@vivo.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paran Lee <p4ranlee@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Song Liu <song@kernel.org> Cc: Sun Haiyong <sunhaiyong@loongson.cn> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Tiezhu Yang <yangtiezhu@loongson.cn> Cc: Yanteng Si <siyanteng@loongson.cn> Cc: zhaimingbing <zhaimingbing@cmss.chinamobile.com> Link: https://lore.kernel.org/r/20240504213803.218974-6-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/tests')
-rw-r--r--tools/perf/tests/code-reading.c8
-rw-r--r--tools/perf/tests/dso-data.c11
-rw-r--r--tools/perf/tests/hists_common.c6
-rw-r--r--tools/perf/tests/hists_cumulate.c4
-rw-r--r--tools/perf/tests/hists_output.c2
-rw-r--r--tools/perf/tests/maps.c4
-rw-r--r--tools/perf/tests/symbols.c8
-rw-r--r--tools/perf/tests/vmlinux-kallsyms.c6
8 files changed, 25 insertions, 24 deletions
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 29d2f3ee4e10..27c82cfb7e7d 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -253,9 +253,9 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
goto out;
}
dso = map__dso(al.map);
- pr_debug("File is: %s\n", dso->long_name);
+ pr_debug("File is: %s\n", dso__long_name(dso));
- if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore(dso)) {
+ if (dso__symtab_type(dso) == DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore(dso)) {
pr_debug("Unexpected kernel address - skipping\n");
goto out;
}
@@ -274,7 +274,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
* modules to manage long jumps. Check if the ip offset falls in stubs
* sections for kernel modules. And skip module address after text end
*/
- if (dso->is_kmod && al.addr > dso->text_end) {
+ if (dso__is_kmod(dso) && al.addr > dso__text_end(dso)) {
pr_debug("skipping the module address %#"PRIx64" after text end\n", al.addr);
goto out;
}
@@ -315,7 +315,7 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
state->done[state->done_cnt++] = map__start(al.map);
}
- objdump_name = dso->long_name;
+ objdump_name = dso__long_name(dso);
if (dso__needs_decompress(dso)) {
if (dso__decompress_kmodule_path(dso, objdump_name,
decomp_name,
diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c
index 2d67422c1222..fde4eca84b6f 100644
--- a/tools/perf/tests/dso-data.c
+++ b/tools/perf/tests/dso-data.c
@@ -228,7 +228,8 @@ static void dsos__delete(int cnt)
for (i = 0; i < cnt; i++) {
struct dso *dso = dsos[i];
- unlink(dso->name);
+ dso__data_close(dso);
+ unlink(dso__name(dso));
dso__put(dso);
}
@@ -289,14 +290,14 @@ static int test__dso_data_cache(struct test_suite *test __maybe_unused, int subt
}
/* verify the first one is already open */
- TEST_ASSERT_VAL("dsos[0] is not open", dsos[0]->data.fd != -1);
+ TEST_ASSERT_VAL("dsos[0] is not open", dso__data(dsos[0])->fd != -1);
/* open +1 dso to reach the allowed limit */
fd = dso__data_fd(dsos[i], &machine);
TEST_ASSERT_VAL("failed to get fd", fd > 0);
/* should force the first one to be closed */
- TEST_ASSERT_VAL("failed to close dsos[0]", dsos[0]->data.fd == -1);
+ TEST_ASSERT_VAL("failed to close dsos[0]", dso__data(dsos[0])->fd == -1);
/* cleanup everything */
dsos__delete(dso_cnt);
@@ -371,7 +372,7 @@ static int test__dso_data_reopen(struct test_suite *test __maybe_unused, int sub
* dso_0 should get closed, because we reached
* the file descriptor limit
*/
- TEST_ASSERT_VAL("failed to close dso_0", dso_0->data.fd == -1);
+ TEST_ASSERT_VAL("failed to close dso_0", dso__data(dso_0)->fd == -1);
/* open dso_0 */
fd = dso__data_fd(dso_0, &machine);
@@ -381,7 +382,7 @@ static int test__dso_data_reopen(struct test_suite *test __maybe_unused, int sub
* dso_1 should get closed, because we reached
* the file descriptor limit
*/
- TEST_ASSERT_VAL("failed to close dso_1", dso_1->data.fd == -1);
+ TEST_ASSERT_VAL("failed to close dso_1", dso__data(dso_1)->fd == -1);
/* cleanup everything */
close(fd_extra);
diff --git a/tools/perf/tests/hists_common.c b/tools/perf/tests/hists_common.c
index d08add0f4da6..187f12f5bc21 100644
--- a/tools/perf/tests/hists_common.c
+++ b/tools/perf/tests/hists_common.c
@@ -146,7 +146,7 @@ struct machine *setup_fake_machine(struct machines *machines)
goto out;
}
- symbols__insert(&dso->symbols, sym);
+ symbols__insert(dso__symbols(dso), sym);
}
dso__put(dso);
@@ -183,7 +183,7 @@ void print_hists_in(struct hists *hists)
pr_info("%2d: entry: %-8s [%-8s] %20s: period = %"PRIu64"\n",
i, thread__comm_str(he->thread),
- dso->short_name,
+ dso__short_name(dso),
he->ms.sym->name, he->stat.period);
}
@@ -212,7 +212,7 @@ void print_hists_out(struct hists *hists)
pr_info("%2d: entry: %8s:%5d [%-8s] %20s: period = %"PRIu64"/%"PRIu64"\n",
i, thread__comm_str(he->thread), thread__tid(he->thread),
- dso->short_name,
+ dso__short_name(dso),
he->ms.sym->name, he->stat.period,
he->stat_acc ? he->stat_acc->period : 0);
}
diff --git a/tools/perf/tests/hists_cumulate.c b/tools/perf/tests/hists_cumulate.c
index 71dacb0fec4d..1e0f5a310fd5 100644
--- a/tools/perf/tests/hists_cumulate.c
+++ b/tools/perf/tests/hists_cumulate.c
@@ -164,11 +164,11 @@ static void put_fake_samples(void)
typedef int (*test_fn_t)(struct evsel *, struct machine *);
#define COMM(he) (thread__comm_str(he->thread))
-#define DSO(he) (map__dso(he->ms.map)->short_name)
+#define DSO(he) (dso__short_name(map__dso(he->ms.map)))
#define SYM(he) (he->ms.sym->name)
#define CPU(he) (he->cpu)
#define DEPTH(he) (he->callchain->max_depth)
-#define CDSO(cl) (map__dso(cl->ms.map)->short_name)
+#define CDSO(cl) (dso__short_name(map__dso(cl->ms.map)))
#define CSYM(cl) (cl->ms.sym->name)
struct result {
diff --git a/tools/perf/tests/hists_output.c b/tools/perf/tests/hists_output.c
index ba1cccf57049..33b5cc8352a7 100644
--- a/tools/perf/tests/hists_output.c
+++ b/tools/perf/tests/hists_output.c
@@ -129,7 +129,7 @@ static void put_fake_samples(void)
typedef int (*test_fn_t)(struct evsel *, struct machine *);
#define COMM(he) (thread__comm_str(he->thread))
-#define DSO(he) (map__dso(he->ms.map)->short_name)
+#define DSO(he) (dso__short_name(map__dso(he->ms.map)))
#define SYM(he) (he->ms.sym->name)
#define CPU(he) (he->cpu)
#define PID(he) (thread__tid(he->thread))
diff --git a/tools/perf/tests/maps.c b/tools/perf/tests/maps.c
index b15417a0d617..4f1f9385ea9c 100644
--- a/tools/perf/tests/maps.c
+++ b/tools/perf/tests/maps.c
@@ -26,7 +26,7 @@ static int check_maps_cb(struct map *map, void *data)
if (map__start(map) != merged->start ||
map__end(map) != merged->end ||
- strcmp(map__dso(map)->name, merged->name) ||
+ strcmp(dso__name(map__dso(map)), merged->name) ||
refcount_read(map__refcnt(map)) != 1) {
return 1;
}
@@ -39,7 +39,7 @@ static int failed_cb(struct map *map, void *data __maybe_unused)
pr_debug("\tstart: %" PRIu64 " end: %" PRIu64 " name: '%s' refcnt: %d\n",
map__start(map),
map__end(map),
- map__dso(map)->name,
+ dso__name(map__dso(map)),
refcount_read(map__refcnt(map)));
return 0;
diff --git a/tools/perf/tests/symbols.c b/tools/perf/tests/symbols.c
index d208105919ed..ee20a366f32f 100644
--- a/tools/perf/tests/symbols.c
+++ b/tools/perf/tests/symbols.c
@@ -81,7 +81,7 @@ static int create_map(struct test_info *ti, char *filename, struct map **map_p)
* If 'filename' matches a current kernel module, must use a kernel
* map. Find the one that already exists.
*/
- if (dso && dso->kernel) {
+ if (dso && dso__kernel(dso) != DSO_SPACE__USER) {
*map_p = find_module_map(ti->machine, dso);
dso__put(dso);
if (!*map_p) {
@@ -116,7 +116,7 @@ static int test_dso(struct dso *dso)
if (verbose > 1)
dso__fprintf(dso, stderr);
- for (nd = rb_first_cached(&dso->symbols); nd; nd = rb_next(nd)) {
+ for (nd = rb_first_cached(dso__symbols(dso)); nd; nd = rb_next(nd)) {
struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
if (sym->type != STT_FUNC && sym->type != STT_GNU_IFUNC)
@@ -145,7 +145,7 @@ static int subdivided_dso_cb(struct dso *dso, struct machine *machine __maybe_un
{
struct dso *text_dso = d;
- if (dso != text_dso && strstarts(dso->short_name, text_dso->short_name))
+ if (dso != text_dso && strstarts(dso__short_name(dso), dso__short_name(text_dso)))
if (test_dso(dso) != TEST_OK)
return -1;
@@ -190,7 +190,7 @@ static int test_file(struct test_info *ti, char *filename)
ret = test_dso(dso);
/* Module dso is split into many dsos by section */
- if (ret == TEST_OK && dso->kernel)
+ if (ret == TEST_OK && dso__kernel(dso) != DSO_SPACE__USER)
ret = process_subdivided_dso(ti->machine, dso);
out_put:
map__put(map);
diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c
index fecbf851bb2e..e30fd55f8e51 100644
--- a/tools/perf/tests/vmlinux-kallsyms.c
+++ b/tools/perf/tests/vmlinux-kallsyms.c
@@ -129,7 +129,7 @@ static int test__vmlinux_matches_kallsyms_cb1(struct map *map, void *data)
* cases.
*/
struct map *pair = maps__find_by_name(args->kallsyms.kmaps,
- (dso->kernel ? dso->short_name : dso->name));
+ (dso__kernel(dso) ? dso__short_name(dso) : dso__name(dso)));
if (pair) {
map__set_priv(pair, 1);
@@ -162,11 +162,11 @@ static int test__vmlinux_matches_kallsyms_cb2(struct map *map, void *data)
}
pr_info("WARN: %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s in kallsyms as",
- map__start(map), map__end(map), map__pgoff(map), dso->name);
+ map__start(map), map__end(map), map__pgoff(map), dso__name(dso));
if (mem_end != map__end(pair))
pr_info(":\nWARN: *%" PRIx64 "-%" PRIx64 " %" PRIx64,
map__start(pair), map__end(pair), map__pgoff(pair));
- pr_info(" %s\n", dso->name);
+ pr_info(" %s\n", dso__name(dso));
map__set_priv(pair, 1);
}
map__put(pair);