From nobody Sat Feb 7 07:10:19 2026 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3D54198E69; Fri, 16 Aug 2024 10:58:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805921; cv=none; b=efqarENKau8nOKUfOBhGvkmteo7NzguT1eWM0VLMHj5SjRu/SJdb52RQYM4NzVEk0S1BcwnCsRWkSOSajqSfw8ToXDCywIXGY2ZBMCB1LVjVj3aJux0oiMEEu/LI7LjU1qzCZJ5HKPNedo2YhSFeTn9WnJ1xnlGxvgrrGJigG4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805921; c=relaxed/simple; bh=s7aXBvF1a57X8SnZNDoNQvvvaLaYIjPR3Jbf76oCENY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IV8CA0ixjBqgSka1pB4caLKjjm1aiPqvtGuD0PMyX/r5DAy2qrMMMbDCeoJ6rln6lTM0wuGIq4MJLxBIKTRYGY1Lu76GzvJXVqohypxqYqfZDxGq6Hq9qGj1gSp3R2ZttzLLic0HwqGBT/a/rIWNzLu4l5/m6fPm5Tmc+0vBZ4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Wlf976NJ1z1T7Td; Fri, 16 Aug 2024 18:58:03 +0800 (CST) Received: from kwepemd100011.china.huawei.com (unknown [7.221.188.204]) by mail.maildlp.com (Postfix) with ESMTPS id 414751800A3; Fri, 16 Aug 2024 18:58:36 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemd100011.china.huawei.com (7.221.188.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 16 Aug 2024 18:58:34 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Nathan Chancellor CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Nick Desaulniers , Bill Wendling , Justin Stitt , , , , Hui Wang , Changbin Du Subject: [PATCH v6 1/8] perf: support specify vdso path in cmdline Date: Fri, 16 Aug 2024 18:58:04 +0800 Message-ID: <20240816105811.1812897-2-changbin.du@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816105811.1812897-1-changbin.du@huawei.com> References: <20240816105811.1812897-1-changbin.du@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd100011.china.huawei.com (7.221.188.204) The vdso dumped from process memory (in buildid-cache) lacks debugging info. To annotate vdso symbols with source lines we need specify a debugging version. For x86, we can find them from your local build as arch/x86/entry/vdso/vdso{32,64}.so.dbg. Or they may reside in /lib/modules//vdso/vdso{32,64}.so on Ubuntu. But notice that the buildid has to match. $ sudo perf record -a $ sudo perf report --objdump=3Dllvm-objdump \ --vdso arch/x86/entry/vdso/vdso64.so.dbg,arch/x86/entry/vdso/vdso32.so.dbg Samples: 17K of event 'cycles:P', 4000 Hz, Event count (approx.): 1760 __vdso_clock_gettime /work/linux-host/arch/x86/entry/vdso/vdso64.so.d Percent=E2=94=82 movq -48(%rbp),%rsi =E2=94=82 testq %rax,%rax =E2=94=82 ; return vread_hvclock(); =E2=94=82 movq %rax,%rdx =E2=94=82 ; if (unlikely(!vdso_cycles_ok(cycles))) =E2=94=82 =E2=86=91 js eb =E2=94=82 =E2=86=91 jmp 74 =E2=94=82 ; ts->tv_sec =3D vdso_ts->sec; 0.02 =E2=94=82147: leaq 2(%rbx),%rax =E2=94=82 shlq $4, %rax =E2=94=82 addq %r10,%rax =E2=94=82 ; while ((seq =3D READ_ONCE(vd->seq)) & = 1) { 9.38 =E2=94=82152: movl (%r10),%ecx When doing cross platform analysis, we also need specify the vdso path if we are interested in its symbols. v2: update documentation. Signed-off-by: Changbin Du --- tools/perf/Documentation/perf-annotate.txt | 3 + tools/perf/Documentation/perf-c2c.txt | 3 + tools/perf/Documentation/perf-inject.txt | 3 + tools/perf/Documentation/perf-report.txt | 3 + tools/perf/Documentation/perf-script.txt | 3 + tools/perf/Documentation/perf-top.txt | 3 + tools/perf/builtin-annotate.c | 2 + tools/perf/builtin-c2c.c | 2 + tools/perf/builtin-inject.c | 2 + tools/perf/builtin-report.c | 2 + tools/perf/builtin-script.c | 2 + tools/perf/builtin-top.c | 2 + tools/perf/util/disasm.c | 7 +- tools/perf/util/symbol.c | 82 +++++++++++++++++++++- tools/perf/util/symbol_conf.h | 5 ++ 15 files changed, 119 insertions(+), 5 deletions(-) diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Docume= ntation/perf-annotate.txt index b95524bea021..4b6692f9a793 100644 --- a/tools/perf/Documentation/perf-annotate.txt +++ b/tools/perf/Documentation/perf-annotate.txt @@ -58,6 +58,9 @@ OPTIONS --ignore-vmlinux:: Ignore vmlinux files. =20 +--vdso=3D:: + Specify vdso pathnames. You can specify up to two for multiarch-support. + --itrace:: Options for decoding instruction tracing data. The options are: =20 diff --git a/tools/perf/Documentation/perf-c2c.txt b/tools/perf/Documentati= on/perf-c2c.txt index 856f0dfb8e5a..7c07efca7542 100644 --- a/tools/perf/Documentation/perf-c2c.txt +++ b/tools/perf/Documentation/perf-c2c.txt @@ -71,6 +71,9 @@ REPORT OPTIONS --vmlinux=3D:: vmlinux pathname =20 +--vdso=3D:: + Specify vdso pathnames. You can specify up to two for multiarch-support. + -v:: --verbose:: Be more verbose (show counter open errors, etc). diff --git a/tools/perf/Documentation/perf-inject.txt b/tools/perf/Document= ation/perf-inject.txt index c972032f4ca0..3c88967b4c7f 100644 --- a/tools/perf/Documentation/perf-inject.txt +++ b/tools/perf/Documentation/perf-inject.txt @@ -62,6 +62,9 @@ OPTIONS --kallsyms=3D:: kallsyms pathname =20 +--vdso=3D:: + Specify vdso pathnames. You can specify up to two for multiarch-support. + --itrace:: Decode Instruction Tracing data, replacing it with synthesized events. Options are: diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Document= ation/perf-report.txt index d2b1593ef700..8a3ba5f74cac 100644 --- a/tools/perf/Documentation/perf-report.txt +++ b/tools/perf/Documentation/perf-report.txt @@ -345,6 +345,9 @@ OPTIONS Load module symbols. WARNING: This should only be used with -k and a LIVE kernel. =20 +--vdso=3D:: + Specify vdso pathnames. You can specify up to two for multiarch-support. + -f:: --force:: Don't do ownership validation. diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Document= ation/perf-script.txt index ff086ef05a0c..48f9974ca4c5 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt @@ -296,6 +296,9 @@ OPTIONS --kallsyms=3D:: kallsyms pathname =20 +--vdso=3D:: + Specify vdso pathnames. You can specify up to two for multiarch-support. + --symfs=3D:: Look for files with symbols relative to this directory. =20 diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentati= on/perf-top.txt index 667e5102075e..99f53b5b336b 100644 --- a/tools/perf/Documentation/perf-top.txt +++ b/tools/perf/Documentation/perf-top.txt @@ -80,6 +80,9 @@ Default is to monitor all CPUS. --kallsyms=3D:: kallsyms pathname =20 +--vdso=3D:: + Specify vdso pathnames. You can specify up to two for multiarch-support. + -m :: --mmap-pages=3D:: Number of mmap data pages (must be a power of two) or size diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index b10b7f005658..e0aa657e6ca0 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c @@ -742,6 +742,8 @@ int cmd_annotate(int argc, const char **argv) "file", "vmlinux pathname"), OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, "load module symbols - WARNING: use only with -k and LIVE kernel"), + OPT_CALLBACK(0, "vdso", NULL, "vdso1[,vdso2]", "vdso pathnames", + parse_vdso_pathnames), OPT_BOOLEAN('l', "print-line", &annotate_opts.print_lines, "print matching source lines (may be slow)"), OPT_BOOLEAN('P', "full-paths", &annotate_opts.full_path, diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index c157bd31f2e5..4764f9139661 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -3018,6 +3018,8 @@ static int perf_c2c__report(int argc, const char **ar= gv) const struct option options[] =3D { OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name, "file", "vmlinux pathname"), + OPT_CALLBACK(0, "vdso", NULL, "vdso1[,vdso2]", "vdso pathnames", + parse_vdso_pathnames), OPT_STRING('i', "input", &input_name, "file", "the input file to process"), OPT_INCR('N', "node-info", &c2c.node_info, diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index a212678d47be..e774e83d0a0f 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -2247,6 +2247,8 @@ int cmd_inject(int argc, const char **argv) "don't load vmlinux even if found"), OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, "file", "kallsyms pathname"), + OPT_CALLBACK(0, "vdso", NULL, "vdso1[,vdso2]", "vdso pathnames", + parse_vdso_pathnames), OPT_BOOLEAN('f', "force", &data.force, "don't complain, do it"), OPT_CALLBACK_OPTARG(0, "itrace", &inject.itrace_synth_opts, NULL, "opts", "Instruction Tracing options\n" diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 6edc0d4ce6fb..00ddf4f06324 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -1321,6 +1321,8 @@ int cmd_report(int argc, const char **argv) "don't load vmlinux even if found"), OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, "file", "kallsyms pathname"), + OPT_CALLBACK(0, "vdso", NULL, "vdso1[,vdso2]", "vdso pathnames", + parse_vdso_pathnames), OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"), OPT_BOOLEAN('m', "modules", &symbol_conf.use_modules, "load module symbols - WARNING: use only with -k and LIVE kernel"), diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index c16224b1fef3..2e358922a8d1 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -3965,6 +3965,8 @@ int cmd_script(int argc, const char **argv) "file", "vmlinux pathname"), OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name, "file", "kallsyms pathname"), + OPT_CALLBACK(0, "vdso", NULL, "vdso1[,vdso2]", "vdso pathnames", + parse_vdso_pathnames), OPT_BOOLEAN('G', "hide-call-graph", &no_callchain, "When printing symbols do not display call chain"), OPT_CALLBACK(0, "symfs", NULL, "directory", diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index e8cbbf10d361..3a4cee6f2d2f 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1488,6 +1488,8 @@ int cmd_top(int argc, const char **argv) "file", "kallsyms pathname"), OPT_BOOLEAN('K', "hide_kernel_symbols", &top.hide_kernel_symbols, "hide kernel symbols"), + OPT_CALLBACK(0, "vdso", NULL, "vdso1[,vdso2]", "vdso pathnames", + parse_vdso_pathnames), OPT_CALLBACK('m', "mmap-pages", &opts->mmap_pages, "pages", "number of mmap data pages", evlist__parse_mmap_pages), OPT_INTEGER('r', "realtime", &top.realtime_prio, diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index e10558b79504..7e26d5215640 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -16,6 +16,7 @@ #include "debug.h" #include "disasm.h" #include "dso.h" +#include "vdso.h" #include "env.h" #include "evsel.h" #include "map.h" @@ -1126,7 +1127,7 @@ static int dso__disassemble_filename(struct dso *dso,= char *filename, size_t fil if (pos && strlen(pos) < SBUILD_ID_SIZE - 2) dirname(build_id_path); =20 - if (dso__is_kcore(dso)) + if (dso__is_kcore(dso) || dso__is_vdso(dso)) goto fallback; =20 len =3D readlink(build_id_path, linkname, sizeof(linkname) - 1); @@ -1134,7 +1135,7 @@ static int dso__disassemble_filename(struct dso *dso,= char *filename, size_t fil goto fallback; =20 linkname[len] =3D '\0'; - if (strstr(linkname, DSO__NAME_KALLSYMS) || + if (strstr(linkname, DSO__NAME_KALLSYMS) || strstr(linkname, DSO__NAME_VD= SO) || access(filename, R_OK)) { fallback: /* @@ -1142,7 +1143,7 @@ static int dso__disassemble_filename(struct dso *dso,= char *filename, size_t fil * cache, or is just a kallsyms file, well, lets hope that this * DSO is the same as when 'perf record' ran. */ - if (dso__kernel(dso) && dso__long_name(dso)[0] =3D=3D '/') + if ((dso__kernel(dso) || dso__is_vdso(dso)) && dso__long_name(dso)[0] = =3D=3D '/') snprintf(filename, filename_size, "%s", dso__long_name(dso)); else __symbol__join_symfs(filename, filename_size, dso__long_name(dso)); diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 19eb623e0826..ad3b7b929e94 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -19,6 +19,7 @@ #include "build-id.h" #include "cap.h" #include "dso.h" +#include "vdso.h" #include "util.h" // lsdir() #include "debug.h" #include "event.h" @@ -44,6 +45,7 @@ =20 static int dso__load_kernel_sym(struct dso *dso, struct map *map); static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map); +static int dso__load_vdso_sym(struct dso *dso, struct map *map); static bool symbol__is_idle(const char *name); =20 int vmlinux_path__nr_entries; @@ -1832,6 +1834,12 @@ int dso__load(struct dso *dso, struct map *map) goto out; } =20 + if (dso__is_vdso(dso)) { + ret =3D dso__load_vdso_sym(dso, map); + if (ret > 0) + goto out; + } + dso__set_adjust_symbols(dso, false); =20 if (perfmap) { @@ -2016,12 +2024,14 @@ int dso__load_vmlinux(struct dso *dso, struct map *= map, dso__set_binary_type(dso, DSO_BINARY_TYPE__VMLINUX); =20 err =3D dso__load_sym(dso, map, &ss, &ss, 0); - symsrc__destroy(&ss); - if (err > 0) { dso__set_loaded(dso); pr_debug("Using %s for symbols\n", symfs_vmlinux); + + if (symsrc__has_symtab(&ss) && !dso__symsrc_filename(dso)) + dso__set_symsrc_filename(dso, strdup(symfs_vmlinux)); } + symsrc__destroy(&ss); =20 return err; } @@ -2348,6 +2358,74 @@ static int vmlinux_path__init(struct perf_env *env) return -1; } =20 +int parse_vdso_pathnames(const struct option *opt __maybe_unused, + const char *arg, int unset __maybe_unused) +{ + char *tmp, *tok, *str =3D strdup(arg); + unsigned int i =3D 0; + + for (tok =3D strtok_r(str, ",", &tmp); tok && i < ARRAY_SIZE(symbol_conf.= vdso_name); + tok =3D strtok_r(NULL, ",", &tmp)) { + symbol_conf.vdso_name[i++] =3D strdup(tok); + } + + free(str); + return 0; +} + +static int dso__load_vdso(struct dso *dso, struct map *map, + const char *vdso) +{ + int err =3D -1; + struct symsrc ss; + char symfs_vdso[PATH_MAX]; + + if (vdso[0] =3D=3D '/') + snprintf(symfs_vdso, sizeof(symfs_vdso), "%s", vdso); + else + symbol__join_symfs(symfs_vdso, vdso); + + if (symsrc__init(&ss, dso, symfs_vdso, DSO_BINARY_TYPE__SYSTEM_PATH_DSO)) + return -1; + + /* + * dso__load_sym() may copy 'dso' which will result in the copies having + * an incorrect long name unless we set it here first. + */ + dso__set_long_name(dso, vdso, false); + dso__set_binary_type(dso, DSO_BINARY_TYPE__SYSTEM_PATH_DSO); + + err =3D dso__load_sym(dso, map, &ss, &ss, 0); + if (err > 0) { + dso__set_loaded(dso); + pr_debug("Using %s for %s symbols\n", symfs_vdso, dso__short_name(dso)); + + if (symsrc__has_symtab(&ss) && !dso__symsrc_filename(dso)) + dso__set_symsrc_filename(dso, strdup(symfs_vdso)); + } + symsrc__destroy(&ss); + + return err; +} + +static int dso__load_vdso_sym(struct dso *dso, struct map *map) +{ + int ret; + + if (!dso__is_vdso(dso)) + return -1; + + for (unsigned int i =3D 0; i < ARRAY_SIZE(symbol_conf.vdso_name); i++) { + if (symbol_conf.vdso_name[i] !=3D NULL) { + ret =3D dso__load_vdso(dso, map, symbol_conf.vdso_name[i]); + if (ret > 0) + return ret; + } + } + + return -1; +} + int setup_list(struct strlist **list, const char *list_str, const char *list_name) { diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h index 657cfa5af43c..deaec9a60904 100644 --- a/tools/perf/util/symbol_conf.h +++ b/tools/perf/util/symbol_conf.h @@ -3,6 +3,7 @@ #define __PERF_SYMBOL_CONF 1 =20 #include +#include =20 struct strlist; struct intlist; @@ -56,6 +57,7 @@ struct symbol_conf { const char *default_guest_vmlinux_name, *default_guest_kallsyms, *default_guest_modules; + const char *vdso_name[2]; const char *guestmount; const char *dso_list_str, *comm_list_str, @@ -86,4 +88,7 @@ struct symbol_conf { =20 extern struct symbol_conf symbol_conf; =20 +int parse_vdso_pathnames(const struct option *opt __maybe_unused, + const char *arg, int unset __maybe_unused); + #endif // __PERF_SYMBOL_CONF --=20 2.34.1 From nobody Sat Feb 7 07:10:19 2026 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A8A919ADAC; Fri, 16 Aug 2024 10:58:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805922; cv=none; b=I83ghozwivnsliDJZ1/6K5ru4GWqNerFcFUn0lO10WBzjrQeqa7T6FKxPLKps970DTFpVA8Sbdbv1G+x0RL7ndELoaIHbhHRCnlMdIQp1Vyyz+Y0vu5FTLnygY+Q5f9E1/INF0oT4APEiKh/l6FeCJzdH1T/HFMQkhtZhatqqO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805922; c=relaxed/simple; bh=MKgoX7MBPsWSbi0jaZmoLefjothuAgU9N/qVCkTkg94=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UkmaKpN+UqFP4sycWSe5LXYWDTMDXOvfREasH5vGPlBUns2q8Nl+l2mJ7JLIKPOCRxd5NEJl9UBVG6p36Co2+0d16QQhQsg1FCeZXJueBDvche7cu6ZjuvfFf9jrFX6u3nRGrydO3ZtQc443QRD1L9fkahpDPH8BDllRcmoRxjM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Wlf8967fnzpTcj; Fri, 16 Aug 2024 18:57:13 +0800 (CST) Received: from kwepemd100011.china.huawei.com (unknown [7.221.188.204]) by mail.maildlp.com (Postfix) with ESMTPS id A18CC140137; Fri, 16 Aug 2024 18:58:37 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemd100011.china.huawei.com (7.221.188.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 16 Aug 2024 18:58:36 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Nathan Chancellor CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Nick Desaulniers , Bill Wendling , Justin Stitt , , , , Hui Wang , Changbin Du Subject: [PATCH v6 2/8] perf: disasm: refactor function dso__disassemble_filename Date: Fri, 16 Aug 2024 18:58:05 +0800 Message-ID: <20240816105811.1812897-3-changbin.du@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816105811.1812897-1-changbin.du@huawei.com> References: <20240816105811.1812897-1-changbin.du@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd100011.china.huawei.com (7.221.188.204) Content-Type: text/plain; charset="utf-8" To make change easy, this change refactors the dso__disassemble_filename() function by extracting two functions read_buildid_linkname() and fallback_filename(). Signed-off-by: Changbin Du --- v2: split refactoring from logical change. --- tools/perf/util/disasm.c | 117 +++++++++++++++++++++++---------------- 1 file changed, 70 insertions(+), 47 deletions(-) diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 7e26d5215640..0ece6e06da6f 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -1092,28 +1092,12 @@ int symbol__strerror_disassemble(struct map_symbol = *ms, int errnum, char *buf, s return 0; } =20 -static int dso__disassemble_filename(struct dso *dso, char *filename, size= _t filename_size) +static int read_buildid_linkname(char *filename, char *linkname, size_t li= nkname_size) { - char linkname[PATH_MAX]; - char *build_id_filename; char *build_id_path =3D NULL; char *pos; int len; =20 - if (dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__KALLSYMS && - !dso__is_kcore(dso)) - return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX; - - build_id_filename =3D dso__build_id_filename(dso, NULL, 0, false); - if (build_id_filename) { - __symbol__join_symfs(filename, filename_size, build_id_filename); - free(build_id_filename); - } else { - if (dso__has_build_id(dso)) - return ENOMEM; - goto fallback; - } - build_id_path =3D strdup(filename); if (!build_id_path) return ENOMEM; @@ -1127,41 +1111,80 @@ static int dso__disassemble_filename(struct dso *ds= o, char *filename, size_t fil if (pos && strlen(pos) < SBUILD_ID_SIZE - 2) dirname(build_id_path); =20 - if (dso__is_kcore(dso) || dso__is_vdso(dso)) - goto fallback; - - len =3D readlink(build_id_path, linkname, sizeof(linkname) - 1); - if (len < 0) - goto fallback; + len =3D readlink(build_id_path, linkname, linkname_size); + if (len < 0) { + free(build_id_path); + return -1; + } =20 linkname[len] =3D '\0'; - if (strstr(linkname, DSO__NAME_KALLSYMS) || strstr(linkname, DSO__NAME_VD= SO) || - access(filename, R_OK)) { -fallback: - /* - * If we don't have build-ids or the build-id file isn't in the - * cache, or is just a kallsyms file, well, lets hope that this - * DSO is the same as when 'perf record' ran. - */ - if ((dso__kernel(dso) || dso__is_vdso(dso)) && dso__long_name(dso)[0] = =3D=3D '/') - snprintf(filename, filename_size, "%s", dso__long_name(dso)); - else - __symbol__join_symfs(filename, filename_size, dso__long_name(dso)); - - mutex_lock(dso__lock(dso)); - if (access(filename, R_OK) && errno =3D=3D ENOENT && dso__nsinfo(dso)) { - char *new_name =3D dso__filename_with_chroot(dso, filename); - if (new_name) { - strlcpy(filename, new_name, filename_size); - free(new_name); - } + free(build_id_path); + return 0; +} + +static int fallback_filename(struct dso *dso, char *filename, size_t filen= ame_size) +{ + char filepath[PATH_MAX]; + + /* + * If we don't have build-ids or the build-id file isn't in the + * cache, or is just a kallsyms file, well, lets hope that this + * DSO is the same as when 'perf record' ran. + */ + if ((dso__kernel(dso) || dso__is_vdso(dso)) && dso__long_name(dso)[0] =3D= =3D '/') + snprintf(filepath, sizeof(filepath), "%s", dso__long_name(dso)); + else + __symbol__join_symfs(filepath, sizeof(filepath), dso__long_name(dso)); + + mutex_lock(dso__lock(dso)); + if (access(filepath, R_OK) && errno =3D=3D ENOENT && dso__nsinfo(dso)) { + char *new_name =3D dso__filename_with_chroot(dso, filepath); + if (new_name) { + strlcpy(filepath, new_name, sizeof(filepath)); + free(new_name); } - mutex_unlock(dso__lock(dso)); - } else if (dso__binary_type(dso) =3D=3D DSO_BINARY_TYPE__NOT_FOUND) { - dso__set_binary_type(dso, DSO_BINARY_TYPE__BUILD_ID_CACHE); } + mutex_unlock(dso__lock(dso)); =20 - free(build_id_path); + if (access(filepath, R_OK) && errno =3D=3D ENOENT) + return ENOENT; + + snprintf(filename, filename_size, "%s", filepath); + return 0; +} + +static int dso__disassemble_filename(struct dso *dso, char *filename, size= _t filename_size) +{ + char linkname[PATH_MAX]; + char *build_id_filename; + + if (dso__symtab_type(dso) =3D=3D DSO_BINARY_TYPE__KALLSYMS && + !dso__is_kcore(dso)) + return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX; + + build_id_filename =3D dso__build_id_filename(dso, NULL, 0, false); + if (build_id_filename) { + __symbol__join_symfs(filename, filename_size, build_id_filename); + free(build_id_filename); + } else { + if (dso__has_build_id(dso)) + return ENOMEM; + return fallback_filename(dso, filename, filename_size); + } + + if (access(filename, R_OK)) + return fallback_filename(dso, filename, filename_size); + + if (dso__is_kcore(dso) || dso__is_vdso(dso)) + return fallback_filename(dso, filename, filename_size); + + if (read_buildid_linkname(filename, linkname, sizeof(linkname) - 1) || + strstr(linkname, DSO__NAME_KALLSYMS) || strstr(linkname, DSO__NAME_VD= SO)) { + return fallback_filename(dso, filename, filename_size); + } + + if (dso__binary_type(dso) =3D=3D DSO_BINARY_TYPE__NOT_FOUND) + dso__set_binary_type(dso, DSO_BINARY_TYPE__BUILD_ID_CACHE); return 0; } =20 --=20 2.34.1 From nobody Sat Feb 7 07:10:19 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B3FC1A01D2; Fri, 16 Aug 2024 10:58:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805923; cv=none; b=HGwBYlVnuLJXU6gKfjJS4eV1VR55j98zWhRbkJ9xS7i9/vR8eFGqeVf5LdbvDGdqUrZIENesoxWvOqS9Fz9so6/6P3Qjk+WJikbuaF8dD8oQ+TZaCnlIfQVaBwJMmRUCVHzG+ZCDAlUSt0QpTulht1/O8umspZ3cUsz6nLbCsPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805923; c=relaxed/simple; bh=BB3GboFitawlrEaYLgZRHevIANxaCt7nCtA+dfku0ak=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EreTbFgojyC2cma1nFArvMxWEkOPsxHKNL5MmB2dlnaVuPSK+8/l46VDEquqE+IBgTVGbHtubG6nhQ2ZBMm/gbqtmuBTH3MZR2SdbZoBO9DNAKUvkFOfBjA5iRgU8RaBv4V7PrJwFH7ADxxZFVt4BK3gbvuD713K9+oFEN7rPBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Wlf9T6bJCzcdMn; Fri, 16 Aug 2024 18:58:21 +0800 (CST) Received: from kwepemd100011.china.huawei.com (unknown [7.221.188.204]) by mail.maildlp.com (Postfix) with ESMTPS id 14129180100; Fri, 16 Aug 2024 18:58:39 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemd100011.china.huawei.com (7.221.188.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 16 Aug 2024 18:58:37 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Nathan Chancellor CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Nick Desaulniers , Bill Wendling , Justin Stitt , , , , Hui Wang , Changbin Du Subject: [PATCH v6 3/8] perf: disasm: use build_id_path if fallback failed Date: Fri, 16 Aug 2024 18:58:06 +0800 Message-ID: <20240816105811.1812897-4-changbin.du@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816105811.1812897-1-changbin.du@huawei.com> References: <20240816105811.1812897-1-changbin.du@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd100011.china.huawei.com (7.221.188.204) Content-Type: text/plain; charset="utf-8" If we can not fallback for special dso (vmlinx and vdso), use the build_id_path found previously. Signed-off-by: Changbin Du --- tools/perf/util/disasm.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 0ece6e06da6f..6af9fbec3a95 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -1176,15 +1176,21 @@ static int dso__disassemble_filename(struct dso *ds= o, char *filename, size_t fil return fallback_filename(dso, filename, filename_size); =20 if (dso__is_kcore(dso) || dso__is_vdso(dso)) - return fallback_filename(dso, filename, filename_size); + goto fallback; =20 - if (read_buildid_linkname(filename, linkname, sizeof(linkname) - 1) || - strstr(linkname, DSO__NAME_KALLSYMS) || strstr(linkname, DSO__NAME_VD= SO)) { - return fallback_filename(dso, filename, filename_size); + if (!read_buildid_linkname(filename, linkname, sizeof(linkname) - 1) && + (!strstr(linkname, DSO__NAME_KALLSYMS) && !strstr(linkname, DSO__NAME= _VDSO))) { + /* It's not kallsysms or vdso, use build_id path found above */ + goto out; } =20 - if (dso__binary_type(dso) =3D=3D DSO_BINARY_TYPE__NOT_FOUND) - dso__set_binary_type(dso, DSO_BINARY_TYPE__BUILD_ID_CACHE); +fallback: + if (fallback_filename(dso, filename, filename_size)) { + /* if fallback failed, use build_id path found above */ +out: + if (dso__binary_type(dso) =3D=3D DSO_BINARY_TYPE__NOT_FOUND) + dso__set_binary_type(dso, DSO_BINARY_TYPE__BUILD_ID_CACHE); + } return 0; } =20 --=20 2.34.1 From nobody Sat Feb 7 07:10:19 2026 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23F00198A33; Fri, 16 Aug 2024 10:58:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805925; cv=none; b=TWtvkVlFq125Hv5FYIO1rm/wp+Tz9bL6oZ6eu+y94ALfTXiWesINUhqe/1uSRi9j170ElxhNDaSl9q6bjSXTsn2vo4+ZHBmKqAYMC2rxcRJtoUYcd9ofC5SmNu+/YgTkFL0KJmYt6AzBFCe2IUhTO5LHZVYpypw0nouJ9Y5aFS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805925; c=relaxed/simple; bh=lA8sWheSHSHoYVlwjTpOll49BLvcZs4jAVi8F76x7Ko=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u9n6ic7Q9Ae57Hbrft2aMFqbJDhA2SJcFLS1fEkj065zKZ/PooSxiXP5aUvnPogqqdqXG6DcZlhZcwnTQGROp1pL3x4rQCK6wuF2z2I4+8ScZKxx/BW5+2/oLny+tMgkkXvlPzHZGBhtNAjG6izZsWx6tawfFrsPZhy330lTnS8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Wlf9D107Tz1T7Vq; Fri, 16 Aug 2024 18:58:08 +0800 (CST) Received: from kwepemd100011.china.huawei.com (unknown [7.221.188.204]) by mail.maildlp.com (Postfix) with ESMTPS id 7EC5C180100; Fri, 16 Aug 2024 18:58:40 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemd100011.china.huawei.com (7.221.188.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 16 Aug 2024 18:58:38 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Nathan Chancellor CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Nick Desaulniers , Bill Wendling , Justin Stitt , , , , Hui Wang , Changbin Du Subject: [PATCH v6 4/8] perf: symbol: generalize vmlinux path searching Date: Fri, 16 Aug 2024 18:58:07 +0800 Message-ID: <20240816105811.1812897-5-changbin.du@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816105811.1812897-1-changbin.du@huawei.com> References: <20240816105811.1812897-1-changbin.du@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd100011.china.huawei.com (7.221.188.204) Content-Type: text/plain; charset="utf-8" This generalizes the vmlinux path searching logic. Later we will add another instance for vdso. The search pattern is described by struct dso_filename_pattern, and the formatted paths are hold in struct dso_filename_paths. Signed-off-by: Changbin Du --- tools/perf/util/machine.c | 4 +- tools/perf/util/symbol.c | 112 +++++++++++++++++++++----------------- tools/perf/util/symbol.h | 8 ++- 3 files changed, 70 insertions(+), 54 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 8477edefc299..68315520f15b 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -896,9 +896,9 @@ size_t machine__fprintf_vmlinux_path(struct machine *ma= chine, FILE *fp) printed +=3D fprintf(fp, "[0] %s\n", filename); } =20 - for (i =3D 0; i < vmlinux_path__nr_entries; ++i) { + for (i =3D 0; i < vmlinux_paths.nr_entries; ++i) { printed +=3D fprintf(fp, "[%d] %s\n", i + dso__has_build_id(kdso), - vmlinux_path[i]); + vmlinux_paths.paths[i]); } return printed; } diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index ad3b7b929e94..6bf75c98e1f2 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -48,8 +48,7 @@ static int dso__load_guest_kernel_sym(struct dso *dso, st= ruct map *map); static int dso__load_vdso_sym(struct dso *dso, struct map *map); static bool symbol__is_idle(const char *name); =20 -int vmlinux_path__nr_entries; -char **vmlinux_path; +struct dso_filename_paths vmlinux_paths; =20 struct symbol_conf symbol_conf =3D { .nanosecs =3D false, @@ -2042,10 +2041,10 @@ int dso__load_vmlinux_path(struct dso *dso, struct = map *map) char *filename =3D NULL; =20 pr_debug("Looking at the vmlinux_path (%d entries long)\n", - vmlinux_path__nr_entries + 1); + vmlinux_paths.nr_entries + 1); =20 - for (i =3D 0; i < vmlinux_path__nr_entries; ++i) { - err =3D dso__load_vmlinux(dso, map, vmlinux_path[i], false); + for (i =3D 0; i < vmlinux_paths.nr_entries; ++i) { + err =3D dso__load_vmlinux(dso, map, vmlinux_paths.paths[i], false); if (err > 0) goto out; } @@ -2209,7 +2208,7 @@ static int dso__load_kernel_sym(struct dso *dso, stru= ct map *map) return err; } =20 - if (!symbol_conf.ignore_vmlinux && vmlinux_path !=3D NULL) { + if (!symbol_conf.ignore_vmlinux && vmlinux_paths.paths !=3D NULL) { err =3D dso__load_vmlinux_path(dso, map); if (err > 0) return err; @@ -2284,57 +2283,55 @@ static int dso__load_guest_kernel_sym(struct dso *d= so, struct map *map) return err; } =20 -static void vmlinux_path__exit(void) -{ - while (--vmlinux_path__nr_entries >=3D 0) - zfree(&vmlinux_path[vmlinux_path__nr_entries]); - vmlinux_path__nr_entries =3D 0; - - zfree(&vmlinux_path); -} - -static const char * const vmlinux_paths[] =3D { - "vmlinux", - "/boot/vmlinux" +struct dso_filename_pattern { + const char *pattern; + /* + * 0 for matching directly, + * 1 for matching by kernel_version, + * 2 for matching by kernel_version + arch. + */ + int match_type; }; =20 -static const char * const vmlinux_paths_upd[] =3D { - "/boot/vmlinux-%s", - "/usr/lib/debug/boot/vmlinux-%s", - "/lib/modules/%s/build/vmlinux", - "/usr/lib/debug/lib/modules/%s/vmlinux", - "/usr/lib/debug/boot/vmlinux-%s.debug" +struct dso_filename_pattern vmlinux_patterns[] =3D { + {"vmlinux", 0}, + {"/boot/vmlinux", 0}, + {"/boot/vmlinux-%s", 1}, + {"/usr/lib/debug/boot/vmlinux-%s", 1}, + {"/lib/modules/%s/build/vmlinux", 1}, + {"/usr/lib/debug/lib/modules/%s/vmlinux", 1}, + {"/usr/lib/debug/boot/vmlinux-%s.debug", 1}, }; =20 -static int vmlinux_path__add(const char *new_entry) +static int dso_filename_path__add(struct dso_filename_paths *paths, const = char *new_entry) { - vmlinux_path[vmlinux_path__nr_entries] =3D strdup(new_entry); - if (vmlinux_path[vmlinux_path__nr_entries] =3D=3D NULL) + paths->paths[paths->nr_entries] =3D strdup(new_entry); + if (paths->paths[paths->nr_entries] =3D=3D NULL) return -1; - ++vmlinux_path__nr_entries; + ++paths->nr_entries; =20 return 0; } =20 -static int vmlinux_path__init(struct perf_env *env) +static void dso_filename_path__exit(struct dso_filename_paths *paths) { - struct utsname uts; - char bf[PATH_MAX]; - char *kernel_version; - unsigned int i; + while (--paths->nr_entries >=3D 0) + zfree(&paths->paths[paths->nr_entries]); + paths->nr_entries =3D 0; =20 - vmlinux_path =3D malloc(sizeof(char *) * (ARRAY_SIZE(vmlinux_paths) + - ARRAY_SIZE(vmlinux_paths_upd))); - if (vmlinux_path =3D=3D NULL) - return -1; - - for (i =3D 0; i < ARRAY_SIZE(vmlinux_paths); i++) - if (vmlinux_path__add(vmlinux_paths[i]) < 0) - goto out_fail; + zfree(&paths->paths); +} =20 - /* only try kernel version if no symfs was given */ - if (symbol_conf.symfs[0] !=3D 0) - return 0; +static int dso_filename_path__init(struct dso_filename_paths *paths, + struct dso_filename_pattern *patterns, + int nr_patterns, + struct perf_env *env) +{ + struct utsname uts; + char bf[PATH_MAX]; + const char *kernel_version; + const char *arch =3D perf_env__arch(env); + int i; =20 if (env) { kernel_version =3D env->os_release; @@ -2345,16 +2342,28 @@ static int vmlinux_path__init(struct perf_env *env) kernel_version =3D uts.release; } =20 - for (i =3D 0; i < ARRAY_SIZE(vmlinux_paths_upd); i++) { - snprintf(bf, sizeof(bf), vmlinux_paths_upd[i], kernel_version); - if (vmlinux_path__add(bf) < 0) + paths->paths =3D malloc(sizeof(char *) * nr_patterns); + if (paths->paths =3D=3D NULL) + return -1; + + for (i =3D 0; i < nr_patterns; i++) { + if (patterns[i].match_type =3D=3D 0) + strlcpy(bf, patterns[i].pattern, sizeof(bf)); + else if (symbol_conf.symfs[0] =3D=3D 0) { + /* only try kernel version if no symfs was given */ + if (patterns[i].match_type =3D=3D 1) + snprintf(bf, sizeof(bf), patterns[i].pattern, kernel_version); + else if (patterns[i].match_type =3D=3D 2) + snprintf(bf, sizeof(bf), patterns[i].pattern, kernel_version, arch); + } + if (dso_filename_path__add(paths, bf) < 0) goto out_fail; } =20 return 0; =20 out_fail: - vmlinux_path__exit(); + dso_filename_path__exit(paths); return -1; } =20 @@ -2550,8 +2559,11 @@ int symbol__init(struct perf_env *env) =20 symbol__elf_init(); =20 - if (symbol_conf.try_vmlinux_path && vmlinux_path__init(env) < 0) + if (symbol_conf.try_vmlinux_path && + dso_filename_path__init(&vmlinux_paths, vmlinux_patterns, + ARRAY_SIZE(vmlinux_patterns), env) < 0) { return -1; + } =20 if (symbol_conf.field_sep && *symbol_conf.field_sep =3D=3D '.') { pr_err("'.' is the only non valid --field-separator argument\n"); @@ -2628,7 +2640,7 @@ void symbol__exit(void) intlist__delete(symbol_conf.tid_list); intlist__delete(symbol_conf.pid_list); intlist__delete(symbol_conf.addr_list); - vmlinux_path__exit(); + dso_filename_path__exit(&vmlinux_paths); symbol_conf.sym_list =3D symbol_conf.dso_list =3D symbol_conf.comm_list = =3D NULL; symbol_conf.bt_stop_list =3D NULL; symbol_conf.initialized =3D false; diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 3fb5d146d9b1..30056884945b 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -101,8 +101,12 @@ static inline int __symbol__join_symfs(char *bf, size_= t size, const char *path) =20 #define symbol__join_symfs(bf, path) __symbol__join_symfs(bf, sizeof(bf), = path) =20 -extern int vmlinux_path__nr_entries; -extern char **vmlinux_path; +struct dso_filename_paths { + int nr_entries; + char **paths; +}; + +extern struct dso_filename_paths vmlinux_paths; =20 static inline void *symbol__priv(struct symbol *sym) { --=20 2.34.1 From nobody Sat Feb 7 07:10:19 2026 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02A941AD9C6; Fri, 16 Aug 2024 10:58:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805925; cv=none; b=cAvgASZIj3939Pszipq7pXmZ+sb1AbCH9jrkJS7xvJ7lyIpXmAYeQx2KGJEckXvu035lTrD2jO2NehDh8UIrPlnsWPLGiYG5P8KpOpiVJA77HgSI8e0rytLMSq7HQCs5MMtOhTJ0u//XqnYB1MqwhcXlAUPg4aXXvMC2WUkNtmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805925; c=relaxed/simple; bh=sisKOpu/Vo7sGSxHa6dVdjlQnbQ+gt2LsAJ8FkZo7YY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RDbdXXWWc2WDwR861n/BJUIztzSfFTsb4hJQs+abawqVJHHY12bx/U2eYXquj/I59AHqhSqCBWRrMvM7nDMA2hXRP9vdDC6/3t/QHCnX6v2oPjWLwGpgFY4suVXekIr6LguwP65xZcsF3te8o2KPy7jn3AIjJsxoR/V+MODeVL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Wlf9F3NrWz1T7Vm; Fri, 16 Aug 2024 18:58:09 +0800 (CST) Received: from kwepemd100011.china.huawei.com (unknown [7.221.188.204]) by mail.maildlp.com (Postfix) with ESMTPS id D2D44140361; Fri, 16 Aug 2024 18:58:41 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemd100011.china.huawei.com (7.221.188.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 16 Aug 2024 18:58:40 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Nathan Chancellor CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Nick Desaulniers , Bill Wendling , Justin Stitt , , , , Hui Wang , Changbin Du Subject: [PATCH v6 5/8] perf: build-id: add support for build-id cache vdso debug Date: Fri, 16 Aug 2024 18:58:08 +0800 Message-ID: <20240816105811.1812897-6-changbin.du@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816105811.1812897-1-changbin.du@huawei.com> References: <20240816105811.1812897-1-changbin.du@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd100011.china.huawei.com (7.221.188.204) Content-Type: text/plain; charset="utf-8" This try to add debugging vdso elf to build-id cache the same as normal objects. Later we will extend this to find local debugging vdso from special paths. Cc: Adrian Hunter Signed-off-by: Changbin Du --- tools/perf/util/build-id.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 83a1581e8cf1..5bda47de5cf2 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -259,8 +259,8 @@ static bool build_id_cache__valid_id(char *sbuild_id) static const char *build_id_cache__basename(bool is_kallsyms, bool is_vdso, bool is_debug) { - return is_kallsyms ? "kallsyms" : (is_vdso ? "vdso" : (is_debug ? - "debug" : "elf")); + return is_kallsyms ? "kallsyms" : (is_debug ? "debug" : (is_vdso ? + "vdso" : "elf")); } =20 char *__dso__build_id_filename(const struct dso *dso, char *bf, size_t siz= e, @@ -701,13 +701,12 @@ build_id_cache__add(const char *sbuild_id, const char= *name, const char *realnam * file itself may not be very useful to users of our tools without a * symtab. */ - if (!is_kallsyms && !is_vdso && - strncmp(".ko", name + strlen(name) - 3, 3)) { + if (!is_kallsyms && strncmp(".ko", name + strlen(name) - 3, 3)) { debugfile =3D build_id_cache__find_debug(sbuild_id, nsi, root_dir); if (debugfile) { zfree(&filename); if (asprintf(&filename, "%s/%s", dir_name, - build_id_cache__basename(false, false, true)) < 0) { + build_id_cache__basename(false, is_vdso, true)) < 0) { filename =3D NULL; goto out_free; } --=20 2.34.1 From nobody Sat Feb 7 07:10:19 2026 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 478261B1417; Fri, 16 Aug 2024 10:58:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.255 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805927; cv=none; b=sQ/hP6YNJqXcqHhILTdAnW5hW6bzHcVRiE3UJTxll+zo+0PFCwQ0Hq5+Wn96VslY+mPuS6fvRmPksaK9D8xl+bFKILH4RHcFOP8tLskqmYabr0CNt7Mg2aLNdQmQKmPjM1nXXnErwwpFlDWuapeKgk1OMTFj1PtgfUK3nGYCv0k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805927; c=relaxed/simple; bh=Unwa8PWdSt7NQ3kAJRMtIfYRWFj1X0rFsL/N3Zn++4g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h6WO69wPku6N3KfeI8kTDmGWCklsKKCY6ewraqWzn3GXPAqVHTfV6T8wA63sGJTsJe+veZvnpxHFSmkLD1Tm/E9m8U8xjgvg1iBjhUpK0GfnCczd5IEQDG/Pl01n/mg5u/BoHjx7N4Tr+1l39onnrVthQKzp2nve67X17mmKU9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.255 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Wlf9G6M4lz1T7Vy; Fri, 16 Aug 2024 18:58:10 +0800 (CST) Received: from kwepemd100011.china.huawei.com (unknown [7.221.188.204]) by mail.maildlp.com (Postfix) with ESMTPS id 42D9F180100; Fri, 16 Aug 2024 18:58:43 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemd100011.china.huawei.com (7.221.188.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 16 Aug 2024 18:58:41 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Nathan Chancellor CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Nick Desaulniers , Bill Wendling , Justin Stitt , , , , Hui Wang , Changbin Du Subject: [PATCH v6 6/8] perf: build-id: extend build_id_cache__find_debug() to find local debugging vdso Date: Fri, 16 Aug 2024 18:58:09 +0800 Message-ID: <20240816105811.1812897-7-changbin.du@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816105811.1812897-1-changbin.du@huawei.com> References: <20240816105811.1812897-1-changbin.du@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd100011.china.huawei.com (7.221.188.204) Content-Type: text/plain; charset="utf-8" Just like vmlinux, try to search vdso in predefined paths when collecting build-ids. The searched paths usually have debugging info. For example, the vdso can be found in /lib/modules//build/arch/x86/entry/vdso/vdso*.so.dbg for local build on x86. Cc: Adrian Hunter Signed-off-by: Changbin Du --- v3: - continue to try build_id_cache__find_debug_normal() if build_id_cache__find_debug_vdso() failed. v2: - Searching the vdso in record stage instead of report. So the debugging vdso will be in build-id cache. This is friendly for cross-machine analysis. --- tools/perf/util/build-id.c | 48 ++++++++++++++++++++++++++++++++++---- tools/perf/util/symbol.c | 17 ++++++++++++++ tools/perf/util/symbol.h | 1 + 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 5bda47de5cf2..67f88b492279 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -593,9 +593,8 @@ static int build_id_cache__add_sdt_cache(const char *sb= uild_id, #define build_id_cache__add_sdt_cache(sbuild_id, realname, nsi) (0) #endif =20 -static char *build_id_cache__find_debug(const char *sbuild_id, - struct nsinfo *nsi, - const char *root_dir) +static char *build_id_cache__find_debug_normal(const char *sbuild_id, + struct nsinfo *nsi, const char *root_dir) { const char *dirname =3D "/usr/lib/debug/.build-id/"; char *realname =3D NULL; @@ -646,6 +645,47 @@ static char *build_id_cache__find_debug(const char *sb= uild_id, return realname; } =20 +static char *build_id_cache__find_debug_vdso(const char *sbuild_id) +{ + char sbuild_id_tmp[SBUILD_ID_SIZE]; + struct build_id bid; + int i, ret =3D 0; + + if (!vdso_paths.paths) + return NULL; + + pr_debug("Looking at the vdso_path (%d entries long)\n", + vdso_paths.nr_entries + 1); + + for (i =3D 0; i < vdso_paths.nr_entries; ++i) { + ret =3D filename__read_build_id(vdso_paths.paths[i], &bid); + if (ret < 0) + continue; + + build_id__sprintf(&bid, sbuild_id_tmp); + if (!strcmp(sbuild_id, sbuild_id_tmp)) { + pr_debug("Found debugging vdso %s\n", vdso_paths.paths[i]); + return strdup(vdso_paths.paths[i]); + } + } + + return NULL; +} + +static char *build_id_cache__find_debug(const char *sbuild_id, + struct nsinfo *nsi, + bool is_vdso, + const char *root_dir) +{ + char *name =3D NULL; + + if (is_vdso) + name =3D build_id_cache__find_debug_vdso(sbuild_id); + if (!name) + name =3D build_id_cache__find_debug_normal(sbuild_id, nsi, root_dir); + return name; +} + int build_id_cache__add(const char *sbuild_id, const char *name, const char *r= ealname, struct nsinfo *nsi, bool is_kallsyms, bool is_vdso, @@ -702,7 +742,7 @@ build_id_cache__add(const char *sbuild_id, const char *= name, const char *realnam * symtab. */ if (!is_kallsyms && strncmp(".ko", name + strlen(name) - 3, 3)) { - debugfile =3D build_id_cache__find_debug(sbuild_id, nsi, root_dir); + debugfile =3D build_id_cache__find_debug(sbuild_id, nsi, is_vdso, root_d= ir); if (debugfile) { zfree(&filename); if (asprintf(&filename, "%s/%s", dir_name, diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 6bf75c98e1f2..8e982e68b717 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -49,6 +49,7 @@ static int dso__load_vdso_sym(struct dso *dso, struct map= *map); static bool symbol__is_idle(const char *name); =20 struct dso_filename_paths vmlinux_paths; +struct dso_filename_paths vdso_paths; =20 struct symbol_conf symbol_conf =3D { .nanosecs =3D false, @@ -2303,6 +2304,16 @@ struct dso_filename_pattern vmlinux_patterns[] =3D { {"/usr/lib/debug/boot/vmlinux-%s.debug", 1}, }; =20 +struct dso_filename_pattern vdso_patterns[] =3D { + {"/lib/modules/%s/vdso/vdso.so", 1}, + {"/lib/modules/%s/vdso/vdso64.so", 1}, + {"/lib/modules/%s/vdso/vdso32.so", 1}, + {"/lib/modules/%s/build/arch/%s/vdso/vdso.so.dbg", 2}, + {"/lib/modules/%s/build/arch/%s/kernel/vdso/vdso.so.dbg", 2}, + {"/lib/modules/%s/build/arch/%s/entry/vdso/vdso32.so.dbg", 2}, + {"/lib/modules/%s/build/arch/%s/entry/vdso/vdso64.so.dbg", 2}, +}; + static int dso_filename_path__add(struct dso_filename_paths *paths, const = char *new_entry) { paths->paths[paths->nr_entries] =3D strdup(new_entry); @@ -2565,6 +2576,11 @@ int symbol__init(struct perf_env *env) return -1; } =20 + if (dso_filename_path__init(&vdso_paths, vdso_patterns, + ARRAY_SIZE(vdso_patterns), env) < 0) { + return -1; + } + if (symbol_conf.field_sep && *symbol_conf.field_sep =3D=3D '.') { pr_err("'.' is the only non valid --field-separator argument\n"); return -1; @@ -2641,6 +2657,7 @@ void symbol__exit(void) intlist__delete(symbol_conf.pid_list); intlist__delete(symbol_conf.addr_list); dso_filename_path__exit(&vmlinux_paths); + dso_filename_path__exit(&vdso_paths); symbol_conf.sym_list =3D symbol_conf.dso_list =3D symbol_conf.comm_list = =3D NULL; symbol_conf.bt_stop_list =3D NULL; symbol_conf.initialized =3D false; diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h index 30056884945b..08c339594d4e 100644 --- a/tools/perf/util/symbol.h +++ b/tools/perf/util/symbol.h @@ -107,6 +107,7 @@ struct dso_filename_paths { }; =20 extern struct dso_filename_paths vmlinux_paths; +extern struct dso_filename_paths vdso_paths; =20 static inline void *symbol__priv(struct symbol *sym) { --=20 2.34.1 From nobody Sat Feb 7 07:10:19 2026 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16EDE1B3F33; Fri, 16 Aug 2024 10:58:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805929; cv=none; b=DLE34FwHzG+GpA1K13o7Rc78NKGllixp+uojyI+5angNcXwjxp4WktqSIyJ5BLStr86t6S4QhYDaVdN4WvVP0pXUpATs3Re6usyGQ+UkkCBSmD06ZHwBnQL78/Z4ZLRKaceobLSAyp+c7hlsPuy7erZaRAUdoUsOoHJd3wTvs+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805929; c=relaxed/simple; bh=YaSqM+yON6vKOgHU+PFjwHs6wYzBXT+CMoR7EDyy+OI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oDXJUN/3MqPYo2PNrr0p4n6H3l5ztmwUttIcei9CDs7K7IwXkxs8r/aT/6H53kQSeCsPOp1QjI6vRH2L0q/pd9q1CpR0dNzMxJGwIHSIpORpUTTd9ci9PFwc4A9MUJH7uC1fpdYeJNEfXsW0xXpFYptLXT64avMRhruh3cmv2d0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Wlf4c3XJ0z20ltp; Fri, 16 Aug 2024 18:54:08 +0800 (CST) Received: from kwepemd100011.china.huawei.com (unknown [7.221.188.204]) by mail.maildlp.com (Postfix) with ESMTPS id A43A11A0188; Fri, 16 Aug 2024 18:58:44 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemd100011.china.huawei.com (7.221.188.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 16 Aug 2024 18:58:43 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Nathan Chancellor CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Nick Desaulniers , Bill Wendling , Justin Stitt , , , , Hui Wang , Changbin Du Subject: [PATCH v6 7/8] perf: disasm: prefer debugging files in build-id cache Date: Fri, 16 Aug 2024 18:58:10 +0800 Message-ID: <20240816105811.1812897-8-changbin.du@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816105811.1812897-1-changbin.du@huawei.com> References: <20240816105811.1812897-1-changbin.du@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd100011.china.huawei.com (7.221.188.204) Content-Type: text/plain; charset="utf-8" The build-id cache might have both debugging and non-debugging files. Here we prefer the debugging version for annotation. Cc: Adrian Hunter Signed-off-by: Changbin Du --- tools/perf/util/disasm.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 6af9fbec3a95..5f66b3632770 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -1162,18 +1162,25 @@ static int dso__disassemble_filename(struct dso *ds= o, char *filename, size_t fil !dso__is_kcore(dso)) return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX; =20 - build_id_filename =3D dso__build_id_filename(dso, NULL, 0, false); - if (build_id_filename) { - __symbol__join_symfs(filename, filename_size, build_id_filename); - free(build_id_filename); - } else { - if (dso__has_build_id(dso)) - return ENOMEM; - return fallback_filename(dso, filename, filename_size); - } + /* Prefer debugging file if exists, otherwise non-debugging one is used. = */ + for (int i =3D 0; i < 2; i++) { + build_id_filename =3D dso__build_id_filename(dso, NULL, 0, !i); + if (build_id_filename) { + __symbol__join_symfs(filename, filename_size, build_id_filename); + free(build_id_filename); + } else { + if (dso__has_build_id(dso)) + return ENOMEM; + return fallback_filename(dso, filename, filename_size); + } =20 - if (access(filename, R_OK)) - return fallback_filename(dso, filename, filename_size); + if (!access(filename, R_OK)) + break; + else if (i !=3D 0) { + /* nor debugging or non-debugging is found */ + return fallback_filename(dso, filename, filename_size); + } + } =20 if (dso__is_kcore(dso) || dso__is_vdso(dso)) goto fallback; --=20 2.34.1 From nobody Sat Feb 7 07:10:19 2026 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0B0A1B5820; Fri, 16 Aug 2024 10:58:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805930; cv=none; b=b7r86gcdpBkJy+t5wkYKUUZyN1eeaz2gdEk6qXD1GRFOa7YNrOwjczrI6TrdXZ1jvQQda+J9Hrq6eIuefAIGkMEkI8OGFwZ3U0KeqdhN+AeR3JUzAAUhLgn0SPXP6hcMXbmRCMUkOZv3AtB8wyw5ITUZbZ1vcdKi/1HjIbh0fxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723805930; c=relaxed/simple; bh=BnKwtgbDOBy6xNe23GdjLGT6tsNsyI/9xyn0n4di9lQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LuuzSbwmUcMb7Orc+CLk5iqDex/6OkJ29uoBZoGMUIFJu/Dm3wtXZSSwHgdZVB9G+2bkJ1vI8AwZpwJaQpmgA3gGWDg/+JnZ/kYKSVs5OL2AA9ZJxENLAIj7QbEmtrm+1+oCC9pb9rtoleWgMqEUm4rzep4OMaboQ4bvOcVQ7C4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.190 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Wlf4d6LJWz20lsH; Fri, 16 Aug 2024 18:54:09 +0800 (CST) Received: from kwepemd100011.china.huawei.com (unknown [7.221.188.204]) by mail.maildlp.com (Postfix) with ESMTPS id 10EF81A016C; Fri, 16 Aug 2024 18:58:46 +0800 (CST) Received: from M910t.huawei.com (10.110.54.157) by kwepemd100011.china.huawei.com (7.221.188.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Fri, 16 Aug 2024 18:58:44 +0800 From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Nathan Chancellor CC: Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Nick Desaulniers , Bill Wendling , Justin Stitt , , , , Hui Wang , Changbin Du Subject: [PATCH v6 8/8] perf buildid-cache: recognize vdso when adding files Date: Fri, 16 Aug 2024 18:58:11 +0800 Message-ID: <20240816105811.1812897-9-changbin.du@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240816105811.1812897-1-changbin.du@huawei.com> References: <20240816105811.1812897-1-changbin.du@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd100011.china.huawei.com (7.221.188.204) Content-Type: text/plain; charset="utf-8" Identify vdso by file name matching. The vdso objects have name as vdso[32,64].so[.dbg]. $ perf buildid-cache -a /work/linux/arch/x86/entry/vdso/vdso64.so.dbg Without this change, adding vdso using above command actually will never be used. Signed-off-by: Changbin Du --- tools/perf/builtin-buildid-cache.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildi= d-cache.c index b0511d16aeb6..8edea9044a65 100644 --- a/tools/perf/builtin-buildid-cache.c +++ b/tools/perf/builtin-buildid-cache.c @@ -172,6 +172,30 @@ static int build_id_cache__add_kcore(const char *filen= ame, bool force) return 0; } =20 +static bool filename_is_vdso(const char *filename) +{ + char *fname, *bname; + static const char * const vdso_names[] =3D { + "vdso.so", "vdso32.so", "vdso64.so", "vdsox32.so" + }; + + fname =3D strdup(filename); + if (!fname) { + pr_err("no mememory\n"); + return false; + } + + bname =3D basename(fname); + if (!bname) + return false; + + for (unsigned int i =3D 0; i < ARRAY_SIZE(vdso_names); i++) { + if (!strncmp(bname, vdso_names[i], strlen(vdso_names[i]))) + return true; + } + return false; +} + static int build_id_cache__add_file(const char *filename, struct nsinfo *n= si) { char sbuild_id[SBUILD_ID_SIZE]; @@ -189,7 +213,7 @@ static int build_id_cache__add_file(const char *filenam= e, struct nsinfo *nsi) =20 build_id__sprintf(&bid, sbuild_id); err =3D build_id_cache__add_s(sbuild_id, filename, nsi, - false, false); + false, filename_is_vdso(filename)); pr_debug("Adding %s %s: %s\n", sbuild_id, filename, err ? "FAIL" : "Ok"); return err; --=20 2.34.1