Skip to contentSkip to conversation

BPF round-robin scheduler

PATCH Superseded Geliang Tang 2 participants 5 messages May 1, 2022 – May 3, 2022

Subsystems (5)

v10 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v10 cover BPF round-robin scheduler

v10:
- init subflows array in mptcp_sched_data_init.
- for (int i = 0; i < data->subflows; i++) is not allowed in BPF, using this instead:

	for (int i = 0; i < MPTCP_SUBFLOWS_MAX && i < data->subflows; i++)

- deponds on: "BPF packet scheduler" series v18.

v9:
- add subflows array in mptcp_sched_data
- deponds on: "BPF packet scheduler" series v17 + Squash to "mptcp: add struct mptcp_sched_ops v17".

v8:
- use struct mptcp_sched_data.
- deponds on: "BPF packet scheduler" series v14.

v7:
- rename retrans to reinject.
- drop last_snd setting.
- deponds on: "BPF packet scheduler" series v13.

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 subflows array in sched data
selftests: bpf: add bpf_rr scheduler
selftests: bpf: add bpf_rr test

 include/net/mptcp.h                           |  3 ++
 net/mptcp/sched.c                             |  7 +++
 .../testing/selftests/bpf/bpf_mptcp_helpers.h |  9 ++++
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 37 +++++++++++++++
 .../selftests/bpf/progs/mptcp_bpf_rr.c        | 45 +++++++++++++++++++
 5 files changed, 101 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v10 1/3 mptcp: add subflows array in sched data

This patch adds a subflow pointers array in struct mptcp_sched_data. Set the array before invoking get_subflow(), then get it in get_subflow() in the BPF contexts.

---
 include/net/mptcp.h                             | 3 +++
 net/mptcp/sched.c                               | 7 +++++++
 tools/testing/selftests/bpf/bpf_mptcp_helpers.h | 3 +++
 3 files changed, 13 insertions(+)
include/net/mptcp.h +3 -0
index bea7608d72d3..1a48e31f3ac7 100644
@@ -96,10 +96,13 @@ struct mptcp_out_options {
 };
 
 #define MPTCP_SCHED_NAME_MAX	16
+#define MPTCP_SUBFLOWS_MAX	8
 
 struct mptcp_sched_data {
 	struct sock	*sock;
 	bool		call_again;
+	u8		subflows;
+	struct mptcp_subflow_context *array[MPTCP_SUBFLOWS_MAX];
 };
 
 struct mptcp_sched_ops {
net/mptcp/sched.c +7 -0
index 7a5654132ed3..1efbcfe80fe7 100644
@@ -93,9 +93,16 @@ void mptcp_release_sched(struct mptcp_sock *msk)
 static int mptcp_sched_data_init(struct mptcp_sock *msk,
 				 struct mptcp_sched_data *data)
 {
+	struct mptcp_subflow_context *subflow;
+	int i = 0;
+
 	data->sock = NULL;
 	data->call_again = 0;
 
+	mptcp_for_each_subflow(msk, subflow)
+		data->array[i++] = subflow;
+	data->subflows = i;
+
 	return 0;
 }
 
tools/testing/selftests/bpf/bpf_mptcp_helpers.h +3 -0
index e863954de701..1f991ff2e325 100644
@@ -7,10 +7,13 @@
 #include "bpf_tcp_helpers.h"
 
 #define MPTCP_SCHED_NAME_MAX	16
+#define MPTCP_SUBFLOWS_MAX	8
 
 struct mptcp_sched_data {
 	struct sock	*sock;
 	bool		call_again;
+	__u8		subflows;
+	struct mptcp_subflow_context *array[MPTCP_SUBFLOWS_MAX];
 };
 
 struct mptcp_sched_ops {
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH mptcp-next v10 1/3] mptcp: add subflows array in sched data

Quoted 16 lines · Geliang Tang

This patch adds a subflow pointers array in struct mptcp_sched_data. Set the array before invoking get_subflow(), then get it in get_subflow() in the BPF contexts.

---

include/net/mptcp.h                             | 3 +++
net/mptcp/sched.c                               | 7 +++++++
tools/testing/selftests/bpf/bpf_mptcp_helpers.h | 3 +++
3 files changed, 13 insertions(+)
include/net/mptcp.h +0 -0
index bea7608d72d3..1a48e31f3ac7 100644

include/net/mptcp.h struct mptcp_out_options { · line 105

Quoted 10 lines
include/net/mptcp.h +3 -0
@@ -96,10 +96,13 @@ struct mptcp_out_options {
 };
 
 #define MPTCP_SCHED_NAME_MAX	16
+#define MPTCP_SUBFLOWS_MAX	8
 
 struct mptcp_sched_data {
 	struct sock	*sock;
 	bool		call_again;
+	u8		subflows;
+	struct mptcp_subflow_context *array[MPTCP_SUBFLOWS_MAX];

I suggest a more descriptive name here: 'contexts' instead of 'array'?

Quoted 9 lines
include/net/mptcp.h +0 -0
 };
 
 struct mptcp_sched_ops {
net/mptcp/sched.c +0 -0
index 7a5654132ed3..1efbcfe80fe7 100644
@@ -93,9 +93,16 @@ void mptcp_release_sched(struct mptcp_sock *msk)
 static int mptcp_sched_data_init(struct mptcp_sock *msk,

net/mptcp/sched.c void mptcp_release_sched(struct mptcp_sock *msk) · line 103

Quoted 10 lines
net/mptcp/sched.c +5 -0
 				 struct mptcp_sched_data *data)
 {
+	struct mptcp_subflow_context *subflow;
+	int i = 0;
+
 	data->sock = NULL;
 	data->call_again = 0;
 
+	mptcp_for_each_subflow(msk, subflow)
+		data->array[i++] = subflow;

Two things here:

The unused array elements should be set to NULL.

There should be strict checking of the MPTCP_SUBFLOWS_MAX array size limit, and if the length of conn_list is larger then pr_warn_once() about that unexpected condition.

- Mat

Quoted 28 lines
net/mptcp/sched.c +2 -0
+	data->subflows = i;
+
 	return 0;
 }
 
tools/testing/selftests/bpf/bpf_mptcp_helpers.h +3 -0
index e863954de701..1f991ff2e325 100644
@@ -7,10 +7,13 @@
 #include "bpf_tcp_helpers.h"
 
 #define MPTCP_SCHED_NAME_MAX	16
+#define MPTCP_SUBFLOWS_MAX	8
 
 struct mptcp_sched_data {
 	struct sock	*sock;
 	bool		call_again;
+	__u8		subflows;
+	struct mptcp_subflow_context *array[MPTCP_SUBFLOWS_MAX];
 };
 
 struct mptcp_sched_ops {
Signature · 1 line
2.34.1

--
Mat Martineau
Intel

#3 lore raw

PATCH v10 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.

---
 .../testing/selftests/bpf/bpf_mptcp_helpers.h |  6 +++
 .../selftests/bpf/progs/mptcp_bpf_rr.c        | 45 +++++++++++++++++++
 2 files changed, 51 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
tools/testing/selftests/bpf/bpf_mptcp_helpers.h +6 -0
index 1f991ff2e325..8ce5b1603962 100644
@@ -30,10 +30,16 @@ struct mptcp_sched_ops {
 struct mptcp_sock {
 	struct inet_connection_sock	sk;
 
+	struct sock	*last_snd;
 	__u32		token;
 	struct sock	*first;
 	struct mptcp_sched_ops *sched;
 	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));
+
 #endif
tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.34.1
#4 lore raw

PATCH v10 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. 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
index 21462c29683c..c400be612f72 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"
 
 #ifndef TCP_CA_NAME_MAX
 #define TCP_CA_NAME_MAX	16
@@ -375,10 +376,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