Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp29638lqs; Thu, 13 Jun 2024 02:50:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWlf+ZXTdXNRI36DT2ov5meB/W+eYAFccrF15NcNJCLgVsSC8JrqbbG13eXYf1PXM4a1kbcKD7F0/INn7RiNFnwdL/IceYuGhz0/PRNjA== X-Google-Smtp-Source: AGHT+IEpmDGxTifQK6aZUEHcB7OFy+SZ5s6RMIFoCyT7zttUEr9hJlIEcc67f9q1Lc7pCbtgJBpT X-Received: by 2002:a05:622a:1a8a:b0:441:2b3:595c with SMTP id d75a77b69052e-4415abf3410mr60269011cf.30.1718272200376; Thu, 13 Jun 2024 02:50:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718272200; cv=pass; d=google.com; s=arc-20160816; b=cgd819ID0sMj/H7KAvmnYTxav1jncYYzaIxdBkiCnOHhq6yXOPIT/RERfMepgQPcAR v6u10B+Jon9rfnjzAzkGxNLufL1uX+ra+7g2fjnnuC9cemaZZtDKhZYkqnj9gATHiQox 6PLNl5oCVns258TtEPWpWBDhlDGAAQ71oIxLuIJK3NYAnwulkD9EfAlIlJAzF8fSZ8/S KzsPxR50dzor/6zEJ1bNV+V0X4GkJ5Rm+VgcPNg0lRTtYopr6c4WeUcUkeC8hHVzXYl5 tjPOom8/rKFz5aahZtghG20oZaedzAGY3j78eeTWaaFrHFcyYz2Mry/Xwdnq8eaKgGfE AKvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:content-id:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=uWYnPw7ipE/jIqOLu7d5R3VfWppJk9RWfRt75qsNAno=; fh=8Ourhkr0tvK0vG9IHJ9QgfFJx8o+EsOFvYXMeRYLVuM=; b=G8nNX04r9XuLrgHZEh8IVXYe20uEtjv6SfMeTpgg9pg7GX2y9pjQmehucFmcjMoIwL bdGZWxNxNDN7h8N8tisATTxgDtGGlvRLbkyjZRGONBpaAybCumVm397FIec9XLDI6H8T +JFG3Tj302T/dr7OQxU8HSBw5w5dZ9WJypcb5rlrCVNBPsWdew3CJ9O9zs42feQxjQPM 8Dvl+pdjHe5cKyW3NJr30hKdRoyqFWPOr1P70s/1TFr/lMGAoIfsiTWaWI9PUEjvE3U4 b231Z8v1VeiBZWf+65GUDndkTTFyW7Yrp8eC2DsCohuyHCTpFzb6O5uSE233DxtpjNqR X8ew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-212979-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212979-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-441f3222da0si9595771cf.809.2024.06.13.02.50.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 02:50:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212979-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-212979-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212979-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0EC481C22578 for ; Thu, 13 Jun 2024 09:50:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 49C3A14037D; Thu, 13 Jun 2024 09:49:54 +0000 (UTC) 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 BD43013D8A1; Thu, 13 Jun 2024 09:49:50 +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=1718272193; cv=none; b=iP/5W7mcbqW1LiN8uL+Oio78xmvtxGA7mFGzp7Sbk+WlqMt20yraaZZ2LHSCe6XAd73Jsgnw17UJ5y1OM2CGfwjwrQNsdi9bwjvBLtOcBYzxStEjLNFS2wd8JuOganqQ2pn+WjY+iEJkoKQ6VUYFANHLv951HMBlSGDmpK7LblY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718272193; c=relaxed/simple; bh=chr9JA/bnKpL3g4g4rv7ud4C6VS38QLsi8tMH8cl5g0=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: Content-Type:MIME-Version; b=YCXX3Y1GwVN3HuPRm4pGvGYP84q+sOVKo/YJQdi/71ufxcHH8+PPVebjxr2G1WQSkNnb5kanaQH3WyVdtalnJ2SdWQVVYALbQGG3u83otN3TOv914JvDrCmyAjmOvOTQPce7p6uTV+FrEWJ57Z3q6KIW6K2VipjH7CmQCxNJFI4= 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.162.112]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4W0HbX22lCz2CkML; Thu, 13 Jun 2024 17:46:00 +0800 (CST) Received: from kwepemd500010.china.huawei.com (unknown [7.221.188.84]) by mail.maildlp.com (Postfix) with ESMTPS id AFB821402CA; Thu, 13 Jun 2024 17:49:48 +0800 (CST) Received: from kwepemd100011.china.huawei.com (7.221.188.204) by kwepemd500010.china.huawei.com (7.221.188.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Thu, 13 Jun 2024 17:49:48 +0800 Received: from kwepemd100011.china.huawei.com ([7.221.188.204]) by kwepemd100011.china.huawei.com ([7.221.188.204]) with mapi id 15.02.1258.034; Thu, 13 Jun 2024 17:49:48 +0800 From: duchangbin To: Adrian Hunter CC: duchangbin , Peter Zijlstra , Ingo Molnar , "Arnaldo Carvalho de Melo" , Namhyung Kim , Nathan Chancellor , Mark Rutland , Alexander Shishkin , Jiri Olsa , "Ian Rogers" , "Liang, Kan" , "Nick Desaulniers" , Bill Wendling , Justin Stitt , "linux-perf-users@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "llvm@lists.linux.dev" Subject: Re: [PATCH 1/2] perf: support specify vdso path in cmdline Thread-Topic: [PATCH 1/2] perf: support specify vdso path in cmdline Thread-Index: AQHavVvgPApptK0OsE6+S63iYUbWKrHE1RgAgACeKQA= Date: Thu, 13 Jun 2024 09:49:48 +0000 Message-ID: <1e17854b16fe46a4b384b6ddec05029a@huawei.com> References: <20240613063510.348692-1-changbin.du@huawei.com> <20240613063510.348692-2-changbin.du@huawei.com> <961fe800-7160-4c53-a3a0-f16700c433cd@intel.com> In-Reply-To: <961fe800-7160-4c53-a3a0-f16700c433cd@intel.com> Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-imapappendstamp: kwepemd100011.china.huawei.com (15.02.1258.034) x-ms-exchange-messagesentrepresentingtype: 1 Content-Type: text/plain; charset="us-ascii" Content-ID: <71BFC53452BD0846B1C74A7511D4179B@huawei.com> Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Thu, Jun 13, 2024 at 11:23:26AM +0300, Adrian Hunter wrote: > On 13/06/24 09:35, Changbin Du wrote: > > 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. > >=20 > > 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. > >=20 > > $ sudo perf record -a > > $ sudo perf report --objdump=3Dllvm-objdump \ > > --vdso arch/x86/entry/vdso/vdso64.so.dbg,arch/x86/entry/vdso/vdso32.s= o.dbg > >=20 > > When doing cross platform analysis, we also need specify the vdso path = if > > we are interested in its symbols. >=20 > We already have logic to find debug files, and to deal with a symbol sour= ce > (syms_ss) and runtime symbol source (runtime_ss). >=20 > Can't we make that work transparently for vdso so that the user does > not have to. > For Ubuntu, we can find the debug files of vdso in /lib/modules//vdso/vdso{32,64}.so. These two are debug version. For local build, seems vdso{32,64}.so.dbg are not installed in /lib/modules= / nor other locations. > >=20 > > Signed-off-by: Changbin Du > > --- > > 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/symbol.c | 74 +++++++++++++++++++++++++++++++++++ > > tools/perf/util/symbol_conf.h | 5 +++ > > 8 files changed, 91 insertions(+) > >=20 > > diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotat= e.c > > index 50d2fb222d48..ff466882065d 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 = **argv) > > 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 69618fb0110b..a64b48460dce 100644 > > --- a/tools/perf/builtin-report.c > > +++ b/tools/perf/builtin-report.c > > @@ -1324,6 +1324,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 1d6aef51c122..a3cce4e76eb9 100644 > > --- a/tools/perf/builtin-top.c > > +++ b/tools/perf/builtin-top.c > > @@ -1479,6 +1479,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/symbol.c b/tools/perf/util/symbol.c > > index 9e5940b5bc59..8d040039a7ce 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; > > @@ -1833,6 +1835,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) { > > @@ -2349,6 +2357,72 @@ static int vmlinux_path__init(struct perf_env *e= nv) > > 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_c= onf.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_D= SO)) > > + return -1; > > + > > + /* > > + * dso__load_sym() may copy 'dso' which will result in the copies hav= ing > > + * 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); > > + symsrc__destroy(&ss); > > + > > + if (err > 0) { > > + dso__set_loaded(dso); > > + pr_debug("Using %s for %s symbols\n", symfs_vdso, dso__short_name(ds= o)); > > + } > > + > > + 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_con= f.h > > index c114bbceef40..108356e3c981 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; > > @@ -55,6 +56,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, > > @@ -85,4 +87,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 >=20 --=20 Cheers, Changbin Du