linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] perf cs-etm: Handle valid-but-zero timestamps
@ 2021-05-07  9:58 James Clark
       [not found] ` <3926c523-3fdb-66de-8b9c-b68290a5053e@arm.com>
  0 siblings, 1 reply; 14+ messages in thread
From: James Clark @ 2021-05-07  9:58 UTC (permalink / raw)
  To: coresight, mathieu.poirier
  Cc: al.grant, branislav.rankov, denik, suzuki.poulose,
	anshuman.khandual, James Clark, Mike Leach, Leo Yan,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	John Garry, Will Deacon, linux-arm-kernel, linux-perf-users,
	linux-kernel

There is an intermittent issue on Trogdor devices that
results in all Coresight timestamps having a value of zero.
Because zero is currently treated as "not found" rather
than "found but zero", this breaks the decoding flow
when it would otherwise work.

This patch adds an out parameter and return code so
the difference between zero and non-existent timestamps
can be determined.

There is also a change to fix an underflow.

Although this is a workaround, the change is technically
a valid way of writing the cs_etm__etmq_get_timestamp()
function. It could have been written similarly to this
without trying to work around this issue, so it's no less
correct. But, because it's a workaround to a problem
elsewhere, I will submit this as an RFC for feedback.

This patch applies on top of the "[PATCH v2 0/2] perf
cs-etm: Set time on synthesised samples to preserve ordering"
patchset.

Co-developed-by: Denis Nikitin <denik@chromium.org>
Signed-off-by: Denis Nikitin <denik@chromium.org>
Signed-off-by: James Clark <james.clark@arm.com>
---
 .../perf/util/cs-etm-decoder/cs-etm-decoder.c |  5 ++++-
 tools/perf/util/cs-etm.c                      | 22 +++++++++----------
 2 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
index b01d363b9301..947e44413c6e 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
@@ -320,7 +320,10 @@ cs_etm_decoder__do_hard_timestamp(struct cs_etm_queue *etmq,
 	 * which instructions started by subtracting the number of instructions
 	 * executed to the timestamp.
 	 */
-	packet_queue->cs_timestamp = elem->timestamp - packet_queue->instr_count;
+	if (packet_queue->instr_count >= elem->timestamp)
+		packet_queue->cs_timestamp = 0;
+	else
+		packet_queue->cs_timestamp = elem->timestamp - packet_queue->instr_count;
 	packet_queue->next_cs_timestamp = elem->timestamp;
 	packet_queue->instr_count = 0;
 
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index e5c1a1b22a2a..1969921c406a 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -210,13 +210,14 @@ void cs_etm__etmq_set_traceid_queue_timestamp(struct cs_etm_queue *etmq,
 	etmq->pending_timestamp_chan_id = trace_chan_id;
 }
 
-static u64 cs_etm__etmq_get_timestamp(struct cs_etm_queue *etmq,
+static int cs_etm__etmq_get_timestamp(struct cs_etm_queue *etmq,
+				      u64 *timestamp,
 				      u8 *trace_chan_id)
 {
 	struct cs_etm_packet_queue *packet_queue;
 
 	if (!etmq->pending_timestamp_chan_id)
-		return 0;
+		return -ENODATA;
 
 	if (trace_chan_id)
 		*trace_chan_id = etmq->pending_timestamp_chan_id;
@@ -224,13 +225,15 @@ static u64 cs_etm__etmq_get_timestamp(struct cs_etm_queue *etmq,
 	packet_queue = cs_etm__etmq_get_packet_queue(etmq,
 						     etmq->pending_timestamp_chan_id);
 	if (!packet_queue)
-		return 0;
+		return -ENODATA;
 
 	/* Acknowledge pending status */
 	etmq->pending_timestamp_chan_id = 0;
 
 	/* See function cs_etm_decoder__do_{hard|soft}_timestamp() */
-	return packet_queue->cs_timestamp;
+	if (timestamp)
+		*timestamp = packet_queue->cs_timestamp;
+	return 0;
 }
 
 static void cs_etm__clear_packet_queue(struct cs_etm_packet_queue *queue)
@@ -864,11 +867,10 @@ static int cs_etm__setup_queue(struct cs_etm_auxtrace *etm,
 		 * Function cs_etm_decoder__do_{hard|soft}_timestamp() does all
 		 * the timestamp calculation for us.
 		 */
-		cs_timestamp = cs_etm__etmq_get_timestamp(etmq, &trace_chan_id);
-
-		/* We found a timestamp, no need to continue. */
-		if (cs_timestamp)
+		if (!cs_etm__etmq_get_timestamp(etmq, &cs_timestamp, &trace_chan_id)) {
+			/* We found a timestamp, no need to continue. */
 			break;
+		}
 
 		/*
 		 * We didn't find a timestamp so empty all the traceid packet
@@ -2286,9 +2288,7 @@ static int cs_etm__process_queues(struct cs_etm_auxtrace *etm)
 		if (ret)
 			goto out;
 
-		cs_timestamp = cs_etm__etmq_get_timestamp(etmq, &trace_chan_id);
-
-		if (!cs_timestamp) {
+		if (cs_etm__etmq_get_timestamp(etmq, &cs_timestamp, &trace_chan_id)) {
 			/*
 			 * Function cs_etm__decode_data_block() returns when
 			 * there is no more traces to decode in the current
-- 
2.28.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-05-13 13:59 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07  9:58 [RFC PATCH] perf cs-etm: Handle valid-but-zero timestamps James Clark
     [not found] ` <3926c523-3fdb-66de-8b9c-b68290a5053e@arm.com>
2021-05-07 14:09   ` Mike Leach
2021-05-11  7:39     ` Denis Nikitin
2021-05-11 10:07     ` James Clark
2021-05-10  5:39   ` Leo Yan
2021-05-11  8:05     ` Leo Yan
2021-05-11 10:00       ` James Clark
2021-05-11  8:06     ` Denis Nikitin
2021-05-11  8:26       ` Leo Yan
2021-05-11 13:53     ` James Clark
2021-05-12  1:20       ` Leo Yan
2021-05-13 13:57         ` James Clark
2021-05-12  2:08       ` Leo Yan
2021-05-13 13:10         ` James Clark

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