Skip to content

Commit f700b37

Browse files
HoyeonRheeMartin KaFai Lau
authored andcommitted
selftests/bpf: Move common TCP helpers into bpf_tracing_net.h
Some BPF selftests contain identical copies of the min(), max(), before(), and after() helpers. These repeated snippets are the same across the tests and do not need to be defined separately. Move these helpers into bpf_tracing_net.h so they can be shared by TCP related BPF programs. This removes repeated code and keeps the helpers in a single place. Reviewed-by: Amery Hung <[email protected]> Signed-off-by: Hoyeon Lee <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent 7dc211c commit f700b37

File tree

5 files changed

+14
-24
lines changed

5 files changed

+14
-24
lines changed

tools/testing/selftests/bpf/progs/bpf_cc_cubic.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
#define TCP_PACING_CA_RATIO (120)
2323
#define TCP_REORDERING (12)
2424

25-
#define min(a, b) ((a) < (b) ? (a) : (b))
26-
#define max(a, b) ((a) > (b) ? (a) : (b))
27-
#define after(seq2, seq1) before(seq1, seq2)
28-
2925
extern void cubictcp_init(struct sock *sk) __ksym;
3026
extern void cubictcp_cwnd_event(struct sock *sk, enum tcp_ca_event event) __ksym;
3127
extern __u32 cubictcp_recalc_ssthresh(struct sock *sk) __ksym;
@@ -34,11 +30,6 @@ extern __u32 tcp_reno_undo_cwnd(struct sock *sk) __ksym;
3430
extern void cubictcp_acked(struct sock *sk, const struct ack_sample *sample) __ksym;
3531
extern void cubictcp_cong_avoid(struct sock *sk, __u32 ack, __u32 acked) __ksym;
3632

37-
static bool before(__u32 seq1, __u32 seq2)
38-
{
39-
return (__s32)(seq1-seq2) < 0;
40-
}
41-
4233
static __u64 div64_u64(__u64 dividend, __u64 divisor)
4334
{
4435
return dividend / divisor;

tools/testing/selftests/bpf/progs/bpf_cubic.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@
2020
char _license[] SEC("license") = "GPL";
2121

2222
#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
23-
#define min(a, b) ((a) < (b) ? (a) : (b))
24-
#define max(a, b) ((a) > (b) ? (a) : (b))
25-
static bool before(__u32 seq1, __u32 seq2)
26-
{
27-
return (__s32)(seq1-seq2) < 0;
28-
}
29-
#define after(seq2, seq1) before(seq1, seq2)
3023

3124
extern __u32 tcp_slow_start(struct tcp_sock *tp, __u32 acked) __ksym;
3225
extern void tcp_cong_avoid_ai(struct tcp_sock *tp, __u32 w, __u32 acked) __ksym;

tools/testing/selftests/bpf/progs/bpf_dctcp.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,10 @@
1313
#ifndef EBUSY
1414
#define EBUSY 16
1515
#endif
16-
#define min(a, b) ((a) < (b) ? (a) : (b))
17-
#define max(a, b) ((a) > (b) ? (a) : (b))
1816
#define min_not_zero(x, y) ({ \
1917
typeof(x) __x = (x); \
2018
typeof(y) __y = (y); \
2119
__x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
22-
static bool before(__u32 seq1, __u32 seq2)
23-
{
24-
return (__s32)(seq1-seq2) < 0;
25-
}
2620

2721
char _license[] SEC("license") = "GPL";
2822

tools/testing/selftests/bpf/progs/bpf_tracing_net.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@
146146

147147
#define tcp_jiffies32 ((__u32)bpf_jiffies64())
148148

149+
#ifndef min
150+
#define min(a, b) ((a) < (b) ? (a) : (b))
151+
#endif
152+
#ifndef max
153+
#define max(a, b) ((a) > (b) ? (a) : (b))
154+
#endif
155+
156+
static inline bool before(__u32 seq1, __u32 seq2)
157+
{
158+
return (__s32)(seq1 - seq2) < 0;
159+
}
160+
161+
#define after(seq2, seq1) before(seq1, seq2)
162+
149163
static inline struct inet_connection_sock *inet_csk(const struct sock *sk)
150164
{
151165
return (struct inet_connection_sock *)sk;

tools/testing/selftests/bpf/progs/tcp_ca_write_sk_pacing.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ char _license[] SEC("license") = "GPL";
88

99
#define USEC_PER_SEC 1000000UL
1010

11-
#define min(a, b) ((a) < (b) ? (a) : (b))
12-
1311
static unsigned int tcp_left_out(const struct tcp_sock *tp)
1412
{
1513
return tp->sacked_out + tp->lost_out;

0 commit comments

Comments
 (0)