Skip to content

Commit d4dd187

Browse files
committed
providers: add support for USDT tracing using libbpf/usdt
Provide lightweight USDT tracing as an alternative to LTTng. This piggybacks on the existing tracing code added for LTTng for a minimal set of changes. The cmake build configuration is updated to allow either one of -DTRACING=LTTNG or -DTRACING=USDT for this functionality (by default tracing is disabled, as before). > $ sudo bpftrace -l usdt:build/lib/lib*.so:* > usdt:build/lib/libefa-rdmav59.so:rdma_core_efa:post_recv > usdt:build/lib/libefa-rdmav59.so:rdma_core_efa:post_send > usdt:build/lib/libefa-rdmav59.so:rdma_core_efa:process_completion > usdt:build/lib/libefa.so:rdma_core_efa:post_recv > usdt:build/lib/libefa.so:rdma_core_efa:post_send > usdt:build/lib/libefa.so:rdma_core_efa:process_completion > usdt:build/lib/libhns-rdmav59.so:rdma_core_hns:poll_cq > usdt:build/lib/libhns-rdmav59.so:rdma_core_hns:post_recv > usdt:build/lib/libhns-rdmav59.so:rdma_core_hns:post_send > usdt:build/lib/libhns.so:rdma_core_hns:poll_cq > usdt:build/lib/libhns.so:rdma_core_hns:post_recv > usdt:build/lib/libhns.so:rdma_core_hns:post_send > usdt:build/lib/libmlx5-rdmav59.so:rdma_core_mlx5:post_send > usdt:build/lib/libmlx5.so:rdma_core_mlx5:post_send > usdt:build/lib/librxe-rdmav59.so:rdma_core_rxe:post_send The USDT header used here is from the libbpf/usdt project at https://github.com/libbpf/usdt.git Further background discussion for this commit is included in linux-rdma#1621 Signed-off-by: Nathan Scott <nathans@redhat.com>
1 parent 6e9643e commit d4dd187

File tree

10 files changed

+634
-20
lines changed

10 files changed

+634
-20
lines changed

CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# Use the historical search path for providers, in the standard system library.
2525
# -DNO_COMPAT_SYMS=1 (default disabled)
2626
# Do not generate backwards compatibility symbols in the shared
27-
# libraries. This may is necessary if using a dynmic linker that does
27+
# libraries. This may be necessary if using a dynamic linker that does
2828
# not support symbol versions, such as uclibc.
2929
# -DIOCTL_MODE=write (default both)
3030
# Disable new kABI ioctl() support and support only the legacy write
@@ -52,8 +52,9 @@
5252
# Disable man pages. Allows rdma-core to be built and installed
5353
# (without man pages) when neither pandoc/rst2man nor the pandoc-prebuilt
5454
# directory are available.
55-
# -DENABLE_LTTNG (default, no tracing support)
56-
# Enable LTTng tracing.
55+
# -DTRACING=LTTNG/USDT/None (default None)
56+
# Enable LTTng (Linux Trace Toolkit) or USDT (Userspace Statically Defined)
57+
# trace points for dynamic tracing.
5758

5859
if (${CMAKE_VERSION} VERSION_LESS "3.18.1")
5960
# Centos 7 support
@@ -171,6 +172,9 @@ endif()
171172
set(DISTRO_FLAVOUR "None" CACHE
172173
STRING "Flavour of distribution to install for. This primarily impacts the init.d scripts installed.")
173174

175+
set(TRACING "None" CACHE
176+
STRING "Enable LTTNG (Linux Trace Toolkit) or USDT (Userspace Statically Defined Tracing).")
177+
174178
#-------------------------
175179
# Load CMake components
176180
set(BUILDLIB "${PROJECT_SOURCE_DIR}/buildlib")
@@ -567,10 +571,14 @@ if (DRM_INCLUDE_DIRS)
567571
endif()
568572
endif()
569573

570-
# LTTng Tracer support
571-
if (DEFINED ENABLE_LTTNG)
574+
# Dynamic Tracing support
575+
if (TRACING STREQUAL "LTTNG")
572576
include(FindLTTngUST REQUIRED)
573577
add_definitions(-DLTTNG_ENABLED)
578+
elseif (TRACING STREQUAL "USDT")
579+
add_definitions(-DUSDT_ENABLED)
580+
elseif (NOT TRACING STREQUAL "None")
581+
message(FATAL_ERROR "-DTRACING=${TRACING} is not a valid choice")
574582
endif()
575583

576584
#-------------------------

Documentation/contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ that are designed to weed out bugs.
6666
Serious errors will result in a red X in the PR and will need to be corrected.
6767
Less serious errors, including checkpatch related, will show up with a green
6868
check but it is necessary to check the details to see that everything is
69-
appropriate. checkpatch is an informative too, not all of its feedback is
69+
appropriate. checkpatch is an informative tool, not all of its feedback is
7070
appropriate to fix.
7171

7272
A build similar to AZP can be run locally using docker and the

providers/efa/efa_trace.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* Copyright 2023-2025 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

6-
#if defined(LTTNG_ENABLED)
6+
#if defined(LTTNG_ENABLED) && defined(USDT_ENABLED)
7+
8+
#error "Only one of LTTNG_ENABLED and USDT_ENABLED allowed"
9+
10+
#elif defined(LTTNG_ENABLED)
711

812
#undef LTTNG_UST_TRACEPOINT_PROVIDER
913
#define LTTNG_UST_TRACEPOINT_PROVIDER rdma_core_efa
@@ -109,7 +113,18 @@ LTTNG_UST_TRACEPOINT_EVENT(
109113

110114
#include <lttng/tracepoint-event.h>
111115

112-
#else
116+
#elif defined (USDT_ENABLED)
117+
118+
#ifndef __EFA_TRACE_H__
119+
#define __EFA_TRACE_H__
120+
121+
#include <util/usdt.h>
122+
123+
#define rdma_tracepoint(arg...) USDT(arg)
124+
125+
#endif /* __EFA_TRACE_H__*/
126+
127+
#else /* !defined(LTTNG_ENABLED) && !defined(USDT_ENABLED) */
113128

114129
#ifndef __EFA_TRACE_H__
115130
#define __EFA_TRACE_H__
@@ -118,4 +133,4 @@ LTTNG_UST_TRACEPOINT_EVENT(
118133

119134
#endif /* __EFA_TRACE_H__*/
120135

121-
#endif /* defined(LTTNG_ENABLED) */
136+
#endif /* defined(LTTNG_ENABLED) || defined(USDT_ENABLED) */

providers/efa/verbs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,7 @@ static void efa_set_common_ctrl_flags(struct efa_io_tx_meta_desc *desc,
21712171
EFA_SET(&desc->ctrl2, EFA_IO_TX_META_DESC_COMP_REQ, 1);
21722172
}
21732173

2174-
#ifdef LTTNG_ENABLED
2174+
#if defined(LTTNG_ENABLED) || defined(USDT_ENABLED)
21752175
static uint32_t efa_get_wqe_length(struct efa_io_tx_wqe *tx_wqe)
21762176
{
21772177
enum efa_io_send_op_type op_type;

providers/hns/hns_roce_u_hw_v2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ static int parse_cqe_for_cq(struct hns_roce_context *ctx, struct hns_roce_cq *cq
683683
return 0;
684684
}
685685

686-
#ifdef LTTNG_ENABLED
686+
#if defined(LTTNG_ENABLED) || defined(USDT_ENABLED)
687687
static uint8_t read_wc_sl(struct hns_roce_qp *hr_qp,
688688
struct hns_roce_v2_cqe *cqe,
689689
struct ibv_wc *wc)

providers/hns/hns_roce_u_trace.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* Copyright (c) 2025 Hisilicon Limited.
44
*/
55

6-
#if defined(LTTNG_ENABLED)
6+
#if defined(LTTNG_ENABLED) && defined(USDT_ENABLED)
7+
8+
#error "Only one of LTTNG_ENABLED and USDT_ENABLED allowed"
9+
10+
#elif defined(LTTNG_ENABLED)
711

812
#undef LTTNG_UST_TRACEPOINT_PROVIDER
913
#define LTTNG_UST_TRACEPOINT_PROVIDER rdma_core_hns
@@ -121,7 +125,18 @@ LTTNG_UST_TRACEPOINT_EVENT(
121125

122126
#include <lttng/tracepoint-event.h>
123127

124-
#else
128+
#elif defined(USDT_ENABLED)
129+
130+
#ifndef __HNS_TRACE_H__
131+
#define __HNS_TRACE_H__
132+
133+
#include <util/usdt.h>
134+
135+
#define rdma_tracepoint(arg...) USDT(arg)
136+
137+
#endif /* __HNS_TRACE_H__*/
138+
139+
#else /* !defined(LTTNG_ENABLED) && !defined(USDT_ENABLED) */
125140

126141
#ifndef __HNS_TRACE_H__
127142
#define __HNS_TRACE_H__
@@ -130,4 +145,4 @@ LTTNG_UST_TRACEPOINT_EVENT(
130145

131146
#endif /* __HNS_TRACE_H__*/
132147

133-
#endif /* defined(LTTNG_ENABLED) */
148+
#endif /* defined(LTTNG_ENABLED) || defined(USDT_ENABLED) */

providers/mlx5/mlx5_trace.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* Copyright 2023 Bytedance.com, Inc. or its affiliates. All rights reserved.
44
*/
55

6-
#if defined(LTTNG_ENABLED)
6+
#if defined(LTTNG_ENABLED) && defined(USDT_ENABLED)
7+
8+
#error "Only one of LTTNG_ENABLED and USDT_ENABLED allowed"
9+
10+
#elif defined(LTTNG_ENABLED)
711

812
#undef LTTNG_UST_TRACEPOINT_PROVIDER
913
#define LTTNG_UST_TRACEPOINT_PROVIDER rdma_core_mlx5
@@ -47,7 +51,18 @@ LTTNG_UST_TRACEPOINT_EVENT(
4751

4852
#include <lttng/tracepoint-event.h>
4953

50-
#else
54+
#elif defined(USDT_ENABLED)
55+
56+
#ifndef __MLX5_TRACE_H__
57+
#define __MLX5_TRACE_H__
58+
59+
#include <util/usdt.h>
60+
61+
#define rdma_tracepoint(arg...) USDT(arg)
62+
63+
#endif /* __MLX5_TRACE_H__*/
64+
65+
#else /* !defined(LTTNG_ENABLED) && !defined(USDT_ENABLED) */
5166

5267
#ifndef __MLX5_TRACE_H__
5368
#define __MLX5_TRACE_H__
@@ -56,4 +71,4 @@ LTTNG_UST_TRACEPOINT_EVENT(
5671

5772
#endif /* __MLX5_TRACE_H__*/
5873

59-
#endif /* defined(LTTNG_ENABLED) */
74+
#endif /* defined(LTTNG_ENABLED) || defined(USDT_ENABLED) */

providers/rxe/rxe_trace.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* Copyright 2023 Bytedance.com, Inc. or its affiliates. All rights reserved.
44
*/
55

6-
#if defined(LTTNG_ENABLED)
6+
#if defined(LTTNG_ENABLED) && defined(USDT_ENABLED)
7+
8+
#error "Only one of LTTNG_ENABLED and USDT_ENABLED allowed"
9+
10+
#elif defined(LTTNG_ENABLED)
711

812
#undef LTTNG_UST_TRACEPOINT_PROVIDER
913
#define LTTNG_UST_TRACEPOINT_PROVIDER rdma_core_rxe
@@ -47,7 +51,18 @@ LTTNG_UST_TRACEPOINT_EVENT(
4751

4852
#include <lttng/tracepoint-event.h>
4953

50-
#else
54+
#elif defined(USDT_ENABLED)
55+
56+
#ifndef __RXE_TRACE_H__
57+
#define __RXE_TRACE_H__
58+
59+
#include <util/usdt.h>
60+
61+
#define rdma_tracepoint(arg...) USDT(arg)
62+
63+
#endif /* __RXE_TRACE_H__*/
64+
65+
#else /* !defined(LTTNG_ENABLED) && !defined(USDT_ENABLED) */
5166

5267
#ifndef __RXE_TRACE_H__
5368
#define __RXE_TRACE_H__
@@ -56,4 +71,4 @@ LTTNG_UST_TRACEPOINT_EVENT(
5671

5772
#endif /* __RXE_TRACE_H__*/
5873

59-
#endif /* defined(LTTNG_ENABLED) */
74+
#endif /* defined(LTTNG_ENABLED) || defined(USDT_ENABLED) */

util/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ publish_internal_headers(util
66
node_name_map.h
77
rdma_nl.h
88
symver.h
9+
usdt.h
910
util.h
1011
)
1112

0 commit comments

Comments
 (0)