mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@linaro.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mathieu Poirier <mathieu.poirier@linaro.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, Mike Leach <mike.leach@linaro.org>,
	Robert Walker <robert.walker@arm.com>,
	Al Grant <Al.Grant@arm.com>,
	Coresight ML <coresight@lists.linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Subject: [PATCH v2 2/2] perf cs-etm: Add support sample flags
Date: Sun, 11 Nov 2018 13:07:56 +0800	[thread overview]
Message-ID: <1541912876-20967-3-git-send-email-leo.yan@linaro.org> (raw)
In-Reply-To: <1541912876-20967-1-git-send-email-leo.yan@linaro.org>

We have prepared the flags in the packet structure, so need to copy
the related value into sample structure thus perf tool can facilitate
sample flags.

The PREV_PACKET contains the branch instruction flags and PACKET
actually contains the flags for next branch instruction.  So this patch
is to set sample flags with 'etmq->prev_packet->flags'.

This patch includes three fixing up for sample flags based on the
packets context:

- If the packet is exception packet or exception return packet, update
  the previous packet for exception specific flags;
- If there has TRACE_ON or TRACE_OFF packet in the middle of instruction
  packets, this indicates the trace is discontinuous, so append the flag
  PERF_IP_FLAG_TRACE_END to the previous packet to indicate the trace
  has been ended;
- If one instruction packet is behind TRACE_OFF packet, this instruction
  is restarting trace packet.  So set flag PERF_IP_FLAG_TRACE_START to
  TRACE_OFF packet if one, this flag isn't used by TRACE_OFF packet but
  used to indicate trace restarting when generate sample.

Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
 tools/perf/util/cs-etm.c | 43 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 455f132..afca6f3 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -676,7 +676,7 @@ static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq,
 	sample.stream_id = etmq->etm->instructions_id;
 	sample.period = period;
 	sample.cpu = etmq->packet->cpu;
-	sample.flags = 0;
+	sample.flags = etmq->prev_packet->flags;
 	sample.insn_len = 1;
 	sample.cpumode = event->sample.header.misc;
 
@@ -735,7 +735,7 @@ static int cs_etm__synth_branch_sample(struct cs_etm_queue *etmq)
 	sample.stream_id = etmq->etm->branches_id;
 	sample.period = 1;
 	sample.cpu = etmq->packet->cpu;
-	sample.flags = 0;
+	sample.flags = etmq->prev_packet->flags;
 	sample.cpumode = event->sample.header.misc;
 
 	/*
@@ -878,6 +878,43 @@ static int cs_etm__synth_events(struct cs_etm_auxtrace *etm,
 	return 0;
 }
 
+static void cs_etm__fixup_flags(struct cs_etm_queue *etmq)
+{
+	/*
+	 * Decoding stream might insert one TRACE_OFF packet in the
+	 * middle of instruction packets, this means it doesn't
+	 * contain the pair packets with TRACE_OFF and TRACE_ON.
+	 * For this case, the instruction packet follows with
+	 * TRACE_OFF packet so we need to fixup prev_packet with flag
+	 * PERF_IP_FLAG_TRACE_BEGIN, this flag finally is used by the
+	 * instruction packet to generate samples.
+	 */
+	if (etmq->prev_packet->sample_type == CS_ETM_TRACE_OFF &&
+	    etmq->packet->sample_type == CS_ETM_RANGE)
+		etmq->prev_packet->flags = PERF_IP_FLAG_BRANCH |
+					   PERF_IP_FLAG_TRACE_BEGIN;
+
+	if (etmq->prev_packet->sample_type == CS_ETM_RANGE) {
+		/*
+		 * When the exception packet is inserted, update flags
+		 * so tell perf it is exception related branches.
+		 */
+		if (etmq->packet->sample_type == CS_ETM_EXCEPTION ||
+		    etmq->packet->sample_type == CS_ETM_EXCEPTION_RET)
+			etmq->prev_packet->flags = etmq->packet->flags;
+
+		/*
+		 * The trace is discontinuous, weather this is caused by
+		 * TRACE_ON packet or TRACE_OFF packet is coming, if the
+		 * previous packet is instruction packet, simply set flag
+		 * PERF_IP_FLAG_TRACE_END for previous packet.
+		 */
+		if (etmq->packet->sample_type == CS_ETM_TRACE_ON ||
+		    etmq->packet->sample_type == CS_ETM_TRACE_OFF)
+			etmq->prev_packet->flags |= PERF_IP_FLAG_TRACE_END;
+	}
+}
+
 static int cs_etm__sample(struct cs_etm_queue *etmq)
 {
 	struct cs_etm_auxtrace *etm = etmq->etm;
@@ -1100,6 +1137,8 @@ static int cs_etm__run_decoder(struct cs_etm_queue *etmq)
 					 */
 					break;
 
+				cs_etm__fixup_flags(etmq);
+
 				switch (etmq->packet->sample_type) {
 				case CS_ETM_RANGE:
 					/*
-- 
2.7.4


  parent reply	other threads:[~2018-11-11  5:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-11  5:07 [PATCH v2 0/2] perf cs-etm: Add support for " Leo Yan
2018-11-11  5:07 ` [PATCH v2 1/2] perf cs-etm: Set branch instruction flags in packet Leo Yan
2018-11-19 22:26   ` Mathieu Poirier
2018-12-05  6:25     ` leo.yan
2018-12-05 17:40       ` Mathieu Poirier
2018-12-06  5:33         ` leo.yan
2018-11-11  5:07 ` Leo Yan [this message]
2018-11-19 23:22   ` [PATCH v2 2/2] perf cs-etm: Add support sample flags Mathieu Poirier
2018-11-20 16:53     ` Mathieu Poirier
2018-12-05  6:38       ` 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=1541912876-20967-3-git-send-email-leo.yan@linaro.org \
    --to=leo.yan@linaro.org \
    --cc=Al.Grant@arm.com \
    --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 \
    /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

all inboxes | Powered by JetHome®