[PATCH 21/25] perf cs-etm: Complete packet draining with end of trace
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
OpenCSD can retain output at the end of an input block even after returning CONT. WAIT driven flushing alone does not use out that output before the decoder is reset for the next block. Submit OCSD_OP_EOT from cs_etm_decoder__drain_packets() after any pending WAIT response has been flushed. Track submission with the eot_sent flag and clear it on reset, make sure to submit EOT only once. This applies to timeless decoding, timestamped decoding and raw packet dumping through their existing drain calls. Return OCSD_RESP_CONT for a clean EOT without queuing a discontinuity. This lets the frontend finish draining while preserving trace history for sample processing. EOT reporting trace loss, NO_SYNC and TRACE_ON still generate discontinuities and flush the thread stack. Assisted-by: Codex:gpt-6 Signed-off-by: Leo Yan <leo.yan@arm.com> --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 24 +++++++++++++++++++++++- tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 2 +- 2 files changed, 24 insertions(+), 2 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 a7a6410481e5c99be14a951493092c145a8512ba..0fcbf91aac63bcc5c40bf1453359d3be3ece684f 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c@@ -46,6 +46,7 @@ struct cs_etm_decoder { void *data; void (*packet_printer)(const char *msg, void *data); bool suppress_printing; + bool eot_sent; dcd_tree_handle_t dcd_tree; cs_etm_mem_cb_type mem_access; ocsd_datapath_resp_t prev_return;
@@ -86,6 +87,7 @@ int cs_etm_decoder__reset(struct cs_etm_decoder *decoder) ocsd_datapath_resp_t dp_ret; decoder->prev_return = OCSD_RESP_CONT; + decoder->eot_sent = false; decoder->suppress_printing = true; dp_ret = ocsd_dt_process_data(decoder->dcd_tree, OCSD_OP_RESET, 0, 0, NULL, NULL);
@@ -592,6 +594,17 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( type = elem->elem_type; + /* + * The frontend uses EOT to drain packets buffered in OpenCSD at the + * end of a data block. Return CONT for a clean EOT so the frontend + * can finish draining without generating a discontinuity, preserving + * trace history for sample processing. EOTs reporting trace loss + * still generate a discontinuity below. + */ + if (type == OCSD_GEN_TRC_ELEM_EO_TRACE && + elem->unsync_eot_info == UNSYNC_EOT) + return OCSD_RESP_CONT; + if (type == OCSD_GEN_TRC_ELEM_EO_TRACE || type == OCSD_GEN_TRC_ELEM_NO_SYNC || type == OCSD_GEN_TRC_ELEM_TRACE_ON)
@@ -803,10 +816,19 @@ int cs_etm_decoder__drain_packets(struct cs_etm_decoder *decoder) NULL, NULL); + if (OCSD_DATA_RESP_IS_CONT(decoder->prev_return) && !decoder->eot_sent) { + decoder->prev_return = ocsd_dt_process_data(decoder->dcd_tree, + OCSD_OP_EOT, + 0, + 0, + NULL, + NULL); + decoder->eot_sent = true; + } + if (OCSD_DATA_RESP_IS_WAIT(decoder->prev_return)) return 1; - /* No further WAIT driven flushing is needed */ return OCSD_DATA_RESP_IS_CONT(decoder->prev_return) ? 0 : -EINVAL; }
diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
index c187f3809ba0a350ca6ee549d2c0c67ed8e16d1e..876b28f6fda099db5694fdfa9552104cc270b49a 100644
--- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
+++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h@@ -92,7 +92,7 @@ int cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder, size_t len, size_t *consumed); /* - * Drain pending packets after consuming a data block. + * Drain pending packets and submit EOT once after consuming a data block. * Process queued packets after each call, including the final call. * Returns 1 for WAIT, 0 when done, or a negative error. */
--
2.34.1