Skip to content

Commit e7bc451

Browse files
MortenBroerupdavid-marchand
authored andcommitted
trace: disable traces at compilation
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. Furthermore, a public function to determine if trace is build time enabled is added; mainly for the benefit of the unit tests. Signed-off-by: Morten Brørup <[email protected]> Acked-by: Stephen Hemminger <[email protected]> Acked-by: Jerin Jacob <[email protected]>
1 parent dbdf3d5 commit e7bc451

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

app/test/test_trace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ static struct unit_test_suite trace_tests = {
245245
static int
246246
test_trace(void)
247247
{
248+
if (!rte_trace_feature_is_enabled()) {
249+
printf("Trace omitted at build-time, skipping test\n");
250+
return TEST_SKIPPED;
251+
}
248252
return unit_test_suite_runner(&trace_tests);
249253
}
250254

config/rte_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#define RTE_MAX_TAILQ 32
5050
#define RTE_LOG_DP_LEVEL RTE_LOG_INFO
5151
#define RTE_MAX_VFIO_CONTAINERS 64
52+
#define RTE_TRACE 1
5253

5354
/* bsd module defines */
5455
#define RTE_CONTIGMEM_MAX_NUM_BUFS 64

lib/eal/include/rte_trace.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ extern "C" {
3535
__rte_experimental
3636
bool rte_trace_is_enabled(void);
3737

38+
/**
39+
* @warning
40+
* @b EXPERIMENTAL: this API may change, or be removed, without prior notice
41+
*
42+
* Test if trace feature is enabled at compile time.
43+
*
44+
* @return
45+
* true if trace feature is enabled, false otherwise.
46+
*/
47+
__rte_experimental
48+
static __rte_always_inline bool
49+
rte_trace_feature_is_enabled(void)
50+
{
51+
#ifdef RTE_TRACE
52+
return true;
53+
#else
54+
return false;
55+
#endif
56+
}
57+
3858
/**
3959
* Enumerate trace mode operation.
4060
*/

lib/eal/include/rte_trace_point.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern "C" {
3030
#include <rte_per_lcore.h>
3131
#include <rte_stdatomic.h>
3232
#include <rte_string_fns.h>
33+
#include <rte_trace.h>
3334
#include <rte_uuid.h>
3435

3536
/** The tracepoint object. */
@@ -359,6 +360,8 @@ __rte_trace_point_emit_ev_header(void *mem, uint64_t in)
359360
#define __rte_trace_point_emit_header_generic(t) \
360361
void *mem; \
361362
do { \
363+
if (!rte_trace_feature_is_enabled()) \
364+
return; \
362365
const uint64_t val = rte_atomic_load_explicit(t, rte_memory_order_acquire); \
363366
if (likely(!(val & __RTE_TRACE_FIELD_ENABLE_MASK))) \
364367
return; \

lib/eal/include/rte_trace_point_register.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ rte_trace_point_t __rte_section("__rte_trace_point") __##trace; \
2323
static const char __##trace##_name[] = RTE_STR(name); \
2424
RTE_INIT(trace##_init) \
2525
{ \
26+
if (!rte_trace_feature_is_enabled()) \
27+
return; \
2628
__rte_trace_point_register(&__##trace, __##trace##_name, \
2729
(void (*)(void)) trace); \
2830
}

0 commit comments

Comments
 (0)