]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sched/ext: Fix scx vs sched_delayed
authorPeter Zijlstra <peterz@infradead.org>
Wed, 30 Oct 2024 10:49:34 +0000 (11:49 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 30 Oct 2024 21:42:12 +0000 (22:42 +0100)
Commit 98442f0ccd82 ("sched: Fix delayed_dequeue vs
switched_from_fair()") forgot about scx :/

Fixes: 98442f0ccd82 ("sched: Fix delayed_dequeue vs switched_from_fair()")
Reported-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Tejun Heo <tj@kernel.org>
Link: https://lkml.kernel.org/r/20241030104934.GK14555@noisy.programming.kicks-ass.net
kernel/sched/ext.c

index 40bdfe84e4f0033ad495c3861cf2ce48363634be..721a75489ff5a07940d4c3faa6c0fdc04a9fb87c 100644 (file)
@@ -4489,11 +4489,16 @@ static void scx_ops_disable_workfn(struct kthread_work *work)
        scx_task_iter_start(&sti);
        while ((p = scx_task_iter_next_locked(&sti))) {
                const struct sched_class *old_class = p->sched_class;
+               const struct sched_class *new_class =
+                       __setscheduler_class(p->policy, p->prio);
                struct sched_enq_and_set_ctx ctx;
 
+               if (old_class != new_class && p->se.sched_delayed)
+                       dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEUE_DELAYED);
+
                sched_deq_and_put_task(p, DEQUEUE_SAVE | DEQUEUE_MOVE, &ctx);
 
-               p->sched_class = __setscheduler_class(p->policy, p->prio);
+               p->sched_class = new_class;
                check_class_changing(task_rq(p), p, old_class);
 
                sched_enq_and_set_task(&ctx);
@@ -5199,12 +5204,17 @@ static int scx_ops_enable(struct sched_ext_ops *ops, struct bpf_link *link)
        scx_task_iter_start(&sti);
        while ((p = scx_task_iter_next_locked(&sti))) {
                const struct sched_class *old_class = p->sched_class;
+               const struct sched_class *new_class =
+                       __setscheduler_class(p->policy, p->prio);
                struct sched_enq_and_set_ctx ctx;
 
+               if (old_class != new_class && p->se.sched_delayed)
+                       dequeue_task(task_rq(p), p, DEQUEUE_SLEEP | DEQUEUE_DELAYED);
+
                sched_deq_and_put_task(p, DEQUEUE_SAVE | DEQUEUE_MOVE, &ctx);
 
                p->scx.slice = SCX_SLICE_DFL;
-               p->sched_class = __setscheduler_class(p->policy, p->prio);
+               p->sched_class = new_class;
                check_class_changing(task_rq(p), p, old_class);
 
                sched_enq_and_set_task(&ctx);