]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
coresight: sysfs: Increment refcount only for software source
authorLeo Yan <leo.yan@arm.com>
Fri, 15 May 2026 20:08:33 +0000 (21:08 +0100)
committerSuzuki K Poulose <suzuki.poulose@arm.com>
Mon, 18 May 2026 11:48:24 +0000 (12:48 +0100)
Except for software sources (e.g. STM), other sources treat multiple
enables as equivalent to a single enable. The device mode already
tracks the binary state, so it is redundant to operate refcount.

Introduce a helper coresight_is_software_source() for check software
source. Refactor to maintain the refcount only for software sources.
This simplifies future CPU PM handling without refcount logic.

Tested-by: James Clark <james.clark@linaro.org>
Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>
Reviewed-by: James Clark <james.clark@linaro.org>
Tested-by: Jie Gan <jie.gan@oss.qualcomm.com>
Signed-off-by: Leo Yan <leo.yan@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20260515-arm_coresight_path_power_management_improvement-v14-26-f88c4a3ecfe9@arm.com
drivers/hwtracing/coresight/coresight-sysfs.c
include/linux/coresight.h

index 21196ee1d2bdf6ccba4afbde2c188432bc4932b1..80b6b634a70d3cec98dfa3e5fd146cd254b96d6f 100644 (file)
@@ -39,6 +39,26 @@ ssize_t coresight_simple_show32(struct device *_dev,
 }
 EXPORT_SYMBOL_GPL(coresight_simple_show32);
 
+static void coresight_source_get_refcnt(struct coresight_device *csdev)
+{
+       /*
+        * There could be multiple applications driving the software
+        * source. So keep the refcount for each such user when the
+        * source is already enabled.
+        *
+        * No need to increment the reference counter for other source
+        * types, as multiple enables are the same as a single enable.
+        */
+       if (coresight_is_software_source(csdev))
+               csdev->refcnt++;
+}
+
+static void coresight_source_put_refcnt(struct coresight_device *csdev)
+{
+       if (coresight_is_software_source(csdev))
+               csdev->refcnt--;
+}
+
 static int coresight_enable_source_sysfs(struct coresight_device *csdev,
                                         enum cs_mode mode,
                                         struct coresight_path *path)
@@ -57,14 +77,14 @@ static int coresight_enable_source_sysfs(struct coresight_device *csdev,
                        return ret;
        }
 
-       csdev->refcnt++;
+       coresight_source_get_refcnt(csdev);
 
        return 0;
 }
 
 /**
- *  coresight_disable_source_sysfs - Drop the reference count by 1 and disable
- *  the device if there are no users left.
+ *  coresight_disable_source_sysfs - Drop the reference count by 1 for software
+ *  sources. Disable the device if there are no users left.
  *
  *  @csdev: The coresight device to disable
  *  @data: Opaque data to pass on to the disable function of the source device.
@@ -79,7 +99,7 @@ static bool coresight_disable_source_sysfs(struct coresight_device *csdev,
        if (coresight_get_mode(csdev) != CS_MODE_SYSFS)
                return false;
 
-       csdev->refcnt--;
+       coresight_source_put_refcnt(csdev);
        if (csdev->refcnt == 0) {
                coresight_disable_source(csdev, data);
                return true;
@@ -156,9 +176,6 @@ int coresight_enable_sysfs(struct coresight_device *csdev)
        int ret = 0;
        struct coresight_device *sink;
        struct coresight_path *path;
-       enum coresight_dev_subtype_source subtype;
-
-       subtype = csdev->subtype.source_subtype;
 
        mutex_lock(&coresight_mutex);
 
@@ -173,13 +190,7 @@ int coresight_enable_sysfs(struct coresight_device *csdev)
         * doesn't hold coresight_mutex.
         */
        if (coresight_get_mode(csdev) == CS_MODE_SYSFS) {
-               /*
-                * There could be multiple applications driving the software
-                * source. So keep the refcount for each such user when the
-                * source is already enabled.
-                */
-               if (subtype == CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE)
-                       csdev->refcnt++;
+               coresight_source_get_refcnt(csdev);
                goto out;
        }
 
index 58d474b269806d32cad6ed87da96550b06f1f30f..76ef4c0965125cd11830df0151a6707d3e3b638d 100644 (file)
@@ -611,6 +611,12 @@ static inline bool coresight_is_percpu_source(struct coresight_device *csdev)
               (csdev->subtype.source_subtype == CORESIGHT_DEV_SUBTYPE_SOURCE_PROC);
 }
 
+static inline bool coresight_is_software_source(struct coresight_device *csdev)
+{
+       return csdev && coresight_is_device_source(csdev) &&
+              (csdev->subtype.source_subtype == CORESIGHT_DEV_SUBTYPE_SOURCE_SOFTWARE);
+}
+
 static inline bool coresight_is_percpu_sink(struct coresight_device *csdev)
 {
        return csdev && (csdev->type == CORESIGHT_DEV_TYPE_SINK) &&