-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/bpf: Add bpf_rr scheduler & test
This patch implements the round-robin BPF MPTCP scheduler, named bpf_rr, which always picks the next available subflow to send data. If no such next subflow available, picks the first one. Using MPTCP_SCHED_TEST macro to add a new test for this bpf_rr scheduler, the arguments "1 1" means data has been sent on both net devices. Run this test by RUN_MPTCP_TEST macro. Signed-off-by: Geliang Tang <[email protected]> Reviewed-by: Mat Martineau <[email protected]> Reviewed-by: Matthieu Baerts (NGI0) <[email protected]>
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2022, SUSE. */ | ||
|
||
#include "mptcp_bpf.h" | ||
#include <bpf/bpf_tracing.h> | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
struct mptcp_rr_storage { | ||
struct sock *last_snd; | ||
}; | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_SK_STORAGE); | ||
__uint(map_flags, BPF_F_NO_PREALLOC); | ||
__type(key, int); | ||
__type(value, struct mptcp_rr_storage); | ||
} mptcp_rr_map SEC(".maps"); | ||
|
||
SEC("struct_ops") | ||
void BPF_PROG(mptcp_sched_rr_init, struct mptcp_sock *msk) | ||
{ | ||
bpf_sk_storage_get(&mptcp_rr_map, msk, 0, | ||
BPF_LOCAL_STORAGE_GET_F_CREATE); | ||
} | ||
|
||
SEC("struct_ops") | ||
void BPF_PROG(mptcp_sched_rr_release, struct mptcp_sock *msk) | ||
{ | ||
bpf_sk_storage_delete(&mptcp_rr_map, msk); | ||
} | ||
|
||
SEC("struct_ops") | ||
int BPF_PROG(bpf_rr_get_send, struct mptcp_sock *msk, | ||
struct mptcp_sched_data *data) | ||
{ | ||
struct mptcp_subflow_context *subflow; | ||
struct mptcp_rr_storage *ptr; | ||
struct sock *last_snd = NULL; | ||
int nr = 0; | ||
|
||
ptr = bpf_sk_storage_get(&mptcp_rr_map, msk, 0, | ||
BPF_LOCAL_STORAGE_GET_F_CREATE); | ||
if (!ptr) | ||
return -1; | ||
|
||
last_snd = ptr->last_snd; | ||
|
||
for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) { | ||
subflow = bpf_mptcp_subflow_ctx_by_pos(data, i); | ||
if (!last_snd || !subflow) | ||
break; | ||
|
||
if (mptcp_subflow_tcp_sock(subflow) == last_snd) { | ||
if (i + 1 == MPTCP_SUBFLOWS_MAX || | ||
!bpf_mptcp_subflow_ctx_by_pos(data, i + 1)) | ||
break; | ||
|
||
nr = i + 1; | ||
break; | ||
} | ||
} | ||
|
||
subflow = bpf_mptcp_subflow_ctx_by_pos(data, nr); | ||
if (!subflow) | ||
return -1; | ||
mptcp_subflow_set_scheduled(subflow, true); | ||
ptr->last_snd = mptcp_subflow_tcp_sock(subflow); | ||
return 0; | ||
} | ||
|
||
SEC(".struct_ops") | ||
struct mptcp_sched_ops rr = { | ||
.init = (void *)mptcp_sched_rr_init, | ||
.release = (void *)mptcp_sched_rr_release, | ||
.get_send = (void *)bpf_rr_get_send, | ||
.name = "bpf_rr", | ||
}; |