Re: [PATCH v1] sched_ext: keep running prev when prev->scx.slice != 0

From: Henry Huang
Date: Tue Jan 07 2025 - 23:14:39 EST


Tue, 7 Jan 2025 11:20:58 -1000, Tejun Heo wrote:
> Update current->scx.slice from ops.dispatch() is the recommended way of
> extending the current execution and the current behavior is just buggy
> especially when scx_ops_enq_last is set.
>
> While the above change fixes the case where ops.dispatch() updates
> current->scx.slice without dispatching any task, it's still theoretically
> wrong in that if ops.dispatch() updates current->scx.slice and dispatches
> tasks, we should keep running current before moving onto other tasks.
>
> To fix this properly, I think what should be done is adding something like
> the following. (untested and we probably should cache SCX_TASK_QUEUED
> testing result). Can you test whether the following fixes the issues you're
> seeing and if so update the patch accordingly?
>
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 19d2699cf638..48deb5d5510e 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -2813,6 +2813,10 @@ static int balance_one(struct rq *rq, struct task_struct *prev)
>
> flush_dispatch_buf(rq);
>
> + if ((prev->scx.flags & SCX_TASK_QUEUED) && prev->scx.slice) {
> + rq->scx.flags |= SCX_RQ_BAL_KEEP;
> + goto has_tasks;
> + }
> if (rq->scx.local_dsq.nr)
> goto has_tasks;
> if (consume_global_dsq(rq))

Thanks, I'll try this. If it works fine, I'll update this patch soon.

--
Henry