mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 19:07:52 +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.
|
* @miscdev: specifics to handle "/dev/xyz.etb" entry.
|
||||||
* @spinlock: only one at a time pls.
|
* @spinlock: only one at a time pls.
|
||||||
* @reading: synchronise user space access to etb buffer.
|
* @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.
|
* @buf: area of memory where ETB buffer content gets sent.
|
||||||
* @mode: this ETB is being used.
|
* @mode: this ETB is being used.
|
||||||
* @buffer_depth: size of @buf.
|
* @buffer_depth: size of @buf.
|
||||||
|
@ -85,6 +87,7 @@ struct etb_drvdata {
|
||||||
struct miscdevice miscdev;
|
struct miscdevice miscdev;
|
||||||
spinlock_t spinlock;
|
spinlock_t spinlock;
|
||||||
local_t reading;
|
local_t reading;
|
||||||
|
pid_t pid;
|
||||||
u8 *buf;
|
u8 *buf;
|
||||||
u32 mode;
|
u32 mode;
|
||||||
u32 buffer_depth;
|
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)
|
static int etb_enable_perf(struct coresight_device *csdev, void *data)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
pid_t pid;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
|
struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
|
||||||
|
struct perf_output_handle *handle = data;
|
||||||
|
|
||||||
spin_lock_irqsave(&drvdata->spinlock, flags);
|
spin_lock_irqsave(&drvdata->spinlock, flags);
|
||||||
|
|
||||||
/* No need to continue if the component is already in use. */
|
/* No need to continue if the component is already in used by sysFS. */
|
||||||
if (drvdata->mode != CS_MODE_DISABLED) {
|
if (drvdata->mode == CS_MODE_SYSFS) {
|
||||||
ret = -EBUSY;
|
ret = -EBUSY;
|
||||||
goto out;
|
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
|
* 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
|
* the perf buffer. So we can perform the step before we turn the
|
||||||
* ETB on and leave without cleaning up.
|
* 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)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret = etb_enable_hw(drvdata);
|
ret = etb_enable_hw(drvdata);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
|
/* Associate with monitored process. */
|
||||||
|
drvdata->pid = pid;
|
||||||
drvdata->mode = CS_MODE_PERF;
|
drvdata->mode = CS_MODE_PERF;
|
||||||
atomic_inc(csdev->refcnt);
|
atomic_inc(csdev->refcnt);
|
||||||
}
|
}
|
||||||
|
@ -336,6 +360,8 @@ static int etb_disable(struct coresight_device *csdev)
|
||||||
/* Complain if we (somehow) got out of sync */
|
/* Complain if we (somehow) got out of sync */
|
||||||
WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED);
|
WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED);
|
||||||
etb_disable_hw(drvdata);
|
etb_disable_hw(drvdata);
|
||||||
|
/* Dissociate from monitored process. */
|
||||||
|
drvdata->pid = -1;
|
||||||
drvdata->mode = CS_MODE_DISABLED;
|
drvdata->mode = CS_MODE_DISABLED;
|
||||||
spin_unlock_irqrestore(&drvdata->spinlock, flags);
|
spin_unlock_irqrestore(&drvdata->spinlock, flags);
|
||||||
|
|
||||||
|
@ -406,7 +432,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev,
|
||||||
const u32 *barrier;
|
const u32 *barrier;
|
||||||
u32 read_ptr, write_ptr, capacity;
|
u32 read_ptr, write_ptr, capacity;
|
||||||
u32 status, read_data;
|
u32 status, read_data;
|
||||||
unsigned long offset, to_read, flags;
|
unsigned long offset, to_read = 0, flags;
|
||||||
struct cs_buffers *buf = sink_config;
|
struct cs_buffers *buf = sink_config;
|
||||||
struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
|
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;
|
capacity = drvdata->buffer_depth * ETB_FRAME_SIZE_WORDS;
|
||||||
|
|
||||||
spin_lock_irqsave(&drvdata->spinlock, flags);
|
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);
|
__etb_disable_hw(drvdata);
|
||||||
CS_UNLOCK(drvdata->base);
|
CS_UNLOCK(drvdata->base);
|
||||||
|
|
||||||
|
@ -526,6 +557,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev,
|
||||||
}
|
}
|
||||||
__etb_enable_hw(drvdata);
|
__etb_enable_hw(drvdata);
|
||||||
CS_LOCK(drvdata->base);
|
CS_LOCK(drvdata->base);
|
||||||
|
out:
|
||||||
spin_unlock_irqrestore(&drvdata->spinlock, flags);
|
spin_unlock_irqrestore(&drvdata->spinlock, flags);
|
||||||
|
|
||||||
return to_read;
|
return to_read;
|
||||||
|
@ -733,6 +765,9 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id)
|
||||||
if (!drvdata->buf)
|
if (!drvdata->buf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
/* This device is not associated with a session */
|
||||||
|
drvdata->pid = -1;
|
||||||
|
|
||||||
desc.type = CORESIGHT_DEV_TYPE_SINK;
|
desc.type = CORESIGHT_DEV_TYPE_SINK;
|
||||||
desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER;
|
desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER;
|
||||||
desc.ops = &etb_cs_ops;
|
desc.ops = &etb_cs_ops;
|
||||||
|
|
Loading…
Reference in a new issue