From: Leo Yan <leo.yan@linaro.org>
To: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Coresight ML <coresight@lists.linaro.org>,
linux-kernel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Robert Walker <robert.walker@arm.com>,
Jiri Olsa <jolsa@redhat.com>,
linux-arm-kernel@lists.infradead.org,
Mike Leach <mike.leach@linaro.org>
Subject: Re: [PATCH v6 8/8] perf cs-etm: Set sample flags for exception return packet
Date: Thu, 24 Jan 2019 07:36:19 +0800 [thread overview]
Message-ID: <20190123233619.GA3268@leoy-ThinkPad-X240s> (raw)
In-Reply-To: <20190123215114.GH620@xps15>
Hi Mathieu,
On Wed, Jan 23, 2019 at 02:51:14PM -0700, Mathieu Poirier wrote:
> On Sat, Jan 19, 2019 at 09:43:47AM +0800, Leo Yan wrote:
> > When return from exception, we need to distinguish if it's system call
> > return or for other type exceptions for setting sample flags. Due to
> > the exception return packet doesn't contain exception number, so we
> > cannot decide sample flags based on exception number.
> >
> > On the other hand, the exception return packet is followed by an
> > instruction range packet; this range packet deliveries the start address
> > after exception handling, we can check if it is a SVC instruction just
> > before the start address. If there has one SVC instruction is found
> > ahead the return address, this means it's an exception return for system
> > call; otherwise it is an normal return for other exceptions.
> >
> > This patch is to set sample flags for exception return packet, firstly
> > it simply set sample flags as PERF_IP_FLAG_INTERRUPT for all exception
> > returns since at this point it doesn't know what's exactly the exception
> > type. We will defer to decide if it's an exception return for system
> > call when the next instruction range packet comes, it checks if there
> > has one SVC instruction prior to the start address and if so we will
> > change sample flags to PERF_IP_FLAG_SYSCALLRET for system call
> > return.
> >
> > Signed-off-by: Leo Yan <leo.yan@linaro.org>
> > ---
> > tools/perf/util/cs-etm.c | 44 ++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 44 insertions(+)
> >
> > diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
> > index 052805de6513..7547a7178f46 100644
> > --- a/tools/perf/util/cs-etm.c
> > +++ b/tools/perf/util/cs-etm.c
> > @@ -1372,6 +1372,20 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq)
> > if (prev_packet->sample_type == CS_ETM_DISCONTINUITY)
> > prev_packet->flags |= PERF_IP_FLAG_BRANCH |
> > PERF_IP_FLAG_TRACE_BEGIN;
> > +
> > + /*
> > + * If the previous packet is an exception return packet
> > + * and the return address just follows SVC instuction,
> > + * it needs to calibrate the previous packet sample flags
> > + * as PERF_IP_FLAG_SYSCALLRET.
> > + */
> > + if (prev_packet->flags == (PERF_IP_FLAG_BRANCH |
> > + PERF_IP_FLAG_RETURN |
> > + PERF_IP_FLAG_INTERRUPT) &&
>
> Would it make more sense to just look for prev-packet->sample_type ==
> CS_ETM_EXCEPTION_RET ?
We cannot check 'prev-packet->sample_type == CS_ETM_EXCEPTION_RET',
since CS_ETM_EXCEPTION_RET is associated to its previous instruction
range packet but not a standalone instruction range packet, we don't
swap for exception and exception return packets, 'prev_packet' is
pointed to the previous instruction range packet at here.
This is why we need to use 'prev_packet->flags' but not
'prev_packet->sample_type' as checking condition.
Thanks,
Leo Yan
> > + cs_etm__is_svc_instr(etmq, packet, packet->start_addr))
> > + prev_packet->flags = PERF_IP_FLAG_BRANCH |
> > + PERF_IP_FLAG_RETURN |
> > + PERF_IP_FLAG_SYSCALLRET;
> > break;
> > case CS_ETM_DISCONTINUITY:
> > /*
> > @@ -1422,6 +1436,36 @@ static int cs_etm__set_sample_flags(struct cs_etm_queue *etmq)
> > prev_packet->flags = packet->flags;
> > break;
> > case CS_ETM_EXCEPTION_RET:
> > + /*
> > + * When the exception return packet is inserted, since
> > + * exception return packet is not used standalone for
> > + * generating samples and it's affiliation to the previous
> > + * instruction range packet; so set previous range packet
> > + * flags to tell perf it is an exception return branch.
> > + *
> > + * The exception return can be for either system call or
> > + * other exception types; unfortunately the packet doesn't
> > + * contain exception type related info so we cannot decide
> > + * the exception type purely based on exception return packet.
> > + * If we record the exception number from exception packet and
> > + * reuse it for excpetion return packet, this is not reliable
> > + * due the trace can be discontinuity or the interrupt can
> > + * be nested, thus the recorded exception number cannot be
> > + * used for exception return packet for these two cases.
> > + *
> > + * For exception return packet, we only need to distinguish the
> > + * packet is for system call or for other types. Thus the
> > + * decision can be deferred when receive the next packet which
> > + * contains the return address, based on the return address we
> > + * can read out the previous instruction and check if it's a
> > + * system call instruction and then calibrate the sample flag
> > + * as needed.
> > + */
> > + if (prev_packet->sample_type == CS_ETM_RANGE)
> > + prev_packet->flags = PERF_IP_FLAG_BRANCH |
> > + PERF_IP_FLAG_RETURN |
> > + PERF_IP_FLAG_INTERRUPT;
> > + break;
> > case CS_ETM_EMPTY:
> > default:
> > break;
> > --
> > 2.17.1
> >
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2019-01-23 23:36 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-19 1:43 [PATCH v6 0/8] perf cs-etm: Add support for sample flags Leo Yan
2019-01-19 1:43 ` [PATCH v6 1/8] perf cs-etm: Add last instruction information in packet Leo Yan
2019-01-23 21:03 ` Mathieu Poirier
2019-01-19 1:43 ` [PATCH v6 2/8] perf cs-etm: Set sample flags for instruction range packet Leo Yan
2019-01-23 21:03 ` Mathieu Poirier
2019-01-19 1:43 ` [PATCH v6 3/8] perf cs-etm: Set sample flags for trace discontinuity Leo Yan
2019-01-23 21:04 ` Mathieu Poirier
2019-01-19 1:43 ` [PATCH v6 4/8] perf cs-etm: Add exception number in exception packet Leo Yan
2019-01-23 21:05 ` Mathieu Poirier
2019-01-19 1:43 ` [PATCH v6 5/8] perf cs-etm: Change tuple from traceID-CPU# to traceID-metadata Leo Yan
2019-01-23 21:13 ` Mathieu Poirier
2019-01-23 23:45 ` Leo Yan
2019-01-19 1:43 ` [PATCH v6 6/8] perf cs-etm: Add traceID in packet Leo Yan
2019-01-23 21:23 ` Mathieu Poirier
2019-01-19 1:43 ` [PATCH v6 7/8] perf cs-etm: Set sample flags for exception packet Leo Yan
2019-01-23 21:39 ` Mathieu Poirier
2019-01-19 1:43 ` [PATCH v6 8/8] perf cs-etm: Set sample flags for exception return packet Leo Yan
2019-01-23 21:51 ` Mathieu Poirier
2019-01-23 23:36 ` Leo Yan [this message]
2019-01-24 0:22 ` [PATCH v6 0/8] perf cs-etm: Add support for sample flags Mathieu Poirier
2019-01-24 4:00 ` 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=20190123233619.GA3268@leoy-ThinkPad-X240s \
--to=leo.yan@linaro.org \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=coresight@lists.linaro.org \
--cc=jolsa@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
--cc=mike.leach@linaro.org \
--cc=namhyung@kernel.org \
--cc=robert.walker@arm.com \
--cc=suzuki.poulose@arm.com \
/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).