[PATCH 2/2] coresight: Retry failed HW_ID writes
From: James Clark
Date: Thu Oct 01 2026 - 10:27:45 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,
which will always succeed if the stop's AUX output also has enough space
to be written. If there is no AUX record then there will be no decoding,
so the missing HW_ID isn't important.
Signed-off-by: James Clark <james.clark@xxxxxxxxxx>
---
drivers/hwtracing/coresight/coresight-etm-perf.c | 50 +++++++++++++++---------
1 file changed, 31 insertions(+), 19 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
index 09b21a711a87..9238a12628fb 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 */
@@ -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