Skip to content

Commit 0f38a15

Browse files
TropicaoKernel Patches Daemon
authored andcommitted
selftests/bpf: do not hardcode target rate in test_tc_edt BPF program
test_tc_edt currently defines the target rate in both the userspace and BPF parts. This value could be defined once in the userspace part if we make it able to configure the BPF program before starting the test. Add a target_rate variable in the BPF part, and make the userspace part set it to the desired rate before attaching the shaping program. Signed-off-by: Alexis Lothoré (eBPF Foundation) <[email protected]>
1 parent 740b7ff commit 0f38a15

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

tools/testing/selftests/bpf/prog_tests/test_tc_edt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static int setup(struct test_tc_edt *skel)
6666
ret = tc_prog_attach("veth2", -1, bpf_program__fd(skel->progs.tc_prog));
6767
if (!ASSERT_OK(ret, "attach bpf prog"))
6868
goto fail_close_server_ns;
69+
skel->bss->target_rate = TARGET_RATE_MBPS * 1000 * 1000;
6970
close_netns(nstoken_server);
7071
close_netns(nstoken_client);
7172

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define TIME_HORIZON_NS (2000 * 1000 * 1000)
1515
#define NS_PER_SEC 1000000000
1616
#define ECN_HORIZON_NS 5000000
17-
#define THROTTLE_RATE_BPS (5 * 1000 * 1000)
1817

1918
/* flow_key => last_tstamp timestamp used */
2019
struct {
@@ -24,12 +23,13 @@ struct {
2423
__uint(max_entries, 1);
2524
} flow_map SEC(".maps");
2625

26+
__uint64_t target_rate;
27+
2728
static inline int throttle_flow(struct __sk_buff *skb)
2829
{
2930
int key = 0;
3031
uint64_t *last_tstamp = bpf_map_lookup_elem(&flow_map, &key);
31-
uint64_t delay_ns = ((uint64_t)skb->len) * NS_PER_SEC /
32-
THROTTLE_RATE_BPS;
32+
uint64_t delay_ns = ((uint64_t)skb->len) * NS_PER_SEC / target_rate;
3333
uint64_t now = bpf_ktime_get_ns();
3434
uint64_t tstamp, next_tstamp = 0;
3535

0 commit comments

Comments
 (0)