Add a deadline server for sched_ext tasks
Subsystems (4)
v3 cover Add a deadline server for sched_ext tasks
sched_ext tasks currently are starved by RT hoggers especially since RT throttling was replaced by deadline servers to boost only CFS tasks. Several users in the community have reported issues with RT stalling sched_ext tasks. Add a sched_ext deadline server as well so that sched_ext tasks are also boosted and do not suffer starvation.
A kselftest is also provided to verify the starvation issues are now fixed.
Btw, there is still something funky going on with CPU hotplug and the relinquish patch. Sometimes the sched_ext's hotplug self-test locks up (./runner -t hotplug). Reverting that patch fixes it, so I am suspecting something is off in dl_server_remove_params() when it is being called on offline CPUs.
v2->v3:
- Removed code duplication in debugfs. Made ext interface separate.
- Fixed issue where rq_lock_irqsave was not used in the relinquish patch.
- Fixed running bw accounting issue in dl_server_remove_params.
Link to v1: https://lore.kernel.org/all/[email protected]/
Link to v2: https://lore.kernel.org/all/[email protected]/
Andrea Righi (1):
selftests/sched_ext: Add test for sched_ext dl_server
Joel Fernandes (9):
sched/debug: Fix updating of ppos on server write ops sched/debug: Stop and start server based on if it was active sched/deadline: Clear the defer params
sched: Add support to pick functions to take rf
sched: Add a server arg to dl_server_update_idle_time() sched/ext: Add a DL server for sched_ext tasks sched/debug: Add support to change sched_ext server params sched/deadline: Add support to remove DL server bandwidth sched/ext: Relinquish DL server reservations when not needed
include/linux/sched.h | 2 +- kernel/sched/core.c | 19 +- kernel/sched/deadline.c | 78 +++++-- kernel/sched/debug.c | 171 +++++++++++--- kernel/sched/ext.c | 108 ++++++++- kernel/sched/fair.c | 15 +- kernel/sched/idle.c | 4 +- kernel/sched/rt.c | 2 +- kernel/sched/sched.h | 13 +- kernel/sched/stop_task.c | 2 +- tools/testing/selftests/sched_ext/Makefile | 1 + .../selftests/sched_ext/rt_stall.bpf.c | 23 ++ tools/testing/selftests/sched_ext/rt_stall.c | 213 ++++++++++++++++++ 13 files changed, 579 insertions(+), 72 deletions(-) create mode 100644 tools/testing/selftests/sched_ext/rt_stall.bpf.c create mode 100644 tools/testing/selftests/sched_ext/rt_stall.c
Signature · 1 line
2.34.1
PATCH v3 1/10 sched/debug: Fix updating of ppos on server write ops
Updating "ppos" on error conditions does not make much sense. The pattern is to return the error code directly without modifying the position, or modify the position on success and return the number of bytes written.
Since on success, the return value of apply is 0, there is no point in modifying ppos either. Fix it by removing all this and just returning error code or number of bytes written on success.
--- kernel/sched/debug.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/sched/debug.c +4 -3
@@ -350,8 +350,8 @@ static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubulong cpu = (long ) ((struct seq_file *) filp->private_data)->private;struct rq *rq =cpu_rq (cpu);u64 runtime, period; +int retval =0 ;size_t err; -int retval;u64 value; err =kstrtoull_from_user (ubuf, cnt,10 , &value);
@@ -387,8 +387,6 @@ static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubu } retval =dl_server_apply_params (&rq->fair_server, runtime, period,0 ); -if (retval) - cnt = retval;if (!runtime) printk_deferred("Fair server disabled in CPU %d, system may crash due to starvation.\n",
@@ -396,6 +394,9 @@ static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubuif (rq->cfs.h_nr_queued)dl_server_start (&rq->fair_server); + +if (retval <0 ) +return retval; } *ppos += cnt;
Signature · 1 line
2.34.1
PATCH v3 2/10 sched/debug: Stop and start server based on if it was active
In reply to Joel FernandesCurrently the DL server interface for applying parameters checks CFS-internals to identify if the server is active. This is error-prone and makes it difficult when adding new servers in the future.
Fix it, by using dl_server_active() which is also used by the DL server code to determine if the DL server was started.
--- kernel/sched/debug.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/sched/debug.c +4 -2
@@ -349,6 +349,7 @@ static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubu {long cpu = (long ) ((struct seq_file *) filp->private_data)->private;struct rq *rq =cpu_rq (cpu); +bool was_active = false;u64 runtime, period;int retval =0 ;size_t err;
@@ -381,7 +382,8 @@ static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubureturn -EINVAL ; } -if (rq->cfs.h_nr_queued) { +if (dl_server_active (&rq->fair_server)) { + was_active = true;update_rq_clock (rq);dl_server_stop (&rq->fair_server); }
@@ -392,7 +394,7 @@ static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubuprintk_deferred ("Fair server disabled in CPU %d, system may crash due to starvation.\n" ,cpu_of (rq)); -if (rq->cfs.h_nr_queued) +if (was_active)dl_server_start (&rq->fair_server);if (retval <0 )
Signature · 1 line
2.34.1
PATCH v3 3/10 sched/deadline: Clear the defer params
In reply to Joel FernandesThe defer params were not cleared in __dl_clear_params. Clear them.
Without this is some of my test cases are flaking and the DL timer is not starting correctly AFAICS.
--- kernel/sched/deadline.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/sched/deadline.c +3 -0
@@ -3431,6 +3431,9 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se) dl_se->dl_non_contending =0 ; dl_se->dl_overrun =0 ; dl_se->dl_server =0 ; + dl_se->dl_defer =0 ; + dl_se->dl_defer_running =0 ; + dl_se->dl_defer_armed =0 ;#ifdef CONFIG_RT_MUTEXES dl_se->pi_se = dl_se;
Signature · 1 line
2.34.1
PATCH v3 4/10 sched: Add support to pick functions to take rf
In reply to Joel FernandesSome pick functions like the internal pick_next_task_fair() already take rf but some others dont. We need this for scx's server pick function. Prepare for this by having pick functions accept it.
--- include/linux/sched.h | 2 +- kernel/sched/core.c | 16 ++++++++-------- kernel/sched/deadline.c | 8 ++++---- kernel/sched/ext.c | 2 +- kernel/sched/fair.c | 13 ++++++++----- kernel/sched/idle.c | 2 +- kernel/sched/rt.c | 2 +- kernel/sched/sched.h | 7 ++++--- kernel/sched/stop_task.c | 2 +- 9 files changed, 29 insertions(+), 25 deletions(-)
include/linux/sched.h +1 -1
@@ -630,7 +630,7 @@ struct sched_rt_entity { } __randomize_layout;typedef bool (*dl_server_has_tasks_f )(struct sched_dl_entity *); -typedef struct task_struct *(*dl_server_pick_f )(struct sched_dl_entity *); +typedef struct task_struct *(*dl_server_pick_f )(struct sched_dl_entity *,void *);struct sched_dl_entity {struct rb_node rb_node;
kernel/sched/core.c +8 -8
@@ -6045,7 +6045,7 @@ __pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)/* Assume the next prioritized class is idle_sched_class */ if (!p) { - p =pick_task_idle (rq); + p =pick_task_idle (rq, rf);put_prev_set_next_task (rq, prev, p); }
@@ -6057,11 +6057,11 @@ __pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)for_each_active_class (class) {if (class->pick_next_task) { - p = class->pick_next_task (rq, prev); + p = class->pick_next_task (rq, prev, rf);if (p)return p; }else { - p = class->pick_task (rq); + p = class->pick_task (rq, rf);if (p) {put_prev_set_next_task (rq, prev, p);return p;
@@ -6091,7 +6091,7 @@ static inline bool cookie_match(struct task_struct *a, struct task_struct *b)return a->core_cookie == b->core_cookie; } -static inline struct task_struct *pick_task (struct rq *rq) +static inline struct task_struct *pick_task (struct rq *rq,struct rq_flags *rf) {const struct sched_class *class;struct task_struct *p;
@@ -6099,7 +6099,7 @@ static inline struct task_struct *pick_task(struct rq *rq) rq->dl_server =NULL ;for_each_active_class (class) { - p = class->pick_task (rq); + p = class->pick_task (rq, rf);if (p)return p; }
@@ -6199,7 +6199,7 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)* and there are no cookied tasks running on siblings. */ if (!need_sync) { - next =pick_task (rq); + next =pick_task (rq, rf);if (!next->core_cookie) { rq->core_pick =NULL ; rq->core_dl_server =NULL ;
@@ -6230,7 +6230,7 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)if (i != cpu && (rq_i != rq->core || !core_clock_updated))update_rq_clock (rq_i); - rq_i->core_pick = p =pick_task (rq_i); + rq_i->core_pick = p =pick_task (rq_i, rf); rq_i->core_dl_server = rq_i->dl_server;if (!max ||prio_less (max, p, fi_before))
@@ -6252,7 +6252,7 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)if (cookie) p =sched_core_find (rq_i, cookie);if (!p) - p = idle_sched_class.pick_task (rq_i); + p = idle_sched_class.pick_task (rq_i, rf); } rq_i->core_pick = p;
kernel/sched/deadline.c +4 -4
@@ -2419,7 +2419,7 @@ static struct sched_dl_entity *pick_next_dl_entity(struct dl_rq *dl_rq)* __pick_next_task_dl - Helper to pick the next -deadline task to run. * @rq: The runqueue to pick the next task from. */ -static struct task_struct *__pick_task_dl (struct rq *rq) +static struct task_struct *__pick_task_dl (struct rq *rq,struct rq_flags *rf) {struct sched_dl_entity *dl_se;struct dl_rq *dl_rq = &rq->dl;
@@ -2433,7 +2433,7 @@ static struct task_struct *__pick_task_dl(struct rq *rq)WARN_ON_ONCE (!dl_se);if (dl_server (dl_se)) { - p = dl_se->server_pick_task (dl_se); + p = dl_se->server_pick_task (dl_se, rf);if (!p) {if (dl_server_active (dl_se)) { dl_se->dl_yielded =1 ;
@@ -2449,9 +2449,9 @@ static struct task_struct *__pick_task_dl(struct rq *rq)return p; } -static struct task_struct *pick_task_dl (struct rq *rq) +static struct task_struct *pick_task_dl (struct rq *rq,struct rq_flags *rf) { -return __pick_task_dl (rq); +return __pick_task_dl (rq, rf); }static void put_prev_task_dl (struct rq *rq,struct task_struct *p,struct task_struct *next)
kernel/sched/ext.c +1 -1
@@ -3281,7 +3281,7 @@ static struct task_struct *first_local_task(struct rq *rq) struct task_struct, scx.dsq_list.node); } -static struct task_struct *pick_task_scx (struct rq *rq) +static struct task_struct *pick_task_scx (struct rq *rq,struct rq_flags *rf) {struct task_struct *prev = rq->curr;struct task_struct *p;
kernel/sched/fair.c +8 -5
@@ -8842,7 +8842,7 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, intresched_curr_lazy (rq); } -static struct task_struct *pick_task_fair (struct rq *rq) +static struct task_struct *pick_task_fair (struct rq *rq,struct rq_flags *rf) {struct sched_entity *se;struct cfs_rq *cfs_rq;
@@ -8880,7 +8880,7 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rfint new_tasks; again: - p =pick_task_fair (rq); + p =pick_task_fair (rq, rf);if (!p) goto idle; se = &p->se;
@@ -8959,7 +8959,8 @@ pick_next_task_fair(struct rq *rq, struct task_struct *prev, struct rq_flags *rfreturn NULL ; } -static struct task_struct *__pick_next_task_fair (struct rq *rq,struct task_struct *prev) +static struct task_struct *__pick_next_task_fair (struct rq *rq,struct task_struct *prev, +struct rq_flags *rf) {return pick_next_task_fair (rq, prev,NULL ); }
@@ -8969,9 +8970,11 @@ static bool fair_server_has_tasks(struct sched_dl_entity *dl_se)return !!dl_se->rq->cfs.nr_queued; } -static struct task_struct *fair_server_pick_task (struct sched_dl_entity *dl_se) +static struct task_struct *fair_server_pick_task (struct sched_dl_entity *dl_se,void *flags) { -return pick_task_fair (dl_se->rq); +struct rq_flags *rf = flags; + +return pick_task_fair (dl_se->rq, rf); }void fair_server_init (struct rq *rq)
kernel/sched/idle.c +1 -1
@@ -463,7 +463,7 @@ static void set_next_task_idle(struct rq *rq, struct task_struct *next, bool fir next->se.exec_start =rq_clock_task (rq); } -struct task_struct *pick_task_idle (struct rq *rq) +struct task_struct *pick_task_idle (struct rq *rq,struct rq_flags *rf) {scx_update_idle (rq, true, false);return rq->idle;
kernel/sched/rt.c +1 -1
@@ -1744,7 +1744,7 @@ static struct task_struct *_pick_next_task_rt(struct rq *rq)return rt_task_of (rt_se); } -static struct task_struct *pick_task_rt (struct rq *rq) +static struct task_struct *pick_task_rt (struct rq *rq,struct rq_flags *rf) {struct task_struct *p;
kernel/sched/sched.h +4 -3
@@ -2401,7 +2401,7 @@ struct sched_class {void (*wakeup_preempt)(struct rq *rq,struct task_struct *p,int flags);int (*balance)(struct rq *rq,struct task_struct *prev,struct rq_flags *rf); -struct task_struct *(*pick_task)(struct rq *rq); +struct task_struct *(*pick_task)(struct rq *rq,struct rq_flags *rf);/* * Optional! When implemented pick_next_task() should be equivalent to: *
@@ -2411,7 +2411,8 @@ struct sched_class {* set_next_task_first(next); * } */ -struct task_struct *(*pick_next_task)(struct rq *rq,struct task_struct *prev); +struct task_struct *(*pick_next_task)(struct rq *rq,struct task_struct *prev, +struct rq_flags *rf);void (*put_prev_task)(struct rq *rq,struct task_struct *p,struct task_struct *next);void (*set_next_task)(struct rq *rq,struct task_struct *p,bool first);
@@ -2574,7 +2575,7 @@ static inline bool sched_fair_runnable(struct rq *rq) }extern struct task_struct *pick_next_task_fair (struct rq *rq,struct task_struct *prev,struct rq_flags *rf); -extern struct task_struct *pick_task_idle (struct rq *rq); +extern struct task_struct *pick_task_idle (struct rq *rq,struct rq_flags *rf);#define SCA_CHECK 0x01#define SCA_MIGRATE_DISABLE 0x02
kernel/sched/stop_task.c +1 -1
@@ -33,7 +33,7 @@ static void set_next_task_stop(struct rq *rq, struct task_struct *stop, bool fir stop->se.exec_start =rq_clock_task (rq); } -static struct task_struct *pick_task_stop (struct rq *rq) +static struct task_struct *pick_task_stop (struct rq *rq,struct rq_flags *rf) {if (!sched_stop_runnable (rq))return NULL ;
Signature · 1 line
2.34.1
PATCH v3 5/10 sched: Add a server arg to dl_server_update_idle_time()
In reply to Joel FernandesSince we are adding more servers, make dl_server_update_idle_time() accept a server argument than a specific server.
--- kernel/sched/deadline.c | 17 +++++++++-------- kernel/sched/fair.c | 2 +- kernel/sched/idle.c | 2 +- kernel/sched/sched.h | 3 ++- 4 files changed, 13 insertions(+), 11 deletions(-)
kernel/sched/deadline.c +9 -8
@@ -1609,28 +1609,29 @@ static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64* as time available for the fair server, avoiding a penalty for the * rt scheduler that did not consumed that time. */ -void dl_server_update_idle_time (struct rq *rq,struct task_struct *p) +void dl_server_update_idle_time (struct rq *rq,struct task_struct *p, +struct sched_dl_entity *rq_dl_server) {s64 delta_exec, scaled_delta_exec; -if (!rq->fair_server.dl_defer) +if (!rq_dl_server->dl_defer)return ;/* no need to discount more */ -if (rq->fair_server.runtime <0 ) +if (rq_dl_server->runtime <0 )return ; delta_exec =rq_clock_task (rq) - p->se.exec_start;if (delta_exec <0 )return ; - scaled_delta_exec =dl_scaled_delta_exec (rq, &rq->fair_server, delta_exec); + scaled_delta_exec =dl_scaled_delta_exec (rq, rq_dl_server, delta_exec); - rq->fair_server.runtime -= scaled_delta_exec; + rq_dl_server->runtime -= scaled_delta_exec; -if (rq->fair_server.runtime <0 ) { - rq->fair_server.dl_defer_running =0 ; - rq->fair_server.runtime =0 ; +if (rq_dl_server->runtime <0 ) { + rq_dl_server->dl_defer_running =0 ; + rq_dl_server->runtime =0 ; } p->se.exec_start =rq_clock_task (rq);
kernel/sched/fair.c +1 -1
@@ -7016,7 +7016,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)if (!rq_h_nr_queued && rq->cfs.h_nr_queued) {/* Account for idle runtime */ if (!rq->nr_running) -dl_server_update_idle_time (rq, rq->curr); +dl_server_update_idle_time (rq, rq->curr, &rq->fair_server);dl_server_start (&rq->fair_server); }
kernel/sched/idle.c +1 -1
@@ -451,7 +451,7 @@ static void wakeup_preempt_idle(struct rq *rq, struct task_struct *p, int flags)static void put_prev_task_idle (struct rq *rq,struct task_struct *prev,struct task_struct *next) { -dl_server_update_idle_time (rq, prev); +dl_server_update_idle_time (rq, prev, &rq->fair_server);scx_update_idle (rq, false, true); }
kernel/sched/sched.h +2 -1
@@ -386,7 +386,8 @@ extern void dl_server_init(struct sched_dl_entity *dl_se, struct rq *rq, dl_server_pick_f pick_task);extern void dl_server_update_idle_time (struct rq *rq, -struct task_struct *p); +struct task_struct *p, +struct sched_dl_entity *rq_dl_server);extern void fair_server_init (struct rq *rq);extern void __dl_server_attach_root (struct sched_dl_entity *dl_se,struct rq *rq); extern int dl_server_apply_params(struct sched_dl_entity *dl_se,
Signature · 1 line
2.34.1
PATCH v3 6/10 sched/ext: Add a DL server for sched_ext tasks
In reply to Joel Fernandessched_ext currently suffers starvation due to RT. The same workload when converted to EXT can get zero runtime if RT is 100% running, causing EXT processes to stall. Fix it by adding a DL server for EXT.
A kselftest is also provided later to verify:
./runner -t rt_stall
===== START =====
TEST: rt_stall
DESCRIPTION: Verify that RT tasks cannot stall SCHED_EXT tasks OUTPUT:
TAP version 13
1..1
ok 1 PASS: CFS task got more than 4.00% of runtime
--- kernel/sched/core.c | 3 ++ kernel/sched/deadline.c | 2 +- kernel/sched/ext.c | 62 +++++++++++++++++++++++++++++++++++++++-- kernel/sched/sched.h | 2 ++ 4 files changed, 66 insertions(+), 3 deletions(-)
kernel/sched/core.c +3 -0
@@ -8645,6 +8645,9 @@ void __init sched_init(void)hrtick_rq_init (rq);atomic_set (&rq->nr_iowait,0 );fair_server_init (rq); +#ifdef CONFIG_SCHED_CLASS_EXT +ext_server_init (rq); +#endif #ifdef CONFIG_SCHED_CORE rq->core = rq;
kernel/sched/deadline.c +1 -1
@@ -1570,7 +1570,7 @@ static void update_curr_dl_se(struct rq *rq, struct sched_dl_entity *dl_se, s64* The fair server (sole dl_server) does not account for real-time * workload because it is running fair work. */ -if (dl_se == &rq->fair_server) +if (dl_se == &rq->fair_server || dl_se == &rq->ext_server)return ;#ifdef CONFIG_RT_GROUP_SCHED
kernel/sched/ext.c +60 -2
98 lines not on this page · raw message
kernel/sched/sched.h +2 -0
@@ -389,6 +389,7 @@ extern void dl_server_update_idle_time(struct rq *rq,struct task_struct *p, struct sched_dl_entity *rq_dl_server);extern void fair_server_init (struct rq *rq); +extern void ext_server_init (struct rq *rq);extern void __dl_server_attach_root (struct sched_dl_entity *dl_se,struct rq *rq);extern int dl_server_apply_params (struct sched_dl_entity *dl_se,u64 runtime,u64 period,bool init);
@@ -1137,6 +1138,7 @@ struct rq {#endif struct sched_dl_entity fair_server; +struct sched_dl_entity ext_server;#ifdef CONFIG_FAIR_GROUP_SCHED /* list of leaf cfs_rq on this CPU: */
Signature · 1 line
2.34.1
PATCH v3 7/10 sched/debug: Add support to change sched_ext server params
In reply to Joel FernandesWhen a sched_ext server is loaded, tasks in CFS are converted to run in sched_ext class. Add support to modify the ext server parameters similar to how the fair server parameters are modified.
Re-use common code between ext and fair servers as needed.
--- kernel/sched/debug.c | 160 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 135 insertions(+), 25 deletions(-)
kernel/sched/debug.c +135 -25
@@ -341,14 +341,16 @@ enum dl_param { DL_PERIOD, }; -static unsigned long fair_server_period_max = (1UL <<22 ) *NSEC_PER_USEC ;/* ~4 seconds */ -static unsigned long fair_server_period_min = (100 ) *NSEC_PER_USEC ;/* 100 us */ +static unsigned long dl_server_period_max = (1UL <<22 ) *NSEC_PER_USEC ;/* ~4 seconds */ +static unsigned long dl_server_period_min = (100 ) *NSEC_PER_USEC ;/* 100 us */ -static ssize_t sched_fair_server_write (struct file *filp,const char __user *ubuf, -size_t cnt,loff_t *ppos,enum dl_param param) +static ssize_t sched_server_write_common (struct file *filp,const char __user *ubuf, +size_t cnt,loff_t *ppos,enum dl_param param, +void *server) {long cpu = (long ) ((struct seq_file *) filp->private_data)->private;struct rq *rq =cpu_rq (cpu); +struct sched_dl_entity *dl_se = (struct sched_dl_entity *)server;bool was_active = false;u64 runtime, period;int retval =0 ;
@@ -360,8 +362,8 @@ static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubureturn err; scoped_guard (rq_lock_irqsave, rq) { - runtime = rq->fair_server.dl_runtime; - period = rq->fair_server.dl_period; + runtime = dl_se->dl_runtime; + period = dl_se->dl_period;switch (param) {case DL_RUNTIME :
@@ -377,25 +379,30 @@ static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubu }if (runtime > period || - period > fair_server_period_max || - period < fair_server_period_min) { + period > dl_server_period_max || + period < dl_server_period_min) {return -EINVAL ; } -if (dl_server_active (&rq->fair_server)) { +if (dl_server_active (dl_se)) { was_active = true;update_rq_clock (rq); -dl_server_stop (&rq->fair_server); +dl_server_stop (dl_se); } - retval =dl_server_apply_params (&rq->fair_server, runtime, period,0 ); + retval =dl_server_apply_params (dl_se, runtime, period,0 ); -if (!runtime) -printk_deferred ("Fair server disabled in CPU %d, system may crash due to starvation.\n" , -cpu_of (rq)); +if (!runtime) { +if (server == &rq->fair_server) +printk_deferred ("Fair server disabled on CPU %d, system may crash due to starvation.\n" , +cpu_of (rq)); +else +printk_deferred ("Ext server disabled on CPU %d, system may crash due to starvation.\n" , +cpu_of (rq)); + }if (was_active) -dl_server_start (&rq->fair_server); +dl_server_start (dl_se);if (retval <0 )return retval;
@@ -405,36 +412,46 @@ static ssize_t sched_fair_server_write(struct file *filp, const char __user *ubureturn cnt; } -static size_t sched_fair_server_show (struct seq_file *m,void *v,enum dl_param param) + + +static size_t sched_server_show_common (struct seq_file *m,void *v,enum dl_param param, +void *server) { -unsigned long cpu = (unsigned long ) m->private; -struct rq *rq =cpu_rq (cpu); +struct sched_dl_entity *dl_se = (struct sched_dl_entity *)server;u64 value;switch (param) {case DL_RUNTIME : - value = rq->fair_server.dl_runtime; + value = dl_se->dl_runtime;break ;case DL_PERIOD : - value = rq->fair_server.dl_period; + value = dl_se->dl_period;break ; }seq_printf (m,"%llu\n" , value);return 0 ; - } + +static ssize_t sched_fair_server_runtime_write (struct file *filp,const char __user *ubuf,size_t cnt,loff_t *ppos) { -return sched_fair_server_write (filp, ubuf, cnt, ppos,DL_RUNTIME ); +long cpu = (long ) ((struct seq_file *) filp->private_data)->private; +struct rq *rq =cpu_rq (cpu); + +return sched_server_write_common (filp, ubuf, cnt, ppos,DL_RUNTIME , + &rq->fair_server); }static int sched_fair_server_runtime_show (struct seq_file *m,void *v) { -return sched_fair_server_show (m, v,DL_RUNTIME ); +unsigned long cpu = (unsigned long ) m->private; +struct rq *rq =cpu_rq (cpu); + +return sched_server_show_common (m, v,DL_RUNTIME , &rq->fair_server); }static int sched_fair_server_runtime_open (struct inode *inode,struct file *filp)
@@ -450,16 +467,55 @@ static const struct file_operations fair_server_runtime_fops = { .release = single_release, }; +static ssize_t +sched_ext_server_runtime_write (struct file *filp,const char __user *ubuf, +size_t cnt,loff_t *ppos) +{ +long cpu = (long ) ((struct seq_file *) filp->private_data)->private; +struct rq *rq =cpu_rq (cpu); + +return sched_server_write_common (filp, ubuf, cnt, ppos,DL_RUNTIME , + &rq->ext_server); +} + +static int sched_ext_server_runtime_show (struct seq_file *m,void *v) +{ +unsigned long cpu = (unsigned long ) m->private; +struct rq *rq =cpu_rq (cpu); + +return sched_server_show_common (m, v,DL_RUNTIME , &rq->ext_server); +} + +static int sched_ext_server_runtime_open (struct inode *inode,struct file *filp) +{ +return single_open (filp, sched_ext_server_runtime_show, inode->i_private); +} + +static const struct file_operations ext_server_runtime_fops = { + .open = sched_ext_server_runtime_open, + .write = sched_ext_server_runtime_write, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +static ssize_t sched_fair_server_period_write (struct file *filp,const char __user *ubuf,size_t cnt,loff_t *ppos) { -return sched_fair_server_write (filp, ubuf, cnt, ppos,DL_PERIOD ); +long cpu = (long ) ((struct seq_file *) filp->private_data)->private; +struct rq *rq =cpu_rq (cpu); + +return sched_server_write_common (filp, ubuf, cnt, ppos,DL_PERIOD , + &rq->fair_server); }static int sched_fair_server_period_show (struct seq_file *m,void *v) { -return sched_fair_server_show (m, v,DL_PERIOD ); +unsigned long cpu = (unsigned long ) m->private; +struct rq *rq =cpu_rq (cpu); + +return sched_server_show_common (m, v,DL_PERIOD , &rq->fair_server); }static int sched_fair_server_period_open (struct inode *inode,struct file *filp)
@@ -475,6 +531,38 @@ static const struct file_operations fair_server_period_fops = { .release = single_release, }; +static ssize_t +sched_ext_server_period_write (struct file *filp,const char __user *ubuf, +size_t cnt,loff_t *ppos) +{ +long cpu = (long ) ((struct seq_file *) filp->private_data)->private; +struct rq *rq =cpu_rq (cpu); + +return sched_server_write_common (filp, ubuf, cnt, ppos,DL_PERIOD , + &rq->ext_server); +} + +static int sched_ext_server_period_show (struct seq_file *m,void *v) +{ +unsigned long cpu = (unsigned long ) m->private; +struct rq *rq =cpu_rq (cpu); + +return sched_server_show_common (m, v,DL_PERIOD , &rq->ext_server); +} + +static int sched_ext_server_period_open (struct inode *inode,struct file *filp) +{ +return single_open (filp, sched_ext_server_period_show, inode->i_private); +} + +static const struct file_operations ext_server_period_fops = { + .open = sched_ext_server_period_open, + .write = sched_ext_server_period_write, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; +static struct dentry *debugfs_sched;static void debugfs_fair_server_init (void )
@@ -498,6 +586,27 @@ static void debugfs_fair_server_init(void) } } +static void debugfs_ext_server_init (void ) +{ +struct dentry *d_ext; +unsigned long cpu; + + d_ext =debugfs_create_dir ("ext_server" , debugfs_sched); +if (!d_ext) +return ; + +for_each_possible_cpu (cpu) { +struct dentry *d_cpu; +char buf[32 ]; + +snprintf (buf,sizeof (buf),"cpu%lu" , cpu); + d_cpu =debugfs_create_dir (buf, d_ext); + +debugfs_create_file ("runtime" ,0644 , d_cpu, (void *) cpu, &ext_server_runtime_fops); +debugfs_create_file ("period" ,0644 , d_cpu, (void *) cpu, &ext_server_period_fops); + } +} +static __init int sched_init_debug (void ) {struct dentry __maybe_unused *numa;
@@ -538,6 +647,7 @@ static __init int sched_init_debug(void)debugfs_create_file ("debug" ,0444 , debugfs_sched,NULL , &sched_debug_fops);debugfs_fair_server_init (); +debugfs_ext_server_init ();return 0 ; }
Signature · 1 line
2.34.1
PATCH v3 8/10 sched/deadline: Add support to remove DL server bandwidth
In reply to Joel FernandesThe DL server for sched_ext will have its bandwidth removed when sched_ext is unloaded. Add support to DEADLINE for this, so that the sched_ext DL server may do so.
--- kernel/sched/deadline.c | 55 +++++++++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 1 + 2 files changed, 56 insertions(+)
kernel/sched/deadline.c +55 -0
@@ -1752,6 +1752,61 @@ int dl_server_apply_params(struct sched_dl_entity *dl_se, u64 runtime, u64 perioreturn retval; } +/** +* dl_server_remove_params - Remove bandwidth reservation for a DL server +* @dl_se: The DL server entity to remove bandwidth for +* +* This function removes the bandwidth reservation for a DL server entity, +* cleaning up all bandwidth accounting and server state. +* +* Returns: 0 on success, negative error code on failure +*/ +int dl_server_remove_params (struct sched_dl_entity *dl_se) +{ +struct rq *rq = dl_se->rq; +int cpu =cpu_of (rq); +struct dl_bw *dl_b; +int cpus; + +if (!dl_se->dl_runtime) +return 0 ;/* Already disabled */ + +/* +* First dequeue if still queued. It should not be queued since +* we call this only after the last dl_server_stop(). +*/ +if (WARN_ON_ONCE (on_dl_rq (dl_se))) +dequeue_dl_entity (dl_se,DEQUEUE_SLEEP ); + +/* Cancel any pending timers */ +hrtimer_try_to_cancel (&dl_se->dl_timer); +hrtimer_try_to_cancel (&dl_se->inactive_timer); + +/* Remove bandwidth from both runqueue and root domain accounting */ + dl_b =dl_bw_of (cpu); +guard (raw_spinlock)(&dl_b->lock); + cpus =dl_bw_cpus (cpu); + +sub_rq_bw (dl_se, &rq->dl); +__dl_sub (dl_b, dl_se->dl_bw, cpus); + +/* +* If server was active and consuming bandwidth, remove it from +* running bandwidth accounting. This should not happen because +* we call this only after the last dl_server_stop(). +*/ +if (WARN_ON_ONCE (!dl_se->dl_non_contending)) +sub_running_bw (dl_se, &rq->dl); + +/* +* Clear all server parameters. This will also clear ->dl_server so +* the next dl_server_apply_params() will reconfigure the server. +*/ +__dl_clear_params (dl_se); + +return 0 ; +} +/* * Update the current task's runtime statistics (provided it is still * a -deadline task and has not been removed from the dl_rq).
kernel/sched/sched.h +1 -0
@@ -393,6 +393,7 @@ extern void ext_server_init(struct rq *rq);extern void __dl_server_attach_root (struct sched_dl_entity *dl_se,struct rq *rq);extern int dl_server_apply_params (struct sched_dl_entity *dl_se,u64 runtime,u64 period,bool init); +extern int dl_server_remove_params (struct sched_dl_entity *dl_se);static inline bool dl_server_active (struct sched_dl_entity *dl_se) {
Signature · 1 line
2.34.1
PATCH v3 9/10 sched/ext: Relinquish DL server reservations when not needed
In reply to Joel FernandesI tested loading a test SCX program and verifying the bandwidth both before and after applying the patch:
Without patch:
Before loading scx:
.dl_bw->total_bw : 1887408
After unloading scx:
.dl_bw->total_bw : 3774816
After patch:
Before loading scx:
.dl_bw->total_bw : 1887408
After unloading scx:
.dl_bw->total_bw : 1887408
--- kernel/sched/deadline.c | 11 ++--------- kernel/sched/ext.c | 44 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 13 deletions(-)
kernel/sched/deadline.c +2 -9
@@ -1786,18 +1786,11 @@ int dl_server_remove_params(struct sched_dl_entity *dl_se) dl_b =dl_bw_of (cpu);guard (raw_spinlock)(&dl_b->lock); cpus =dl_bw_cpus (cpu); - +if (dl_se->dl_non_contending) +sub_running_bw (dl_se, &rq->dl);sub_rq_bw (dl_se, &rq->dl);__dl_sub (dl_b, dl_se->dl_bw, cpus); -/* -* If server was active and consuming bandwidth, remove it from -* running bandwidth accounting. This should not happen because -* we call this only after the last dl_server_stop(). -*/ -if (WARN_ON_ONCE (!dl_se->dl_non_contending)) -sub_running_bw (dl_se, &rq->dl); -/* * Clear all server parameters. This will also clear ->dl_server so * the next dl_server_apply_params() will reconfigure the server.
kernel/sched/ext.c +40 -4
59 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 10/10 selftests/sched_ext: Add test for sched_ext dl_server
In reply to Joel FernandesFrom: Andrea Righi <[email protected]>
Add a selftest to validate the correct behavior of the deadline server for the ext_sched_class.
[ Joel: Replaced occurences of CFS in the test with EXT. ]
--- tools/testing/selftests/sched_ext/Makefile | 1 + .../selftests/sched_ext/rt_stall.bpf.c | 23 ++ tools/testing/selftests/sched_ext/rt_stall.c | 213 ++++++++++++++++++ 3 files changed, 237 insertions(+) create mode 100644 tools/testing/selftests/sched_ext/rt_stall.bpf.c create mode 100644 tools/testing/selftests/sched_ext/rt_stall.c
tools/testing/selftests/sched_ext/Makefile +1 -0
@@ -181,6 +181,7 @@ auto-test-targets := \ select_cpu_dispatch_bad_dsq \ select_cpu_dispatch_dbl_dsp \ select_cpu_vtime \ + rt_stall \ test_example \ testcase-targets := $(addsuffix .o,$(addprefix $(SCXOBJ_DIR)/,$(auto-test-targets)))
tools/testing/selftests/sched_ext/rt_stall.bpf.c new file +23 -0
@@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* A scheduler that verified if RT tasks can stall SCHED_EXT tasks. +* +* Copyright (c) 2025 NVIDIA Corporation. +*/ + +#include <scx/common.bpf.h> + +char _license[] SEC("license") = "GPL"; + +UEI_DEFINE (uei); + +void BPF_STRUCT_OPS (rt_stall_exit ,struct scx_exit_info *ei) +{ +UEI_RECORD (uei, ei); +} + +SEC(".struct_ops.link") +struct sched_ext_ops rt_stall_ops = { + .exit = (void *)rt_stall_exit, + .name ="rt_stall" , +};
tools/testing/selftests/sched_ext/rt_stall.c new file +213 -0
213 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 6 lines · Joel Fernandes
sched_exttasks currently are starved by RT hoggers especially since RT throttling was replaced by deadline servers to boost only CFS tasks. Several users in the community have reported issues with RT stallingsched_exttasks. Add asched_extdeadline server as well so thatsched_exttasks are also boosted and do not suffer starvation.
Quoted 7 lines
A kselftest is also provided to verify the starvation issues are now fixed.
Btw, there is still something funky going on with CPU hotplug and the relinquish patch. Sometimes the sched_ext's hotplug self-test locks up (./runner -t hotplug). Reverting that patch fixes it, so I am suspecting something is off in
dl_server_remove_params()when it is being called on offline CPUs.
I think I got somewhere here with this sched_ext hotplug test but still not there yet. Juri, Andrea, Tejun, can you take a look at the below when you get a chance?
In the hotplug test, when the CPU is brought online, I see the following warning fire [1]. Basically, dl_server_apply_params() fails with -EBUSY due to overflow checks.
@@ -1657,8 +1657,7 @@ void dl_server_start(struct sched_dl_entity *dl_se)
u64 runtime = 50 * NSEC_PER_MSEC;
u64 period = 1000 * NSEC_PER_MSEC;- dl_server_apply_params(dl_se, runtime, period, 1);
-
+ WARN_ON_ONCE(dl_server_apply_params(dl_se, runtime, period, 1));
dl_se->dl_server = 1;
dl_se->dl_defer = 1;
setup_new_dl_entity(dl_se);I dug deeper, and it seems CPU 1 was previously brought offline and then online before the warning happened during *that onlining*. During the onlining, enqueue_task_scx() -> dl_server_start() was called but dl_server_apply_params() returned -EBUSY.
In dl_server_apply_params() -> __dl_overflow(), it appears dl_bw_cpus()=0 and cap=0. That is really odd and probably the reason for warning. Is that because the CPU was offlined earlier and is not yet attached to the root domain?
The problem also comes down to why does this happen only when calling my dl_server_remove_params() only and not otherwise, and why on earth is dl_bw_cpus() returning 0. There's at least 2 other CPUs online at the time.
Anyway, other than this mystery, I fixed all other bandwidth-related warnings due to dl_server_remove_params() and the updated patch below [2].
[1] Warning:
[ 11.878005] DL server bandwidth overflow on CPU 1: dl_b->bw=996147, cap=0,
total_bw=0, old_bw=0, new_bw=52428, dl_bw_cpus=0
[ 11.878356] ------------[ cut here ]------------
[ 11.878528] WARNING: CPU: 0 PID: 145 at
kernel/sched/deadline.c:1670 dl_server_start+0x96/0xa0
[ 11.879400] Sched_ext: hotplug_cbs (enabled+all), task: runnable_at=+0ms[ 11.879404] RIP: 0010:dl_server_start+0x96/0xa0 [ 11.879732] Code: 53 10 75 1d 49 8b 86 10 0c 00 00 48 8b [ 11.882510] Call Trace: [ 11.882592] <TASK> [ 11.882685] enqueue_task_scx+0x190/0x280 [ 11.882802] ttwu_do_activate+0xaa/0x2a0 [ 11.882925] try_to_wake_up+0x371/0x600 [ 11.883047] cpuhp_bringup_ap+0xd6/0x170
[ 11.883172] cpuhp_invoke_callback+0x142/0x540
[ 11.883327] _cpu_up+0x15b/0x270 [ 11.883450] cpu_up+0x52/0xb0 [ 11.883576] cpu_subsys_online+0x32/0x120 [ 11.883704] online_store+0x98/0x130 [ 11.883824] kernfs_fop_write_iter+0xeb/0x170 [ 11.883972] vfs_write+0x2c7/0x430
[ 11.884091] ksys_write+0x70/0xe0 [ 11.884209] do_syscall_64+0xd6/0x250 [ 11.884327] ? clear_bhb_loop+0x40/0x90
[ 11.884443] entry_SYSCALL_64_after_hwframe+0x77/0x7f
[2]: Updated patch "sched/ext: Relinquish DL server reservations when not needed":
https://git.kernel.org/pub/scm/linux/kernel/git/jfern/linux.git/commit/?h=sched/scx-dlserver-boost-rebase&id=56581c2a6bb8e78593df80ad47520a8399055eae
thanks,
- Joel
Quoted 40 lines
v2->v3:
- Removed code duplication in debugfs. Made ext interface separate.
- Fixed issue whererq_lock_irqsavewas not used in the relinquish patch.
- Fixed running bw accounting issue indl_server_remove_params.Link to v1: https://lore.kernel.org/all/[email protected]/
Link to v2: https://lore.kernel.org/all/[email protected]/Andrea Righi (1):
selftests/sched_ext: Add test forsched_extdl_serverJoel Fernandes (9):
sched/debug: Fix updating of ppos on server write ops sched/debug: Stop and start server based on if it was active sched/deadline: Clear the defer params
sched: Add support to pick functions to take rf
sched: Add a server arg todl_server_update_idle_time()sched/ext: Add a DL server forsched_exttasks sched/debug: Add support to changesched_extserver params sched/deadline: Add support to remove DL server bandwidth sched/ext: Relinquish DL server reservations when not neededinclude/linux/sched.h | 2 +- kernel/sched/core.c | 19 +- kernel/sched/deadline.c | 78 +++++-- kernel/sched/debug.c | 171 +++++++++++--- kernel/sched/ext.c | 108 ++++++++- kernel/sched/fair.c | 15 +- kernel/sched/idle.c | 4 +- kernel/sched/rt.c | 2 +- kernel/sched/sched.h | 13 +- kernel/sched/stop_task.c | 2 +- tools/testing/selftests/sched_ext/Makefile | 1 + .../selftests/sched_ext/rt_stall.bpf.c | 23 ++ tools/testing/selftests/sched_ext/rt_stall.c | 213 ++++++++++++++++++ 13 files changed, 579 insertions(+), 72 deletions(-) create mode 100644 tools/testing/selftests/sched_ext/rt_stall.bpf.c create mode 100644 tools/testing/selftests/sched_ext/rt_stall.c
Quoted 17 lines · Joel Fernandes
Quoted 6 lines · Joel Fernandes
sched_exttasks currently are starved by RT hoggers especially since RT throttling was replaced by deadline servers to boost only CFS tasks. Several users in the community have reported issues with RT stallingsched_exttasks. Add asched_extdeadline server as well so thatsched_exttasks are also boosted and do not suffer starvation.Quoted 7 lines
A kselftest is also provided to verify the starvation issues are now fixed.
Btw, there is still something funky going on with CPU hotplug and the relinquish patch. Sometimes the sched_ext's hotplug self-test locks up (./runner -t hotplug). Reverting that patch fixes it, so I am suspecting something is off in
dl_server_remove_params()when it is being called on offline CPUs.
Quoted 3 lines
I think I got somewhere here with this
sched_exthotplug test but still not there yet. Juri, Andrea, Tejun, can you take a look at the below when you get a chance?
The following patch makes the sched_ext hotplug test reliably pass for me now. Thoughts?
From: Joel Fernandes <[email protected]>
Subject: [PATCH] sched/deadline: Prevent setting server as started if params
couldn't be applied
The following call trace fails to set dl_server_apply_params() as dl_bw_cpus() is 0 during CPU onlining in the below path.
[ 11.878356] ------------[ cut here ]------------ [ 11.882592] <TASK> [ 11.882685] enqueue_task_scx+0x190/0x280 [ 11.882802] ttwu_do_activate+0xaa/0x2a0 [ 11.882925] try_to_wake_up+0x371/0x600 [ 11.883047] cpuhp_bringup_ap+0xd6/0x170
[ 11.883172] cpuhp_invoke_callback+0x142/0x540
[ 11.883327] _cpu_up+0x15b/0x270 [ 11.883450] cpu_up+0x52/0xb0 [ 11.883576] cpu_subsys_online+0x32/0x120 [ 11.883704] online_store+0x98/0x130 [ 11.883824] kernfs_fop_write_iter+0xeb/0x170 [ 11.883972] vfs_write+0x2c7/0x430
[ 11.884091] ksys_write+0x70/0xe0 [ 11.884209] do_syscall_64+0xd6/0x250 [ 11.884327] ? clear_bhb_loop+0x40/0x90
[ 11.884443] entry_SYSCALL_64_after_hwframe+0x77/0x7f
It seems too early to start the server. Simply defer the starting of the server to the next enqueue if dl_server_apply_params() returns an error. In any case, we should not pretend like the server started and it does seem to mess up with the sched_ext CPU hotplug test.
With this, the sched_ext hotplug test reliably passes.
--- kernel/sched/deadline.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/sched/deadline.c +3 -3
@@ -1657,8 +1657,8 @@ void dl_server_start(struct sched_dl_entity *dl_se)u64 runtime =50 *NSEC_PER_MSEC ;u64 period =1000 *NSEC_PER_MSEC ; -dl_server_apply_params (dl_se, runtime, period,1 ); - +if (dl_server_apply_params (dl_se, runtime, period,1 )) +return ; dl_se->dl_server =1 ; dl_se->dl_defer =1 ;setup_new_dl_entity (dl_se);
@@ -1675,7 +1675,7 @@ void dl_server_start(struct sched_dl_entity *dl_se)void dl_server_stop (struct sched_dl_entity *dl_se) { -if (!dl_se->dl_runtime) +if (!dl_se->dl_runtime || !dl_se->dl_server_active)return ;dequeue_dl_entity (dl_se,DEQUEUE_SLEEP );
Andrea Righi
reviewerHi Joel,
Quoted 20 lines · Joel Fernandes
Quoted 17 lines · Joel Fernandes
Quoted 13 lines · Joel Fernandes
sched_exttasks currently are starved by RT hoggers especially since RT throttling was replaced by deadline servers to boost only CFS tasks. Several users in the community have reported issues with RT stallingsched_exttasks. Add asched_extdeadline server as well so thatsched_exttasks are also boosted and do not suffer starvation.A kselftest is also provided to verify the starvation issues are now fixed.
Btw, there is still something funky going on with CPU hotplug and the relinquish patch. Sometimes the sched_ext's hotplug self-test locks up (./runner -t hotplug). Reverting that patch fixes it, so I am suspecting something is off in
dl_server_remove_params()when it is being called on offline CPUs.
Quoted 6 lines
Quoted 3 lines
I think I got somewhere here with this
sched_exthotplug test but still not there yet. Juri, Andrea, Tejun, can you take a look at the below when you get a chance?The following patch makes the
sched_exthotplug test reliably pass for me now. Thoughts?
For me it gets stuck here, when the hotplug test tries to bring the CPU offline:
TEST: hotplug
DESCRIPTION: Verify hotplug behavior
OUTPUT:
[ 5.042497] smpboot: CPU 1 is now offline [ 5.069691] sched_ext: BPF scheduler "hotplug_cbs" enabled [ 5.108705] smpboot: Booting Node 0 Processor 1 APIC 0x1 [ 5.149484] sched_ext: BPF scheduler "hotplug_cbs" disabled (unregistered from BPF) EXIT: unregistered from BPF (hotplug event detected (1 going online)) [ 5.204500] sched_ext: BPF scheduler "hotplug_cbs" enabled
Failed to bring CPU offline (Device or resource busy)
However, if I don't stop rq->fair_server in the scx_switching_all case everything seems to work (which I still don't understand why).
I didn't have much time to look at this today, I'll investigate more tomorrow.
-Andrea
Quoted 66 lines
From: Joel Fernandes <[email protected]>
Subject: [PATCH] sched/deadline: Prevent setting server as started if params
couldn't be appliedThe following call trace fails to set
dl_server_apply_params()asdl_bw_cpus()is 0 during CPU onlining in the below path.[ 11.878356] ------------[ cut here ]------------ [ 11.882592] <TASK> [ 11.882685] enqueue_task_scx+0x190/0x280 [ 11.882802] ttwu_do_activate+0xaa/0x2a0 [ 11.882925] try_to_wake_up+0x371/0x600 [ 11.883047] cpuhp_bringup_ap+0xd6/0x170[ 11.883172] cpuhp_invoke_callback+0x142/0x540[ 11.883327] _cpu_up+0x15b/0x270 [ 11.883450] cpu_up+0x52/0xb0 [ 11.883576] cpu_subsys_online+0x32/0x120 [ 11.883704] online_store+0x98/0x130 [ 11.883824] kernfs_fop_write_iter+0xeb/0x170 [ 11.883972] vfs_write+0x2c7/0x430[ 11.884091] ksys_write+0x70/0xe0 [ 11.884209] do_syscall_64+0xd6/0x250 [ 11.884327] ? clear_bhb_loop+0x40/0x90[ 11.884443] entry_SYSCALL_64_after_hwframe+0x77/0x7fIt seems too early to start the server. Simply defer the starting of the server to the next enqueue if
dl_server_apply_params()returns an error. In any case, we should not pretend like the server started and it does seem to mess up with thesched_extCPU hotplug test.With this, the
sched_exthotplug test reliably passes.Signed-off-by Joel Fernandes <[email protected]>--- kernel/sched/deadline.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)kernel/sched/deadline.c +3
-3@@ -1657,8 +1657,8 @@ void dl_server_start(struct sched_dl_entity *dl_se)u64 runtime =50 *NSEC_PER_MSEC ;u64 period =1000 *NSEC_PER_MSEC ; -dl_server_apply_params (dl_se, runtime, period,1 ); - +if (dl_server_apply_params (dl_se, runtime, period,1 )) +return ; dl_se->dl_server =1 ; dl_se->dl_defer =1 ;setup_new_dl_entity (dl_se);@@ -1675,7 +1675,7 @@ void dl_server_start(struct sched_dl_entity *dl_se)void dl_server_stop (struct sched_dl_entity *dl_se) { -if (!dl_se->dl_runtime) +if (!dl_se->dl_runtime || !dl_se->dl_server_active)return ;dequeue_dl_entity (dl_se,DEQUEUE_SLEEP );