DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Morten Brørup" <mb@smartsharesystems.com>
To: Jerin Jacob <jerinj@marvell.com>, Sunil Kumar Kori <skori@marvell.com>
Cc: dev@dpdk.org, "Morten Brørup" <mb@smartsharesystems.com>
Subject: [PATCH v7] eal: add build-time option to omit trace
Date: Sun,  6 Oct 2024 14:03:42 +0000	[thread overview]
Message-ID: <20241006140342.2799985-1-mb@smartsharesystems.com> (raw)
In-Reply-To: <20240918085551.231015-1-mb@smartsharesystems.com>

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 <mb@smartsharesystems.com>
---
v7:
  Updated version.map to not export __rte_trace_feature_is_enabled for
  Windows target.
v6:
  Removed test_trace_perf.c changes; they don't compile for Windows
  target, and are superfluous.
v5:
  Added public function rte_trace_feature_is_enabled(), to test if trace
  is build time enabled in both the DPDK and the application. Use in test
  application instead of private function. (Jerin Jacob)
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 +++
 config/rte_config.h                        |  1 +
 lib/eal/common/eal_common_trace.c          | 10 +++++++
 lib/eal/include/rte_trace.h                | 33 ++++++++++++++++++++++
 lib/eal/include/rte_trace_point.h          | 21 ++++++++++++++
 lib/eal/include/rte_trace_point_register.h |  2 ++
 lib/eal/version.map                        |  3 ++
 7 files changed, 74 insertions(+)

diff --git a/app/test/test_trace.c b/app/test/test_trace.c
index 00809f433b..8ea1443044 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_feature_is_enabled()) {
+		printf("Trace omitted at build-time, skipping test\n");
+		return TEST_SKIPPED;
+	}
 	return unit_test_suite_runner(&trace_tests);
 }
 
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/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index 918f49bf4f..06130c756d 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -100,6 +100,16 @@ rte_trace_is_enabled(void)
 	return rte_atomic_load_explicit(&trace.status, rte_memory_order_acquire) != 0;
 }
 
+bool
+__rte_trace_feature_is_enabled(void)
+{
+#ifdef RTE_TRACE
+	return true;
+#else
+	return false;
+#endif
+}
+
 static void
 trace_mode_set(rte_trace_point_t *t, enum rte_trace_mode mode)
 {
diff --git a/lib/eal/include/rte_trace.h b/lib/eal/include/rte_trace.h
index a6e991fad3..340df4f8a0 100644
--- a/lib/eal/include/rte_trace.h
+++ b/lib/eal/include/rte_trace.h
@@ -35,6 +35,39 @@ extern "C" {
 __rte_experimental
 bool rte_trace_is_enabled(void);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * @internal
+ *
+ * Test if trace feature is enabled at compile time.
+ *
+ * @return
+ *   true if trace feature is enabled, false otherwise.
+ */
+__rte_experimental
+bool __rte_trace_feature_is_enabled(void);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
+ *
+ * Test if trace feature is enabled at compile time.
+ *
+ * @return
+ *   true if trace feature is enabled, false otherwise.
+ */
+static __rte_always_inline
+bool rte_trace_feature_is_enabled(void)
+{
+#ifdef RTE_TRACE
+	return __rte_trace_feature_is_enabled();
+#else
+	return false;
+#endif
+}
+
 /**
  * Enumerate trace mode operation.
  */
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); \
 }
diff --git a/lib/eal/version.map b/lib/eal/version.map
index e3ff412683..6fd3dba85e 100644
--- a/lib/eal/version.map
+++ b/lib/eal/version.map
@@ -396,6 +396,9 @@ EXPERIMENTAL {
 
 	# added in 24.03
 	rte_vfio_get_device_info; # WINDOWS_NO_EXPORT
+
+	# added in 24.11
+	__rte_trace_feature_is_enabled; # WINDOWS_NO_EXPORT
 };
 
 INTERNAL {
-- 
2.43.0


  parent reply	other threads:[~2024-10-06 14:03 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-18  8:55 [PATCH] " Morten Brørup
2024-09-18  9:49 ` Jerin Jacob
2024-09-18 10:23   ` Morten Brørup
2024-09-19  8:06 ` [PATCH v2] " Morten Brørup
2024-09-19  8:51   ` Jerin Jacob
2024-09-19 13:15     ` Morten Brørup
2024-09-19 13:54       ` Jerin Jacob
2024-09-19 15:35         ` Morten Brørup
2024-09-19 15:49           ` Jerin Jacob
2024-09-19 16:08             ` Morten Brørup
2024-09-19 16:34               ` Jerin Jacob
2024-09-20  9:08 ` [PATCH v3] " Morten Brørup
2024-09-23  8:39   ` Jerin Jacob
2024-09-24 13:50     ` Morten Brørup
2024-09-24 13:39 ` [PATCH v4] " Morten Brørup
2024-09-24 15:30   ` Stephen Hemminger
2024-09-24 15:41   ` Jerin Jacob
2024-09-24 15:53     ` Morten Brørup
2024-09-24 15:57       ` Jerin Jacob
2024-10-01 13:49         ` Morten Brørup
2024-10-01 14:05           ` Jerin Jacob
2024-10-01 14:14             ` Morten Brørup
2024-10-01 15:01               ` Jerin Jacob
2024-10-01 16:01                 ` Morten Brørup
2024-10-01 16:06                   ` Jerin Jacob
2024-10-01 16:15                     ` Morten Brørup
2024-10-02 16:17                       ` Jerin Jacob
2024-10-06 12:58                         ` Morten Brørup
2024-10-06 12:38 ` [PATCH v5] " Morten Brørup
2024-10-06 13:58 ` [PATCH v6] " Morten Brørup
2024-10-07  5:45   ` Jerin Jacob
2024-10-07  6:07     ` Morten Brørup
2024-10-06 14:03 ` Morten Brørup [this message]
2024-10-06 14:09   ` [PATCH v7] " Morten Brørup
2024-10-07 11:46 ` [PATCH v9] " Morten Brørup
2024-10-08  7:16   ` Morten Brørup
2024-10-08 10:15   ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241006140342.2799985-1-mb@smartsharesystems.com \
    --to=mb@smartsharesystems.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=skori@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).