This is a note to let you know that I've just added the patch titled perf record: Lazy load kernel symbols to the 6.6-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: perf-record-lazy-load-kernel-symbols.patch and it can be found in the queue-6.6 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 2ac5c718173e7a88dc3c2ab2ef77339cb40e3550 Author: Ian Rogers <irogers@xxxxxxxxxx> Date: Thu Nov 2 10:56:44 2023 -0700 perf record: Lazy load kernel symbols [ Upstream commit 1a27fc01700fbff2f205000edf0d1d315b5f85cc ] Commit 5b7ba82a75915e73 ("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@xxxxxxxxx> Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx> Acked-by: Namhyung Kim <namhyung@xxxxxxxxxx> Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx> Cc: Andi Kleen <ak@xxxxxxxxxxxxxxx> Cc: Athira Jajeev <atrajeev@xxxxxxxxxxxxxxxxxx> Cc: Changbin Du <changbin.du@xxxxxxxxxx> Cc: Colin Ian King <colin.i.king@xxxxxxxxx> Cc: Dmitrii Dolgov <9erthalion6@xxxxxxxxx> Cc: German Gomez <german.gomez@xxxxxxx> Cc: Huacai Chen <chenhuacai@xxxxxxxxxx> Cc: Ingo Molnar <mingo@xxxxxxxxxx> Cc: James Clark <james.clark@xxxxxxx> Cc: Jiri Olsa <jolsa@xxxxxxxxxx> Cc: K Prateek Nayak <kprateek.nayak@xxxxxxx> Cc: Kajol Jain <kjain@xxxxxxxxxxxxx> Cc: Kan Liang <kan.liang@xxxxxxxxxxxxxxx> Cc: Leo Yan <leo.yan@xxxxxxxxxx> Cc: Li Dong <lidong@xxxxxxxx> Cc: Liam Howlett <liam.howlett@xxxxxxxxxx> Cc: Mark Rutland <mark.rutland@xxxxxxx> Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx> Cc: Miguel Ojeda <ojeda@xxxxxxxxxx> Cc: Ming Wang <wangming01@xxxxxxxxxxx> Cc: Nick Terrell <terrelln@xxxxxx> Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx> Cc: Ravi Bangoria <ravi.bangoria@xxxxxxx> Cc: Sandipan Das <sandipan.das@xxxxxxx> Cc: Sean Christopherson <seanjc@xxxxxxxxxx> Cc: Steinar H. Gunderson <sesse@xxxxxxxxxx> Cc: Vincent Whitchurch <vincent.whitchurch@xxxxxxxx> Cc: Wenyu Liu <liuwenyu7@xxxxxxxxxx> Cc: Yang Jihong <yangjihong1@xxxxxxxxxx> Link: https://lore.kernel.org/r/20231102175735.2272696-3-irogers@xxxxxxxxxx Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> Stable-dep-of: aaf494cf483a ("perf annotate: Fix annotation_calc_lines() to pass correct address to get_srcline()") Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index c8cf2fdd9cff9..eb3ef5c24b662 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -2265,6 +2265,12 @@ int cmd_inject(int argc, const char **argv) "perf inject [<options>]", 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 set_option_nobuild(options, 'j', "jit", "NO_LIBELF=1", true); #endif diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index ea80bf4dc4343..5c54fda63b581 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -3936,6 +3936,8 @@ int cmd_record(int argc, const char **argv) # undef set_nobuild #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->evlist = evlist__new(); diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 923c0fb151222..68f45e9e63b6e 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c @@ -617,13 +617,13 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr, if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) { al->level = 'k'; 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) { al->level = '.'; } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) { al->level = 'g'; 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) { al->level = 'u'; } else { diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h index 0b589570d1d09..2b2fb9e224b00 100644 --- a/tools/perf/util/symbol_conf.h +++ b/tools/perf/util/symbol_conf.h @@ -42,7 +42,8 @@ struct symbol_conf { inline_name, disable_add2line_warn, buildid_mmap2, - guest_code; + guest_code, + lazy_load_kernel_maps; const char *vmlinux_name, *kallsyms_name, *source_prefix,