BPF round-robin scheduler
Subsystems (5)
v6 cover BPF round-robin scheduler
v6:
- set call_me_again flag.
- deponds on: "BPF packet scheduler" series v12.
v5:
- update patch 2, use temporary storage instead.
- update patch 3, use new helpers.
- deponds on: "BPF packet scheduler" series v11.
v4:
- add retrans argment for get_subflow()
v3:
- add last_snd write access.
- keep msk->last_snd setting in get_subflow().
- deponds on: "BPF packet scheduler" series v10.
v2:
- merge the squash-to patch.
- implement bpf_mptcp_get_subflows helper, instead of bpf_mptcp_get_next_subflow.
- deponds on: "BPF packet scheduler v9".
This patchset implements round-robin scheduler using BPF. Address to some commends for the RFC version:
https://patchwork.kernel.org/project/mptcp/cover/[email protected]/
Geliang Tang (3):
mptcp: add bpf get_subflows helper
selftests: bpf: add bpf_rr scheduler
selftests: bpf: add bpf_rr test
net/mptcp/bpf.c | 44 +++++++++++++++ net/mptcp/protocol.h | 7 +++ .../testing/selftests/bpf/bpf_mptcp_helpers.h | 12 ++++ .../testing/selftests/bpf/prog_tests/mptcp.c | 37 +++++++++++++ .../selftests/bpf/progs/mptcp_bpf_rr.c | 55 +++++++++++++++++++ 5 files changed, 155 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
Signature · 1 line
2.34.1
PATCH v6 1/3 mptcp: add bpf get_subflows helper
This patch implements a new helper bpf_mptcp_get_subflows() to get all the subflows of the given mptcp_sock, it returns the number of suflows. Add a new member subflows in struct mptcp_sock as a pointers array of all the subflows.
Register this helper in bpf_mptcp_sched_kfunc_init() to make sure it can be accessed from the BPF context.
--- net/mptcp/bpf.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 7 +++++++ 2 files changed, 51 insertions(+)
net/mptcp/bpf.c +44 -0
@@ -160,6 +160,23 @@ struct bpf_struct_ops bpf_mptcp_sched_ops = { .name = "mptcp_sched_ops", }; +BTF_SET_START (bpf_mptcp_sched_kfunc_ids) +BTF_ID (func ,bpf_mptcp_get_subflows_array ) +BTF_ID (func, bpf_mptcp_put_subflows_array) +BTF_SET_END (bpf_mptcp_sched_kfunc_ids) + +static const struct btf_kfunc_id_set bpf_mptcp_sched_kfunc_set = { + .owner =THIS_MODULE , + .check_set = &bpf_mptcp_sched_kfunc_ids, +}; + +static int __init bpf_mptcp_sched_kfunc_init (void ) +{ +return register_btf_kfunc_id_set (BPF_PROG_TYPE_STRUCT_OPS , + &bpf_mptcp_sched_kfunc_set); +} +late_initcall (bpf_mptcp_sched_kfunc_init); +struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk) {if (sk &&sk_fullsock (sk) && sk->sk_protocol ==IPPROTO_TCP &&sk_is_mptcp (sk))
@@ -168,3 +185,30 @@ struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk)return NULL ; }EXPORT_SYMBOL (bpf_mptcp_sock_from_subflow); + +struct mptcp_subflows_array *bpf_mptcp_get_subflows_array (struct mptcp_sock *msk) +{ +struct mptcp_subflow_context *subflow; +struct mptcp_subflows_array *array; + + array =kzalloc (sizeof (*array),GFP_KERNEL ); +if (!array) +return array; + +mptcp_for_each_subflow (msk, subflow) + array->subflows[array->nr++] = subflow; + +return array; +} +EXPORT_SYMBOL (bpf_mptcp_get_subflows_array); + +void bpf_mptcp_put_subflows_array (struct mptcp_subflows_array *array) +{ +int i; + +for (i =0 ; i <MPTCP_SUBFLOWS_MAX ; i++) + array->subflows[i] =NULL ; + array->nr =0 ; +kfree (array); +} +EXPORT_SYMBOL (bpf_mptcp_put_subflows_array);
net/mptcp/protocol.h +7 -0
@@ -501,6 +501,13 @@ struct mptcp_subflow_context {struct rcu_head rcu; }; +#define MPTCP_SUBFLOWS_MAX 8 + +struct mptcp_subflows_array { +u8 nr; +struct mptcp_subflow_context *subflows[MPTCP_SUBFLOWS_MAX ]; +}; +static inline struct mptcp_subflow_context *mptcp_subflow_ctx (const struct sock *sk) {
Signature · 1 line
2.34.1
PATCH v6 2/3 selftests: bpf: add bpf_rr scheduler
In reply to Geliang TangThis 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.
--- .../testing/selftests/bpf/bpf_mptcp_helpers.h | 12 ++++ .../selftests/bpf/progs/mptcp_bpf_rr.c | 55 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
tools/testing/selftests/bpf/bpf_mptcp_helpers.h +12 -0
@@ -29,4 +29,16 @@ struct mptcp_sock {char ca_name[TCP_CA_NAME_MAX ]; } __attribute__((preserve_access_index)); +struct mptcp_subflow_context { +__u32 token; +struct sock *tcp_sock;/* tcp sk backpointer */ +} __attribute__((preserve_access_index)); + +#define MPTCP_SUBFLOWS_MAX 8 + +struct mptcp_subflows_array { +__u8 nr; +struct mptcp_subflow_context *subflows[MPTCP_SUBFLOWS_MAX ]; +}; +#endif
tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v6 3/3 selftests: bpf: add bpf_rr test
In reply to Geliang TangThis patch adds the round-robin BPF MPTCP scheduler test. Use sysctl to set net.mptcp.scheduler to use this sched. Add a veth net device to simulate the multiple addresses case. Use 'ip mptcp endpoint' command to add this new endpoint to PM netlink.
--- .../testing/selftests/bpf/prog_tests/mptcp.c | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +37 -0
@@ -6,6 +6,7 @@#include "cgroup_helpers.h" #include "network_helpers.h" #include "mptcp_bpf_first.skel.h" +#include "mptcp_bpf_rr.skel.h" #ifndef TCP_CA_NAME_MAX #define TCP_CA_NAME_MAX 16
@@ -362,10 +363,46 @@ static void test_first(void)mptcp_bpf_first__destroy (first_skel); } +static void test_rr (void ) +{ +struct mptcp_bpf_rr *rr_skel; +int server_fd, client_fd; +struct bpf_link *link; + + rr_skel =mptcp_bpf_rr__open_and_load (); +if (CHECK (!rr_skel,"bpf_rr__open_and_load" ,"failed\n" )) +return ; + + link =bpf_map__attach_struct_ops (rr_skel->maps.rr); +if (!ASSERT_OK_PTR (link,"bpf_map__attach_struct_ops" )) { +mptcp_bpf_rr__destroy (rr_skel); +return ; + } + +system ("ip link add veth1 type veth; \ +ip addr add 10.0.1.1/24 dev veth1; \ +ip link set veth1 up" ); +system ("ip mptcp endpoint add 10.0.1.1 subflow" ); +system ("sysctl -q net.mptcp.scheduler=bpf_rr" ); + server_fd =start_mptcp_server (AF_INET ,NULL ,0 ,0 ); + client_fd =connect_to_mptcp_fd (server_fd,0 ); + +send_data (server_fd, client_fd); + +close (client_fd); +close (server_fd); +system ("ip mptcp endpoint flush" ); +system ("ip link del veth1" ); +bpf_link__destroy (link); +mptcp_bpf_rr__destroy (rr_skel); +} +void test_mptcp (void ) {if (test__start_subtest ("base" ))test_base ();if (test__start_subtest ("first" ))test_first (); +if (test__start_subtest ("rr" )) +test_rr (); }
Signature · 1 line
2.34.1