[PATCH 02/17] sched/core: Dequeue waking proxy donors before reset
Andrea Righi <[email protected]>
| Newsgroups | dev.linux.lists.sched-ext,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
proxy_needs_return() resets an active donor while holding blocked_lock. proxy_reset_donor() invokes scheduling-class callbacks, adding an unnecessary raw-spinlock nesting. It also presents the waking donor to put_prev_task() as still runnable immediately before block_task() removes it from the runqueue. Split block_task() so the waking donor can first be dequeued from its scheduling class. Release blocked_lock, dequeue the donor while its generic on_rq state still prevents migration, replace all donor references, and only then complete the generic runqueue removal. This follows the normal sleep ordering and avoids transiently re-enqueuing the waking donor. This is a preparatory change to support proxy execution with sched_ext. Signed-off-by: Andrea Righi <[email protected]> --- kernel/sched/core.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e1b597e6bf413..27164afc7b0aa 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2253,7 +2253,8 @@ void deactivate_task(struct rq *rq, struct task_struct *p, int flags) dequeue_task(rq, p, flags); } -static void block_task(struct rq *rq, struct task_struct *p, unsigned long task_state) +static bool dequeue_block_task(struct rq *rq, struct task_struct *p, + unsigned long task_state) { int flags = DEQUEUE_NOCLOCK; @@ -2274,9 +2275,15 @@ static void block_task(struct rq *rq, struct task_struct *p, unsigned long task_ * * Where __schedule() and ttwu() have matching control dependencies. * - * After this, schedule() must not care about p->state any more. + * Once the caller invokes __block_task(), schedule() must not care about + * p->state any more. */ - if (dequeue_task(rq, p, DEQUEUE_SLEEP | flags)) + return dequeue_task(rq, p, DEQUEUE_SLEEP | flags); +} + +static void block_task(struct rq *rq, struct task_struct *p, unsigned long task_state) +{ + if (dequeue_block_task(rq, p, task_state)) __block_task(rq, p); } @@ -3775,6 +3782,8 @@ static inline void proxy_reset_donor(struct rq *rq) */ static inline bool proxy_needs_return(struct rq *rq, struct task_struct *p) { + bool reset_donor = false; + /* * Typically per __set_task_cpu(), task_cpu(p) == p->wake_cpu. * @@ -3798,11 +3807,19 @@ static inline bool proxy_needs_return(struct rq *rq, struct task_struct *p) if (task_current(rq, p)) return false; - /* If we're return migrating the rq->donor, switch it out for idle */ - if (task_current_donor(rq, p)) - proxy_reset_donor(rq); + reset_donor = task_current_donor(rq, p); + } + + if (reset_donor) { + bool dequeued = dequeue_block_task(rq, p, TASK_WAKING); + + /* Keep on_rq set until all donor references have been replaced. */ + proxy_reset_donor(rq); + if (dequeued) + __block_task(rq, p); + } else { + block_task(rq, p, TASK_WAKING); } - block_task(rq, p, TASK_WAKING); return true; } #else /* !CONFIG_SCHED_PROXY_EXEC */ -- 2.55.0