sched: Combine the last put_prev_task() and the first set_next_task()

Ensure the last put_prev_task() and the first set_next_task() always
go together.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240813224016.158454756@infradead.org
This commit is contained in:
Peter Zijlstra 2024-08-14 00:25:54 +02:00
parent fd03c5b858
commit 436f3eed5c
3 changed files with 14 additions and 16 deletions

View File

@ -5894,8 +5894,7 @@ __pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
/* Assume the next prioritized class is idle_sched_class */ /* Assume the next prioritized class is idle_sched_class */
if (!p) { if (!p) {
p = pick_task_idle(rq); p = pick_task_idle(rq);
put_prev_task(rq, prev); put_prev_set_next_task(rq, prev, p);
set_next_task_first(rq, p);
} }
/* /*
@ -5926,8 +5925,7 @@ restart:
} else { } else {
p = class->pick_task(rq); p = class->pick_task(rq);
if (p) { if (p) {
put_prev_task(rq, prev); put_prev_set_next_task(rq, prev, p);
set_next_task_first(rq, p);
return p; return p;
} }
} }
@ -6016,13 +6014,8 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
WRITE_ONCE(rq->core_sched_seq, rq->core->core_pick_seq); WRITE_ONCE(rq->core_sched_seq, rq->core->core_pick_seq);
next = rq->core_pick; next = rq->core_pick;
if (next != prev) {
put_prev_task(rq, prev);
set_next_task_first(rq, next);
}
rq->core_pick = NULL; rq->core_pick = NULL;
goto out; goto out_set_next;
} }
prev_balance(rq, prev, rf); prev_balance(rq, prev, rf);
@ -6192,9 +6185,7 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
} }
out_set_next: out_set_next:
put_prev_task(rq, prev); put_prev_set_next_task(rq, prev, next);
set_next_task_first(rq, next);
out:
if (rq->core->core_forceidle_count && next == rq->idle) if (rq->core->core_forceidle_count && next == rq->idle)
queue_core_balance(rq); queue_core_balance(rq);

View File

@ -8819,8 +8819,7 @@ again:
simple: simple:
#endif #endif
put_prev_task(rq, prev); put_prev_set_next_task(rq, prev, p);
set_next_task_fair(rq, p, true);
return p; return p;
idle: idle:

View File

@ -2370,8 +2370,16 @@ static inline void set_next_task(struct rq *rq, struct task_struct *next)
next->sched_class->set_next_task(rq, next, false); next->sched_class->set_next_task(rq, next, false);
} }
static inline void set_next_task_first(struct rq *rq, struct task_struct *next) static inline void put_prev_set_next_task(struct rq *rq,
struct task_struct *prev,
struct task_struct *next)
{ {
WARN_ON_ONCE(rq->curr != prev);
if (next == prev)
return;
prev->sched_class->put_prev_task(rq, prev);
next->sched_class->set_next_task(rq, next, true); next->sched_class->set_next_task(rq, next, true);
} }