sched/core: Add assertions to QUEUE_CLASS
Add some checks to the sched_change pattern to validate assumptions around changing classes. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://patch.msgid.link/20251127154725.771691954@infradead.orgmaster
parent
95a0155224
commit
47efe2ddcc
|
|
@ -10782,6 +10782,7 @@ struct sched_change_ctx *sched_change_begin(struct task_struct *p, unsigned int
|
|||
|
||||
*ctx = (struct sched_change_ctx){
|
||||
.p = p,
|
||||
.class = p->sched_class,
|
||||
.flags = flags,
|
||||
.queued = task_on_rq_queued(p),
|
||||
.running = task_current_donor(rq, p),
|
||||
|
|
@ -10812,6 +10813,11 @@ void sched_change_end(struct sched_change_ctx *ctx)
|
|||
|
||||
lockdep_assert_rq_held(rq);
|
||||
|
||||
/*
|
||||
* Changing class without *QUEUE_CLASS is bad.
|
||||
*/
|
||||
WARN_ON_ONCE(p->sched_class != ctx->class && !(ctx->flags & ENQUEUE_CLASS));
|
||||
|
||||
if ((ctx->flags & ENQUEUE_CLASS) && p->sched_class->switching_to)
|
||||
p->sched_class->switching_to(rq, p);
|
||||
|
||||
|
|
@ -10823,6 +10829,13 @@ void sched_change_end(struct sched_change_ctx *ctx)
|
|||
if (ctx->flags & ENQUEUE_CLASS) {
|
||||
if (p->sched_class->switched_to)
|
||||
p->sched_class->switched_to(rq, p);
|
||||
|
||||
/*
|
||||
* If this was a degradation in class someone should have set
|
||||
* need_resched by now.
|
||||
*/
|
||||
WARN_ON_ONCE(sched_class_above(ctx->class, p->sched_class) &&
|
||||
!test_tsk_need_resched(p));
|
||||
} else {
|
||||
p->sched_class->prio_changed(rq, p, ctx->prio);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3968,6 +3968,7 @@ extern void balance_callbacks(struct rq *rq, struct balance_callback *head);
|
|||
struct sched_change_ctx {
|
||||
u64 prio;
|
||||
struct task_struct *p;
|
||||
const struct sched_class *class;
|
||||
int flags;
|
||||
bool queued;
|
||||
bool running;
|
||||
|
|
|
|||
Loading…
Reference in New Issue