/** * struct etb_drvdata - specifics associated to an ETB component * @base: memory mapped base address for this component. * @atclk: optional clock for the core parts of the ETB. * @csdev: component vitals needed by the framework. * @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. * @buffer_depth: size of @buf. * @trigger_cntr: amount of words to store after a trigger.
*/ struct etb_drvdata { void __iomem *base; struct clk *atclk; struct coresight_device *csdev; struct miscdevice miscdev;
raw_spinlock_t spinlock;
local_t reading;
pid_t pid;
u8 *buf;
u32 buffer_depth;
u32 trigger_cntr;
};
/* No need to continue if the component is already in used by sysFS. */ if (coresight_get_mode(drvdata->csdev) == CS_MODE_SYSFS) {
ret = -EBUSY; goto out;
}
/* Get a handle on the pid of the process to monitor */
pid = buf->pid;
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) {
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, handle); if (ret) goto out;
ret = etb_enable_hw(drvdata); if (!ret) { /* Associate with monitored process. */
drvdata->pid = pid;
coresight_set_mode(drvdata->csdev, CS_MODE_PERF);
csdev->refcnt++;
}
switch (mode) { case CS_MODE_SYSFS:
ret = etb_enable_sysfs(csdev); break; case CS_MODE_PERF:
ret = etb_enable_perf(csdev, data); break; default:
ret = -EINVAL; break;
}
/* unit is in words, not bytes */
read_ptr = readl_relaxed(drvdata->base + ETB_RAM_READ_POINTER);
write_ptr = readl_relaxed(drvdata->base + ETB_RAM_WRITE_POINTER);
/* * Entries should be aligned to the frame size. If they are not * go back to the last alignment point to give decoding tools a * chance to fix things.
*/ if (write_ptr % ETB_FRAME_SIZE_WORDS) {
dev_err(&csdev->dev, "write_ptr: %lu not aligned to formatter frame size\n",
(unsignedlong)write_ptr);
write_ptr &= ~(ETB_FRAME_SIZE_WORDS - 1);
lost = true;
}
/* * Get a hold of the status register and see if a wrap around * has occurred. If so adjust things accordingly. Otherwise * start at the beginning and go until the write pointer has * been reached.
*/
status = readl_relaxed(drvdata->base + ETB_STATUS_REG); if (status & ETB_STATUS_RAM_FULL) {
lost = true;
to_read = capacity;
read_ptr = write_ptr;
} else {
to_read = CIRC_CNT(write_ptr, read_ptr, drvdata->buffer_depth);
to_read *= ETB_FRAME_SIZE_WORDS;
}
/* * Make sure we don't overwrite data that hasn't been consumed yet. * It is entirely possible that the HW buffer has more data than the * ring buffer can currently handle. If so adjust the start address * to take only the last traces. * * In snapshot mode we are looking to get the latest traces only and as * such, we don't care about not overwriting data that hasn't been * processed by user space.
*/ if (!buf->snapshot && to_read > handle->size) {
u32 mask = ~(ETB_FRAME_SIZE_WORDS - 1);
/* The new read pointer must be frame size aligned */
to_read = handle->size & mask; /* * Move the RAM read pointer up, keeping in mind that * everything is in frame size units.
*/
read_ptr = (write_ptr + drvdata->buffer_depth) -
to_read / ETB_FRAME_SIZE_WORDS; /* Wrap around if need be*/ if (read_ptr > (drvdata->buffer_depth - 1))
read_ptr -= drvdata->buffer_depth; /* let the decoder know we've skipped ahead */
lost = true;
}
/* * Don't set the TRUNCATED flag in snapshot mode because 1) the * captured buffer is expected to be truncated and 2) a full buffer * prevents the event from being re-enabled by the perf core, * resulting in stale data being send to user space.
*/ if (!buf->snapshot && lost)
perf_aux_output_flag(handle, PERF_AUX_FLAG_TRUNCATED);
/* finally tell HW where we want to start reading from */
writel_relaxed(read_ptr, drvdata->base + ETB_RAM_READ_POINTER);
cur = buf->cur;
offset = buf->offset;
barrier = coresight_barrier_pkt;
for (i = 0; i < to_read; i += 4) {
buf_ptr = buf->data_pages[cur] + offset;
read_data = readl_relaxed(drvdata->base +
ETB_RAM_READ_DATA_REG); if (lost && i < CORESIGHT_BARRIER_PKT_SIZE) {
read_data = *barrier;
barrier++;
}
*(u32 *)buf_ptr = read_data;
buf_ptr += 4;
offset += 4; if (offset >= PAGE_SIZE) {
offset = 0;
cur++; /* wrap around at the end of the buffer */
cur &= buf->nr_pages - 1;
}
}
/* reset ETB buffer for next run */
writel_relaxed(0x0, drvdata->base + ETB_RAM_READ_POINTER);
writel_relaxed(0x0, drvdata->base + ETB_RAM_WRITE_POINTER);
/* * In snapshot mode we simply increment the head by the number of byte * that were written. User space will figure out how many bytes to get * from the AUX buffer based on the position of the head.
*/ if (buf->snapshot)
handle->head += to_read;
/* * Since misc_open() holds a refcount on the f_ops, which is * etb fops in this case, device is there until last file * handler to this device is closed.
*/
misc_deregister(&drvdata->miscdev);
coresight_unregister(drvdata->csdev);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.