Skip to content

Commit 53b00ff

Browse files
captain5050namhyung
authored andcommitted
perf record: Make --buildid-mmap the default
Support for build IDs in mmap2 perf events has been present since Linux v5.12: https://lore.kernel.org/lkml/[email protected]/ Build ID mmap events don't avoid the need to inject build IDs for DSO touched by samples as the build ID cache is populated by perf record. They can avoid some cases of symbol mis-resolution caused by the file system changing from when a sample occurred and when the DSO is sought. Unlike the --buildid-mmap option, this chnage doesn't disable the build ID cache but it does disable the processing of samples looking for DSOs to inject build IDs for. To disable the build ID cache the -B (--no-buildid) option should be used. Making this option the default was raised on the list in: https://lore.kernel.org/linux-perf-users/CAP-5=fXP7jN_QrGUcd55_QH5J-Y-FCaJ6=NaHVtyx0oyNh8_-Q@mail.gmail.com/ Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 5b11409 commit 53b00ff

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

tools/perf/Documentation/perf-record.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,9 @@ Specify vmlinux path which has debuginfo.
563563
Record build-id of all DSOs regardless whether it's actually hit or not.
564564

565565
--buildid-mmap::
566-
Record build ids in mmap2 events, disables build id cache (implies --no-buildid).
566+
Legacy record build-id in map events option which is now the
567+
default. Behaves indentically to --no-buildid. Disable with
568+
--no-buildid-mmap.
567569

568570
--aio[=n]::
569571
Use <n> control blocks in asynchronous (Posix AIO) trace writing mode (default: 1, max: 4).

tools/perf/builtin-record.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ struct record {
171171
bool no_buildid_cache_set;
172172
bool buildid_all;
173173
bool buildid_mmap;
174+
bool buildid_mmap_set;
174175
bool timestamp_filename;
175176
bool timestamp_boundary;
176177
bool off_cpu;
@@ -1811,6 +1812,7 @@ record__finish_output(struct record *rec)
18111812
data->dir.files[i].size = lseek(data->dir.files[i].fd, 0, SEEK_CUR);
18121813
}
18131814

1815+
/* Buildid scanning disabled or build ID in kernel and synthesized map events. */
18141816
if (!rec->no_buildid) {
18151817
process_buildids(rec);
18161818

@@ -3005,6 +3007,8 @@ static int perf_record_config(const char *var, const char *value, void *cb)
30053007
rec->no_buildid = true;
30063008
else if (!strcmp(value, "mmap"))
30073009
rec->buildid_mmap = true;
3010+
else if (!strcmp(value, "no-mmap"))
3011+
rec->buildid_mmap = false;
30083012
else
30093013
return -1;
30103014
return 0;
@@ -3411,6 +3415,7 @@ static struct record record = {
34113415
.synth = PERF_SYNTH_ALL,
34123416
.off_cpu_thresh_ns = OFFCPU_THRESH,
34133417
},
3418+
.buildid_mmap = true,
34143419
};
34153420

34163421
const char record_callchain_help[] = CALLCHAIN_RECORD_HELP
@@ -3577,8 +3582,8 @@ static struct option __record_options[] = {
35773582
"file", "vmlinux pathname"),
35783583
OPT_BOOLEAN(0, "buildid-all", &record.buildid_all,
35793584
"Record build-id of all DSOs regardless of hits"),
3580-
OPT_BOOLEAN(0, "buildid-mmap", &record.buildid_mmap,
3581-
"Record build-id in map events"),
3585+
OPT_BOOLEAN_SET(0, "buildid-mmap", &record.buildid_mmap, &record.buildid_mmap_set,
3586+
"Record build-id in mmap events and skip build-id processing."),
35823587
OPT_BOOLEAN(0, "timestamp-filename", &record.timestamp_filename,
35833588
"append timestamp to output filename"),
35843589
OPT_BOOLEAN(0, "timestamp-boundary", &record.timestamp_boundary,
@@ -4108,19 +4113,24 @@ int cmd_record(int argc, const char **argv)
41084113
record.opts.record_switch_events = true;
41094114
}
41104115

4116+
if (!rec->buildid_mmap) {
4117+
pr_debug("Disabling build id in synthesized mmap2 events.\n");
4118+
symbol_conf.no_buildid_mmap2 = true;
4119+
} else if (rec->buildid_mmap_set) {
4120+
/*
4121+
* Explicitly passing --buildid-mmap disables buildid processing
4122+
* and cache generation.
4123+
*/
4124+
rec->no_buildid = true;
4125+
}
4126+
if (rec->buildid_mmap && !perf_can_record_build_id()) {
4127+
pr_warning("Missing support for build id in kernel mmap events.\n"
4128+
"Disable this warning with --no-buildid-mmap\n");
4129+
rec->buildid_mmap = false;
4130+
}
41114131
if (rec->buildid_mmap) {
4112-
if (!perf_can_record_build_id()) {
4113-
pr_err("Failed: no support to record build id in mmap events, update your kernel.\n");
4114-
err = -EINVAL;
4115-
goto out_opts;
4116-
}
4117-
pr_debug("Enabling build id in mmap2 events.\n");
4118-
/* Enable mmap build id synthesizing. */
4119-
symbol_conf.buildid_mmap2 = true;
41204132
/* Enable perf_event_attr::build_id bit. */
41214133
rec->opts.build_id = true;
4122-
/* Disable build id cache. */
4123-
rec->no_buildid = true;
41244134
}
41254135

41264136
if (rec->opts.record_cgroup && !perf_can_record_cgroup()) {

tools/perf/util/symbol_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct symbol_conf {
4343
report_individual_block,
4444
inline_name,
4545
disable_add2line_warn,
46-
buildid_mmap2,
46+
no_buildid_mmap2,
4747
guest_code,
4848
lazy_load_kernel_maps,
4949
keep_exited_threads,

tools/perf/util/synthetic-events.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ int perf_event__synthesize_mmap_events(const struct perf_tool *tool,
532532
event->mmap2.pid = tgid;
533533
event->mmap2.tid = pid;
534534

535-
if (symbol_conf.buildid_mmap2)
535+
if (!symbol_conf.no_buildid_mmap2)
536536
perf_record_mmap2__read_build_id(&event->mmap2, machine, false);
537537

538538
if (perf_tool__process_synth_event(tool, event, machine, process) != 0) {
@@ -690,7 +690,7 @@ static int perf_event__synthesize_modules_maps_cb(struct map *map, void *data)
690690
return 0;
691691

692692
dso = map__dso(map);
693-
if (symbol_conf.buildid_mmap2) {
693+
if (!symbol_conf.no_buildid_mmap2) {
694694
size = PERF_ALIGN(dso__long_name_len(dso) + 1, sizeof(u64));
695695
event->mmap2.header.type = PERF_RECORD_MMAP2;
696696
event->mmap2.header.size = (sizeof(event->mmap2) -
@@ -734,9 +734,9 @@ int perf_event__synthesize_modules(const struct perf_tool *tool, perf_event__han
734734
.process = process,
735735
.machine = machine,
736736
};
737-
size_t size = symbol_conf.buildid_mmap2
738-
? sizeof(args.event->mmap2)
739-
: sizeof(args.event->mmap);
737+
size_t size = symbol_conf.no_buildid_mmap2
738+
? sizeof(args.event->mmap)
739+
: sizeof(args.event->mmap2);
740740

741741
args.event = zalloc(size + machine->id_hdr_size);
742742
if (args.event == NULL) {
@@ -1124,8 +1124,8 @@ static int __perf_event__synthesize_kernel_mmap(const struct perf_tool *tool,
11241124
struct machine *machine)
11251125
{
11261126
union perf_event *event;
1127-
size_t size = symbol_conf.buildid_mmap2 ?
1128-
sizeof(event->mmap2) : sizeof(event->mmap);
1127+
size_t size = symbol_conf.no_buildid_mmap2 ?
1128+
sizeof(event->mmap) : sizeof(event->mmap2);
11291129
struct map *map = machine__kernel_map(machine);
11301130
struct kmap *kmap;
11311131
int err;
@@ -1159,7 +1159,7 @@ static int __perf_event__synthesize_kernel_mmap(const struct perf_tool *tool,
11591159
event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
11601160
}
11611161

1162-
if (symbol_conf.buildid_mmap2) {
1162+
if (!symbol_conf.no_buildid_mmap2) {
11631163
size = snprintf(event->mmap2.filename, sizeof(event->mmap2.filename),
11641164
"%s%s", machine->mmap_name, kmap->ref_reloc_sym->name) + 1;
11651165
size = PERF_ALIGN(size, sizeof(u64));

0 commit comments

Comments
 (0)