perf record: Lazy load kernel symbols

Commit 5b7ba82a75 ("perf symbols: Load kernel maps before using")
changed it so that loading a kernel DSO would cause the symbols for the
DSO to be eagerly loaded.

For 'perf record' this is overhead as the symbols won't be used. Add a
field to 'struct symbol_conf' to control the behavior and disable it for
'perf record' and 'perf inject'.

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Changbin Du <changbin.du@huawei.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Dmitrii Dolgov <9erthalion6@gmail.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
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: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Li Dong <lidong@vivo.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Ming Wang <wangming01@loongson.cn>
Cc: Nick Terrell <terrelln@fb.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Steinar H. Gunderson <sesse@google.com>
Cc: Vincent Whitchurch <vincent.whitchurch@axis.com>
Cc: Wenyu Liu <liuwenyu7@huawei.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Link: https://lore.kernel.org/r/20231102175735.2272696-3-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Ian Rogers 2023-11-02 10:56:44 -07:00 committed by Arnaldo Carvalho de Melo
parent 7ff7b7afe3
commit 1a27fc0170
4 changed files with 12 additions and 3 deletions

View File

@ -2265,6 +2265,12 @@ int cmd_inject(int argc, const char **argv)
"perf inject [<options>]", "perf inject [<options>]",
NULL NULL
}; };
if (!inject.itrace_synth_opts.set) {
/* Disable eager loading of kernel symbols that adds overhead to perf inject. */
symbol_conf.lazy_load_kernel_maps = true;
}
#ifndef HAVE_JITDUMP #ifndef HAVE_JITDUMP
set_option_nobuild(options, 'j', "jit", "NO_LIBELF=1", true); set_option_nobuild(options, 'j', "jit", "NO_LIBELF=1", true);
#endif #endif

View File

@ -3989,6 +3989,8 @@ int cmd_record(int argc, const char **argv)
# undef set_nobuild # undef set_nobuild
#endif #endif
/* Disable eager loading of kernel symbols that adds overhead to perf record. */
symbol_conf.lazy_load_kernel_maps = true;
rec->opts.affinity = PERF_AFFINITY_SYS; rec->opts.affinity = PERF_AFFINITY_SYS;
rec->evlist = evlist__new(); rec->evlist = evlist__new();

View File

@ -617,13 +617,13 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) { if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
al->level = 'k'; al->level = 'k';
maps = machine__kernel_maps(machine); maps = machine__kernel_maps(machine);
load_map = true; load_map = !symbol_conf.lazy_load_kernel_maps;
} else if (cpumode == PERF_RECORD_MISC_USER && perf_host) { } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
al->level = '.'; al->level = '.';
} else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) { } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
al->level = 'g'; al->level = 'g';
maps = machine__kernel_maps(machine); maps = machine__kernel_maps(machine);
load_map = true; load_map = !symbol_conf.lazy_load_kernel_maps;
} else if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) { } else if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) {
al->level = 'u'; al->level = 'u';
} else { } else {

View File

@ -42,7 +42,8 @@ struct symbol_conf {
inline_name, inline_name,
disable_add2line_warn, disable_add2line_warn,
buildid_mmap2, buildid_mmap2,
guest_code; guest_code,
lazy_load_kernel_maps;
const char *vmlinux_name, const char *vmlinux_name,
*kallsyms_name, *kallsyms_name,
*source_prefix, *source_prefix,