linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: James Clark <james.clark@arm.com>
Cc: acme@kernel.org, linux-perf-users@vger.kernel.org,
	coresight@lists.linaro.org, Denis Nikitin <denik@chromium.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] perf: Set build-id using build-id header on new mmap records
Date: Sun, 27 Feb 2022 23:50:38 +0100	[thread overview]
Message-ID: <YhwAPrOP/ky4HLfC@krava> (raw)
In-Reply-To: <20220224171955.862983-2-james.clark@arm.com>

On Thu, Feb 24, 2022 at 05:19:55PM +0000, James Clark wrote:
> MMAP records that occur after the build-id header is parsed do not have
> their build-id set even if the filename matches an entry from the
> header. Set the build-id on these dsos as long as the MMAP record
> doesn't have its own build-id set.
> 
> This fixes an issue with off target analysis where the local version of
> a dso is loaded rather than one from ~/.debug via a build-id.

nice catch :)

> 
> Reported-by: Denis Nikitin <denik@chromium.org>
> Signed-off-by: James Clark <james.clark@arm.com>
> ---
>  tools/perf/util/dso.h    |  1 +
>  tools/perf/util/header.c |  1 +
>  tools/perf/util/map.c    | 16 ++++++++++++++--
>  3 files changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
> index 011da3924fc1..3a9fd4d389b5 100644
> --- a/tools/perf/util/dso.h
> +++ b/tools/perf/util/dso.h
> @@ -167,6 +167,7 @@ struct dso {
>  	enum dso_load_errno	load_errno;
>  	u8		 adjust_symbols:1;
>  	u8		 has_build_id:1;
> +	u8		 header_build_id:1;
>  	u8		 has_srcline:1;
>  	u8		 hit:1;
>  	u8		 annotate_warned:1;
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index 6da12e522edc..571d73d4f976 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -2200,6 +2200,7 @@ static int __event_process_build_id(struct perf_record_header_build_id *bev,
>  
>  		build_id__init(&bid, bev->data, size);
>  		dso__set_build_id(dso, &bid);
> +		dso->header_build_id = 1;
>  
>  		if (dso_space != DSO_SPACE__USER) {
>  			struct kmod_path m = { .name = NULL, };
> diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
> index 1803d3887afe..4ae91e491e23 100644
> --- a/tools/perf/util/map.c
> +++ b/tools/perf/util/map.c
> @@ -127,7 +127,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
>  
>  	if (map != NULL) {
>  		char newfilename[PATH_MAX];
> -		struct dso *dso;
> +		struct dso *dso, *header_bid_dso;
>  		int anon, no_dso, vdso, android;
>  
>  		android = is_android_lib(filename);
> @@ -185,7 +185,19 @@ struct map *map__new(struct machine *machine, u64 start, u64 len,
>  
>  		if (build_id__is_defined(bid))
>  			dso__set_build_id(dso, bid);
> -
> +		else {

nit please add { } to the if clause as well

> +			/*
> +			 * If the mmap event had no build ID, search for an existing dso from the
> +			 * build ID header by name. Otherwise only the dso loaded at the time of
> +			 * reading the header will have the build ID set and all future mmaps will
> +			 * have it missing.
> +			 */
> +			header_bid_dso = __dsos__find(&machine->dsos, filename, false);

is this 'perf top' safe? I think dso should be added in the
same thread, but please check and add comment why we don't
need locking in here

thanks,
jirka

> +			if (header_bid_dso && header_bid_dso->header_build_id) {
> +				dso__set_build_id(dso, &header_bid_dso->bid);
> +				dso->header_build_id = 1;
> +			}
> +		}
>  		dso__put(dso);
>  	}
>  	return map;
> -- 
> 2.28.0
> 

  reply	other threads:[~2022-02-27 22:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-24 17:19 [PATCH 0/1] perf: Set build-id using build-id header on new mmap records James Clark
2022-02-24 17:19 ` [PATCH 1/1] " James Clark
2022-02-27 22:50   ` Jiri Olsa [this message]
2022-03-02 16:20     ` James Clark
2022-03-03 11:36       ` Jiri Olsa
2022-03-04  9:11         ` James Clark

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YhwAPrOP/ky4HLfC@krava \
    --to=olsajiri@gmail.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=coresight@lists.linaro.org \
    --cc=denik@chromium.org \
    --cc=james.clark@arm.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).