sched_ext: Block donor on rt_mutex_setprio() switch to SCX
Subsystems (2)
PATCH 1/1 sched_ext: Block donor on rt_mutex_setprio() switch to SCX
scx_prepare_setscheduler() and scx_root_enable_workfn() block any retained proxy donor before entering sched_ext so a blocked task is not carried across scheduling classes without sched_ext admission. rt_mutex_setprio() misses this cleanup when PI deboost returns a blocked RT or DL donor back to ext_sched_class.
Expose scx_block_proxy_donor() via scx_prepare_class_switch() in ext.h and invoke it in rt_mutex_setprio() before sched_change when transitioning a task into ext_sched_class. Because rt_mutex_setprio() has already updated rq->clock, calling scx_block_proxy_donor() directly matches scx_prepare_setscheduler() and avoids double clock updates.
Fixes be8be8acb268 ("sched_ext: Block proxy donors before taking control")
Signed-off-by Peng Huang <[email protected]>
--- kernel/sched/core.c | 4 +++- kernel/sched/ext/ext.c | 8 ++++++-- kernel/sched/ext/ext.h | 12 ++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-)
kernel/sched/core.c +3 -1
@@ -7814,8 +7814,10 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task) prev_class = p->sched_class; next_class =__setscheduler_class (p->policy, prio); -if (prev_class != next_class) +if (prev_class != next_class) { +scx_prepare_class_switch (rq, p, next_class); queue_flag |=DEQUEUE_CLASS ; + } scoped_guard (sched_change, p, queue_flag) {/*
kernel/sched/ext/ext.c +6 -2
@@ -26,10 +26,14 @@ DEFINE_RAW_SPINLOCK(scx_sched_lock);/* * Block a retained proxy donor, telling put_prev_task_scx() that the donor is -* about to be dequeued and must not be reenqueued. +* about to be dequeued and must not be reenqueued. Caller holds @p->pi_lock +* and @rq's lock and has already updated @rq's clock. */ -static void scx_block_proxy_donor (struct rq *rq,struct task_struct *p) +void scx_block_proxy_donor (struct rq *rq,struct task_struct *p) { +lockdep_assert_held (&p->pi_lock); +lockdep_assert_rq_held (rq); + rq->scx.flags |=SCX_RQ_PROXY_BLOCKING ;sched_proxy_block_task (rq, p); rq->scx.flags &= ~SCX_RQ_PROXY_BLOCKING ;
kernel/sched/ext/ext.h +12 -0
@@ -19,6 +19,7 @@ void scx_rq_activate(struct rq *rq);void scx_rq_deactivate (struct rq *rq);int scx_check_setscheduler (struct task_struct *p,int policy);void scx_prepare_setscheduler (struct task_struct *p,int policy); +void scx_block_proxy_donor (struct rq *rq,struct task_struct *p);bool task_should_scx (int policy);bool scx_allow_ttwu_queue (const struct task_struct *p);bool __scx_allow_proxy_exec (const struct task_struct *p);
@@ -54,6 +55,14 @@ static inline bool task_on_scx(const struct task_struct *p)return scx_enabled () && p->sched_class == &ext_sched_class; } +static inline void +scx_prepare_class_switch (struct rq *rq,struct task_struct *p, +const struct sched_class *next_class) +{ +if (scx_enabled () && next_class == &ext_sched_class) +scx_block_proxy_donor (rq, p); +} +#ifdef CONFIG_SCHED_CORE bool scx_prio_less (const struct task_struct *a,const struct task_struct *b,bool in_fi);
@@ -73,6 +82,9 @@ static inline void scx_rq_deactivate(struct rq *rq) {}static inline int scx_check_setscheduler (struct task_struct *p,int policy) {return 0 ; }static inline void scx_prepare_setscheduler (struct task_struct *p,int policy) {}static inline bool task_on_scx (const struct task_struct *p) {return false; } +static inline void +scx_prepare_class_switch (struct rq *rq,struct task_struct *p, +const struct sched_class *next_class) {}static inline bool scx_allow_ttwu_queue (const struct task_struct *p) {return true; }static inline bool scx_allow_proxy_exec (const struct task_struct *p) {return true; }static inline void scx_proxy_donor_start (struct rq *rq) {}
Signature · 1 line
2.56.1.750.gf70dc682cf-goog