Skip to contentSkip to conversation

BPF round-robin scheduler

PATCH Superseded Geliang Tang 1 participant 4 messages Apr 5, 2022

Subsystems (5)

v1 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

cover BPF round-robin scheduler

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]/

deponds on: "BPF packet scheduler v9"

Geliang Tang (3):
mptcp: add get_next_subflow helper
selftests: bpf: add bpf_rr scheduler
selftests: bpf: add bpf_rr test

 net/mptcp/bpf.c                               | 34 +++++++++++++++
 .../testing/selftests/bpf/bpf_mptcp_helpers.h | 27 ++++++++++++
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 31 ++++++++++++++
 .../selftests/bpf/progs/mptcp_bpf_rr.c        | 42 +++++++++++++++++++
 4 files changed, 134 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 mptcp: add get_next_subflow helper

This patch implements a new helper bpf_mptcp_get_next_subflow() to get the next available subflow of msk.

Register this helper in bpf_mptcp_sched_kfunc_init() to make sure it can be invoked from the BPF context.

---
 net/mptcp/bpf.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
net/mptcp/bpf.c +34 -0
index a3c41c079fe4..94671d5e80d1 100644
@@ -114,6 +114,22 @@ 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_next_subflow)
+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))
@@ -122,3 +138,21 @@ struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk)
 	return NULL;
 }
 EXPORT_SYMBOL(bpf_mptcp_sock_from_subflow);
+
+struct mptcp_subflow_context *bpf_mptcp_get_next_subflow(struct mptcp_sock *msk)
+{
+	struct mptcp_subflow_context *subflow, *next;
+
+	next = list_first_entry_or_null(&msk->conn_list, typeof(*subflow), node);
+	mptcp_for_each_subflow(msk, subflow) {
+		if (msk->last_snd && subflow->tcp_sock == msk->last_snd) {
+			if (!list_is_last(&subflow->node, &msk->conn_list)) {
+				next = list_next_entry(subflow, node);
+				break;
+			}
+		}
+	}
+
+	return next;
+}
+EXPORT_SYMBOL(bpf_mptcp_get_next_subflow);
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/3 selftests: bpf: add bpf_rr scheduler

In reply to Geliang Tang

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.

Use the helper bpf_mptcp_get_next_subflow() to get the next available subflow.

---
 .../testing/selftests/bpf/bpf_mptcp_helpers.h | 27 ++++++++++++
 .../selftests/bpf/progs/mptcp_bpf_rr.c        | 42 +++++++++++++++++++
 2 files changed, 69 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
tools/testing/selftests/bpf/bpf_mptcp_helpers.h +27 -0
index 5135eb6710e8..972fd2e56ed4 100644
@@ -26,4 +26,31 @@ struct mptcp_sched_ops {
 	void *owner;
 };
 
+struct mptcp_subflow_context {
+	__u32	token;
+	__u32	request_mptcp : 1,  /* send MP_CAPABLE */
+		request_join : 1,   /* send MP_JOIN */
+		request_bkup : 1,
+		mp_capable : 1,	    /* remote is MPTCP capable */
+		mp_join : 1,	    /* remote is JOINing */
+		fully_established : 1,	    /* path validated */
+		pm_notified : 1,    /* PM hook called for established status */
+		conn_finished : 1,
+		map_valid : 1,
+		map_csum_reqd : 1,
+		map_data_fin : 1,
+		mpc_map : 1,
+		backup : 1,
+		send_mp_prio : 1,
+		send_mp_fail : 1,
+		send_fastclose : 1,
+		send_infinite_map : 1,
+		rx_eof : 1,
+		can_ack : 1,        /* only after processing the remote a key */
+		disposable : 1,	    /* ctx can be free at ulp release time */
+		stale : 1,	    /* unable to snd/rcv data, do not use for xmit */
+		local_id_valid : 1; /* local_id is correctly initialized */
+	struct	sock *tcp_sock;	    /* tcp sk backpointer */
+} __attribute__((preserve_access_index));
+
 #endif
tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/3 selftests: bpf: add bpf_rr test

In reply to Geliang Tang

This patch adds the round-robin BPF MPTCP scheduler test. Use sysctl to set net.mptcp.scheduler to use this sched.

---
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 31 +++++++++++++++++++
 1 file changed, 31 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +31 -0
index 467769e229f5..12287f086238 100644
@@ -5,6 +5,7 @@
 #include "cgroup_helpers.h"
 #include "network_helpers.h"
 #include "mptcp_bpf_first.skel.h"
+#include "mptcp_bpf_rr.skel.h"
 
 #define min(a, b) ((a) < (b) ? (a) : (b))
 
@@ -363,10 +364,40 @@ 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("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);
+	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