[PATCH 2/4] coresight/etm4x: remove redundant usage of drvdata->spinlock

From: Yeoreum Yun
Date: Sat Dec 21 2024 - 12:00:26 EST


Remove redundant usage of drvdata->spinlock in etm4_starting/dying_cpu()
by preventing cpu hotplug while enabling etm4x via sysfs since
- perf and sysfs enable method are serialized by csdev->mode
- etm4_starting/dying_cpu() aren't called concurrently with
etm4_enable_perf/sysfs() because they're called in cpu offline status.
- while etm4x_enable_sysfs(), config isn't altered since csdev->mode
isn't DISABLED.

Signed-off-by: Yeoreum Yun <yeoreum.yun@xxxxxxx>
---
.../coresight/coresight-etm4x-core.c | 20 +++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
index 86893115df17..5c9475b44194 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
@@ -799,16 +799,21 @@ static int etm4_enable_sysfs(struct coresight_device *csdev)
unsigned long cfg_hash;
int ret, preset;

+ cpus_read_lock();
+
+ if (cpu_is_offline(drvdata->cpu)) {
+ ret = -EPERM;
+ goto unlock_sysfs_enable;
+ }
+
/* enable any config activated by configfs */
cscfg_config_sysfs_get_active_cfg(&cfg_hash, &preset);
if (cfg_hash) {
ret = cscfg_csdev_enable_active_config(csdev, cfg_hash, preset);
if (ret)
- return ret;
+ goto unlock_sysfs_enable;
}

- raw_spin_lock(&drvdata->spinlock);
-
/* sysfs needs to read and allocate a trace ID */
ret = etm4_read_alloc_trace_id(drvdata);
if (ret < 0)
@@ -830,10 +835,11 @@ static int etm4_enable_sysfs(struct coresight_device *csdev)
etm4_release_trace_id(drvdata);

unlock_sysfs_enable:
- raw_spin_unlock(&drvdata->spinlock);
+ cpus_read_unlock();

if (!ret)
dev_dbg(&csdev->dev, "ETM tracing enabled\n");
+
return ret;
}

@@ -977,7 +983,6 @@ static void etm4_disable_sysfs(struct coresight_device *csdev)
* DYING hotplug callback is serviced by the ETM driver.
*/
cpus_read_lock();
- raw_spin_lock(&drvdata->spinlock);

/*
* Executing etm4_disable_hw on the cpu whose ETM is being disabled
@@ -985,7 +990,6 @@ static void etm4_disable_sysfs(struct coresight_device *csdev)
*/
smp_call_function_single(drvdata->cpu, etm4_disable_hw, drvdata, 1);

- raw_spin_unlock(&drvdata->spinlock);
cpus_read_unlock();

/*
@@ -1663,13 +1667,11 @@ static int etm4_starting_cpu(unsigned int cpu)
if (!etmdrvdata[cpu])
return 0;

- raw_spin_lock(&etmdrvdata[cpu]->spinlock);
if (!etmdrvdata[cpu]->os_unlock)
etm4_os_unlock(etmdrvdata[cpu]);

if (coresight_get_mode(etmdrvdata[cpu]->csdev))
etm4_enable_hw(etmdrvdata[cpu]);
- raw_spin_unlock(&etmdrvdata[cpu]->spinlock);
return 0;
}

@@ -1678,10 +1680,8 @@ static int etm4_dying_cpu(unsigned int cpu)
if (!etmdrvdata[cpu])
return 0;

- raw_spin_lock(&etmdrvdata[cpu]->spinlock);
if (coresight_get_mode(etmdrvdata[cpu]->csdev))
etm4_disable_hw(etmdrvdata[cpu]);
- raw_spin_unlock(&etmdrvdata[cpu]->spinlock);
return 0;
}

--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}