Skip to content

Commit 4cb79b4

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. > $ 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 <[email protected]>
1 parent 7528827 commit 4cb79b4

File tree

10 files changed

+634
-18
lines changed

10 files changed

+634
-18
lines changed

CMakeLists.txt

Lines changed: 12 additions & 2 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,10 @@
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)
55+
# -DENABLE_LTTNG (default, no LTTng tracing support)
5656
# Enable LTTng tracing.
57+
# -DENABLE_USDT (default, no USDT tracing support)
58+
# Enable USDT tracing.
5759

5860
if (${CMAKE_VERSION} VERSION_LESS "3.18.1")
5961
# Centos 7 support
@@ -573,6 +575,14 @@ if (DEFINED ENABLE_LTTNG)
573575
add_definitions(-DLTTNG_ENABLED)
574576
endif()
575577

578+
# User Static-Defined Tracing (USDT) support
579+
if (NOT DEFINED ENABLE_USDT)
580+
set(ENABLE_USDT "OFF" CACHE BOOL "Enable USDT tracing support")
581+
endif()
582+
if (ENABLE_USDT)
583+
add_definitions(-DUSDT_ENABLED)
584+
endif()
585+
576586
#-------------------------
577587
# Apply fixups
578588

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
@@ -2170,7 +2170,7 @@ static void efa_set_common_ctrl_flags(struct efa_io_tx_meta_desc *desc,
21702170
EFA_SET(&desc->ctrl2, EFA_IO_TX_META_DESC_COMP_REQ, 1);
21712171
}
21722172

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

providers/hns/hns_roce_u_hw_v2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ static int parse_cqe_for_cq(struct hns_roce_context *ctx, struct hns_roce_cq *cq
678678
return 0;
679679
}
680680

681-
#ifdef LTTNG_ENABLED
681+
#if defined(LTTNG_ENABLED) || defined(USDT_ENABLED)
682682
static uint8_t read_wc_sl(struct hns_roce_qp *hr_qp,
683683
struct hns_roce_v2_cqe *cqe,
684684
struct ibv_wc *wc)
@@ -687,6 +687,7 @@ static uint8_t read_wc_sl(struct hns_roce_qp *hr_qp,
687687
hr_reg_read(cqe, CQE_S_R) == CQE_FOR_RQ ?
688688
wc->sl : UINT8_MAX;
689689
}
690+
#endif
690691

691692
static uint32_t read_wc_rqpn(struct hns_roce_qp *hr_qp,
692693
struct hns_roce_v2_cqe *cqe,
@@ -750,7 +751,6 @@ static uint8_t get_send_wr_tclass(struct ibv_send_wr *wr,
750751
return qp_type == IBV_QPT_UD ?
751752
to_hr_ah(wr->wr.ud.ah)->av.tclass : UINT8_MAX;
752753
}
753-
#endif
754754

755755
static int hns_roce_poll_one(struct hns_roce_context *ctx,
756756
struct hns_roce_qp **cur_qp, struct hns_roce_cq *cq,

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)