Skip to content

Commit 30dd3b1

Browse files
Henry Huanghtejun
authored andcommitted
sched_ext: keep running prev when prev->scx.slice != 0
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@antgroup.com> Acked-by: Andrea Righi <arighi@nvidia.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent ce2b93f commit 30dd3b1

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

kernel/sched/ext.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,6 +2747,7 @@ static int balance_one(struct rq *rq, struct task_struct *prev)
27472747
{
27482748
struct scx_dsp_ctx *dspc = this_cpu_ptr(scx_dsp_ctx);
27492749
bool prev_on_scx = prev->sched_class == &ext_sched_class;
2750+
bool prev_on_rq = prev->scx.flags & SCX_TASK_QUEUED;
27502751
int nr_loops = SCX_DSP_MAX_LOOPS;
27512752

27522753
lockdep_assert_rq_held(rq);
@@ -2779,8 +2780,7 @@ static int balance_one(struct rq *rq, struct task_struct *prev)
27792780
* See scx_ops_disable_workfn() for the explanation on the
27802781
* bypassing test.
27812782
*/
2782-
if ((prev->scx.flags & SCX_TASK_QUEUED) &&
2783-
prev->scx.slice && !scx_rq_bypassing(rq)) {
2783+
if (prev_on_rq && prev->scx.slice && !scx_rq_bypassing(rq)) {
27842784
rq->scx.flags |= SCX_RQ_BAL_KEEP;
27852785
goto has_tasks;
27862786
}
@@ -2813,6 +2813,10 @@ static int balance_one(struct rq *rq, struct task_struct *prev)
28132813

28142814
flush_dispatch_buf(rq);
28152815

2816+
if (prev_on_rq && prev->scx.slice) {
2817+
rq->scx.flags |= SCX_RQ_BAL_KEEP;
2818+
goto has_tasks;
2819+
}
28162820
if (rq->scx.local_dsq.nr)
28172821
goto has_tasks;
28182822
if (consume_global_dsq(rq))
@@ -2838,8 +2842,7 @@ static int balance_one(struct rq *rq, struct task_struct *prev)
28382842
* Didn't find another task to run. Keep running @prev unless
28392843
* %SCX_OPS_ENQ_LAST is in effect.
28402844
*/
2841-
if ((prev->scx.flags & SCX_TASK_QUEUED) &&
2842-
(!static_branch_unlikely(&scx_ops_enq_last) ||
2845+
if (prev_on_rq && (!static_branch_unlikely(&scx_ops_enq_last) ||
28432846
scx_rq_bypassing(rq))) {
28442847
rq->scx.flags |= SCX_RQ_BAL_KEEP;
28452848
goto has_tasks;

0 commit comments

Comments
 (0)