Skip to content

Commit ee756ef

Browse files
captain5050acmel
authored andcommitted
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>
1 parent 7a9418c commit ee756ef

57 files changed

Lines changed: 1169 additions & 739 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tools/perf/builtin-annotate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static int process_branch_callback(struct evsel *evsel,
219219
}
220220

221221
if (a.map != NULL)
222-
map__dso(a.map)->hit = 1;
222+
dso__set_hit(map__dso(a.map));
223223

224224
hist__account_cycles(sample->branch_stack, al, sample, false, NULL);
225225

@@ -254,7 +254,7 @@ static int evsel__add_sample(struct evsel *evsel, struct perf_sample *sample,
254254
if (al->sym != NULL) {
255255
struct dso *dso = map__dso(al->map);
256256

257-
rb_erase_cached(&al->sym->rb_node, &dso->symbols);
257+
rb_erase_cached(&al->sym->rb_node, dso__symbols(dso));
258258
symbol__delete(al->sym);
259259
dso__reset_find_symbol_cache(dso);
260260
}
@@ -419,7 +419,7 @@ static void hists__find_annotations(struct hists *hists,
419419
struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
420420
struct annotation *notes;
421421

422-
if (he->ms.sym == NULL || map__dso(he->ms.map)->annotate_warned)
422+
if (he->ms.sym == NULL || dso__annotate_warned(map__dso(he->ms.map)))
423423
goto find_next;
424424

425425
if (ann->sym_hist_filter &&

tools/perf/builtin-buildid-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
286286

287287
pr_warning("Problems with %s file, consider removing it from the cache\n",
288288
filename);
289-
} else if (memcmp(dso->bid.data, bid.data, bid.size)) {
289+
} else if (memcmp(dso__bid(dso)->data, bid.data, bid.size)) {
290290
pr_warning("Problems with %s file, consider removing it from the cache\n",
291291
filename);
292292
}

tools/perf/builtin-buildid-list.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ static int buildid__map_cb(struct map *map, void *arg __maybe_unused)
2626
{
2727
const struct dso *dso = map__dso(map);
2828
char bid_buf[SBUILD_ID_SIZE];
29+
const char *dso_long_name = dso__long_name(dso);
30+
const char *dso_short_name = dso__short_name(dso);
2931

3032
memset(bid_buf, 0, sizeof(bid_buf));
31-
if (dso->has_build_id)
32-
build_id__sprintf(&dso->bid, bid_buf);
33+
if (dso__has_build_id(dso))
34+
build_id__sprintf(dso__bid_const(dso), bid_buf);
3335
printf("%s %16" PRIx64 " %16" PRIx64, bid_buf, map__start(map), map__end(map));
34-
if (dso->long_name != NULL) {
35-
printf(" %s", dso->long_name);
36-
} else if (dso->short_name != NULL) {
37-
printf(" %s", dso->short_name);
38-
}
36+
if (dso_long_name != NULL)
37+
printf(" %s", dso_long_name);
38+
else if (dso_short_name != NULL)
39+
printf(" %s", dso_short_name);
40+
3941
printf("\n");
4042

4143
return 0;
@@ -76,7 +78,7 @@ static int filename__fprintf_build_id(const char *name, FILE *fp)
7678

7779
static bool dso__skip_buildid(struct dso *dso, int with_hits)
7880
{
79-
return with_hits && !dso->hit;
81+
return with_hits && !dso__hit(dso);
8082
}
8183

8284
static int perf_session__list_build_ids(bool force, bool with_hits)

tools/perf/builtin-inject.c

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,9 @@ static struct dso *findnew_dso(int pid, int tid, const char *filename,
445445
}
446446

447447
if (dso) {
448-
mutex_lock(&dso->lock);
449-
nsinfo__put(dso->nsinfo);
450-
dso->nsinfo = nsi;
451-
mutex_unlock(&dso->lock);
448+
mutex_lock(dso__lock(dso));
449+
dso__set_nsinfo(dso, nsi);
450+
mutex_unlock(dso__lock(dso));
452451
} else
453452
nsinfo__put(nsi);
454453

@@ -466,8 +465,8 @@ static int perf_event__repipe_buildid_mmap(struct perf_tool *tool,
466465
dso = findnew_dso(event->mmap.pid, event->mmap.tid,
467466
event->mmap.filename, NULL, machine);
468467

469-
if (dso && !dso->hit) {
470-
dso->hit = 1;
468+
if (dso && !dso__hit(dso)) {
469+
dso__set_hit(dso);
471470
dso__inject_build_id(dso, tool, machine, sample->cpumode, 0);
472471
}
473472
dso__put(dso);
@@ -492,7 +491,7 @@ static int perf_event__repipe_mmap2(struct perf_tool *tool,
492491
event->mmap2.filename, NULL, machine);
493492
if (dso) {
494493
/* mark it not to inject build-id */
495-
dso->hit = 1;
494+
dso__set_hit(dso);
496495
}
497496
dso__put(dso);
498497
}
@@ -544,7 +543,7 @@ static int perf_event__repipe_buildid_mmap2(struct perf_tool *tool,
544543
event->mmap2.filename, NULL, machine);
545544
if (dso) {
546545
/* mark it not to inject build-id */
547-
dso->hit = 1;
546+
dso__set_hit(dso);
548547
}
549548
dso__put(dso);
550549
perf_event__repipe(tool, event, sample, machine);
@@ -554,8 +553,8 @@ static int perf_event__repipe_buildid_mmap2(struct perf_tool *tool,
554553
dso = findnew_dso(event->mmap2.pid, event->mmap2.tid,
555554
event->mmap2.filename, &dso_id, machine);
556555

557-
if (dso && !dso->hit) {
558-
dso->hit = 1;
556+
if (dso && !dso__hit(dso)) {
557+
dso__set_hit(dso);
559558
dso__inject_build_id(dso, tool, machine, sample->cpumode,
560559
event->mmap2.flags);
561560
}
@@ -631,24 +630,24 @@ static int dso__read_build_id(struct dso *dso)
631630
{
632631
struct nscookie nsc;
633632

634-
if (dso->has_build_id)
633+
if (dso__has_build_id(dso))
635634
return 0;
636635

637-
mutex_lock(&dso->lock);
638-
nsinfo__mountns_enter(dso->nsinfo, &nsc);
639-
if (filename__read_build_id(dso->long_name, &dso->bid) > 0)
640-
dso->has_build_id = true;
641-
else if (dso->nsinfo) {
642-
char *new_name = dso__filename_with_chroot(dso, dso->long_name);
636+
mutex_lock(dso__lock(dso));
637+
nsinfo__mountns_enter(dso__nsinfo(dso), &nsc);
638+
if (filename__read_build_id(dso__long_name(dso), dso__bid(dso)) > 0)
639+
dso__set_has_build_id(dso);
640+
else if (dso__nsinfo(dso)) {
641+
char *new_name = dso__filename_with_chroot(dso, dso__long_name(dso));
643642

644-
if (new_name && filename__read_build_id(new_name, &dso->bid) > 0)
645-
dso->has_build_id = true;
643+
if (new_name && filename__read_build_id(new_name, dso__bid(dso)) > 0)
644+
dso__set_has_build_id(dso);
646645
free(new_name);
647646
}
648647
nsinfo__mountns_exit(&nsc);
649-
mutex_unlock(&dso->lock);
648+
mutex_unlock(dso__lock(dso));
650649

651-
return dso->has_build_id ? 0 : -1;
650+
return dso__has_build_id(dso) ? 0 : -1;
652651
}
653652

654653
static struct strlist *perf_inject__parse_known_build_ids(
@@ -700,14 +699,14 @@ static bool perf_inject__lookup_known_build_id(struct perf_inject *inject,
700699
dso_name = strchr(build_id, ' ');
701700
bid_len = dso_name - pos->s;
702701
dso_name = skip_spaces(dso_name);
703-
if (strcmp(dso->long_name, dso_name))
702+
if (strcmp(dso__long_name(dso), dso_name))
704703
continue;
705704
for (int ix = 0; 2 * ix + 1 < bid_len; ++ix) {
706-
dso->bid.data[ix] = (hex(build_id[2 * ix]) << 4 |
707-
hex(build_id[2 * ix + 1]));
705+
dso__bid(dso)->data[ix] = (hex(build_id[2 * ix]) << 4 |
706+
hex(build_id[2 * ix + 1]));
708707
}
709-
dso->bid.size = bid_len / 2;
710-
dso->has_build_id = 1;
708+
dso__bid(dso)->size = bid_len / 2;
709+
dso__set_has_build_id(dso);
711710
return true;
712711
}
713712
return false;
@@ -720,24 +719,24 @@ static int dso__inject_build_id(struct dso *dso, struct perf_tool *tool,
720719
tool);
721720
int err;
722721

723-
if (is_anon_memory(dso->long_name) || flags & MAP_HUGETLB)
722+
if (is_anon_memory(dso__long_name(dso)) || flags & MAP_HUGETLB)
724723
return 0;
725-
if (is_no_dso_memory(dso->long_name))
724+
if (is_no_dso_memory(dso__long_name(dso)))
726725
return 0;
727726

728727
if (inject->known_build_ids != NULL &&
729728
perf_inject__lookup_known_build_id(inject, dso))
730729
return 1;
731730

732731
if (dso__read_build_id(dso) < 0) {
733-
pr_debug("no build_id found for %s\n", dso->long_name);
732+
pr_debug("no build_id found for %s\n", dso__long_name(dso));
734733
return -1;
735734
}
736735

737736
err = perf_event__synthesize_build_id(tool, dso, cpumode,
738737
perf_event__repipe, machine);
739738
if (err) {
740-
pr_err("Can't synthesize build_id event for %s\n", dso->long_name);
739+
pr_err("Can't synthesize build_id event for %s\n", dso__long_name(dso));
741740
return -1;
742741
}
743742

@@ -763,8 +762,8 @@ int perf_event__inject_buildid(struct perf_tool *tool, union perf_event *event,
763762
if (thread__find_map(thread, sample->cpumode, sample->ip, &al)) {
764763
struct dso *dso = map__dso(al.map);
765764

766-
if (!dso->hit) {
767-
dso->hit = 1;
765+
if (!dso__hit(dso)) {
766+
dso__set_hit(dso);
768767
dso__inject_build_id(dso, tool, machine,
769768
sample->cpumode, map__flags(al.map));
770769
}
@@ -1146,8 +1145,8 @@ static bool dso__is_in_kernel_space(struct dso *dso)
11461145
return false;
11471146

11481147
return dso__is_kcore(dso) ||
1149-
dso->kernel ||
1150-
is_kernel_module(dso->long_name, PERF_RECORD_MISC_CPUMODE_UNKNOWN);
1148+
dso__kernel(dso) ||
1149+
is_kernel_module(dso__long_name(dso), PERF_RECORD_MISC_CPUMODE_UNKNOWN);
11511150
}
11521151

11531152
static u64 evlist__first_id(struct evlist *evlist)
@@ -1181,7 +1180,7 @@ static int synthesize_build_id(struct perf_inject *inject, struct dso *dso, pid_
11811180
if (!machine)
11821181
return -ENOMEM;
11831182

1184-
dso->hit = 1;
1183+
dso__set_hit(dso);
11851184

11861185
return perf_event__synthesize_build_id(&inject->tool, dso, cpumode,
11871186
process_build_id, machine);
@@ -1192,7 +1191,7 @@ static int guest_session__add_build_ids_cb(struct dso *dso, void *data)
11921191
struct guest_session *gs = data;
11931192
struct perf_inject *inject = container_of(gs, struct perf_inject, guest_session);
11941193

1195-
if (!dso->has_build_id)
1194+
if (!dso__has_build_id(dso))
11961195
return 0;
11971196

11981197
return synthesize_build_id(inject, dso, gs->machine_pid);

tools/perf/builtin-kallsyms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static int __cmd_kallsyms(int argc, const char **argv)
3838

3939
dso = map__dso(map);
4040
printf("%s: %s %s %#" PRIx64 "-%#" PRIx64 " (%#" PRIx64 "-%#" PRIx64")\n",
41-
symbol->name, dso->short_name, dso->long_name,
41+
symbol->name, dso__short_name(dso), dso__long_name(dso),
4242
map__unmap_ip(map, symbol->start), map__unmap_ip(map, symbol->end),
4343
symbol->start, symbol->end);
4444
}

tools/perf/builtin-mem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ dump_raw_samples(struct perf_tool *tool,
213213
if (al.map != NULL) {
214214
dso = map__dso(al.map);
215215
if (dso)
216-
dso->hit = 1;
216+
dso__set_hit(dso);
217217
}
218218

219219
field_sep = symbol_conf.field_sep;
@@ -255,7 +255,7 @@ dump_raw_samples(struct perf_tool *tool,
255255
symbol_conf.field_sep,
256256
sample->data_src,
257257
symbol_conf.field_sep,
258-
dso ? dso->long_name : "???",
258+
dso ? dso__long_name(dso) : "???",
259259
al.sym ? al.sym->name : "???");
260260
out_put:
261261
addr_location__exit(&al);

tools/perf/builtin-report.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static int process_sample_event(struct perf_tool *tool,
322322
}
323323

324324
if (al.map != NULL)
325-
map__dso(al.map)->hit = 1;
325+
dso__set_hit(map__dso(al.map));
326326

327327
if (ui__has_annotation() || rep->symbol_ipc || rep->total_cycles_mode) {
328328
hist__account_cycles(sample->branch_stack, &al, sample,
@@ -609,7 +609,7 @@ static void report__warn_kptr_restrict(const struct report *rep)
609609
return;
610610

611611
if (kernel_map == NULL ||
612-
(map__dso(kernel_map)->hit &&
612+
(dso__hit(map__dso(kernel_map)) &&
613613
(kernel_kmap->ref_reloc_sym == NULL ||
614614
kernel_kmap->ref_reloc_sym->addr == 0))) {
615615
const char *desc =
@@ -850,7 +850,7 @@ static int maps__fprintf_task_cb(struct map *map, void *data)
850850
prot & PROT_EXEC ? 'x' : '-',
851851
map__flags(map) ? 's' : 'p',
852852
map__pgoff(map),
853-
dso->id.ino, dso->name);
853+
dso__id_const(dso)->ino, dso__name(dso));
854854

855855
if (ret < 0)
856856
return ret;

tools/perf/builtin-script.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,11 +1017,11 @@ static int perf_sample__fprintf_brstackoff(struct perf_sample *sample,
10171017
to = entries[i].to;
10181018

10191019
if (thread__find_map_fb(thread, sample->cpumode, from, &alf) &&
1020-
!map__dso(alf.map)->adjust_symbols)
1020+
!dso__adjust_symbols(map__dso(alf.map)))
10211021
from = map__dso_map_ip(alf.map, from);
10221022

10231023
if (thread__find_map_fb(thread, sample->cpumode, to, &alt) &&
1024-
!map__dso(alt.map)->adjust_symbols)
1024+
!dso__adjust_symbols(map__dso(alt.map)))
10251025
to = map__dso_map_ip(alt.map, to);
10261026

10271027
printed += fprintf(fp, " 0x%"PRIx64, from);
@@ -1082,7 +1082,7 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
10821082
pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
10831083
goto out;
10841084
}
1085-
if (dso->data.status == DSO_DATA_STATUS_ERROR) {
1085+
if (dso__data(dso)->status == DSO_DATA_STATUS_ERROR) {
10861086
pr_debug("\tcannot resolve %" PRIx64 "-%" PRIx64 "\n", start, end);
10871087
goto out;
10881088
}
@@ -1094,7 +1094,7 @@ static int grab_bb(u8 *buffer, u64 start, u64 end,
10941094
len = dso__data_read_offset(dso, machine, offset, (u8 *)buffer,
10951095
end - start + MAXINSN);
10961096

1097-
*is64bit = dso->is_64_bit;
1097+
*is64bit = dso__is_64_bit(dso);
10981098
if (len <= 0)
10991099
pr_debug("\tcannot fetch code for block at %" PRIx64 "-%" PRIx64 "\n",
11001100
start, end);

tools/perf/builtin-top.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)
129129
/*
130130
* We can't annotate with just /proc/kallsyms
131131
*/
132-
if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore(dso)) {
132+
if (dso__symtab_type(dso) == DSO_BINARY_TYPE__KALLSYMS && !dso__is_kcore(dso)) {
133133
pr_err("Can't annotate %s: No vmlinux file was found in the "
134134
"path\n", sym->name);
135135
sleep(1);
@@ -182,7 +182,7 @@ static void ui__warn_map_erange(struct map *map, struct symbol *sym, u64 ip)
182182
"Tools: %s\n\n"
183183
"Not all samples will be on the annotation output.\n\n"
184184
"Please report to linux-kernel@vger.kernel.org\n",
185-
ip, dso->long_name, dso__symtab_origin(dso),
185+
ip, dso__long_name(dso), dso__symtab_origin(dso),
186186
map__start(map), map__end(map), sym->start, sym->end,
187187
sym->binding == STB_GLOBAL ? 'g' :
188188
sym->binding == STB_LOCAL ? 'l' : 'w', sym->name,

tools/perf/builtin-trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2917,7 +2917,7 @@ static void print_location(FILE *f, struct perf_sample *sample,
29172917
{
29182918

29192919
if ((verbose > 0 || print_dso) && al->map)
2920-
fprintf(f, "%s@", map__dso(al->map)->long_name);
2920+
fprintf(f, "%s@", dso__long_name(map__dso(al->map)));
29212921

29222922
if ((verbose > 0 || print_sym) && al->sym)
29232923
fprintf(f, "%s+0x%" PRIx64, al->sym->name,

0 commit comments

Comments
 (0)