Link contextID packets received from the decoder with the perf tool thread mechanic so that we know the specifics of the currently executing process.
Signed-off-by: Mathieu Poirier mathieu.poirier@linaro.org --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 34 +++++++++++++++++++++++++ tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 2 -- tools/perf/util/cs-etm.c | 30 +++++++++++++++++++--- tools/perf/util/cs-etm.h | 5 ++++ 4 files changed, 66 insertions(+), 5 deletions(-)
diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c index 24aabf01d754..3e69abbfa2c5 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -345,6 +345,37 @@ cs_etm_decoder__buffer_trace_on(struct cs_etm_decoder *decoder, CS_ETM_TRACE_ON); }
+static ocsd_datapath_resp_t +cs_etm_decoder__set_tid(struct cs_etm_decoder *decoder, + const ocsd_generic_trace_elem *elem, + const uint8_t trace_chan_id) +{ + int cpu; + pid_t tid; + struct int_node *inode = NULL; + struct cs_etm_queue *etmq = decoder->data; + ocsd_datapath_resp_t ret = OCSD_RESP_CONT; + + /* Ignore PE_CONTEXT packets that don't have a valid contextID */ + if (!elem->context.ctxt_id_valid) + goto out; + + /* Search the RB tree for the cpu associated with this traceID */ + inode = intlist__find(traceid_list, trace_chan_id); + if (!inode) { + ret = OCSD_RESP_FATAL_SYS_ERR; + goto out; + } + + cpu = *((int *)inode->priv); + tid = elem->context.context_id; + + cs_etm__etmq_set_tid_cpu(etmq, tid, cpu); + +out: + return ret; +} + static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( const void *context, const ocsd_trc_index_t indx __maybe_unused, @@ -376,6 +407,9 @@ static ocsd_datapath_resp_t cs_etm_decoder__gen_trace_elem_printer( decoder->packet_buffer[decoder->tail].exc_ret = true; break; case OCSD_GEN_TRC_ELEM_PE_CONTEXT: + resp = cs_etm_decoder__set_tid(decoder, elem, + trace_chan_id); + break; case OCSD_GEN_TRC_ELEM_EO_TRACE: case OCSD_GEN_TRC_ELEM_ADDR_NACC: case OCSD_GEN_TRC_ELEM_TIMESTAMP: diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h index b2b6c8b5ba95..a61a8f75a135 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -33,8 +33,6 @@ struct cs_etm_packet { int cpu; };
-struct cs_etm_queue; - typedef u32 (*cs_etm_mem_cb_type)(struct cs_etm_queue *, u64, size_t, u8 *);
diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 632237b54b81..91b77353429e 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -658,9 +658,11 @@ static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm, { struct cs_etm_queue *etmq = queue->priv;
- /* CPU-wide tracing isn't supported yet */ - if (queue->tid == -1) - return; + /* queue-tid == -1 is CPU-wide scenario */ + if (queue->tid == -1) { + etmq->tid = machine__get_current_tid(etm->machine, etmq->cpu); + thread__zput(etmq->thread); + }
if ((!etmq->thread) && (etmq->tid != -1)) etmq->thread = machine__find_thread(etm->machine, -1, @@ -673,6 +675,28 @@ static void cs_etm__set_pid_tid_cpu(struct cs_etm_auxtrace *etm, } }
+void cs_etm__etmq_set_tid_cpu(struct cs_etm_queue *etmq, + pid_t tid, int cpu) +{ int err; + struct cs_etm_auxtrace *etm = etmq->etm; + int queue_nr = etmq->queue_nr; + struct auxtrace_queue *queue = &etm->queues.queue_array[queue_nr]; + + err = machine__set_current_tid(etm->machine, cpu, tid, tid); + + /* + * What else can we do here? All valid process should have been + * registed in cs_etm__process_itrace_start() and + * cs_etm__process_cpu_wide(). + */ + if (err) { + pr_err("%s: failed to set tid: %d\n", __func__, tid); + return; + } + + cs_etm__set_pid_tid_cpu(etm, queue); +} + static int cs_etm__synth_instruction_sample(struct cs_etm_queue *etmq, u64 addr, u64 period) { diff --git a/tools/perf/util/cs-etm.h b/tools/perf/util/cs-etm.h index 11fac3116d64..2aa63ee6aae2 100644 --- a/tools/perf/util/cs-etm.h +++ b/tools/perf/util/cs-etm.h @@ -56,6 +56,8 @@ enum { /* RB tree for quick conversion between traceID and CPUs */ struct intlist *traceid_list;
+struct cs_etm_queue; + #define KiB(x) ((x) * 1024) #define MiB(x) ((x) * 1024 * 1024)
@@ -78,6 +80,9 @@ static const u64 __perf_cs_etmv4_magic = 0x4040404040404040ULL; #define CS_ETMV3_PRIV_SIZE (CS_ETM_PRIV_MAX * sizeof(u64)) #define CS_ETMV4_PRIV_SIZE (CS_ETMV4_PRIV_MAX * sizeof(u64))
+void cs_etm__etmq_set_tid_cpu(struct cs_etm_queue *etmq, + pid_t tid, int cpu); + #ifdef HAVE_CSTRACE_SUPPORT int cs_etm__process_auxtrace_info(union perf_event *event, struct perf_session *session);