The actual decode of the binary trace is performed by a separate open source library that is linked in when enabled in the build process. The code that interacts with the decoder library is factored out into the cs-etm-decoder subdirectory, and has it's own api that is called from the auxtrace handling performed in cs-etm.c
This patch defines the initial basic data structures for the library interface.
Signed-off-by: Tor Jeremiassen tor@ti.com --- tools/perf/Makefile.config | 21 +++++ tools/perf/util/Build | 1 + tools/perf/util/cs-etm-decoder/Build | 2 + tools/perf/util/cs-etm-decoder/cs-etm-decoder.c | 45 ++++++++++ tools/perf/util/cs-etm-decoder/cs-etm-decoder.h | 107 ++++++++++++++++++++++++ 5 files changed, 176 insertions(+) create mode 100644 tools/perf/util/cs-etm-decoder/Build create mode 100644 tools/perf/util/cs-etm-decoder/cs-etm-decoder.c create mode 100644 tools/perf/util/cs-etm-decoder/cs-etm-decoder.h
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index d2c3f47..397ffbd 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -332,6 +332,27 @@ endif
ifdef CSTRACE_PATH CFLAGS-$(CONFIG_AUXTRACE) += -DHAVE_CSTRACE_SUPPORT + ifeq (${IS_64_BIT}, 1) + CSTRACE_LNX = linux64 + ifeq (${ARCH}, arm64) + CSTRACE_LNX = linux-arm64 + endif + else + CSTRACE_LNX = linux + ifeq (${ARCH}, arm) + CSTRACE_LNX = linux-arm + endif + endif + ifeq (${DEBUG}, 1) + LIBCSTRACE = -lcstraced_c_api -lcstraced + CSTRACE_LIB_PATH = $(CSTRACE_PATH)/lib/$(CSTRACE_LNX)/dbg + else + LIBCSTRACE = -lcstraced_c_api -lcstraced + CSTRACE_LIB_PATH = $(CSTRACE_PATH)/lib/$(CSTRACE_LNX)/rel + endif + $(call detected,CSTRACE) + $(call detected_var,CSTRACE_PATH) + EXTLIBS += -L$(CSTRACE_LIB_PATH) $(LIBCSTRACE) -lstdc++ endif
diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 2377b9b..1b39769 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -85,6 +85,7 @@ libperf-$(CONFIG_AUXTRACE) += intel-bts.o
ifdef HAVE_CSTRACE_SUPPORT libperf-$(CONFIG_AUXTRACE) += cs-etm.o +libperf-$(CONFIG_AUXTRACE) += cs-etm-decoder/ endif
libperf-y += parse-branch-options.o diff --git a/tools/perf/util/cs-etm-decoder/Build b/tools/perf/util/cs-etm-decoder/Build new file mode 100644 index 0000000..d926514 --- /dev/null +++ b/tools/perf/util/cs-etm-decoder/Build @@ -0,0 +1,2 @@ +CFLAGS_cs-etm-decoder.o += -I$(CSTRACE_PATH)/include +libperf-$(CONFIG_AUXTRACE) += cs-etm-decoder.o diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c new file mode 100644 index 0000000..ee213a1 --- /dev/null +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.c @@ -0,0 +1,45 @@ +/* + * Copyright(C) 2015-2017 Linaro Limited. All rights reserved. + * Author: Tor Jeremiassen tor@ti.com + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU GEneral Public License along + * with this program. If not, see http://www.gnu.org/licenses/. + */ + +#include <linux/err.h> +#include <stdlib.h> + +#include "cs-etm.h" +#include "cs-etm-decoder.h" +#include "c_api/opencsd_c_api.h" +#include "etmv4/trc_pkt_types_etmv4.h" +#include "ocsd_if_types.h" +#include "util.h" + + +#define MAX_BUFFER 1024 + +struct cs_etm_decoder { + struct cs_etm_state state; + dcd_tree_handle_t dcd_tree; + void (*packet_printer)(const char *); + cs_etm_mem_cb_type mem_access; + ocsd_datapath_resp_t prev_return; + size_t prev_processed; + bool trace_on; + bool discontinuity; + struct cs_etm_packet packet_buffer[MAX_BUFFER]; + uint32_t packet_count; + uint32_t head; + uint32_t tail; + uint32_t end_tail; +}; diff --git a/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h new file mode 100644 index 0000000..ff4a2c6 --- /dev/null +++ b/tools/perf/util/cs-etm-decoder/cs-etm-decoder.h @@ -0,0 +1,107 @@ +/* + * Copyright(C) 2015-2017 Linaro Limited. All rights reserved. + * Author: Tor Jeremiassen tor@ti.com + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU GEneral Public License along + * with this program. If not, see http://www.gnu.org/licenses/. + */ + +#ifndef INCLUDE__CS_ETM_DECODER_H__ +#define INCLUDE__CS_ETM_DECODER_H__ + +#include <linux/types.h> +#include <stdio.h> + +struct cs_etm_decoder; + +struct cs_etm_buffer { + const unsigned char *buf; + size_t len; + uint64_t offset; + uint64_t ref_timestamp; +}; + +enum cs_etm_sample_type { + CS_ETM_RANGE = 1 << 0, +}; + +struct cs_etm_state { + int err; + void *data; + unsigned int isa; + uint64_t start; + uint64_t end; + uint64_t timestamp; +}; + +struct cs_etm_packet { + enum cs_etm_sample_type sample_type; + uint64_t start_addr; + uint64_t end_addr; + bool exc; + bool exc_ret; + int cpu; +}; + +struct cs_etm_queue; + +typedef uint32_t (*cs_etm_mem_cb_type)(struct cs_etm_queue *, uint64_t, + size_t, uint8_t *); + +struct cs_etm_trace_params { + void *etmv4i_packet_handler; + uint32_t reg_idr0; + uint32_t reg_idr1; + uint32_t reg_idr2; + uint32_t reg_idr8; + uint32_t reg_configr; + uint32_t reg_traceidr; + int protocol; +}; + +struct cs_etm_decoder_params { + int operation; + void (*packet_printer)(const char *); + cs_etm_mem_cb_type mem_acc_cb; + bool formatted; + bool fsyncs; + bool hsyncs; + bool frame_aligned; + void *data; +}; + + +/* Error return codes */ +enum { + CS_ETM_ERR_NOMEM = 1, + CS_ETM_ERR_NODATA, + CS_ETM_ERR_PARAM, + CS_ETM_ERR_OVERFLOW, + CS_ETM_ERR_DECODER, +}; + +/* + * The following enums are indexed starting with 1 to align with the + * open source coresight trace decoder library. + */ + +enum { + CS_ETM_PROTO_ETMV3 = 1, + CS_ETM_PROTO_ETMV4i, + CS_ETM_PROTO_ETMV4d, +}; + +enum { + CS_ETM_OPERATION_PRINT = 1, + CS_ETM_OPERATION_DECODE, +}; +#endif /* INCLUDE__CS_ETM_DECODER_H__ */