From: James Clark <james.clark@arm.com>
To: coresight@lists.linaro.org, suzuki.poulose@arm.com
Cc: James Clark <james.clark@arm.com>,
Mike Leach <mike.leach@linaro.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
linux-stm32@st-md-mailman.stormreply.com
Subject: [PATCH v2 10/12] coresight: Add helper for atomically taking the device
Date: Mon, 29 Jan 2024 15:40:41 +0000 [thread overview]
Message-ID: <20240129154050.569566-11-james.clark@arm.com> (raw)
In-Reply-To: <20240129154050.569566-1-james.clark@arm.com>
Now that mode is in struct coresight_device, this pattern can be wrapped
in a helper.
Signed-off-by: James Clark <james.clark@arm.com>
---
drivers/hwtracing/coresight/coresight-etm3x-core.c | 8 +++-----
drivers/hwtracing/coresight/coresight-etm4x-core.c | 8 +++-----
drivers/hwtracing/coresight/coresight-stm.c | 8 +++-----
include/linux/coresight.h | 11 +++++++++++
4 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-etm3x-core.c b/drivers/hwtracing/coresight/coresight-etm3x-core.c
index a8be115636f0..ce2b3ed90fb9 100644
--- a/drivers/hwtracing/coresight/coresight-etm3x-core.c
+++ b/drivers/hwtracing/coresight/coresight-etm3x-core.c
@@ -556,14 +556,12 @@ static int etm_enable(struct coresight_device *csdev, struct perf_event *event,
enum cs_mode mode)
{
int ret;
- u32 val;
struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
- val = local_cmpxchg(&drvdata->csdev->mode, CS_MODE_DISABLED, mode);
-
- /* Someone is already using the tracer */
- if (val)
+ if (!coresight_take_mode(csdev, mode)) {
+ /* Someone is already using the tracer */
return -EBUSY;
+ }
switch (mode) {
case CS_MODE_SYSFS:
diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
index 3480b563981c..8fca7fc379e6 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x-core.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
@@ -840,13 +840,11 @@ static int etm4_enable(struct coresight_device *csdev, struct perf_event *event,
enum cs_mode mode)
{
int ret;
- u32 val;
- val = local_cmpxchg(&csdev->mode, CS_MODE_DISABLED, mode);
-
- /* Someone is already using the tracer */
- if (val)
+ if (!coresight_take_mode(csdev, mode)) {
+ /* Someone is already using the tracer */
return -EBUSY;
+ }
switch (mode) {
case CS_MODE_SYSFS:
diff --git a/drivers/hwtracing/coresight/coresight-stm.c b/drivers/hwtracing/coresight/coresight-stm.c
index af9b21224246..80fed4c377f1 100644
--- a/drivers/hwtracing/coresight/coresight-stm.c
+++ b/drivers/hwtracing/coresight/coresight-stm.c
@@ -193,17 +193,15 @@ 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)
{
- u32 val;
struct stm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
if (mode != CS_MODE_SYSFS)
return -EINVAL;
- val = local_cmpxchg(&csdev->mode, CS_MODE_DISABLED, mode);
-
- /* Someone is already using the tracer */
- if (val)
+ if (!coresight_take_mode(csdev, mode)) {
+ /* Someone is already using the tracer */
return -EBUSY;
+ }
pm_runtime_get_sync(csdev->dev.parent);
diff --git a/include/linux/coresight.h b/include/linux/coresight.h
index c5be46d7f85c..175d184b3a1b 100644
--- a/include/linux/coresight.h
+++ b/include/linux/coresight.h
@@ -580,6 +580,17 @@ static inline bool coresight_is_percpu_sink(struct coresight_device *csdev)
(csdev->subtype.sink_subtype == CORESIGHT_DEV_SUBTYPE_SINK_PERCPU_SYSMEM);
}
+/*
+ * Atomically try to take the device and set a new mode. Returns true on
+ * success, false if the device is already taken by someone else.
+ */
+static inline bool coresight_take_mode(struct coresight_device *csdev,
+ enum cs_mode new_mode)
+{
+ return local_cmpxchg(&csdev->mode, CS_MODE_DISABLED, new_mode) ==
+ CS_MODE_DISABLED;
+}
+
extern struct coresight_device *
coresight_register(struct coresight_desc *desc);
extern void coresight_unregister(struct coresight_device *csdev);
--
2.34.1
next prev parent reply other threads:[~2024-01-29 15:42 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-29 15:40 [PATCH v2 00/12] coresight: Separate sysfs and Perf usage and some other cleanups James Clark
2024-01-29 15:40 ` [PATCH v2 01/12] coresight: Fix issue where a source device's helpers aren't disabled James Clark
2024-01-29 15:40 ` [PATCH v2 02/12] coresight: Make language around "activated" sinks consistent James Clark
2024-01-29 15:40 ` [PATCH v2 03/12] coresight: Remove ops callback checks James Clark
2024-01-29 15:40 ` [PATCH v2 04/12] coresight: Move mode to struct coresight_device James Clark
2024-01-29 15:40 ` [PATCH v2 05/12] coresight: Remove the 'enable' field James Clark
2024-01-29 15:40 ` [PATCH v2 06/12] coresight: Move all sysfs code to sysfs file James Clark
2024-01-29 15:40 ` [PATCH v2 07/12] coresight: Remove atomic type from refcnt James Clark
2024-01-29 15:40 ` [PATCH v2 08/12] coresight: Remove unused stubs James Clark
2024-01-29 15:40 ` [PATCH v2 09/12] coresight: Add explicit member initializers to coresight_dev_type James Clark
2024-01-29 15:40 ` James Clark [this message]
2024-01-29 15:40 ` [PATCH v2 11/12] coresight: Add a helper for getting csdev->mode James Clark
2024-01-29 15:40 ` [PATCH v2 12/12] coresight: Add helper for setting csdev->mode James Clark
2024-02-12 11:27 ` [PATCH v2 00/12] coresight: Separate sysfs and Perf usage and some other cleanups Suzuki K Poulose
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=20240129154050.569566-11-james.clark@arm.com \
--to=james.clark@arm.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=alexandre.torgue@foss.st.com \
--cc=coresight@lists.linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--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
all inboxes | Powered by JetHome®