linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yeoreum Yun <yeoreum.yun@arm.com>
To: suzuki.poulose@arm.com, mike.leach@linaro.org,
	james.clark@linaro.org, alexander.shishkin@linux.intel.com
Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, Yeoreum Yun <yeoreum.yun@arm.com>
Subject: [PATCH 4/4] coresight/etm3x: remove redundant usage of drvdata->spinlock
Date: Sat, 21 Dec 2024 16:59:34 +0000	[thread overview]
Message-ID: <20241221165934.1161856-5-yeoreum.yun@arm.com> (raw)
In-Reply-To: <20241221165934.1161856-1-yeoreum.yun@arm.com>

Remove redundant usage of drvdata->spinlock in etm_starting/dying_cpu()
by preventing cpu hotplug while enabling etm3x via sysfs since
 - perf and sysfs enable method are serialized by csdev->mode
 - etm_starting/dying_cpu() aren't called concurrently with
   etm_enable_perf/sysfs() because they're called in cpu offline status.
 - while etm_enable_sysfs(), config isn't changed since csdev->mode is
   not DISABLED.

Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
---
 .../coresight/coresight-etm3x-core.c          | 33 ++++++++-----------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etm3x-core.c b/drivers/hwtracing/coresight/coresight-etm3x-core.c
index c103f4c70f5d..5ec871979ef7 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x-core.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c
@@ -519,7 +519,12 @@ static int etm_enable_sysfs(struct coresight_device *csdev)
 	struct etm_enable_arg arg = { };
 	int ret;
 
-	spin_lock(&drvdata->spinlock);
+	cpus_read_lock();
+
+	if (cpu_is_offline(drvdata->cpu)) {
+		ret = -ENODEV;
+		goto unlock_sysfs_enable;
+	}
 
 	/* sysfs needs to allocate and set a trace ID */
 	ret = etm_read_alloc_trace_id(drvdata);
@@ -530,23 +535,19 @@ static int etm_enable_sysfs(struct coresight_device *csdev)
 	 * Configure the ETM only if the CPU is online.  If it isn't online
 	 * hw configuration will take place on the local CPU during bring up.
 	 */
-	if (cpu_online(drvdata->cpu)) {
-		arg.drvdata = drvdata;
-		ret = smp_call_function_single(drvdata->cpu,
-					       etm_enable_hw_smp_call, &arg, 1);
-		if (!ret)
-			ret = arg.rc;
-		if (!ret)
-			drvdata->sticky_enable = true;
-	} else {
-		ret = -ENODEV;
-	}
+	arg.drvdata = drvdata;
+	ret = smp_call_function_single(drvdata->cpu,
+				       etm_enable_hw_smp_call, &arg, 1);
+	if (!ret)
+		ret = arg.rc;
+	if (!ret)
+		drvdata->sticky_enable = true;
 
 	if (ret)
 		etm_release_trace_id(drvdata);
 
 unlock_enable_sysfs:
-	spin_unlock(&drvdata->spinlock);
+	cpus_read_unlock();
 
 	if (!ret)
 		dev_dbg(&csdev->dev, "ETM tracing enabled\n");
@@ -646,7 +647,6 @@ static void etm_disable_sysfs(struct coresight_device *csdev)
 	 * DYING hotplug callback is serviced by the ETM driver.
 	 */
 	cpus_read_lock();
-	spin_lock(&drvdata->spinlock);
 
 	/*
 	 * Executing etm_disable_hw on the cpu whose ETM is being disabled
@@ -654,7 +654,6 @@ static void etm_disable_sysfs(struct coresight_device *csdev)
 	 */
 	smp_call_function_single(drvdata->cpu, etm_disable_hw, drvdata, 1);
 
-	spin_unlock(&drvdata->spinlock);
 	cpus_read_unlock();
 
 	/*
@@ -722,7 +721,6 @@ static int etm_starting_cpu(unsigned int cpu)
 	if (!etmdrvdata[cpu])
 		return 0;
 
-	spin_lock(&etmdrvdata[cpu]->spinlock);
 	if (!etmdrvdata[cpu]->os_unlock) {
 		etm_os_unlock(etmdrvdata[cpu]);
 		etmdrvdata[cpu]->os_unlock = true;
@@ -730,7 +728,6 @@ static int etm_starting_cpu(unsigned int cpu)
 
 	if (coresight_get_mode(etmdrvdata[cpu]->csdev))
 		etm_enable_hw(etmdrvdata[cpu]);
-	spin_unlock(&etmdrvdata[cpu]->spinlock);
 	return 0;
 }
 
@@ -739,10 +736,8 @@ static int etm_dying_cpu(unsigned int cpu)
 	if (!etmdrvdata[cpu])
 		return 0;
 
-	spin_lock(&etmdrvdata[cpu]->spinlock);
 	if (coresight_get_mode(etmdrvdata[cpu]->csdev))
 		etm_disable_hw(etmdrvdata[cpu]);
-	spin_unlock(&etmdrvdata[cpu]->spinlock);
 	return 0;
 }
 
-- 
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}


  parent reply	other threads:[~2024-12-21 16:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-21 16:59 [PATCH 0/4] small fix for configuaring etm csdev via sysfs Yeoreum Yun
2024-12-21 16:59 ` [PATCH 1/4] coresight/etm4x: disallow altering config via sysfs while enabled Yeoreum Yun
2025-01-09 11:46   ` Suzuki K Poulose
2025-01-09 12:01     ` Yeoreum Yun
2025-01-09 12:21       ` Suzuki K Poulose
2025-01-09 12:27         ` Yeoreum Yun
2025-01-09 17:39         ` Yeoreum Yun
2025-01-09 17:48           ` Yeo Reum Yun
2025-03-12  6:45             ` Yeo Reum Yun
2024-12-21 16:59 ` [PATCH 2/4] coresight/etm4x: remove redundant usage of drvdata->spinlock Yeoreum Yun
2024-12-21 16:59 ` [PATCH 3/4] coresight/etm3x: disallow altering config via sysfs while enabled Yeoreum Yun
2024-12-21 16:59 ` Yeoreum Yun [this message]
2024-12-31 14:39 ` [PATCH 0/4] small fix for configuaring etm csdev via sysfs Yeo Reum Yun
2025-05-02 10:53 ` Yeoreum Yun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241221165934.1161856-5-yeoreum.yun@arm.com \
    --to=yeoreum.yun@arm.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=coresight@lists.linaro.org \
    --cc=james.clark@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mike.leach@linaro.org \
    --cc=suzuki.poulose@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).