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

From: Henry Huang
Date: Tue Jan 07 2025 - 00:27:39 EST


When %SCX_OPS_ENQ_LAST is set and prev->scx.slice != 0,
@prev will be dispacthed into the local DSQ in put_prev_task_scx().
However, pick_task_scx() is executed before put_prev_task_scx(),
so it will not pick @prev.
Set %SCX_RQ_BAL_KEEP in balance_one() to ensure that pick_task_scx()
can pick @prev.

Signed-off-by: Henry Huang <henry.hj@xxxxxxxxxxxx>
---
kernel/sched/ext.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 81da76a..5f6eb45 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -2837,10 +2837,15 @@ static int balance_one(struct rq *rq, struct task_struct *prev)
/*
* Didn't find another task to run. Keep running @prev unless
* %SCX_OPS_ENQ_LAST is in effect.
+ *
+ * If %SCX_OPS_ENQ_LAST is set and prev->scx.slice != 0 (configured in ops.dispatch()),
+ * @prev would be dispatched into the local DSQ in put_prev_task_scx()
+ * (excuted after pick_task_scx()). Set %SCX_RQ_BAL_KEEP to ensure that @prev
+ * would be picked in pick_task_scx()
*/
if ((prev->scx.flags & SCX_TASK_QUEUED) &&
(!static_branch_unlikely(&scx_ops_enq_last) ||
- scx_rq_bypassing(rq))) {
+ scx_rq_bypassing(rq) || prev->scx.slice)) {
rq->scx.flags |= SCX_RQ_BAL_KEEP;
goto has_tasks;
}
--
1.8.3.1