The decoder library can be configured to do full trace decoding or just parse the compressed trace stream to generate string representation of the individual trace packets that can be printed.
This patch adds code to the decoder library interface that generates basic configuration for ETMv4 trace decoding and configures the trace decoder library to perform basic packet printing for ETMv4, using a callback function registered from the coresight ETM code.
Signed-off-by: Tor Jeremiassen tor@ti.com --- tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 106 ++++++++++++++++++++++++ tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 5 ++ 2 files changed, 111 insertions(+)
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 b5ee127..6850afb 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -103,3 +103,109 @@ cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder, decoder->state.err = ret; return &decoder->state; } + +static void cs_etm_decoder__gen_etmv4_config(struct cs_etm_trace_params *params, + ocsd_etmv4_cfg *config) +{ + config->reg_configr = params->reg_configr; + config->reg_traceidr = params->reg_traceidr; + config->reg_idr0 = params->reg_idr0; + config->reg_idr1 = params->reg_idr1; + config->reg_idr2 = params->reg_idr2; + config->reg_idr8 = params->reg_idr8; + config->reg_idr9 = 0; + config->reg_idr10 = 0; + config->reg_idr11 = 0; + config->reg_idr12 = 0; + config->reg_idr13 = 0; + config->arch_ver = ARCH_V8; + config->core_prof = profile_CortexA; +} + +static ocsd_datapath_resp_t +cs_etm_decoder__etmv4i_packet_printer(const void *context, + const ocsd_datapath_op_t op, + const ocsd_trc_index_t indx, + const ocsd_etmv4_i_pkt *pkt) +{ + const size_t PACKET_STR_LEN = 1024; + ocsd_datapath_resp_t ret = OCSD_RESP_CONT; + char packet_str[PACKET_STR_LEN]; + size_t offset; + struct cs_etm_decoder *decoder = (struct cs_etm_decoder *) context; + + sprintf(packet_str, "%ld: ", (long int) indx); + offset = strlen(packet_str); + + switch (op) { + case OCSD_OP_DATA: + if (ocsd_pkt_str(OCSD_PROTOCOL_ETMV4I, + (void *)pkt, packet_str + offset, + PACKET_STR_LEN - offset) != OCSD_OK) + ret = OCSD_RESP_FATAL_INVALID_PARAM; + break; + case OCSD_OP_EOT: + sprintf(packet_str, "**** END OF TRACE ****\n"); + break; + case OCSD_OP_FLUSH: + case OCSD_OP_RESET: + default: + break; + } + + decoder->packet_printer(packet_str); + + return ret; +} + +static int cs_etm_decoder__create_etmv4i_packet_printer( + struct cs_etm_decoder_params *d_params, + struct cs_etm_trace_params *t_params, + struct cs_etm_decoder *decoder) +{ + ocsd_etmv4_cfg trace_config; + int ret = 0; + unsigned char CSID; /* CSID extracted from the config data */ + + if (!d_params->packet_printer) + return -CS_ETM_ERR_PARAM; + + cs_etm_decoder__gen_etmv4_config(t_params, &trace_config); + + decoder->packet_printer = d_params->packet_printer; + + ret = ocsd_dt_create_decoder(decoder->dcd_tree, + OCSD_BUILTIN_DCD_ETMV4I, + OCSD_CREATE_FLG_PACKET_PROC, + (void *)&trace_config, &CSID); + + if (ret != 0) + return -CS_ETM_ERR_DECODER; + + ret = ocsd_dt_attach_packet_callback(decoder->dcd_tree, + CSID, OCSD_C_API_CB_PKT_SINK, + cs_etm_decoder__etmv4i_packet_printer, + decoder); + + if (ret != 0) + return -CS_ETM_ERR_DECODER; + + return 0; +} + +int +cs_etm_decoder__create_etmv4i_decoder(struct cs_etm_decoder_params *d_params, + struct cs_etm_trace_params *t_params, + struct cs_etm_decoder *decoder) +{ + int ret; + + if (d_params->operation == CS_ETM_OPERATION_PRINT) + ret = cs_etm_decoder__create_etmv4i_packet_printer(d_params, + t_params, + decoder); + else + ret = -CS_ETM_ERR_PARAM; + + return ret; +} 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 9420f0f..88aa2b4 100644 --- a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -109,4 +109,9 @@ const struct cs_etm_state * cs_etm_decoder__process_data_block(struct cs_etm_decoder *decoder, uint64_t indx, const uint8_t *buf, size_t len, size_t *consumed); + +int +cs_etm_decoder__create_etmv4i_decoder(struct cs_etm_decoder_params *d_params, + struct cs_etm_trace_params *t_params, + struct cs_etm_decoder *decoder); #endif /* INCLUDE__CS_ETM_DECODER_H__ */