[PATCH v6 8/8] perf buildid-cache: recognize vdso when adding files

Changbin Du posted 8 patches 1 year, 6 months ago
There is a newer version of this series
[PATCH v6 8/8] perf buildid-cache: recognize vdso when adding files
Posted by Changbin Du 1 year, 6 months ago
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 <changbin.du@huawei.com>
---
 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-buildid-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 *filename, bool force)
 	return 0;
 }
 
+static bool filename_is_vdso(const char *filename)
+{
+	char *fname, *bname;
+	static const char * const vdso_names[] = {
+		"vdso.so", "vdso32.so", "vdso64.so", "vdsox32.so"
+	};
+
+	fname = strdup(filename);
+	if (!fname) {
+		pr_err("no mememory\n");
+		return false;
+	}
+
+	bname = basename(fname);
+	if (!bname)
+		return false;
+
+	for (unsigned int i = 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 *nsi)
 {
 	char sbuild_id[SBUILD_ID_SIZE];
@@ -189,7 +213,7 @@ static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
 
 	build_id__sprintf(&bid, sbuild_id);
 	err = 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;
-- 
2.34.1
Re: [PATCH v6 8/8] perf buildid-cache: recognize vdso when adding files
Posted by Adrian Hunter 1 year, 5 months ago
On 25/07/24 05:15, Changbin Du wrote:
> 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 <changbin.du@huawei.com>

A couple of comments, but address those then add:

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  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-buildid-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 *filename, bool force)
>  	return 0;
>  }
>  
> +static bool filename_is_vdso(const char *filename)
> +{
> +	char *fname, *bname;
> +	static const char * const vdso_names[] = {
> +		"vdso.so", "vdso32.so", "vdso64.so", "vdsox32.so"
> +	};
> +
> +	fname = strdup(filename);
> +	if (!fname) {
> +		pr_err("no mememory\n");

mememory -> memory

> +		return false;
> +	}

fname is never freed.

> +
> +	bname = basename(fname);
> +	if (!bname)
> +		return false;
> +
> +	for (unsigned int i = 0; i < ARRAY_SIZE(vdso_names); i++) {

'unsigned' is unnecessary

> +		if (!strncmp(bname, vdso_names[i], strlen(vdso_names[i])))

Use strstarts()

> +			return true;
> +	}
> +	return false;
> +}
> +
>  static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
>  {
>  	char sbuild_id[SBUILD_ID_SIZE];
> @@ -189,7 +213,7 @@ static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
>  
>  	build_id__sprintf(&bid, sbuild_id);
>  	err = 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;
Re: [PATCH v6 8/8] perf buildid-cache: recognize vdso when adding files
Posted by duchangbin 1 year, 4 months ago
On Wed, Sep 11, 2024 at 11:05:20AM +0300, Adrian Hunter wrote:
> On 25/07/24 05:15, Changbin Du wrote:
> > 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 <changbin.du@huawei.com>
> 
> A couple of comments, but address those then add:
> 
> Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
> 
> > ---
> >  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-buildid-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 *filename, bool force)
> >  	return 0;
> >  }
> >  
> > +static bool filename_is_vdso(const char *filename)
> > +{
> > +	char *fname, *bname;
> > +	static const char * const vdso_names[] = {
> > +		"vdso.so", "vdso32.so", "vdso64.so", "vdsox32.so"
> > +	};
> > +
> > +	fname = strdup(filename);
> > +	if (!fname) {
> > +		pr_err("no mememory\n");
> 
> mememory -> memory
>
fixed.

> > +		return false;
> > +	}
> 
> fname is never freed.
> 
fixed.

> > +
> > +	bname = basename(fname);
> > +	if (!bname)
> > +		return false;
> > +
> > +	for (unsigned int i = 0; i < ARRAY_SIZE(vdso_names); i++) {
> 
> 'unsigned' is unnecessary
> 
This is required to supress this error.
error: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’

> > +		if (!strncmp(bname, vdso_names[i], strlen(vdso_names[i])))
> 
> Use strstarts()
> 
okay.

> > +			return true;
> > +	}
> > +	return false;
> > +}
> > +
> >  static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
> >  {
> >  	char sbuild_id[SBUILD_ID_SIZE];
> > @@ -189,7 +213,7 @@ static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
> >  
> >  	build_id__sprintf(&bid, sbuild_id);
> >  	err = 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;
> 
> 

-- 
Cheers,
Changbin Du