linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: gregkh@linuxfoundation.org
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH 32/32] coresight: etb10: Add support for CPU-wide trace scenarios
Date: Thu, 25 Apr 2019 13:53:10 -0600	[thread overview]
Message-ID: <20190425195310.31562-33-mathieu.poirier@linaro.org> (raw)
In-Reply-To: <20190425195310.31562-1-mathieu.poirier@linaro.org>

This patch adds support for CPU-wide trace scenarios by making sure that
only the sources monitoring the same process have access to a common sink.
Because the sink is shared between sources, the first source to use the
sink switches it on while the last one does the cleanup.  Any attempt to
modify the HW is overlooked for as long as more than one source is using
a sink.

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Tested-by: Leo Yan <leo.yan@linaro.org>
Tested-by: Robert Walker <robert.walker@arm.com>
---
 drivers/hwtracing/coresight/coresight-etb10.c | 43 +++++++++++++++++--
 1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c
index eeae375c7aed..4ee4c80a4354 100644
--- a/drivers/hwtracing/coresight/coresight-etb10.c
+++ b/drivers/hwtracing/coresight/coresight-etb10.c
@@ -72,6 +72,8 @@
  * @miscdev:	specifics to handle "/dev/xyz.etb" entry.
  * @spinlock:	only one at a time pls.
  * @reading:	synchronise user space access to etb buffer.
+ * @pid:	Process ID of the process being monitored by the session
+ *		that is using this component.
  * @buf:	area of memory where ETB buffer content gets sent.
  * @mode:	this ETB is being used.
  * @buffer_depth: size of @buf.
@@ -85,6 +87,7 @@ struct etb_drvdata {
 	struct miscdevice	miscdev;
 	spinlock_t		spinlock;
 	local_t			reading;
+	pid_t			pid;
 	u8			*buf;
 	u32			mode;
 	u32			buffer_depth;
@@ -169,28 +172,49 @@ static int etb_enable_sysfs(struct coresight_device *csdev)
 static int etb_enable_perf(struct coresight_device *csdev, void *data)
 {
 	int ret = 0;
+	pid_t pid;
 	unsigned long flags;
 	struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
+	struct perf_output_handle *handle = data;
 
 	spin_lock_irqsave(&drvdata->spinlock, flags);
 
-	/* No need to continue if the component is already in use. */
-	if (drvdata->mode != CS_MODE_DISABLED) {
+	/* No need to continue if the component is already in used by sysFS. */
+	if (drvdata->mode == CS_MODE_SYSFS) {
+		ret = -EBUSY;
+		goto out;
+	}
+
+	/* Get a handle on the pid of the process to monitor */
+	pid = task_pid_nr(handle->event->owner);
+
+	if (drvdata->pid != -1 && drvdata->pid != pid) {
 		ret = -EBUSY;
 		goto out;
 	}
 
+	/*
+	 * No HW configuration is needed if the sink is already in
+	 * use for this session.
+	 */
+	if (drvdata->pid == pid) {
+		atomic_inc(csdev->refcnt);
+		goto out;
+	}
+
 	/*
 	 * We don't have an internal state to clean up if we fail to setup
 	 * the perf buffer. So we can perform the step before we turn the
 	 * ETB on and leave without cleaning up.
 	 */
-	ret = etb_set_buffer(csdev, (struct perf_output_handle *)data);
+	ret = etb_set_buffer(csdev, handle);
 	if (ret)
 		goto out;
 
 	ret = etb_enable_hw(drvdata);
 	if (!ret) {
+		/* Associate with monitored process. */
+		drvdata->pid = pid;
 		drvdata->mode = CS_MODE_PERF;
 		atomic_inc(csdev->refcnt);
 	}
@@ -336,6 +360,8 @@ static int etb_disable(struct coresight_device *csdev)
 	/* Complain if we (somehow) got out of sync */
 	WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED);
 	etb_disable_hw(drvdata);
+	/* Dissociate from monitored process. */
+	drvdata->pid = -1;
 	drvdata->mode = CS_MODE_DISABLED;
 	spin_unlock_irqrestore(&drvdata->spinlock, flags);
 
@@ -406,7 +432,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev,
 	const u32 *barrier;
 	u32 read_ptr, write_ptr, capacity;
 	u32 status, read_data;
-	unsigned long offset, to_read, flags;
+	unsigned long offset, to_read = 0, flags;
 	struct cs_buffers *buf = sink_config;
 	struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
 
@@ -416,6 +442,11 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev,
 	capacity = drvdata->buffer_depth * ETB_FRAME_SIZE_WORDS;
 
 	spin_lock_irqsave(&drvdata->spinlock, flags);
+
+	/* Don't do anything if another tracer is using this sink */
+	if (atomic_read(csdev->refcnt) != 1)
+		goto out;
+
 	__etb_disable_hw(drvdata);
 	CS_UNLOCK(drvdata->base);
 
@@ -526,6 +557,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev,
 	}
 	__etb_enable_hw(drvdata);
 	CS_LOCK(drvdata->base);
+out:
 	spin_unlock_irqrestore(&drvdata->spinlock, flags);
 
 	return to_read;
@@ -733,6 +765,9 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id)
 	if (!drvdata->buf)
 		return -ENOMEM;
 
+	/* This device is not associated with a session */
+	drvdata->pid = -1;
+
 	desc.type = CORESIGHT_DEV_TYPE_SINK;
 	desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER;
 	desc.ops = &etb_cs_ops;
-- 
2.17.1


      parent reply	other threads:[~2019-04-25 19:54 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-25 19:52 [PATCH 00/32] coresight: next v5.1-rc6 Mathieu Poirier
2019-04-25 19:52 ` [PATCH 01/32] coresight: catu: fix clang build warning Mathieu Poirier
2019-04-25 19:52 ` [PATCH 02/32] coresight: catu: Make catu_helper_ops and catu_ops static Mathieu Poirier
2019-04-25 19:52 ` [PATCH 03/32] coresight: tmc: Report DMA setup failures Mathieu Poirier
2019-04-25 19:52 ` [PATCH 04/32] coresight: dynamic-replicator: Clean up error handling Mathieu Poirier
2019-04-25 19:52 ` [PATCH 05/32] coresight: replicator: Prepare for merging with dynamic-replicator Mathieu Poirier
2019-04-25 19:52 ` [PATCH 06/32] coresight: dynamic-replicator: Prepare for merging with static replicator Mathieu Poirier
2019-04-25 19:52 ` [PATCH 07/32] coresight: Merge the static and dynamic replicator drivers Mathieu Poirier
2019-04-25 19:52 ` [PATCH 08/32] coresight: Fix freeing up the coresight connections Mathieu Poirier
2019-04-25 19:52 ` [PATCH 09/32] coresight: etb10: Cleanup power management Mathieu Poirier
2019-04-25 19:52 ` [PATCH 10/32] coresight: tpiu: " Mathieu Poirier
2019-04-25 19:52 ` [PATCH 11/32] coresight: catu: " Mathieu Poirier
2019-04-25 19:52 ` [PATCH 12/32] coresight: tmc: " Mathieu Poirier
2019-04-25 19:52 ` [PATCH 13/32] coresight: pmu: Adding ITRACE property to cs_etm PMU Mathieu Poirier
2019-04-25 19:52 ` [PATCH 14/32] coresight: etm4x: Add kernel configuration for CONTEXTID Mathieu Poirier
2019-04-25 19:52 ` [PATCH 15/32] coresight: etm4x: Skip selector pair 0 Mathieu Poirier
2019-04-25 19:52 ` [PATCH 16/32] coresight: etm4x: Configure tracers to emit timestamps Mathieu Poirier
2019-04-25 19:52 ` [PATCH 17/32] coresight: Adding return code to sink::disable() operation Mathieu Poirier
2019-04-25 19:52 ` [PATCH 18/32] coresight: Move reference counting inside sink drivers Mathieu Poirier
2019-04-25 19:52 ` [PATCH 19/32] coresight: Properly address errors in sink::disable() functions Mathieu Poirier
2019-04-25 19:52 ` [PATCH 20/32] coresight: Properly address concurrency in sink::update() functions Mathieu Poirier
2019-04-25 19:52 ` [PATCH 21/32] coresight: perf: Clean up function etm_setup_aux() Mathieu Poirier
2019-04-25 19:53 ` [PATCH 22/32] coresight: perf: Refactor function free_event_data() Mathieu Poirier
2019-04-25 19:53 ` [PATCH 23/32] coresight: Communicate perf event to sink buffer allocation functions Mathieu Poirier
2019-04-25 19:53 ` [PATCH 24/32] coresight: tmc-etr: Refactor function tmc_etr_setup_perf_buf() Mathieu Poirier
2019-04-25 19:53 ` [PATCH 25/32] coresight: tmc-etr: Create per-thread buffer allocation function Mathieu Poirier
2019-04-25 19:53 ` [PATCH 26/32] coresight: tmc-etr: Introduce the notion of process ID to ETR devices Mathieu Poirier
2019-04-25 19:53 ` [PATCH 27/32] coresight: tmc-etr: Introduce the notion of reference counting " Mathieu Poirier
2019-04-25 19:53 ` [PATCH 28/32] coresight: tmc-etr: Introduce the notion of IDR " Mathieu Poirier
2019-04-25 19:53 ` [PATCH 29/32] coresight: tmc-etr: Allocate and free ETR memory buffers for CPU-wide scenarios Mathieu Poirier
2019-04-25 19:53 ` [PATCH 30/32] coresight: tmc-etr: Add support for CPU-wide trace scenarios Mathieu Poirier
2019-04-25 19:53 ` [PATCH 31/32] coresight: tmc-etf: " Mathieu Poirier
2019-04-25 19:53 ` Mathieu Poirier [this message]

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=20190425195310.31562-33-mathieu.poirier@linaro.org \
    --to=mathieu.poirier@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /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).