[PATCH v5 02/19] coresight: Set per-CPU source pointer

Leo Yan leo.yan at arm.com
Wed Nov 19 07:49:00 PST 2025


Add coresight_set_percpu_source() to set the CPU source device.  Source
devices are stored in the per-CPU structure csdev_source.

When the CPU is online, set the per-CPU pointer on the local CPU to
avoid race conditions between setting and fetching the same pointer.

Reviewed-by: Mike Leach <mike.leach at linaro.org>
Tested-by: James Clark <james.clark at linaro.org>
Signed-off-by: Leo Yan <leo.yan at arm.com>
---
 drivers/hwtracing/coresight/coresight-core.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/hwtracing/coresight/coresight-core.c b/drivers/hwtracing/coresight/coresight-core.c
index 0c48f5c85db6a7ec0377335eaa734527959d57c4..f22fd89f29b97ffe7004a2c988b09d5fd412af8d 100644
--- a/drivers/hwtracing/coresight/coresight-core.c
+++ b/drivers/hwtracing/coresight/coresight-core.c
@@ -34,6 +34,7 @@
  */
 DEFINE_MUTEX(coresight_mutex);
 static DEFINE_PER_CPU(struct coresight_device *, csdev_sink);
+static DEFINE_PER_CPU(struct coresight_device *, csdev_source);
 
 /**
  * struct coresight_node - elements of a path, from source to sink
@@ -79,6 +80,22 @@ struct coresight_device *coresight_get_percpu_sink(int cpu)
 }
 EXPORT_SYMBOL_GPL(coresight_get_percpu_sink);
 
+static void coresight_set_percpu_source_local(void *csdev)
+{
+	this_cpu_write(csdev_source, csdev);
+}
+
+static void coresight_set_percpu_source(int cpu, struct coresight_device *csdev)
+{
+	cpus_read_lock();
+	if (cpu_online(cpu))
+		smp_call_function_single(cpu, coresight_set_percpu_source_local,
+					 csdev, 1);
+	else
+		per_cpu(csdev_source, cpu) = csdev;
+	cpus_read_unlock();
+}
+
 static struct coresight_device *coresight_get_source(struct coresight_path *path)
 {
 	struct coresight_device *csdev;
@@ -1397,6 +1414,10 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
 			goto out_unlock;
 		}
 	}
+
+	if (coresight_is_percpu_source(csdev))
+		coresight_set_percpu_source(csdev->cpu, csdev);
+
 	/* Device is now registered */
 	registered = true;
 
@@ -1428,6 +1449,8 @@ EXPORT_SYMBOL_GPL(coresight_register);
 
 void coresight_unregister(struct coresight_device *csdev)
 {
+	if (coresight_is_percpu_source(csdev))
+		coresight_set_percpu_source(csdev->cpu, NULL);
 	etm_perf_del_symlink_sink(csdev);
 	/* Remove references of that device in the topology */
 	if (cti_assoc_ops && cti_assoc_ops->remove)

-- 
2.34.1




More information about the linux-arm-kernel mailing list