mptcp: update scheduler API
Subsystems (5)
cover mptcp: update scheduler API
This patchset proposes an updated API for mptcp schedulers to provide more flexibility for future scheduling strategies. This does not change the current behavior of get_subflow. It adds an optional hook to control scheduling behavior after selecting a subflow in get_subflow.
The main idea is to provide a way to perform a scheduling per-MSS or per chunk of data. To demonstrate this, the mptcp_bpf_rr scheduler has been modified to send one MSS per subflow in an alternating fashion.
The other potential application of this API could be to define a scheduler that will proactivelly reinject data on available subflows based on some heuristics (eg. when one subflow RTT increases when moving away from WiFi AP). It could also allow to limit the usage of a specific subflow, eg., in the case of high BDP.
I am mainly looking for feedback to see whether this design make sense. Matthieu already did a quick pass on it.
The API introduces a push() function (name TBD) that takes the subflow and data chunk (sequence number and length) as arguments. The scheduler can then control packet scheduling by:
- Setting data transmission limits (e.g., per-MSS on a subflow or per window).
- Setting flags associated with the data. Currently, only MPTCP_SCHED_FLAG_RESCHEDULE is defined, forcing the scheduler to call get_subflow after sending the chunk.
I am envisioning another flag MPTCP_SCHED_FLAG_REINJECT that will ensure that chunk of data can be rescheduled directly on another subflow.
I've written some packetdrill tests to validate the update RR scheduler the test are available on my fork:
https://github.com/gdetal/packetdrill/tree/mptcp-net-next/gtests/net/mptcp-bpf/round-robin
Open questions:
- Is the current API for setting flags and limits appropriate? What are eBPF best practices to pass back information to kernel ?
- should get_scheduler and this new API be merged somehow as to provide a single way of scheduling data ? Eg. could pass chunk and return flags, limit and subflow to send this data to.
---
Gregory Detal (4):
mptcp: add push sched callback
mptcp: use new push callback to schedule chunks
mptcp: bpf: allow to write to mptcp_sched_chunk selftests/bpf: mptcp RR: send 1 MSS on each subflow
include/net/mptcp.h | 29 ++++++++++++++++++++++++ net/mptcp/bpf.c | 25 ++++++++++++++++++-- net/mptcp/protocol.c | 14 ++++++++---- net/mptcp/protocol.h | 9 ++++++++ net/mptcp/sched.c | 20 ++++++++++++++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 1 + tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c | 18 +++++++++++++++ 7 files changed, 110 insertions(+), 6 deletions(-)
---
base-commit: c98f8dc106a6d6c4424f2e612762821e1be14bf0
change-id: 20240503-sched_per_packet-d6e4488e54e8
Best regards,
Signature · 1 line
Gregory Detal <[email protected]>
RFC PATCH 1/4 mptcp: add push sched callback
The callback is optional. It takes the current subflow and the current chunk of data that is scheduled on that subflow.
When defined, a scheduler will be able to:
- update the limit field to limit the number of bytes sent on the ongoing scheduled subflow.
- set the flag MPTCP_SCHED_FLAG_RESCHEDULE to force the get_subflow to be called again after sending the chunk.
--- include/net/mptcp.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
include/net/mptcp.h +29 -0
@@ -108,10 +108,39 @@ struct mptcp_sched_data {struct mptcp_subflow_context *contexts[MPTCP_SUBFLOWS_MAX ]; }; +/* MPTCP scheduler push flags */ +#define MPTCP_SCHED_FLAG_RESCHEDULE BIT(0) + +/* Represent a chunk of data that will be sent on a subflow */ +struct mptcp_sched_chunk { +/* The data sequence number of the first byte of the chunk. read-only. */ +u64 data_seq; + +/* The maximum number of bytes to send in this chunk. +* Update this value to limit the amount of data to be sent. +*/ +u16 limit; + +/* Define the behavior of the scheduler to apply to this chunk. +* Available flags are: +* - MPTCP_SCHED_FLAG_RESCHEDULE: the scheduler will be called again +* after processing this chunk (potentially limited). +* +* 0 means default behavior, ie. full chunk sent and subflow continue +* being used for further chunks. +*/ +u16 flags; +}; +struct mptcp_sched_ops {int (*get_subflow)(struct mptcp_sock *msk,struct mptcp_sched_data *data); +/* Called before sending data on a subflow. (optional) */ +void (*push)(struct mptcp_sock *msk, +struct mptcp_subflow_context *subflow, +struct mptcp_sched_chunk *chunk); +char name[MPTCP_SCHED_NAME_MAX ];struct module *owner;struct list_head list;
Signature · 1 line
2.43.0
RFC PATCH 2/4 mptcp: use new push callback to schedule chunks
In reply to Gregory DetalThis commit modifies the subflow push pending function to call for each data that will be sent over this subflow.
Only send the amount of data defined by the scheduler. If it sets MPTCP_SCHED_FLAG_RESCHEDULE, the function will ignore further data to be sent. This will cause the get_subflow function to be called again.
The previous behavior is maintained if the push function isn't defined by the scheduler.
--- net/mptcp/protocol.c | 14 ++++++++++---- net/mptcp/protocol.h | 9 +++++++++ net/mptcp/sched.c | 20 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-)
net/mptcp/protocol.c +10 -4
@@ -1526,12 +1526,15 @@ static int __subflow_push_pending(struct sock *sk, struct sock *ssk,struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_data_frag *dfrag;int len, copied =0 , err =0 ; +u16 sflags =0 ; + +while ((dfrag =mptcp_send_head (sk)) && !(sflags &MPTCP_SCHED_FLAG_RESCHEDULE )) { +u16 limit =mptcp_sched_push (msk, ssk, dfrag, &sflags); -while ((dfrag =mptcp_send_head (sk))) { info->sent = dfrag->already_sent; - info->limit = dfrag->data_len; len = dfrag->data_len - dfrag->already_sent; -while (len >0 ) { + info->limit = limit ? info->sent +min_t (u16, limit, len) : dfrag->data_len; +while (len >0 && info->sent < info->limit) {int ret =0 ; ret =mptcp_sendmsg_frag (sk, ssk, dfrag, info);
@@ -1546,7 +1549,10 @@ static int __subflow_push_pending(struct sock *sk, struct sock *ssk,mptcp_update_post_push (msk, dfrag, ret); } -WRITE_ONCE (msk->first_pending,mptcp_send_next (sk)); + +/* if the whole data has been sent, move to next data segment: */ +if (len <=0 ) +WRITE_ONCE (msk->first_pending,mptcp_send_next (sk)); if (msk->snd_burst <= 0 || !sk_stream_memory_free(ssk) ||
net/mptcp/protocol.h +9 -0
@@ -742,6 +742,15 @@ struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk);struct sock *mptcp_subflow_get_retrans (struct mptcp_sock *msk);int mptcp_sched_get_send (struct mptcp_sock *msk);int mptcp_sched_get_retrans (struct mptcp_sock *msk); +u16 __mptcp_sched_push (struct mptcp_sock *msk,struct sock *ssk, +struct mptcp_data_frag *dfrag,u16 *flags); +static inline u16 mptcp_sched_push (struct mptcp_sock *msk,struct sock *ssk, +struct mptcp_data_frag *dfrag,u16 *flags) { +if (likely (!msk->sched || !msk->sched->push)) +return 0 ; + +return __mptcp_sched_push (msk, ssk, dfrag, flags); +}static inline u64 mptcp_data_avail (const struct mptcp_sock *msk) {
net/mptcp/sched.c +20 -0
@@ -193,6 +193,26 @@ int mptcp_sched_get_send(struct mptcp_sock *msk)return msk->sched->get_subflow (msk, &data); } +/* This is called before the data has been sent on a subflow. It returns flags +* that defines what the scheduler should do with the ongoing data. +*/ +u16 __mptcp_sched_push (struct mptcp_sock *msk,struct sock *ssk, +struct mptcp_data_frag *dfrag,u16 *flags) +{ +struct mptcp_sched_chunk chunk = { + .data_seq = dfrag->data_seq + dfrag->already_sent, + .limit =0 , + .flags =0 , + }; + +msk_owned_by_me (msk); + + msk->sched->push (msk,mptcp_subflow_ctx (ssk), &chunk); + *flags = chunk.flags; + +return chunk.limit; +} +int mptcp_sched_get_retrans (struct mptcp_sock *msk) {struct mptcp_subflow_context *subflow;
Signature · 1 line
2.43.0
Mat Martineau
maintainerRe: [PATCH mptcp-next RFC 2/4] mptcp: use new push callback to schedule chunks
Quoted 41 lines · Gregory Detal
This commit modifies the subflow push pending function to call for each data that will be sent over this subflow.
Only send the amount of data defined by the scheduler. If it sets
MPTCP_SCHED_FLAG_RESCHEDULE, the function will ignore further data to be sent. This will cause theget_subflowfunction to be called again.The previous behavior is maintained if the push function isn't defined by the scheduler.
Signed-off-by Gregory Detal <[email protected]>---
net/mptcp/protocol.c | 14 ++++++++++---- net/mptcp/protocol.h | 9 +++++++++ net/mptcp/sched.c | 20 ++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-)net/mptcp/protocol.c +6
-3@@ -1526,12 +1526,15 @@ static int __subflow_push_pending(struct sock *sk, struct sock *ssk,struct mptcp_sock *msk =mptcp_sk (sk);struct mptcp_data_frag *dfrag;int len, copied =0 , err =0 ; +u16 sflags =0 ; + +while ((dfrag =mptcp_send_head (sk)) && !(sflags &MPTCP_SCHED_FLAG_RESCHEDULE )) { +u16 limit =mptcp_sched_push (msk, ssk, dfrag, &sflags); -while ((dfrag =mptcp_send_head (sk))) { info->sent = dfrag->already_sent; - info->limit = dfrag->data_len; len = dfrag->data_len - dfrag->already_sent; -while (len >0 ) { + info->limit = limit ? info->sent +min_t (u16, limit, len) : dfrag->data_len; +while (len >0 && info->sent < info->limit) {int ret =0 ; ret =mptcp_sendmsg_frag (sk, ssk, dfrag, info);
net/mptcp/protocol.c static int __subflow_push_pending(struct sock *sk, struct sock *ssk, · line 1555
Quoted 8 lines
net/mptcp/protocol.c +4
-1@@ -1546,7 +1549,10 @@ static int __subflow_push_pending(struct sock *sk, struct sock *ssk,mptcp_update_post_push (msk, dfrag, ret); } -WRITE_ONCE (msk->first_pending,mptcp_send_next (sk)); + +/* if the whole data has been sent, move to next data segment: */ +if (len <=0 ) +WRITE_ONCE (msk->first_pending,mptcp_send_next (sk));
Hi Gregory -
It's important to be careful with possible race conditions here, since this changes existing assumptions about updates to msk->first_pending. I believe __mptcp_clean_una() (called when processing acks) will not get called until the msk socket lock is released so the data in msk->rtx_queue _should_ be available for reinjection. But we should be careful to verify all locking assumptions around these msk values. For example, sometimes the msk socket lock is held here but other times it's the mptcp_data_lock.
Also, it looks like there are some error paths that could exit this loop without updating msk->first_pending, which would be problematic.
- Mat
Quoted 60 lines
net/mptcp/protocol.c +0
-0if (msk->snd_burst <= 0 || !sk_stream_memory_free(ssk) ||net/mptcp/protocol.h +9
-0@@ -742,6 +742,15 @@ struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk);struct sock *mptcp_subflow_get_retrans (struct mptcp_sock *msk);int mptcp_sched_get_send (struct mptcp_sock *msk);int mptcp_sched_get_retrans (struct mptcp_sock *msk); +u16 __mptcp_sched_push (struct mptcp_sock *msk,struct sock *ssk, +struct mptcp_data_frag *dfrag,u16 *flags); +static inline u16 mptcp_sched_push (struct mptcp_sock *msk,struct sock *ssk, +struct mptcp_data_frag *dfrag,u16 *flags) { +if (likely (!msk->sched || !msk->sched->push)) +return 0 ; + +return __mptcp_sched_push (msk, ssk, dfrag, flags); +}static inline u64 mptcp_data_avail (const struct mptcp_sock *msk) {net/mptcp/sched.c +20
-0@@ -193,6 +193,26 @@ int mptcp_sched_get_send(struct mptcp_sock *msk)return msk->sched->get_subflow (msk, &data); } +/* This is called before the data has been sent on a subflow. It returns flags +* that defines what the scheduler should do with the ongoing data. +*/ +u16 __mptcp_sched_push (struct mptcp_sock *msk,struct sock *ssk, +struct mptcp_data_frag *dfrag,u16 *flags) +{ +struct mptcp_sched_chunk chunk = { + .data_seq = dfrag->data_seq + dfrag->already_sent, + .limit =0 , + .flags =0 , + }; + +msk_owned_by_me (msk); + + msk->sched->push (msk,mptcp_subflow_ctx (ssk), &chunk); + *flags = chunk.flags; + +return chunk.limit; +} +int mptcp_sched_get_retrans (struct mptcp_sock *msk) {struct mptcp_subflow_context *subflow;Signature · 2 lines
-- 2.43.0
RFC PATCH 3/4 mptcp: bpf: allow to write to mptcp_sched_chunk
In reply to Gregory DetalThis patch allows to write to either limit or flags, allowing a bpf program to change the packet scheduling behavior.
The fields will be used in next commit.
--- net/mptcp/bpf.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
net/mptcp/bpf.c +23 -2
@@ -18,8 +18,9 @@#ifdef CONFIG_BPF_JIT static struct bpf_struct_ops bpf_mptcp_sched_ops; -static const struct btf_type *mptcp_sock_type, *mptcp_subflow_type__read_mostly ; -static u32 mptcp_sock_id, mptcp_subflow_id; +static const struct btf_type *mptcp_sock_type, *mptcp_subflow_type__read_mostly , + *mptcp_sched_chunk_type; +static u32 mptcp_sock_id, mptcp_subflow_id, mptcp_sched_chunk_id;static const struct bpf_func_proto * bpf_mptcp_sched_get_func_proto(enum bpf_func_id func_id,
@@ -71,6 +72,19 @@ static int bpf_mptcp_sched_btf_struct_access(struct bpf_verifier_log *log, off);return -EACCES ; } + }else if (t == mptcp_sched_chunk_type) { +switch (off) { +case offsetof(struct mptcp_sched_chunk , limit): + end = offsetofend(struct mptcp_sched_chunk, limit); +break ; +case offsetof(struct mptcp_sched_chunk , flags): + end = offsetofend(struct mptcp_sched_chunk, flags); +break ; +default : +bpf_log (log,"no write support to mptcp_sched_chunk at off %d\n" , + off); +return -EACCES ; + } }else {bpf_log (log,"only access to mptcp sock or subflow is supported\n" );return -EACCES ;
@@ -152,6 +166,13 @@ static int bpf_mptcp_sched_init(struct btf *btf) mptcp_subflow_id = type_id; mptcp_subflow_type =btf_type_by_id (btf, mptcp_subflow_id); + type_id =btf_find_by_name_kind (btf,"mptcp_sched_chunk" , +BTF_KIND_STRUCT ); +if (type_id <0 ) +return -EINVAL ; + mptcp_sched_chunk_id = type_id; + mptcp_sched_chunk_type =btf_type_by_id (btf, mptcp_sched_chunk_id); +return 0 ; }
Signature · 1 line
2.43.0
RFC PATCH 4/4 selftests/bpf: mptcp RR: send 1 MSS on each subflow
In reply to Gregory DetalThis uses the helper and APIs to schedule one MSS on alternance on each subflow.
This now really acts at a round-robin scheduler: packets are equally balanced on each path
--- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 1 + tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+)
tools/testing/selftests/bpf/progs/mptcp_bpf.h +1 -0
@@ -6,6 +6,7 @@#include <bpf/bpf_core_read.h> #define MPTCP_SUBFLOWS_MAX 8 +#define MPTCP_SCHED_FLAG_RESCHEDULE (1 << 0) extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, bool scheduled) __ksym;
tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c +18 -0
@@ -69,10 +69,28 @@ int BPF_PROG(bpf_rr_get_subflow, struct mptcp_sock *msk,return 0 ; } +SEC("struct_ops") +void BPF_PROG (bpf_rr_push ,struct mptcp_sock *msk, +struct mptcp_subflow_context *subflow, +struct mptcp_sched_chunk *chunk) +{ +struct tcp_sock *tp =bpf_skc_to_tcp_sock (mptcp_subflow_tcp_sock (subflow)); + +if (!tp) { +/* Should not happen, in that case let default behavior. */ +return ; + } + +/* Make sure to reschedule for each MSS. */ + chunk->limit = tp->mss_cache; + chunk->flags |=MPTCP_SCHED_FLAG_RESCHEDULE ; +} + SEC(".struct_ops")struct mptcp_sched_ops rr = { .init = (void *)mptcp_sched_rr_init, .release = (void *)mptcp_sched_rr_release, .get_subflow = (void *)bpf_rr_get_subflow, + .push = (void *)bpf_rr_push, .name ="bpf_rr" , };
Signature · 1 line
2.43.0
Hi Gregory,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/9255729312
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/d60094641280
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=856158
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
Mat Martineau
maintainerQuoted 9 lines · Gregory Detal
This patchset proposes an updated API for mptcp schedulers to provide more flexibility for future scheduling strategies. This does not change the current behavior of
get_subflow. It adds an optional hook to control scheduling behavior after selecting a subflow inget_subflow.The main idea is to provide a way to perform a scheduling per-MSS or per chunk of data. To demonstrate this, the
mptcp_bpf_rrscheduler has been modified to send one MSS per subflow in an alternating fashion.
Quoted 9 lines
The other potential application of this API could be to define a scheduler that will proactivelly reinject data on available subflows based on some heuristics (eg. when one subflow RTT increases when moving away from WiFi AP). It could also allow to limit the usage of a specific subflow, eg., in the case of high BDP.
I am mainly looking for feedback to see whether this design make sense. Matthieu already did a quick pass on it.
Hi Gregory -
Sorry about the delay, thanks for working on this scheduler code!
Quoted 11 lines
The API introduces a
push()function (name TBD) that takes the subflow and data chunk (sequence number and length) as arguments. The scheduler can then control packet scheduling by:
- Setting data transmission limits (e.g., per-MSS on a subflow or per window).
- Setting flags associated with the data. Currently, onlyMPTCP_SCHED_FLAG_RESCHEDULEis defined, forcing the scheduler to callget_subflowafter sending the chunk.I am envisioning another flag
MPTCP_SCHED_FLAG_REINJECTthat will ensure that chunk of data can be rescheduled directly on another subflow.
Quoted 8 lines
I've written some packetdrill tests to validate the update RR scheduler the test are available on my fork:
https://github.com/gdetal/packetdrill/tree/mptcp-net-next/gtests/net/mptcp-bpf/round-robin
Open questions:
- Is the current API for setting flags and limits appropriate? What are eBPF best practices to pass back information to kernel ?
I think the approach of using a regular u16 for the flags and preprocessor constants like MPTCP_SCHED_FLAG_RESCHEDULE isn't a good fit for eBPF. The main reasons I see:
* The user's eBPF code can set any combination of bits in the u16 flags without the kernel automatically checking that those bits are known/expected.
* The flag values as preprocessor constants can't be represented in BTF format to allow compiling the BPF scheduler using type information from the kernel (rather than manually setting those #defines in the scheduler code).
Even though it's not as space-efficient, I think individual struct members would be better than an integer bitfield for this kind of flag. Then the struct_access hook can check what's supported at load time.
Quoted 3 lines
- should
get_schedulerand this new API be merged somehow as to provide a single way of scheduling data ? Eg. could pass chunk and return flags, limit and subflow to send this data to.
Yes, I think it would be good to consolidate get_scheduler and the new API, so two calls out to the BPF scheduler are not required for each packet. It's ok to change the internal scheduler APIs, and I think that will be required to support reinjection.
- Mat
Quoted 28 lines
Co-Developed-By Matthieu Baerts <[email protected]>Signed-off-by Gregory Detal <[email protected]>---
Gregory Detal (4):
mptcp: add push sched callback
mptcp: use new push callback to schedule chunks
mptcp: bpf: allow to write tomptcp_sched_chunkselftests/bpf: mptcp RR: send 1 MSS on each subflowinclude/net/mptcp.h | 29 ++++++++++++++++++++++++ net/mptcp/bpf.c | 25 ++++++++++++++++++-- net/mptcp/protocol.c | 14 ++++++++---- net/mptcp/protocol.h | 9 ++++++++ net/mptcp/sched.c | 20 ++++++++++++++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 1 + tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c | 18 +++++++++++++++ 7 files changed, 110 insertions(+), 6 deletions(-)---
base-commit:c98f8dc106a6d6c4424f2e612762821e1be14bf0
change-id: 20240503-sched_per_packet-d6e4488e54e8Best regards,
Signature · 1 line
Gregory Detal <[email protected]>