In preparation to support CPU-wide trace scenarios, add the notion of process ID to ETR devices so that memory buffers can be shared between events.
Signed-off-by: Mathieu Poirier mathieu.poirier@linaro.org --- .../hwtracing/coresight/coresight-tmc-etr.c | 26 +++++++++++++++---- drivers/hwtracing/coresight/coresight-tmc.h | 6 +++++ 2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 4ec78f9cdc74..3bd03cd890e8 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1160,8 +1160,8 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) }
static struct etr_buf * -tmc_etr_get_etr_buf(struct tmc_drvdata *drvdata, int node, - int nr_pages, void **pages) +alloc_etr_buf(struct tmc_drvdata *drvdata, int node, + int nr_pages, void **pages) { struct etr_buf *etr_buf; unsigned long size; @@ -1195,6 +1195,22 @@ tmc_etr_get_etr_buf(struct tmc_drvdata *drvdata, int node, return etr_buf; }
+static struct etr_buf * +tmc_etr_get_etr_buf(struct tmc_drvdata *drvdata, int node, pid_t pid, + int nr_pages, void **pages) +{ + struct etr_buf *etr_buf; + + etr_buf = alloc_etr_buf(drvdata, node, nr_pages, pages); + if (IS_ERR(etr_buf)) + return etr_buf; + + etr_buf->pid = pid; + refcount_set(&etr_buf->refcount, 1); + + return etr_buf; +} + /* * tmc_etr_setup_perf_buf: Allocate ETR buffer for use by perf. * The size of the hardware buffer is dependent on the size configured @@ -1203,7 +1219,7 @@ tmc_etr_get_etr_buf(struct tmc_drvdata *drvdata, int node, * reaches a minimum limit (1M), beyond which we give up. */ static struct etr_perf_buffer * -tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, int node, +tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, int node, pid_t pid, int nr_pages, void **pages, bool snapshot) { struct etr_buf *etr_buf; @@ -1213,7 +1229,7 @@ tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, int node, if (!etr_perf) return ERR_PTR(-ENOMEM);
- etr_buf = tmc_etr_get_etr_buf(drvdata, node, nr_pages, pages); + etr_buf = tmc_etr_get_etr_buf(drvdata, node, pid, nr_pages, pages); if (!IS_ERR(etr_buf)) goto done;
@@ -1236,7 +1252,7 @@ static void *tmc_alloc_etr_buffer(struct coresight_device *csdev, int cpu, if (cpu == -1) cpu = smp_processor_id();
- etr_perf = tmc_etr_setup_perf_buf(drvdata, cpu_to_node(cpu), + etr_perf = tmc_etr_setup_perf_buf(drvdata, cpu_to_node(cpu), pid, nr_pages, pages, snapshot); if (IS_ERR(etr_perf)) { dev_dbg(drvdata->dev, "Unable to allocate ETR buffer\n"); diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h index 487c53701e9c..d3657acb6cbf 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -9,6 +9,8 @@
#include <linux/dma-mapping.h> #include <linux/miscdevice.h> +#include <linux/refcount.h> +#include <linux/types.h>
#define TMC_RSZ 0x004 #define TMC_STS 0x00c @@ -133,6 +135,8 @@ struct etr_buf_operations;
/** * struct etr_buf - Details of the buffer used by ETR + * @pid : The pid this etr_buf belongs to. + * @refcount : Number of sources currently using this etr_buf. * @mode : Mode of the ETR buffer, contiguous, Scatter Gather etc. * @full : Trace data overflow * @size : Size of the buffer. @@ -143,6 +147,8 @@ struct etr_buf_operations; * @private : Backend specific information for the buf */ struct etr_buf { + pid_t pid; + refcount_t refcount; enum etr_mode mode; bool full; ssize_t size;