]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sched/deadline: Prepare for switched_from() change
authorPeter Zijlstra <peterz@infradead.org>
Thu, 9 Oct 2025 14:09:25 +0000 (16:09 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Thu, 16 Oct 2025 09:13:51 +0000 (11:13 +0200)
Prepare for the sched_class::switch*() methods getting folded into the
change pattern. As a result of that, the location of switched_from
will change slightly. SCHED_DEADLINE is affected by this change in
location:

  OLD                              NEW
|
|  switching_from()
  dequeue_task(); |  dequeue_task()
  put_prev_task(); |  put_prev_task()
|  switched_from()
|
  ... change task ... |  ... change task ...
|
  switching_to(); |  switching_to()
  enqueue_task(); |  enqueue_task()
  set_next_task(); |  set_next_task()
  prev_class->switched_from() |
  switched_to() |  switched_to()
|

Notably, where switched_from() was called *after* the change to the
task, it will get called before it. Specifically, switched_from_dl()
uses dl_task(p) which uses p->prio; which is changed when switching
class (it might be the reason to switch class in case of PI).

When switched_from_dl() gets called, the task will have left the
deadline class and dl_task() must be false, while when doing
dequeue_dl_entity() the task must be a dl_task(), otherwise we'd have
called a different dequeue method.

Reported-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
kernel/sched/deadline.c

index 933bd1f82c7456ec7ea147b7e020d886471a3fd7..fd147a78f7ed2f0907fbdaa6fdba4727e9a13851 100644 (file)
@@ -405,7 +405,7 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se);
  * up, and checks if the task is still in the "ACTIVE non contending"
  * state or not (in the second case, it updates running_bw).
  */
-static void task_non_contending(struct sched_dl_entity *dl_se)
+static void task_non_contending(struct sched_dl_entity *dl_se, bool dl_task)
 {
        struct hrtimer *timer = &dl_se->inactive_timer;
        struct rq *rq = rq_of_dl_se(dl_se);
@@ -444,10 +444,10 @@ static void task_non_contending(struct sched_dl_entity *dl_se)
                } else {
                        struct task_struct *p = dl_task_of(dl_se);
 
-                       if (dl_task(p))
+                       if (dl_task)
                                sub_running_bw(dl_se, dl_rq);
 
-                       if (!dl_task(p) || READ_ONCE(p->__state) == TASK_DEAD) {
+                       if (!dl_task || READ_ONCE(p->__state) == TASK_DEAD) {
                                struct dl_bw *dl_b = dl_bw_of(task_cpu(p));
 
                                if (READ_ONCE(p->__state) == TASK_DEAD)
@@ -2045,7 +2045,7 @@ static void dequeue_dl_entity(struct sched_dl_entity *dl_se, int flags)
         * or "inactive")
         */
        if (flags & DEQUEUE_SLEEP)
-               task_non_contending(dl_se);
+               task_non_contending(dl_se, true);
 }
 
 static void enqueue_task_dl(struct rq *rq, struct task_struct *p, int flags)
@@ -2970,7 +2970,7 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)
         * will reset the task parameters.
         */
        if (task_on_rq_queued(p) && p->dl.dl_runtime)
-               task_non_contending(&p->dl);
+               task_non_contending(&p->dl, false);
 
        /*
         * In case a task is setscheduled out from SCHED_DEADLINE we need to