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 07584A0562; Sun, 29 Mar 2020 16:45:34 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1E1031C0D4; Sun, 29 Mar 2020 16:43:52 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by dpdk.org (Postfix) with ESMTP id A78C41C0B5 for ; Sun, 29 Mar 2020 16:43:47 +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 02TEeRWq013022; Sun, 29 Mar 2020 07:43:47 -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=qzf/Sm1/YLtz2n4hedGYJHFXdC69AWsTdShrTYVCYoo=; b=BghKDH2d2dXh8TcUpUeJdRlHiSE1ZF+DehW07eDNlKGG9Kf1hjqAiHHo4Pqur+YtJUdz 5Y94ZPwLf6nvag9dFEtHvzek49jsn61B1w4QP4iypATiR9TDJtitCXSM5aSIbJC8QT7/ gtVO3+wXuK5OgdBxTzK+p6EDcq8FwCCRtuLfHaZDRsWSxvHc+Jom+mSij7byEZ4zTl6Z ypklTh/Jig7RXRqFZn9fhDwDqD8NLcyuairaQ0H42ow0f6Z/Y9ahrTWavVZ69luq0qA+ 6yLgucl+WsmDhHlhiyCuIWAU0+Yn885vboY6VS8Zcv9RGWa+pHUKTOSWROwnZlzv0l1r 5g== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 30263kb5gw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Sun, 29 Mar 2020 07:43:47 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sun, 29 Mar 2020 07:43:44 -0700 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sun, 29 Mar 2020 07:43:44 -0700 Received: from jerin-lab.marvell.com (jerin-lab.marvell.com [10.28.34.14]) by maili.marvell.com (Postfix) with ESMTP id ABE583F703F; Sun, 29 Mar 2020 07:43:42 -0700 (PDT) From: To: Thomas Monjalon , Jerin Jacob , Sunil Kumar Kori CC: , , , Date: Sun, 29 Mar 2020 20:13:13 +0530 Message-ID: <20200329144342.1543749-5-jerinj@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200329144342.1543749-1-jerinj@marvell.com> References: <20200325211603.240288-1-jerinj@marvell.com> <20200329144342.1543749-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.645 definitions=2020-03-29_05:2020-03-27, 2020-03-29 signatures=0 Subject: [dpdk-dev] [PATCH v3 04/33] eal/trace: implement trace register API 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 The consumers of trace API defines the tracepoint and registers to eal. Internally these tracepoints will be stored in STAILQ for future use. This patch implements the tracepoint registration function. Signed-off-by: Jerin Jacob --- MAINTAINERS | 1 + lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_trace.c | 107 +++++++++++++++++- lib/librte_eal/common/eal_trace.h | 36 ++++++ lib/librte_eal/common/include/rte_trace.h | 29 +++++ .../common/include/rte_trace_provider.h | 24 ++++ .../common/include/rte_trace_register.h | 20 ++++ lib/librte_eal/common/meson.build | 2 + lib/librte_eal/rte_eal_version.map | 1 + 9 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 lib/librte_eal/common/eal_trace.h create mode 100644 lib/librte_eal/common/include/rte_trace_provider.h create mode 100644 lib/librte_eal/common/include/rte_trace_register.h diff --git a/MAINTAINERS b/MAINTAINERS index 7ce224330..cdaed3f5a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -201,6 +201,7 @@ M: Jerin Jacob M: Sunil Kumar Kori F: lib/librte_eal/common/include/rte_trace*.h F: lib/librte_eal/common/eal_common_trace*.c +F: lib/librte_eal/common/eal_trace.h Memory Allocation M: Anatoly Burakov diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile index 9384d6f6e..8f2f25c1d 100644 --- a/lib/librte_eal/common/Makefile +++ b/lib/librte_eal/common/Makefile @@ -9,7 +9,7 @@ INC += rte_debug.h rte_eal.h rte_eal_interrupts.h INC += rte_errno.h rte_launch.h rte_lcore.h INC += rte_log.h rte_memory.h rte_memzone.h INC += rte_per_lcore.h rte_random.h -INC += rte_trace.h +INC += rte_trace.h rte_trace_provider.h rte_trace_register.h INC += rte_tailq.h rte_interrupts.h rte_alarm.h INC += rte_string_fns.h rte_version.h INC += rte_eal_memconfig.h diff --git a/lib/librte_eal/common/eal_common_trace.c b/lib/librte_eal/common/eal_common_trace.c index e18ba1c95..a8890345b 100644 --- a/lib/librte_eal/common/eal_common_trace.c +++ b/lib/librte_eal/common/eal_common_trace.c @@ -2,5 +2,110 @@ * Copyright(C) 2020 Marvell International Ltd. */ -#include +#include +#include +#include +#include +#include +#include +#include + +#include "eal_trace.h" + +RTE_DEFINE_PER_LCORE(volatile int, trace_point_sz); +RTE_DEFINE_PER_LCORE(char, ctf_field[TRACE_CTF_FIELD_SIZE]); +RTE_DEFINE_PER_LCORE(int, ctf_count); + +static struct trace_point_head tp_list = STAILQ_HEAD_INITIALIZER(tp_list); +static struct trace trace; + +int +__rte_trace_point_register(rte_trace_t *handle, const char *name, + uint32_t level, void (*register_fn)(void)) +{ + char *field = RTE_PER_LCORE(ctf_field); + struct trace_point *tp; + uint16_t sz; + + /* Sanity checks of arguments */ + if (name == NULL || register_fn == NULL || handle == NULL) { + trace_err("invalid arguments"); + rte_errno = EINVAL; goto fail; + } + + /* Sanity check of level */ + if (level > RTE_LOG_DEBUG || level > UINT8_MAX) { + trace_err("invalid log level=%d", level); + rte_errno = EINVAL; goto fail; + + } + + /* Check the size of the trace point object */ + RTE_PER_LCORE(trace_point_sz) = 0; + RTE_PER_LCORE(ctf_count) = 0; + register_fn(); + if (RTE_PER_LCORE(trace_point_sz) == 0) { + trace_err("missing rte_trace_emit_header() in register fn"); + rte_errno = EBADF; goto fail; + } + + /* Is size overflowed */ + if (RTE_PER_LCORE(trace_point_sz) > UINT16_MAX) { + trace_err("trace point size overflowed"); + rte_errno = ENOSPC; goto fail; + } + + /* Are we running out of space to store trace points? */ + if (trace.nb_trace_points > UINT16_MAX) { + trace_err("trace point exceeds the max count"); + rte_errno = ENOSPC; goto fail; + } + + /* Get the size of the trace point */ + sz = RTE_PER_LCORE(trace_point_sz); + tp = calloc(1, sizeof(struct trace_point)); + if (tp == NULL) { + trace_err("fail to allocate trace point memory"); + rte_errno = ENOMEM; goto fail; + } + + /* Initialize the trace point */ + if (rte_strscpy(tp->name, name, TRACE_POINT_NAME_SIZE) < 0) { + trace_err("name is too long"); + rte_errno = E2BIG; + goto free; + } + + /* Copy the field data for future use */ + if (rte_strscpy(tp->ctf_field, field, TRACE_CTF_FIELD_SIZE) < 0) { + trace_err("CTF field size is too long"); + rte_errno = E2BIG; + goto free; + } + + /* Clear field memory for the next event */ + memset(field, 0, TRACE_CTF_FIELD_SIZE); + + /* Form the trace handle */ + *handle = sz; + *handle |= trace.nb_trace_points << __RTE_TRACE_FIELD_ID_SHIFT; + *handle |= (uint64_t)level << __RTE_TRACE_FIELD_LEVEL_SHIFT; + + trace.nb_trace_points++; + tp->handle = handle; + + /* Add the trace point at tail */ + STAILQ_INSERT_TAIL(&tp_list, tp, next); + __atomic_thread_fence(__ATOMIC_RELEASE); + + /* All Good !!! */ + return 0; +free: + free(tp); +fail: + if (trace.register_errno == 0) + trace.register_errno = rte_errno; + + return -rte_errno; +} diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h new file mode 100644 index 000000000..7665bd6be --- /dev/null +++ b/lib/librte_eal/common/eal_trace.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ + +#ifndef __EAL_TRACE_H +#define __EAL_TRACE_H + +#include + +#define trace_err(fmt, args...)\ + RTE_LOG(ERR, EAL, "%s():%u " fmt "\n",\ + __func__, __LINE__, ## args) + +#define trace_crit(fmt, args...)\ + RTE_LOG(CRIT, EAL, "%s():%u " fmt "\n",\ + __func__, __LINE__, ## args) + +#define TRACE_CTF_FIELD_SIZE 384 +#define TRACE_POINT_NAME_SIZE 64 + +struct trace_point { + STAILQ_ENTRY(trace_point) next; + rte_trace_t *handle; + char name[TRACE_POINT_NAME_SIZE]; + char ctf_field[TRACE_CTF_FIELD_SIZE]; +}; + +struct trace { + int register_errno; + uint32_t nb_trace_points; +}; + +/* Trace point list functions */ +STAILQ_HEAD(trace_point_head, trace_point); + +#endif /* __EAL_TRACE_H */ diff --git a/lib/librte_eal/common/include/rte_trace.h b/lib/librte_eal/common/include/rte_trace.h index 459374d86..90b9d5894 100644 --- a/lib/librte_eal/common/include/rte_trace.h +++ b/lib/librte_eal/common/include/rte_trace.h @@ -515,6 +515,35 @@ _tp _args \ #endif /* __DOXYGEN__ */ +/** + * @internal @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Helper function to register a dynamic tracepoint. + * Use RTE_TRACE_POINT_REGISTER() macro for tracepoint registration. + * + * @param trace + * The tracepoint object created using RTE_TRACE_POINT_DEFINE(). + * @param name + * The name of the tracepoint object. + * @param level + * Trace level. A value between RTE_LOG_EMERG (1) and RTE_LOG_DEBUG (8). + * @param register_fn + * Trace registration function. + * @return + * - 0: Successfully registered the tracepoint. + * - <0: Failure to register the tracepoint. + */ +__rte_experimental +int __rte_trace_point_register(rte_trace_t *trace, const char *name, + uint32_t level, void (*register_fn)(void)); + +#ifdef RTE_TRACE_POINT_REGISTER_SELECT +#include +#else +#include +#endif + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/common/include/rte_trace_provider.h b/lib/librte_eal/common/include/rte_trace_provider.h new file mode 100644 index 000000000..b4da87ba1 --- /dev/null +++ b/lib/librte_eal/common/include/rte_trace_provider.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ + +#ifndef _RTE_TRACE_H_ +#error do not include this file directly, use instead +#endif + +#ifndef _RTE_TRACE_PROVIDER_H_ +#define _RTE_TRACE_PROVIDER_H_ + +#define __RTE_TRACE_EVENT_HEADER_ID_SHIFT (48) + +#define __RTE_TRACE_FIELD_ENABLE_MASK (1ULL << 63) +#define __RTE_TRACE_FIELD_ENABLE_DISCARD (1ULL << 62) +#define __RTE_TRACE_FIELD_SIZE_SHIFT 0 +#define __RTE_TRACE_FIELD_SIZE_MASK (0xffffULL << __RTE_TRACE_FIELD_SIZE_SHIFT) +#define __RTE_TRACE_FIELD_ID_SHIFT (16) +#define __RTE_TRACE_FIELD_ID_MASK (0xffffULL << __RTE_TRACE_FIELD_ID_SHIFT) +#define __RTE_TRACE_FIELD_LEVEL_SHIFT (32) +#define __RTE_TRACE_FIELD_LEVEL_MASK (0xffULL << __RTE_TRACE_FIELD_LEVEL_SHIFT) + + +#endif /* _RTE_TRACE_PROVIDER_H_ */ diff --git a/lib/librte_eal/common/include/rte_trace_register.h b/lib/librte_eal/common/include/rte_trace_register.h new file mode 100644 index 000000000..e9940b414 --- /dev/null +++ b/lib/librte_eal/common/include/rte_trace_register.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2020 Marvell International Ltd. + */ + +#ifndef _RTE_TRACE_H_ +#error do not include this file directly, use instead +#endif + +#ifndef _RTE_TRACE_REGISTER_H_ +#define _RTE_TRACE_REGISTER_H_ + +#include + +RTE_DECLARE_PER_LCORE(volatile int, trace_point_sz); + +#define RTE_TRACE_POINT_REGISTER(trace, name, level)\ + __rte_trace_point_register(&__##trace, RTE_STR(name),\ + RTE_LOG_ ## level, (void (*)(void)) trace) + +#endif /* _RTE_TRACE_REGISTER_H_ */ diff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build index 30fb9b85f..88c14ebe5 100644 --- a/lib/librte_eal/common/meson.build +++ b/lib/librte_eal/common/meson.build @@ -86,6 +86,8 @@ common_headers = files( 'include/rte_string_fns.h', 'include/rte_tailq.h', 'include/rte_trace.h', + 'include/rte_trace_provider.h', + 'include/rte_trace_register.h', 'include/rte_time.h', 'include/rte_uuid.h', 'include/rte_version.h', diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 71098581f..3a1be3e3f 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -339,4 +339,5 @@ EXPERIMENTAL { # added in 20.05 rte_log_can_log; rte_thread_getname; + __rte_trace_point_register; }; -- 2.25.1