From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2528F459FA; Tue, 24 Sep 2024 15:40:08 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C499A40274; Tue, 24 Sep 2024 15:40:07 +0200 (CEST) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 746C4400D5 for ; Tue, 24 Sep 2024 15:40:06 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id 3DB9120E90; Tue, 24 Sep 2024 15:40:06 +0200 (CEST) Received: from dkrd4.smartsharesys.local ([192.168.4.26]) by smartserver.smartsharesystems.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 24 Sep 2024 15:40:03 +0200 From: =?UTF-8?q?Morten=20Br=C3=B8rup?= To: Jerin Jacob , Sunil Kumar Kori Cc: dev@dpdk.org, =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH v4] eal: add build-time option to omit trace Date: Tue, 24 Sep 2024 13:39:57 +0000 Message-ID: <20240924133957.1505113-1-mb@smartsharesystems.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240918085551.231015-1-mb@smartsharesystems.com> References: <20240918085551.231015-1-mb@smartsharesystems.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-OriginalArrivalTime: 24 Sep 2024 13:40:03.0737 (UTC) FILETIME=[428B7090:01DB0E87] X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Some applications want to omit the trace feature. Either to reduce the memory footprint, to reduce the exposed attack surface, or for other reasons. This patch adds an option in rte_config.h to include or omit trace in the build. Trace is included by default. Omitting trace works by omitting all trace points. For API and ABI compatibility, the trace feature itself remains. Signed-off-by: Morten Brørup --- v4: * Added check for generic trace enabled when registering trace points, in RTE_INIT. (Jerin Jacob) * Test application uses function instead of macro to check if generic trace is enabled. (Jerin Jacob) * Performance test application uses function to check if generic trace is enabled. v3: * Simpler version with much fewer ifdefs. (Jerin Jacob) v2: * Added/modified macros required for building applications with trace omitted. --- app/test/test_trace.c | 4 ++++ app/test/test_trace_perf.c | 5 +++++ config/rte_config.h | 1 + lib/eal/include/rte_trace_point.h | 21 +++++++++++++++++++++ lib/eal/include/rte_trace_point_register.h | 2 ++ 5 files changed, 33 insertions(+) diff --git a/app/test/test_trace.c b/app/test/test_trace.c index 00809f433b..26656fe024 100644 --- a/app/test/test_trace.c +++ b/app/test/test_trace.c @@ -245,6 +245,10 @@ static struct unit_test_suite trace_tests = { static int test_trace(void) { + if (!__rte_trace_point_generic_is_enabled()) { + printf("Trace omitted at build-time, skipping test\n"); + return TEST_SKIPPED; + } return unit_test_suite_runner(&trace_tests); } diff --git a/app/test/test_trace_perf.c b/app/test/test_trace_perf.c index 8257cc02be..504574ef8a 100644 --- a/app/test/test_trace_perf.c +++ b/app/test/test_trace_perf.c @@ -150,6 +150,11 @@ test_trace_perf(void) struct test_data *data; size_t sz; + if (!__rte_trace_point_generic_is_enabled()) { + printf("Trace omitted at build-time, skipping test\n"); + return TEST_SKIPPED; + } + nb_cores = rte_lcore_count(); nb_workers = nb_cores - 1; if (nb_cores < 2) { diff --git a/config/rte_config.h b/config/rte_config.h index dd7bb0d35b..fd6f8a2f1a 100644 --- a/config/rte_config.h +++ b/config/rte_config.h @@ -49,6 +49,7 @@ #define RTE_MAX_TAILQ 32 #define RTE_LOG_DP_LEVEL RTE_LOG_INFO #define RTE_MAX_VFIO_CONTAINERS 64 +#define RTE_TRACE 1 /* bsd module defines */ #define RTE_CONTIGMEM_MAX_NUM_BUFS 64 diff --git a/lib/eal/include/rte_trace_point.h b/lib/eal/include/rte_trace_point.h index 41e2a7f99e..b80688ce89 100644 --- a/lib/eal/include/rte_trace_point.h +++ b/lib/eal/include/rte_trace_point.h @@ -212,6 +212,25 @@ bool rte_trace_point_is_enabled(rte_trace_point_t *tp); __rte_experimental rte_trace_point_t *rte_trace_point_lookup(const char *name); +/** + * @internal + * + * Test if the tracepoint compile-time option is enabled. + * + * @return + * true if tracepoint enabled, false otherwise. + */ +__rte_experimental +static __rte_always_inline bool +__rte_trace_point_generic_is_enabled(void) +{ +#ifdef RTE_TRACE + return true; +#else + return false; +#endif +} + /** * @internal * @@ -359,6 +378,8 @@ __rte_trace_point_emit_ev_header(void *mem, uint64_t in) #define __rte_trace_point_emit_header_generic(t) \ void *mem; \ do { \ + if (!__rte_trace_point_generic_is_enabled()) \ + return; \ const uint64_t val = rte_atomic_load_explicit(t, rte_memory_order_acquire); \ if (likely(!(val & __RTE_TRACE_FIELD_ENABLE_MASK))) \ return; \ diff --git a/lib/eal/include/rte_trace_point_register.h b/lib/eal/include/rte_trace_point_register.h index 41260e5964..429b993fc2 100644 --- a/lib/eal/include/rte_trace_point_register.h +++ b/lib/eal/include/rte_trace_point_register.h @@ -23,6 +23,8 @@ rte_trace_point_t __rte_section("__rte_trace_point") __##trace; \ static const char __##trace##_name[] = RTE_STR(name); \ RTE_INIT(trace##_init) \ { \ + if (!__rte_trace_point_generic_is_enabled()) \ + return; \ __rte_trace_point_register(&__##trace, __##trace##_name, \ (void (*)(void)) trace); \ } -- 2.43.0