[PATCH 6/6] coresight: perf: Retry failed HW_ID writes

From: James Clark

Date: Fri Aug 21 2026 - 06:04:33 EST


Don't set the aux_hwid_done bit when writes fail so that it can be
retried later if the ring buffer was full.

Add a second attempt on stop in case this session only has one call
to start. Otherwise there is no chance to retry and it isn't fixed by
not setting aux_hwid_done.

Signed-off-by: James Clark <james.clark@xxxxxxxxxx>
---
drivers/hwtracing/coresight/coresight-etm-perf.c | 52 +++++++++++++++---------
1 file changed, 32 insertions(+), 20 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 09b21a711a87..0ffc5cd9c88f 100644
--- a/drivers/hwtracing/coresight/coresight-etm-perf.c
+++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
@@ -536,6 +536,31 @@ static int etm_event_resume(struct coresight_path *path)
return ret;
}

+static void etm_output_hw_id(struct perf_event *event,
+ struct etm_event_data *event_data,
+ struct coresight_path *path,
+ struct coresight_device *sink)
+{
+ int cpu = smp_processor_id();
+ u64 hw_id;
+
+ /*
+ * output cpu / trace ID in perf record, once for the lifetime
+ * of the event.
+ */
+ if (!cpumask_test_cpu(cpu, &event_data->aux_hwid_done)) {
+ hw_id = FIELD_PREP(CS_AUX_HW_ID_MAJOR_VERSION_MASK,
+ CS_AUX_HW_ID_MAJOR_VERSION);
+ hw_id |= FIELD_PREP(CS_AUX_HW_ID_MINOR_VERSION_MASK,
+ CS_AUX_HW_ID_MINOR_VERSION);
+ hw_id |= FIELD_PREP(CS_AUX_HW_ID_TRACE_ID_MASK, path->trace_id);
+ hw_id |= FIELD_PREP(CS_AUX_HW_ID_SINK_ID_MASK, coresight_get_sink_id(sink));
+
+ if (!perf_report_aux_output_id(event, hw_id))
+ cpumask_set_cpu(cpu, &event_data->aux_hwid_done);
+ }
+}
+
static void etm_event_start(struct perf_event *event, int flags)
{
int cpu = smp_processor_id();
@@ -544,7 +569,6 @@ static void etm_event_start(struct perf_event *event, int flags)
struct perf_output_handle *handle = &ctxt->handle;
struct coresight_device *source, *sink;
struct coresight_path *path;
- u64 hw_id;

if (flags & PERF_EF_RESUME) {
path = etm_event_get_ctxt_path(ctxt);
@@ -596,22 +620,7 @@ static void etm_event_start(struct perf_event *event, int flags)
if (coresight_enable_source(source, event, CS_MODE_PERF, path))
goto fail_disable_path;

- /*
- * output cpu / trace ID in perf record, once for the lifetime
- * of the event.
- */
- if (!cpumask_test_cpu(cpu, &event_data->aux_hwid_done)) {
- cpumask_set_cpu(cpu, &event_data->aux_hwid_done);
-
- hw_id = FIELD_PREP(CS_AUX_HW_ID_MAJOR_VERSION_MASK,
- CS_AUX_HW_ID_MAJOR_VERSION);
- hw_id |= FIELD_PREP(CS_AUX_HW_ID_MINOR_VERSION_MASK,
- CS_AUX_HW_ID_MINOR_VERSION);
- hw_id |= FIELD_PREP(CS_AUX_HW_ID_TRACE_ID_MASK, path->trace_id);
- hw_id |= FIELD_PREP(CS_AUX_HW_ID_SINK_ID_MASK, coresight_get_sink_id(sink));
-
- perf_report_aux_output_id(event, hw_id);
- }
+ etm_output_hw_id(event, event_data, path, sink);

out:
/* Tell the perf core the event is alive */
@@ -630,7 +639,7 @@ static void etm_event_start(struct perf_event *event, int flags)
*/
if (READ_ONCE(handle->event)) {
perf_aux_output_flag(handle, PERF_AUX_FLAG_TRUNCATED);
- perf_aux_output_end(handle, 0);
+ perf_aux_output_end(path->handle, 0);
}
fail:
event->hw.state = PERF_HES_STOPPED;
@@ -679,6 +688,7 @@ static void etm_event_pause(struct coresight_path *path,
if (!size)
return;

+ etm_output_hw_id(event, event_data, path, sink);
perf_aux_output_end(handle, size);
perf_aux_output_begin(handle, event);
} else {
@@ -769,10 +779,12 @@ static void etm_event_stop(struct perf_event *event, int mode)
* But we should never get a non-zero size with
* an invalid handle.
*/
- if (READ_ONCE(handle->event))
+ if (READ_ONCE(handle->event)) {
+ etm_output_hw_id(event, event_data, path, sink);
perf_aux_output_end(handle, size);
- else
+ } else {
WARN_ON(size);
+ }
}

/* Disabling the path make its elements available to other sessions */

--
2.43.0