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