Thread (26 messages) flat view 26 messages, 1 author, 4d ago
COOLING4d

[PATCH 19/25] perf cs-etm: Propagate errors from trace queue flushing

From: Leo Yan <leo.yan@arm.com>
Date: 2026-09-15 15:50:48
Also in: linux-doc, linux-perf-users, lkml
Subsystem: arm/coresight framework and drivers, performance events subsystem, performance events tooling arm64, the rest · Maintainers: Suzuki K Poulose, Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Linus Torvalds

cs_etm__flush() can fail while synthesizing or delivering a sample at a
trace discontinuity. cs_etm__process_traceid_queue() ignores the result
and continues even though the packet swap and thread stack flush may
not have completed.

The timestamped decoder also loses errors when it processes packets
left at the end of an AUX buffer: cs_etm__clear_all_traceid_queues()
discards the result from each trace ID queue and allows decoding to
fetch the next buffer.

Check the discontinuity flush result, make
cs_etm__clear_all_traceid_queues() return the first queue-processing
error, and propagate that error through
cs_etm__process_timestamped_queues(). This stops decoding on failure
and reports the error to the caller, including sample delivery errors
from a perf script dlfilter.

Assisted-by: Codex:gpt-6
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/util/cs-etm.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c
index 1a53431161e995ba6b3cfdc86e338ed26e675774..8340b8a16fed363795fc78ffbc419661a61442a3 100644
--- a/tools/perf/util/cs-etm.c
+++ b/tools/perf/util/cs-etm.c
@@ -2644,10 +2644,13 @@ static int cs_etm__process_traceid_queue(struct cs_etm_queue *etmq,
 			break;
 		case CS_ETM_DISCONTINUITY:
 			/*
-			 * Discontinuity in trace, flush
-			 * previous branch stack
+			 * Flush the previous branch stack at a discontinuity.
+			 * Propagate sample delivery errors, which can occur before
+			 * the packet swap and thread stack flush are complete.
 			 */
-			cs_etm__flush(etmq, tidq);
+			ret = cs_etm__flush(etmq, tidq);
+			if (ret)
+				goto out;
 			break;
 		case CS_ETM_EMPTY:
 			/*
@@ -2665,9 +2668,9 @@ static int cs_etm__process_traceid_queue(struct cs_etm_queue *etmq,
 	return ret;
 }
 
-static void cs_etm__clear_all_traceid_queues(struct cs_etm_queue *etmq)
+static int cs_etm__clear_all_traceid_queues(struct cs_etm_queue *etmq)
 {
-	int idx;
+	int idx, ret;
 	struct int_node *inode;
 	struct cs_etm_traceid_queue *tidq;
 	struct intlist *traceid_queues_list = etmq->traceid_queues_list;
@@ -2676,9 +2679,12 @@ static void cs_etm__clear_all_traceid_queues(struct cs_etm_queue *etmq)
 		idx = (int)(intptr_t)inode->priv;
 		tidq = etmq->traceid_queues[idx];
 
-		/* Ignore return value */
-		cs_etm__process_traceid_queue(etmq, tidq);
+		ret = cs_etm__process_traceid_queue(etmq, tidq);
+		if (ret)
+			return ret;
 	}
+
+	return 0;
 }
 
 static int cs_etm__run_timeless_decoder(struct cs_etm_queue *etmq)
@@ -2893,7 +2899,9 @@ static int cs_etm__process_timestamped_queues(struct cs_etm_auxtrace *etm,
 			 * process in this auxtrace_buffer.  As such empty and
 			 * flush all traceID queues.
 			 */
-			cs_etm__clear_all_traceid_queues(etmq);
+			ret = cs_etm__clear_all_traceid_queues(etmq);
+			if (ret)
+				goto out;
 
 			/* Fetch another auxtrace_buffer for this etmq */
 			goto refetch;
-- 
2.34.1

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help