]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Coresight: Allocate trace ID after building the path
authorJie Gan <quic_jiegan@quicinc.com>
Mon, 3 Mar 2025 03:29:26 +0000 (11:29 +0800)
committerSuzuki K Poulose <suzuki.poulose@arm.com>
Tue, 4 Mar 2025 18:06:18 +0000 (18:06 +0000)
The trace_id will be stored in coresight_path instead of being declared
everywhere and allocated after building the path.

Co-developed-by: James Clark <james.clark@linaro.org>
Signed-off-by: James Clark <james.clark@linaro.org>
Signed-off-by: Jie Gan <quic_jiegan@quicinc.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20250303032931.2500935-6-quic_jiegan@quicinc.com
drivers/hwtracing/coresight/coresight-core.c
drivers/hwtracing/coresight/coresight-etm-perf.c
drivers/hwtracing/coresight/coresight-priv.h
drivers/hwtracing/coresight/coresight-sysfs.c

index b34b5e4776c4db424d3a3bf2404cfda6b0d2f219..58f5106e0f4b05b3ab2394bb257e8947a0eb1bac 100644 (file)
@@ -655,6 +655,50 @@ static void coresight_drop_device(struct coresight_device *csdev)
        }
 }
 
+/*
+ * coresight device will read their existing or alloc a trace ID, if their trace_id
+ * callback is set.
+ *
+ * Return 0 if the trace_id callback is not set.
+ * Return the result of the trace_id callback if it is set. The return value
+ * will be the trace_id if successful, and an error number if it fails.
+ */
+static int coresight_get_trace_id(struct coresight_device *csdev,
+                                 enum cs_mode mode,
+                                 struct coresight_device *sink)
+{
+       if (coresight_ops(csdev)->trace_id)
+               return coresight_ops(csdev)->trace_id(csdev, mode, sink);
+
+       return 0;
+}
+
+/*
+ * Call this after creating the path and before enabling it. This leaves
+ * the trace ID set on the path, or it remains 0 if it couldn't be assigned.
+ */
+void coresight_path_assign_trace_id(struct coresight_path *path,
+                                   enum cs_mode mode)
+{
+       struct coresight_device *sink = coresight_get_sink(&path->path_list);
+       struct coresight_node *nd;
+       int trace_id;
+
+       list_for_each_entry(nd, &path->path_list, link) {
+               /* Assign a trace ID to the path for the first device that wants to do it */
+               trace_id = coresight_get_trace_id(nd->csdev, mode, sink);
+
+               /*
+                * 0 in this context is that it didn't want to assign so keep searching.
+                * Non 0 is either success or fail.
+                */
+               if (trace_id != 0) {
+                       path->trace_id = trace_id;
+                       return;
+               }
+       }
+}
+
 /**
  * _coresight_build_path - recursively build a path from a @csdev to a sink.
  * @csdev:     The device to start from.
index b0426792f08a4f0a29e43c3d203cd227352b9dc3..134290ab622e31829916f0ad0853263326587ab4 100644 (file)
@@ -319,7 +319,6 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
 {
        u32 id, cfg_hash;
        int cpu = event->cpu;
-       int trace_id;
        cpumask_t *mask;
        struct coresight_device *sink = NULL;
        struct coresight_device *user_sink = NULL, *last_sink = NULL;
@@ -409,8 +408,8 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
                }
 
                /* ensure we can allocate a trace ID for this CPU */
-               trace_id = coresight_trace_id_get_cpu_id_map(cpu, &sink->perf_sink_id_map);
-               if (!IS_VALID_CS_TRACE_ID(trace_id)) {
+               coresight_path_assign_trace_id(path, CS_MODE_PERF);
+               if (!IS_VALID_CS_TRACE_ID(path->trace_id)) {
                        cpumask_clear_cpu(cpu, mask);
                        coresight_release_path(path);
                        continue;
index 27b7dc348d4af56f3d9a4d2bc0382748b96a9d8d..2bea35bae0d43632df92d79b3b0a2c10bc1bc22d 100644 (file)
@@ -152,6 +152,8 @@ int coresight_make_links(struct coresight_device *orig,
 void coresight_remove_links(struct coresight_device *orig,
                            struct coresight_connection *conn);
 u32 coresight_get_sink_id(struct coresight_device *csdev);
+void coresight_path_assign_trace_id(struct coresight_path *path,
+                                  enum cs_mode mode);
 
 #if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM3X)
 extern int etm_readl_cp14(u32 off, unsigned int *val);
index cb4c39732d26fdd414783ba359588f62955dec54..d03751bf3d8a38be69aad29de75bbff4c0b1b170 100644 (file)
@@ -209,6 +209,10 @@ int coresight_enable_sysfs(struct coresight_device *csdev)
                goto out;
        }
 
+       coresight_path_assign_trace_id(path, CS_MODE_SYSFS);
+       if (!IS_VALID_CS_TRACE_ID(path->trace_id))
+               goto err_path;
+
        ret = coresight_enable_path(&path->path_list, CS_MODE_SYSFS, NULL);
        if (ret)
                goto err_path;