The coresight trace event queues are organized one to a cpu. This patch adds a function to map a cpu number to a specific event queue.
Signed-off-by: Tor Jeremiassen tor@ti.com --- tools/perf/util/cs-etm.c | 32 ++++++++++++++++++++++++++++++++ tools/perf/util/cs-etm.h | 2 ++ 2 files changed, 34 insertions(+)
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 354f3b5..527733a 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -208,6 +208,38 @@ static void cs_etm__free(struct perf_session *session) zfree(&aux); }
+struct cs_etm_queue *cs_etm__cpu_to_etmq(struct cs_etm_auxtrace *etm, int cpu) +{ + int q, j; + + if (etm->queues.nr_queues == 0) + return NULL; + + /* make sure q is in range even if cpu is not */ + if (cpu < 0) + q = 0; + else if ((unsigned int) cpu >= etm->queues.nr_queues) + q = etm->queues.nr_queues - 1; + else + q = cpu; + + /* try the obvious one first */ + if (etm->queues.queue_array[q].cpu == cpu) + return etm->queues.queue_array[q].priv; + + /* search for a match in queues with index < q */ + for (j = q - 1; j >= 0; j--) + if (etm->queues.queue_array[j].cpu == cpu) + return etm->queues.queue_array[j].priv; + + /* search for a match in the queues with index > q */ + for (j = q + 1; j < (int) etm->queues.nr_queues; j++) + if (etm->queues.queue_array[j].cpu == cpu) + return etm->queues.queue_array[j].priv; + + return NULL; +} + uint32_t cs_etm__mem_access(struct cs_etm_queue *etmq, uint64_t address, size_t size, diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index d0205a3..846cd48 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -100,4 +100,6 @@ struct cs_etm_queue;
uint32_t cs_etm__mem_access(struct cs_etm_queue *etmq, uint64_t address, size_t size, uint8_t *buffer); + +struct cs_etm_queue *cs_etm__cpu_to_etmq(struct cs_etm_auxtrace *etm, int cpu); #endif