LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>, leo.yan@linaro.org
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Coresight ML <coresight@lists.linaro.org>
Subject: Re: [PATCH] perf cs-etm: Correct CPU mode for samples
Date: Tue, 30 Oct 2018 17:30:55 +0200	[thread overview]
Message-ID: <b00357d2-10ab-e75e-6748-13341641f107@intel.com> (raw)
In-Reply-To: <20181030151137.GF23310@kernel.org>

On 30/10/18 5:11 PM, Arnaldo Carvalho de Melo wrote:
> Em Tue, Oct 30, 2018 at 11:04:49PM +0800, leo.yan@linaro.org escreveu:
>> Hi Arnaldo,
>>
>> On Tue, Oct 30, 2018 at 11:32:26AM -0300, Arnaldo Carvalho de Melo wrote:
>>> Em Tue, Oct 30, 2018 at 03:18:28PM +0800, Leo Yan escreveu:
>>>> Since commit 9042f5e3539e ("perf tools: Stop fallbacking to kallsyms
>>>> for vdso symbols lookup"), the kernel address cannot be properly parsed
>>>> to kernel symbol with command 'perf script -k vmlinux'.  The reason is
>>>> CoreSight samples is always to set CPU mode as PERF_RECORD_MISC_USER,
>>>> thus it fails to find corresponding map/dso in below flows:
>>>>
>>>>   process_sample_event()
>>>>     `-> machine__resolve()
>>>> 	  `-> thread__find_map(thread, sample->cpumode, sample->ip, al);
>>>>
>>>> In this flow it needs to pass argument 'sample->cpumode' to tell what's
>>>> the CPU mode, before it always passed PERF_RECORD_MISC_USER but without
>>>> any failure until the commit 9042f5e3539e ("perf tools: Stop fallbacking
>>>> to kallsyms for vdso symbols lookup") has been merged.  The reason is
>>>> even with the wrong CPU mode the function thread__find_map() firstly
>>>> fails to find map but it will rollback to find kernel map for vdso
>>>> symbols lookup.  In the latest code it has removed the fallback code,
>>>> thus if CPU mode is PERF_RECORD_MISC_USER then it cannot find map
>>>> anymore with kernel address.
>>>>
>>>> This patch is to correct samples CPU mode setting, it creates a new
>>>> helper function cs_etm__cpu_mode() to tell what's the CPU mode based on
>>>> the address with the info from machine structure; this patch has a bit
>>>> extension to check not only kernel and user mode, but also check for
>>>> host/guest and hypervisor mode.  Finally this patch uses the function
>>>> in instruction and branch samples and also apply in cs_etm__mem_access()
>>>> for a minor polishing.
>>>
>>> Mathieu, can I have your Acked-by, please? Leo, thanks for acting so
>>> quickly on this one! 
>>
>> Thanks for reivewing.  Yeah, let's wait for Mathieu reviewing as well,
>> as I know he is travelling so might be delay a bit.
> 
> I'm tentatively applying the patch, as this needs fixing ASAP, and I
> take that you have tested it and it cured the problem for you, so should
> be a good indication for the acceptance of the patch.
> 
> We can always fix some detail later.
>  
>> Just remind, we might need the similiar change for util/intel-pt.c and
>> util/intel-bts.c when generate samples, otherwise they might have the
>> same regression for kernel symbols.  I am not the best person to change
>> these two files, but bring up this for attention.
> 
> Right, I think Adrian is working on it, Adrian?

Yes although I am more concerned with branches from user space to kernel
space and vice versa, which this patch doesn't deal with.  Also there are
many cpumode issues in perf tools, and really the only way to deal with
them simply at the moment is to put back the fallback for arches other
than sparc i.e.

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index bc646185f8d9..b7a79cf490ad 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1561,9 +1561,18 @@ struct map *thread__find_map(struct thread *thread, u8 cpumode, u64 addr,
 
 		return NULL;
 	}
-
+try_again:
 	al->map = map_groups__find(mg, al->addr);
-	if (al->map != NULL) {
+	if (al->map == NULL) {
+		if (cpumode == PERF_RECORD_MISC_USER && machine &&
+		    strcmp(perf_env__arch(machine->env), "sparc") &&
+		    mg != &machine->kmaps &&
+		    machine__kernel_ip(machine, al->addr)) {
+			mg = &machine->kmaps;
+			load_map = true;
+			goto try_again;
+		}
+	} else {
 		/*
 		 * Kernel maps might be changed when loading symbols so loading
 		 * must be done prior to using kernel maps.



  reply	other threads:[~2018-10-30 15:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-30  7:18 Leo Yan
2018-10-30 14:32 ` Arnaldo Carvalho de Melo
2018-10-30 15:04   ` leo.yan
2018-10-30 15:11     ` Arnaldo Carvalho de Melo
2018-10-30 15:30       ` Adrian Hunter [this message]
2018-10-30 15:45         ` Arnaldo Carvalho de Melo
2018-10-31 22:04 ` [tip:perf/urgent] " tip-bot for Leo Yan

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=b00357d2-10ab-e75e-6748-13341641f107@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=coresight@lists.linaro.org \
    --cc=jolsa@redhat.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --subject='Re: [PATCH] perf cs-etm: Correct CPU mode for samples' \
    /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

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).