]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
coresight: perf: Update buffer on AUX pause
authorLeo Yan <leo.yan@arm.com>
Tue, 1 Apr 2025 18:07:07 +0000 (19:07 +0100)
committerSuzuki K Poulose <suzuki.poulose@arm.com>
Wed, 14 May 2025 10:56:17 +0000 (11:56 +0100)
Due to sinks like ETR and ETB don't support interrupt handling, the
hardware trace data might be lost for continuous running tasks.

This commit takes advantage of the AUX pause for updating trace buffer
to mitigate the trace data losing issue.

The per CPU sink has its own interrupt handling.  Thus, there will be a
race condition between the updating buffer in NMI and sink's interrupt
handler.  To avoid the race condition, this commit disallows updating
buffer on AUX pause for the per CPU sink.  Currently, this is only
applied for TRBE.

Signed-off-by: Leo Yan <leo.yan@arm.com>
Reviewed-by: James Clark <james.clark@linaro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20250401180708.385396-7-leo.yan@arm.com
drivers/hwtracing/coresight/coresight-etm-perf.c

index 2dcf1809cb7f9a7e4b030f9435b13f2f17493790..f1551c08ecb20ebd7feab82dbaee3176e6bcc999 100644 (file)
@@ -574,14 +574,53 @@ fail:
        return;
 }
 
-static void etm_event_pause(struct coresight_device *csdev,
+static void etm_event_pause(struct perf_event *event,
+                           struct coresight_device *csdev,
                            struct etm_ctxt *ctxt)
 {
+       int cpu = smp_processor_id();
+       struct coresight_device *sink;
+       struct perf_output_handle *handle = &ctxt->handle;
+       struct coresight_path *path;
+       unsigned long size;
+
        if (!ctxt->event_data)
                return;
 
        /* Stop tracer */
        coresight_pause_source(csdev);
+
+       path = etm_event_cpu_path(ctxt->event_data, cpu);
+       sink = coresight_get_sink(path);
+       if (WARN_ON_ONCE(!sink))
+               return;
+
+       /*
+        * The per CPU sink has own interrupt handling, it might have
+        * race condition with updating buffer on AUX trace pause if
+        * it is invoked from NMI.  To avoid the race condition,
+        * disallows updating buffer for the per CPU sink case.
+        */
+       if (coresight_is_percpu_sink(sink))
+               return;
+
+       if (WARN_ON_ONCE(handle->event != event))
+               return;
+
+       if (!sink_ops(sink)->update_buffer)
+               return;
+
+       size = sink_ops(sink)->update_buffer(sink, handle,
+                                            ctxt->event_data->snk_config);
+       if (READ_ONCE(handle->event)) {
+               if (!size)
+                       return;
+
+               perf_aux_output_end(handle, size);
+               perf_aux_output_begin(handle, event);
+       } else {
+               WARN_ON_ONCE(size);
+       }
 }
 
 static void etm_event_stop(struct perf_event *event, int mode)
@@ -595,7 +634,7 @@ static void etm_event_stop(struct perf_event *event, int mode)
        struct coresight_path *path;
 
        if (mode & PERF_EF_PAUSE)
-               return etm_event_pause(csdev, ctxt);
+               return etm_event_pause(event, csdev, ctxt);
 
        /*
         * If we still have access to the event_data via handle,