Skip to content

Commit 4c7bc04

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 5d49c87 commit 4c7bc04

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
@@ -175,6 +175,7 @@ static int setup(struct test_tc_edt *skel)
175175
SYS(fail_close_client_ns, "ip -4 addr add " IP4_ADDR_VETH1 "/24 dev veth1");
176176
SYS(fail_close_client_ns, "ip link set veth1 up");
177177
SYS(fail_close_client_ns, "tc qdisc add dev veth1 root fq");
178+
skel->bss->target_rate = TARGET_RATE_MBPS * 1000 * 1000;
178179
ret = tc_prog_attach("veth1", -1, bpf_program__fd(skel->progs.tc_prog));
179180
if (!ASSERT_OK(ret, "attach bpf prog"))
180181
goto fail_close_client_ns;

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)