mirror of
https://github.com/torvalds/linux
synced 2024-11-05 18:23:50 +00:00
coresight: etb10: Add support for CPU-wide trace scenarios
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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
880af782c6
commit
75d7dbd388
1 changed files with 39 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue