Commit ed1ad86b authored by Geliang Tang's avatar Geliang Tang Committed by Jakub Kicinski

mptcp: register default scheduler

This patch defines the default packet scheduler mptcp_sched_default.
Register it in mptcp_sched_init(), which is invoked in mptcp_proto_init().
Skip deleting this default scheduler in mptcp_unregister_scheduler().

Set msk->sched to the default scheduler when the input parameter of
mptcp_init_sched() is NULL.

Invoke mptcp_sched_default_get_subflow in get_send() and get_retrans()
if the defaut scheduler is set or msk->sched is NULL.
Acked-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarGeliang Tang <geliang.tang@suse.com>
Signed-off-by: default avatarMat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20230821-upstream-net-next-20230818-v1-10-0c860fb256a8@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent ee2708ae
...@@ -3965,6 +3965,7 @@ void __init mptcp_proto_init(void) ...@@ -3965,6 +3965,7 @@ void __init mptcp_proto_init(void)
mptcp_subflow_init(); mptcp_subflow_init();
mptcp_pm_init(); mptcp_pm_init();
mptcp_sched_init();
mptcp_token_init(); mptcp_token_init();
if (proto_register(&mptcp_prot, 1) != 0) if (proto_register(&mptcp_prot, 1) != 0)
......
...@@ -661,6 +661,7 @@ void mptcp_info2sockaddr(const struct mptcp_addr_info *info, ...@@ -661,6 +661,7 @@ void mptcp_info2sockaddr(const struct mptcp_addr_info *info,
struct mptcp_sched_ops *mptcp_sched_find(const char *name); struct mptcp_sched_ops *mptcp_sched_find(const char *name);
int mptcp_register_scheduler(struct mptcp_sched_ops *sched); int mptcp_register_scheduler(struct mptcp_sched_ops *sched);
void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched); void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched);
void mptcp_sched_init(void);
int mptcp_init_sched(struct mptcp_sock *msk, int mptcp_init_sched(struct mptcp_sock *msk,
struct mptcp_sched_ops *sched); struct mptcp_sched_ops *sched);
void mptcp_release_sched(struct mptcp_sock *msk); void mptcp_release_sched(struct mptcp_sock *msk);
......
...@@ -16,6 +16,26 @@ ...@@ -16,6 +16,26 @@
static DEFINE_SPINLOCK(mptcp_sched_list_lock); static DEFINE_SPINLOCK(mptcp_sched_list_lock);
static LIST_HEAD(mptcp_sched_list); static LIST_HEAD(mptcp_sched_list);
static int mptcp_sched_default_get_subflow(struct mptcp_sock *msk,
struct mptcp_sched_data *data)
{
struct sock *ssk;
ssk = data->reinject ? mptcp_subflow_get_retrans(msk) :
mptcp_subflow_get_send(msk);
if (!ssk)
return -EINVAL;
mptcp_subflow_set_scheduled(mptcp_subflow_ctx(ssk), true);
return 0;
}
static struct mptcp_sched_ops mptcp_sched_default = {
.get_subflow = mptcp_sched_default_get_subflow,
.name = "default",
.owner = THIS_MODULE,
};
/* Must be called with rcu read lock held */ /* Must be called with rcu read lock held */
struct mptcp_sched_ops *mptcp_sched_find(const char *name) struct mptcp_sched_ops *mptcp_sched_find(const char *name)
{ {
...@@ -50,16 +70,24 @@ int mptcp_register_scheduler(struct mptcp_sched_ops *sched) ...@@ -50,16 +70,24 @@ int mptcp_register_scheduler(struct mptcp_sched_ops *sched)
void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched) void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched)
{ {
if (sched == &mptcp_sched_default)
return;
spin_lock(&mptcp_sched_list_lock); spin_lock(&mptcp_sched_list_lock);
list_del_rcu(&sched->list); list_del_rcu(&sched->list);
spin_unlock(&mptcp_sched_list_lock); spin_unlock(&mptcp_sched_list_lock);
} }
void mptcp_sched_init(void)
{
mptcp_register_scheduler(&mptcp_sched_default);
}
int mptcp_init_sched(struct mptcp_sock *msk, int mptcp_init_sched(struct mptcp_sock *msk,
struct mptcp_sched_ops *sched) struct mptcp_sched_ops *sched)
{ {
if (!sched) if (!sched)
goto out; sched = &mptcp_sched_default;
if (!bpf_try_module_get(sched, sched->owner)) if (!bpf_try_module_get(sched, sched->owner))
return -EBUSY; return -EBUSY;
...@@ -70,7 +98,6 @@ int mptcp_init_sched(struct mptcp_sock *msk, ...@@ -70,7 +98,6 @@ int mptcp_init_sched(struct mptcp_sock *msk,
pr_debug("sched=%s", msk->sched->name); pr_debug("sched=%s", msk->sched->name);
out:
return 0; return 0;
} }
...@@ -117,17 +144,9 @@ int mptcp_sched_get_send(struct mptcp_sock *msk) ...@@ -117,17 +144,9 @@ int mptcp_sched_get_send(struct mptcp_sock *msk)
return 0; return 0;
} }
if (!msk->sched) {
struct sock *ssk;
ssk = mptcp_subflow_get_send(msk);
if (!ssk)
return -EINVAL;
mptcp_subflow_set_scheduled(mptcp_subflow_ctx(ssk), true);
return 0;
}
data.reinject = false; data.reinject = false;
if (msk->sched == &mptcp_sched_default || !msk->sched)
return mptcp_sched_default_get_subflow(msk, &data);
return msk->sched->get_subflow(msk, &data); return msk->sched->get_subflow(msk, &data);
} }
...@@ -147,16 +166,8 @@ int mptcp_sched_get_retrans(struct mptcp_sock *msk) ...@@ -147,16 +166,8 @@ int mptcp_sched_get_retrans(struct mptcp_sock *msk)
return 0; return 0;
} }
if (!msk->sched) {
struct sock *ssk;
ssk = mptcp_subflow_get_retrans(msk);
if (!ssk)
return -EINVAL;
mptcp_subflow_set_scheduled(mptcp_subflow_ctx(ssk), true);
return 0;
}
data.reinject = true; data.reinject = true;
if (msk->sched == &mptcp_sched_default || !msk->sched)
return mptcp_sched_default_get_subflow(msk, &data);
return msk->sched->get_subflow(msk, &data); return msk->sched->get_subflow(msk, &data);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment