Skip to content

Commit 6de4a9c

Browse files
iamkafaiAlexei Starovoitov
authored andcommitted
bpf: tcp: Add bpf_cubic example
This patch adds a bpf_cubic example. Some highlights: 1. CONFIG_HZ .kconfig map is used. 2. In bictcp_update(), calculation is changed to use usec resolution (i.e. USEC_PER_JIFFY) instead of using jiffies. Thus, usecs_to_jiffies() is not used in the bpf_cubic.c. 3. In bitctcp_update() [under tcp_friendliness], the original "while (ca->ack_cnt > delta)" loop is changed to the equivalent "ca->ack_cnt / delta" operation. Signed-off-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200122233658.903774-1-kafai@fb.com
1 parent 0a49c1a commit 6de4a9c

3 files changed

Lines changed: 585 additions & 0 deletions

File tree

‎tools/testing/selftests/bpf/bpf_tcp_helpers.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,28 @@
66
#include <linux/types.h>
77
#include <bpf/bpf_helpers.h>
88
#include <bpf/bpf_core_read.h>
9+
#include "bpf_trace_helpers.h"
10+
11+
#define BPF_STRUCT_OPS(name, args...) \
12+
SEC("struct_ops/"#name) \
13+
BPF_PROG(name, args)
14+
15+
#define tcp_jiffies32 ((__u32)bpf_jiffies64())
916

1017
struct sock_common {
1118
unsigned char skc_state;
1219
} __attribute__((preserve_access_index));
1320

21+
enum sk_pacing {
22+
SK_PACING_NONE = 0,
23+
SK_PACING_NEEDED = 1,
24+
SK_PACING_FQ = 2,
25+
};
26+
1427
struct sock {
1528
struct sock_common __sk_common;
29+
unsigned long sk_pacing_rate;
30+
__u32 sk_pacing_status; /* see enum sk_pacing */
1631
} __attribute__((preserve_access_index));
1732

1833
struct inet_sock {
@@ -54,6 +69,7 @@ struct tcp_sock {
5469
__u32 max_packets_out;
5570
__u32 lsndtime;
5671
__u32 prior_cwnd;
72+
__u64 tcp_mstamp; /* most recent packet received/sent */
5773
} __attribute__((preserve_access_index));
5874

5975
static __always_inline struct inet_connection_sock *inet_csk(const struct sock *sk)

‎tools/testing/selftests/bpf/prog_tests/bpf_tcp_ca.c‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <linux/err.h>
55
#include <test_progs.h>
66
#include "bpf_dctcp.skel.h"
7+
#include "bpf_cubic.skel.h"
78

89
#define min(a, b) ((a) < (b) ? (a) : (b))
910

@@ -158,6 +159,28 @@ static void do_test(const char *tcp_ca)
158159
close(fd);
159160
}
160161

162+
static void test_cubic(void)
163+
{
164+
struct bpf_cubic *cubic_skel;
165+
struct bpf_link *link;
166+
167+
cubic_skel = bpf_cubic__open_and_load();
168+
if (CHECK(!cubic_skel, "bpf_cubic__open_and_load", "failed\n"))
169+
return;
170+
171+
link = bpf_map__attach_struct_ops(cubic_skel->maps.cubic);
172+
if (CHECK(IS_ERR(link), "bpf_map__attach_struct_ops", "err:%ld\n",
173+
PTR_ERR(link))) {
174+
bpf_cubic__destroy(cubic_skel);
175+
return;
176+
}
177+
178+
do_test("bpf_cubic");
179+
180+
bpf_link__destroy(link);
181+
bpf_cubic__destroy(cubic_skel);
182+
}
183+
161184
static void test_dctcp(void)
162185
{
163186
struct bpf_dctcp *dctcp_skel;
@@ -184,4 +207,6 @@ void test_bpf_tcp_ca(void)
184207
{
185208
if (test__start_subtest("dctcp"))
186209
test_dctcp();
210+
if (test__start_subtest("cubic"))
211+
test_cubic();
187212
}

0 commit comments

Comments
 (0)