From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 13A80A00C2; Wed, 22 Apr 2020 21:05:09 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C6B6E1D582; Wed, 22 Apr 2020 21:04:33 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id C52D31D44D for ; Wed, 22 Apr 2020 21:04:22 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03MJ1RxG005822; Wed, 22 Apr 2020 12:04:22 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=wLz7nZWRBHwuqemcNf7ZHIUlDtp0KZ2pcZ1mjyhjFPM=; b=LP1SRIA7pOq4SYvpH67IjolAuyWyyk4WULtKwsyRFaGmr0vcw/ssGwYMPu0UH44yRSPe I6PlsMd9iW5E3K7d9ignDj1YV5tExWLExN4liiqzjhQnBixgxiWHs0sG82rpJ/leyELc Uwlp/YGabUjSxI2+1DP7nXcnkP7R5HJHa21pxABBYdq47r5btpsQfVI6myivxbCn5DfY zm10q2MqVBVWn0MChoR9G4JgVJkicZ4XNqS7nfAw4Fvv3lT4uUTZmUYOMNfKYnhH/Rz+ Le+LZrqedRbeJRl8QrKZeugLW+HLR1dw1CBqTPQXIDzDeSE1PVIi5ifr7CFaAoIED0jI Iw== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0b-0016f401.pphosted.com with ESMTP id 30jd013jee-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 22 Apr 2020 12:04:22 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 22 Apr 2020 12:04:19 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 22 Apr 2020 12:04:19 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id AF8643F7053; Wed, 22 Apr 2020 12:04:17 -0700 (PDT) From: To: Jerin Jacob , Sunil Kumar Kori , Bruce Richardson CC: , , , Date: Thu, 23 Apr 2020 00:33:24 +0530 Message-ID: <20200422190349.3768487-8-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200422190349.3768487-1-jerinj@marvell.com> References: <20200419100133.3232316-1-jerinj@marvell.com> <20200422190349.3768487-1-jerinj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676 definitions=2020-04-22_06:2020-04-22, 2020-04-22 signatures=0 Subject: [dpdk-dev] [PATCH v7 07/32] eal/trace: create CTF TDSL metadata in memory X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Jerin Jacob Common trace format(CTF) defines the metadata[1][2] for trace events, This patch creates the metadata for the DPDK events in memory and latter this will be saved to trace directory on rte_trace_save() invocation. [1] https://diamon.org/ctf/#specification [2] https://diamon.org/ctf/#examples Signed-off-by: Jerin Jacob --- lib/librte_eal/common/eal_common_trace.c | 9 +- lib/librte_eal/common/eal_common_trace_ctf.c | 302 +++++++++++++++++++ lib/librte_eal/common/eal_trace.h | 7 + lib/librte_eal/common/meson.build | 1 + lib/librte_eal/freebsd/Makefile | 1 + lib/librte_eal/linux/Makefile | 1 + 6 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 lib/librte_eal/common/eal_common_trace_ctf.c diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c index c02be897a..0d1d071f5 100644 --- a/lib/librte_eal/common/eal_common_trace.c +++ b/lib/librte_eal/common/eal_common_trace.c @@ -55,9 +55,13 @@ eal_trace_init(void) /* Generate UUID ver 4 with total size of events and number of events */ trace_uuid_generate(); + /* Generate CTF TDSL metadata */ + if (trace_metadata_create() < 0) + goto fail; + /* Create trace directory */ if (trace_mkdir()) - goto fail; + goto free_meta; /* Save current epoch timestamp for future use */ if (trace_epoch_time_save() < 0) @@ -67,6 +71,8 @@ eal_trace_init(void) return 0; +free_meta: + trace_metadata_destroy(); fail: trace_err("failed to initialize trace [%s]", rte_strerror(rte_errno)); return -rte_errno; @@ -77,6 +83,7 @@ eal_trace_fini(void) { if (!rte_trace_is_enabled()) return; + trace_metadata_destroy(); } bool diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c b/lib/librte_eal/common/eal_common_trace_ctf.c new file mode 100644 index 000000000..5ad44cc8d --- /dev/null +++ b/lib/librte_eal/common/eal_common_trace_ctf.c @@ -0,0 +1,302 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ + +#include +#include + +#include +#include +#include +#include +#include + +#include "eal_trace.h" + +__rte_format_printf(2, 0) +static int +metadata_printf(char **str, const char *fmt, ...) +{ + va_list ap; + int rc; + + *str = NULL; + va_start(ap, fmt); + rc = vasprintf(str, fmt, ap); + va_end(ap); + + return rc; +} + +static int +meta_copy(char **meta, int *offset, char *str, int rc) +{ + int count = *offset; + char *ptr = *meta; + + if (rc < 0) + return rc; + + ptr = realloc(ptr, count + rc); + if (ptr == NULL) + goto free_str; + + memcpy(RTE_PTR_ADD(ptr, count), str, rc); + count += rc; + free(str); + + *meta = ptr; + *offset = count; + + return rc; + +free_str: + if (str) + free(str); + return -ENOMEM; +} + +static int +meta_data_type_emit(char **meta, int *offset) +{ + char *str = NULL; + int rc; + + rc = metadata_printf(&str, + "/* CTF 1.8 */\n" + "typealias integer {size = 8; base = x;}:= uint8_t;\n" + "typealias integer {size = 16; base = x;} := uint16_t;\n" + "typealias integer {size = 32; base = x;} := uint32_t;\n" + "typealias integer {size = 64; base = x;} := uint64_t;\n" + "typealias integer {size = 8; signed = true;} := int8_t;\n" + "typealias integer {size = 16; signed = true;} := int16_t;\n" + "typealias integer {size = 32; signed = true;} := int32_t;\n" + "typealias integer {size = 64; signed = true;} := int64_t;\n" +#ifdef RTE_ARCH_64 + "typealias integer {size = 64; base = x;} := uintptr_t;\n" +#else + "typealias integer {size = 32; base = x;} := uintptr_t;\n" +#endif +#ifdef RTE_ARCH_64 + "typealias integer {size = 64; base = x;} := long;\n" +#else + "typealias integer {size = 32; base = x;} := long;\n" +#endif + "typealias integer {size = 8; signed = false; encoding = ASCII; } := string_bounded_t;\n\n" + "typealias floating_point {\n" + " exp_dig = 8;\n" + " mant_dig = 24;\n" + "} := float;\n\n" + "typealias floating_point {\n" + " exp_dig = 11;\n" + " mant_dig = 53;\n" + "} := double;\n\n"); + + return meta_copy(meta, offset, str, rc); +} + +static int +is_be(void) +{ +#if RTE_BYTE_ORDER == RTE_BIG_ENDIAN + return 1; +#else + return 0; +#endif +} + +static int +meta_header_emit(char **meta, int *offset) +{ + struct trace *trace = trace_obj_get(); + char uustr[RTE_UUID_STRLEN]; + char *str = NULL; + int rc; + + rte_uuid_unparse(trace->uuid, uustr, RTE_UUID_STRLEN); + rc = metadata_printf(&str, + "trace {\n" + " major = 1;\n" + " minor = 8;\n" + " uuid = \"%s\";\n" + " byte_order = %s;\n" + " packet.header := struct {\n" + " uint32_t magic;\n" + " uint8_t uuid[16];\n" + " };\n" + "};\n\n", uustr, is_be() ? "be" : "le"); + return meta_copy(meta, offset, str, rc); +} + +static int +meta_env_emit(char **meta, int *offset) +{ + char *str = NULL; + int rc; + + rc = metadata_printf(&str, + "env {\n" + " dpdk_version = \"%s\";\n" + " tracer_name = \"dpdk\";\n" + "};\n\n", rte_version()); + return meta_copy(meta, offset, str, rc); +} + +static int +meta_clock_pass1_emit(char **meta, int *offset) +{ + char *str = NULL; + int rc; + + rc = metadata_printf(&str, + "clock {\n" + " name = \"dpdk\";\n" + " freq = "); + return meta_copy(meta, offset, str, rc); +} + +static int +meta_clock_pass2_emit(char **meta, int *offset) +{ + char *str = NULL; + int rc; + + rc = metadata_printf(&str, + "%20"PRIu64";\n" + " offset_s =", 0); + return meta_copy(meta, offset, str, rc); +} + +static int +meta_clock_pass3_emit(char **meta, int *offset) +{ + char *str = NULL; + int rc; + + rc = metadata_printf(&str, + "%20"PRIu64";\n" + " offset =", 0); + return meta_copy(meta, offset, str, rc); +} + +static int +meta_clock_pass4_emit(char **meta, int *offset) +{ + char *str = NULL; + int rc; + + rc = metadata_printf(&str, + "%20"PRIu64";\n};\n\n" + "typealias integer {\n" + " size = 48; align = 1; signed = false;\n" + " map = clock.dpdk.value;\n" + "} := uint48_clock_dpdk_t;\n\n", 0); + + return meta_copy(meta, offset, str, rc); +} + +static int +meta_stream_emit(char **meta, int *offset) +{ + char *str = NULL; + int rc; + + rc = metadata_printf(&str, + "stream {\n" + " packet.context := struct {\n" + " uint32_t cpu_id;\n" + " string_bounded_t name[32];\n" + " };\n" + " event.header := struct {\n" + " uint48_clock_dpdk_t timestamp;\n" + " uint16_t id;\n" + " } align(64);\n" + "};\n\n"); + return meta_copy(meta, offset, str, rc); +} + +static int +meta_event_emit(char **meta, int *offset, struct trace_point *tp) +{ + char *str = NULL; + int rc; + + rc = metadata_printf(&str, + "event {\n" + " id = %d;\n" + " name = \"%s\";\n" + " fields := struct {\n" + " %s\n" + " };\n" + "};\n\n", trace_id_get(tp->handle), tp->name, tp->ctf_field); + return meta_copy(meta, offset, str, rc); +} + +int +trace_metadata_create(void) +{ + struct trace_point_head *tp_list = trace_list_head_get(); + struct trace *trace = trace_obj_get(); + struct trace_point *tp; + int rc, offset = 0; + char *meta = NULL; + + rc = meta_data_type_emit(&meta, &offset); + if (rc < 0) + goto fail; + + rc = meta_header_emit(&meta, &offset); + if (rc < 0) + goto fail; + + rc = meta_env_emit(&meta, &offset); + if (rc < 0) + goto fail; + + rc = meta_clock_pass1_emit(&meta, &offset); + if (rc < 0) + goto fail; + trace->ctf_meta_offset_freq = offset; + + rc = meta_clock_pass2_emit(&meta, &offset); + if (rc < 0) + goto fail; + trace->ctf_meta_offset_freq_off_s = offset; + + rc = meta_clock_pass3_emit(&meta, &offset); + if (rc < 0) + goto fail; + trace->ctf_meta_offset_freq_off = offset; + + rc = meta_clock_pass4_emit(&meta, &offset); + if (rc < 0) + goto fail; + + rc = meta_stream_emit(&meta, &offset); + if (rc < 0) + goto fail; + + STAILQ_FOREACH(tp, tp_list, next) + if (meta_event_emit(&meta, &offset, tp) < 0) + goto fail; + + trace->ctf_meta = meta; + return 0; + +fail: + if (meta) + free(meta); + return -EBADF; +} + +void +trace_metadata_destroy(void) +{ + struct trace *trace = trace_obj_get(); + + if (trace->ctf_meta) { + free(trace->ctf_meta); + trace->ctf_meta = NULL; + } +} + diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h index 493163c1c..8e8d1160e 100644 --- a/lib/librte_eal/common/eal_trace.h +++ b/lib/librte_eal/common/eal_trace.h @@ -43,6 +43,11 @@ struct trace { uint64_t epoch_sec; uint64_t epoch_nsec; uint64_t uptime_ticks; + char *ctf_meta; + uint32_t ctf_meta_offset_freq; + uint32_t ctf_meta_offset_freq_off_s; + uint32_t ctf_meta_offset_freq_off; + uint16_t ctf_fixup_done; rte_spinlock_t lock; }; @@ -64,6 +69,8 @@ struct trace_point_head *trace_list_head_get(void); /* Util functions */ bool trace_has_duplicate_entry(void); void trace_uuid_generate(void); +int trace_metadata_create(void); +void trace_metadata_destroy(void); int trace_mkdir(void); int trace_epoch_time_save(void); diff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build index 3dc320327..d2ac44313 100644 --- a/lib/librte_eal/common/meson.build +++ b/lib/librte_eal/common/meson.build @@ -43,6 +43,7 @@ sources += files( 'eal_common_thread.c', 'eal_common_timer.c', 'eal_common_trace.c', + 'eal_common_trace_ctf.c', 'eal_common_trace_utils.c', 'eal_common_uuid.c', 'hotplug_mp.c', diff --git a/lib/librte_eal/freebsd/Makefile b/lib/librte_eal/freebsd/Makefile index ae59c8c19..539ad44a7 100644 --- a/lib/librte_eal/freebsd/Makefile +++ b/lib/librte_eal/freebsd/Makefile @@ -60,6 +60,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_proc.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_uuid.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_trace.c +SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_trace_ctf.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_trace_utils.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += hotplug_mp.c diff --git a/lib/librte_eal/linux/Makefile b/lib/librte_eal/linux/Makefile index 7992500a9..f00588d6e 100644 --- a/lib/librte_eal/linux/Makefile +++ b/lib/librte_eal/linux/Makefile @@ -67,6 +67,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_proc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_fbarray.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_uuid.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_trace.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_trace_ctf.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_trace_utils.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += rte_malloc.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += hotplug_mp.c -- 2.25.1