]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Coresight: Change to read the trace ID from coresight_path
authorJie Gan <quic_jiegan@quicinc.com>
Mon, 3 Mar 2025 03:29:27 +0000 (11:29 +0800)
committerSuzuki K Poulose <suzuki.poulose@arm.com>
Tue, 4 Mar 2025 18:06:18 +0000 (18:06 +0000)
The source device can directly read the trace ID from the coresight_path
which result in etm_read_alloc_trace_id and etm4_read_alloc_trace_id being
deleted.

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-7-quic_jiegan@quicinc.com
drivers/hwtracing/coresight/coresight-dummy.c
drivers/hwtracing/coresight/coresight-etm-perf.c
drivers/hwtracing/coresight/coresight-etm.h
drivers/hwtracing/coresight/coresight-etm3x-core.c
drivers/hwtracing/coresight/coresight-etm4x-core.c
drivers/hwtracing/coresight/coresight-etm4x.h
drivers/hwtracing/coresight/coresight-stm.c
drivers/hwtracing/coresight/coresight-sysfs.c
drivers/hwtracing/coresight/coresight-tpdm.c
include/linux/coresight.h

index b5692ba358c10a0fa6ca9926d74639a317a5f0d1..aaa92b5081e3d2bb85d57f90ab68a1dc6a1f0dd8 100644 (file)
@@ -24,7 +24,7 @@ DEFINE_CORESIGHT_DEVLIST(sink_devs, "dummy_sink");
 
 static int dummy_source_enable(struct coresight_device *csdev,
                               struct perf_event *event, enum cs_mode mode,
-                              __maybe_unused struct coresight_trace_id_map *id_map)
+                              __maybe_unused struct coresight_path *path)
 {
        if (!coresight_take_mode(csdev, mode))
                return -EBUSY;
index 134290ab622e31829916f0ad0853263326587ab4..300305d67a1d0971e1132a738c47f9741c7279cf 100644 (file)
@@ -461,7 +461,6 @@ static void etm_event_start(struct perf_event *event, int flags)
        struct coresight_device *sink, *csdev = per_cpu(csdev_src, cpu);
        struct coresight_path *path;
        u64 hw_id;
-       u8 trace_id;
 
        if (!csdev)
                goto fail;
@@ -504,8 +503,7 @@ static void etm_event_start(struct perf_event *event, int flags)
                goto fail_end_stop;
 
        /* Finally enable the tracer */
-       if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF,
-                                     &sink->perf_sink_id_map))
+       if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF, path))
                goto fail_disable_path;
 
        /*
@@ -515,13 +513,11 @@ static void etm_event_start(struct perf_event *event, int flags)
        if (!cpumask_test_cpu(cpu, &event_data->aux_hwid_done)) {
                cpumask_set_cpu(cpu, &event_data->aux_hwid_done);
 
-               trace_id = coresight_trace_id_read_cpu_id_map(cpu, &sink->perf_sink_id_map);
-
                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, trace_id);
+               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);
index e02c3ea972c9286506bac2d198a712a8a1f970d4..171f1384f7c03492dfff8fc777fb8f5c0e0ee683 100644 (file)
@@ -284,6 +284,5 @@ extern const struct attribute_group *coresight_etm_groups[];
 void etm_set_default(struct etm_config *config);
 void etm_config_trace_mode(struct etm_config *config);
 struct etm_config *get_etm_config(struct etm_drvdata *drvdata);
-int etm_read_alloc_trace_id(struct etm_drvdata *drvdata);
 void etm_release_trace_id(struct etm_drvdata *drvdata);
 #endif
index c1dda4bc4a2ffd8b3958cc6504f76b44a6143643..8927bfaf3af2197fcf74388b89219934d266745f 100644 (file)
@@ -455,26 +455,6 @@ static int etm_cpu_id(struct coresight_device *csdev)
        return drvdata->cpu;
 }
 
-int etm_read_alloc_trace_id(struct etm_drvdata *drvdata)
-{
-       int trace_id;
-
-       /*
-        * This will allocate a trace ID to the cpu,
-        * or return the one currently allocated.
-        *
-        * trace id function has its own lock
-        */
-       trace_id = coresight_trace_id_get_cpu_id(drvdata->cpu);
-       if (IS_VALID_CS_TRACE_ID(trace_id))
-               drvdata->traceid = (u8)trace_id;
-       else
-               dev_err(&drvdata->csdev->dev,
-                       "Failed to allocate trace ID for %s on CPU%d\n",
-                       dev_name(&drvdata->csdev->dev), drvdata->cpu);
-       return trace_id;
-}
-
 void etm_release_trace_id(struct etm_drvdata *drvdata)
 {
        coresight_trace_id_put_cpu_id(drvdata->cpu);
@@ -482,38 +462,22 @@ void etm_release_trace_id(struct etm_drvdata *drvdata)
 
 static int etm_enable_perf(struct coresight_device *csdev,
                           struct perf_event *event,
-                          struct coresight_trace_id_map *id_map)
+                          struct coresight_path *path)
 {
        struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
-       int trace_id;
 
        if (WARN_ON_ONCE(drvdata->cpu != smp_processor_id()))
                return -EINVAL;
 
        /* Configure the tracer based on the session's specifics */
        etm_parse_event_config(drvdata, event);
-
-       /*
-        * perf allocates cpu ids as part of _setup_aux() - device needs to use
-        * the allocated ID. This reads the current version without allocation.
-        *
-        * This does not use the trace id lock to prevent lock_dep issues
-        * with perf locks - we know the ID cannot change until perf shuts down
-        * the session
-        */
-       trace_id = coresight_trace_id_read_cpu_id_map(drvdata->cpu, id_map);
-       if (!IS_VALID_CS_TRACE_ID(trace_id)) {
-               dev_err(&drvdata->csdev->dev, "Failed to set trace ID for %s on CPU%d\n",
-                       dev_name(&drvdata->csdev->dev), drvdata->cpu);
-               return -EINVAL;
-       }
-       drvdata->traceid = (u8)trace_id;
+       drvdata->traceid = path->trace_id;
 
        /* And enable it */
        return etm_enable_hw(drvdata);
 }
 
-static int etm_enable_sysfs(struct coresight_device *csdev)
+static int etm_enable_sysfs(struct coresight_device *csdev, struct coresight_path *path)
 {
        struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
        struct etm_enable_arg arg = { };
@@ -521,10 +485,7 @@ static int etm_enable_sysfs(struct coresight_device *csdev)
 
        spin_lock(&drvdata->spinlock);
 
-       /* sysfs needs to allocate and set a trace ID */
-       ret = etm_read_alloc_trace_id(drvdata);
-       if (ret < 0)
-               goto unlock_enable_sysfs;
+       drvdata->traceid = path->trace_id;
 
        /*
         * Configure the ETM only if the CPU is online.  If it isn't online
@@ -545,7 +506,6 @@ static int etm_enable_sysfs(struct coresight_device *csdev)
        if (ret)
                etm_release_trace_id(drvdata);
 
-unlock_enable_sysfs:
        spin_unlock(&drvdata->spinlock);
 
        if (!ret)
@@ -554,7 +514,7 @@ unlock_enable_sysfs:
 }
 
 static int etm_enable(struct coresight_device *csdev, struct perf_event *event,
-                     enum cs_mode mode, struct coresight_trace_id_map *id_map)
+                     enum cs_mode mode, struct coresight_path *path)
 {
        int ret;
        struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
@@ -566,10 +526,10 @@ static int etm_enable(struct coresight_device *csdev, struct perf_event *event,
 
        switch (mode) {
        case CS_MODE_SYSFS:
-               ret = etm_enable_sysfs(csdev);
+               ret = etm_enable_sysfs(csdev, path);
                break;
        case CS_MODE_PERF:
-               ret = etm_enable_perf(csdev, event, id_map);
+               ret = etm_enable_perf(csdev, event, path);
                break;
        default:
                ret = -EINVAL;
index 07e2dee54688f16be17eed813860b6c7c0deb629..bb1e80df29140a1cdb7e9509bac101043b5fb417 100644 (file)
@@ -232,25 +232,6 @@ static int etm4_cpu_id(struct coresight_device *csdev)
        return drvdata->cpu;
 }
 
-int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata)
-{
-       int trace_id;
-
-       /*
-        * This will allocate a trace ID to the cpu,
-        * or return the one currently allocated.
-        * The trace id function has its own lock
-        */
-       trace_id = coresight_trace_id_get_cpu_id(drvdata->cpu);
-       if (IS_VALID_CS_TRACE_ID(trace_id))
-               drvdata->trcid = (u8)trace_id;
-       else
-               dev_err(&drvdata->csdev->dev,
-                       "Failed to allocate trace ID for %s on CPU%d\n",
-                       dev_name(&drvdata->csdev->dev), drvdata->cpu);
-       return trace_id;
-}
-
 void etm4_release_trace_id(struct etmv4_drvdata *drvdata)
 {
        coresight_trace_id_put_cpu_id(drvdata->cpu);
@@ -810,9 +791,9 @@ out:
 
 static int etm4_enable_perf(struct coresight_device *csdev,
                            struct perf_event *event,
-                           struct coresight_trace_id_map *id_map)
+                           struct coresight_path *path)
 {
-       int ret = 0, trace_id;
+       int ret = 0;
        struct etmv4_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
 
        if (WARN_ON_ONCE(drvdata->cpu != smp_processor_id())) {
@@ -825,22 +806,7 @@ static int etm4_enable_perf(struct coresight_device *csdev,
        if (ret)
                goto out;
 
-       /*
-        * perf allocates cpu ids as part of _setup_aux() - device needs to use
-        * the allocated ID. This reads the current version without allocation.
-        *
-        * This does not use the trace id lock to prevent lock_dep issues
-        * with perf locks - we know the ID cannot change until perf shuts down
-        * the session
-        */
-       trace_id = coresight_trace_id_read_cpu_id_map(drvdata->cpu, id_map);
-       if (!IS_VALID_CS_TRACE_ID(trace_id)) {
-               dev_err(&drvdata->csdev->dev, "Failed to set trace ID for %s on CPU%d\n",
-                       dev_name(&drvdata->csdev->dev), drvdata->cpu);
-               ret = -EINVAL;
-               goto out;
-       }
-       drvdata->trcid = (u8)trace_id;
+       drvdata->trcid = path->trace_id;
 
        /* And enable it */
        ret = etm4_enable_hw(drvdata);
@@ -849,7 +815,7 @@ out:
        return ret;
 }
 
-static int etm4_enable_sysfs(struct coresight_device *csdev)
+static int etm4_enable_sysfs(struct coresight_device *csdev, struct coresight_path *path)
 {
        struct etmv4_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
        struct etm4_enable_arg arg = { };
@@ -866,10 +832,7 @@ static int etm4_enable_sysfs(struct coresight_device *csdev)
 
        spin_lock(&drvdata->spinlock);
 
-       /* sysfs needs to read and allocate a trace ID */
-       ret = etm4_read_alloc_trace_id(drvdata);
-       if (ret < 0)
-               goto unlock_sysfs_enable;
+       drvdata->trcid = path->trace_id;
 
        /*
         * Executing etm4_enable_hw on the cpu whose ETM is being enabled
@@ -886,7 +849,6 @@ static int etm4_enable_sysfs(struct coresight_device *csdev)
        if (ret)
                etm4_release_trace_id(drvdata);
 
-unlock_sysfs_enable:
        spin_unlock(&drvdata->spinlock);
 
        if (!ret)
@@ -895,7 +857,7 @@ unlock_sysfs_enable:
 }
 
 static int etm4_enable(struct coresight_device *csdev, struct perf_event *event,
-                      enum cs_mode mode, struct coresight_trace_id_map *id_map)
+                      enum cs_mode mode, struct coresight_path *path)
 {
        int ret;
 
@@ -906,10 +868,10 @@ static int etm4_enable(struct coresight_device *csdev, struct perf_event *event,
 
        switch (mode) {
        case CS_MODE_SYSFS:
-               ret = etm4_enable_sysfs(csdev);
+               ret = etm4_enable_sysfs(csdev, path);
                break;
        case CS_MODE_PERF:
-               ret = etm4_enable_perf(csdev, event, id_map);
+               ret = etm4_enable_perf(csdev, event, path);
                break;
        default:
                ret = -EINVAL;
index 1119762b5cece8fd4d5aea81b67ec1ec24f8a5fd..2b92de17b5a2e57419ecdced4f4b8ca1aaa2befb 100644 (file)
@@ -1066,6 +1066,5 @@ static inline bool etm4x_is_ete(struct etmv4_drvdata *drvdata)
        return drvdata->arch >= ETM_ARCH_ETE;
 }
 
-int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata);
 void etm4_release_trace_id(struct etmv4_drvdata *drvdata);
 #endif
index aca25b5e3be2c4ef4f89fbd1832572dd30f2b7d9..26f9339f38b938a90440463b74e924d5102e319d 100644 (file)
@@ -195,7 +195,7 @@ static void stm_enable_hw(struct stm_drvdata *drvdata)
 
 static int stm_enable(struct coresight_device *csdev, struct perf_event *event,
                      enum cs_mode mode,
-                     __maybe_unused struct coresight_trace_id_map *trace_id)
+                     __maybe_unused struct coresight_path *path)
 {
        struct stm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
 
index d03751bf3d8a38be69aad29de75bbff4c0b1b170..3ac5b52413a646e05382ddb48820c3f14b3771b3 100644 (file)
@@ -53,7 +53,8 @@ ssize_t coresight_simple_show32(struct device *_dev,
 EXPORT_SYMBOL_GPL(coresight_simple_show32);
 
 static int coresight_enable_source_sysfs(struct coresight_device *csdev,
-                                        enum cs_mode mode, void *data)
+                                        enum cs_mode mode,
+                                        struct coresight_path *path)
 {
        int ret;
 
@@ -64,7 +65,7 @@ static int coresight_enable_source_sysfs(struct coresight_device *csdev,
         */
        lockdep_assert_held(&coresight_mutex);
        if (coresight_get_mode(csdev) != CS_MODE_SYSFS) {
-               ret = source_ops(csdev)->enable(csdev, data, mode, NULL);
+               ret = source_ops(csdev)->enable(csdev, NULL, mode, path);
                if (ret)
                        return ret;
        }
@@ -217,7 +218,7 @@ int coresight_enable_sysfs(struct coresight_device *csdev)
        if (ret)
                goto err_path;
 
-       ret = coresight_enable_source_sysfs(csdev, CS_MODE_SYSFS, NULL);
+       ret = coresight_enable_source_sysfs(csdev, CS_MODE_SYSFS, path);
        if (ret)
                goto err_source;
 
index af806d2275d25fd3e3673474a804a6baf785d5c9..7214e65097ec9ac69f6c7c9278bcd28d25945c9e 100644 (file)
@@ -480,7 +480,7 @@ static void __tpdm_enable(struct tpdm_drvdata *drvdata)
 
 static int tpdm_enable(struct coresight_device *csdev, struct perf_event *event,
                       enum cs_mode mode,
-                      __maybe_unused struct coresight_trace_id_map *id_map)
+                      __maybe_unused struct coresight_path *path)
 {
        struct tpdm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
 
index 509e1f256412fc42c732b80f784374200771c78c..bc0c853ffa6d90e2873f5b1ccdc9ce0abab05c30 100644 (file)
@@ -401,7 +401,7 @@ struct coresight_ops_link {
 struct coresight_ops_source {
        int (*cpu_id)(struct coresight_device *csdev);
        int (*enable)(struct coresight_device *csdev, struct perf_event *event,
-                     enum cs_mode mode, struct coresight_trace_id_map *id_map);
+                     enum cs_mode mode, struct coresight_path *path);
        void (*disable)(struct coresight_device *csdev,
                        struct perf_event *event);
 };