Commit 1862d8e2 authored by Peter Zijlstra's avatar Peter Zijlstra
Browse files

sched: Fix faulty assertion in sched_change_end()



Commit 47efe2dd ("sched/core: Add assertions to QUEUE_CLASS") added an
assert to sched_change_end() verifying that a class demotion would result in a
reschedule.

As it turns out; rt_mutex_setprio() does not force a resched on class
demontion. Furthermore, this is only relevant to running tasks.

Change the warning into a reschedule and make sure to only do so for running
tasks.

Fixes: 47efe2dd ("sched/core: Add assertions to QUEUE_CLASS")
Reported-by: default avatarNaresh Kamboju <naresh.kamboju@linaro.org>
Tested-by: default avatarLinux Kernel Functional Testing <lkft@linaro.org>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251216141725.GW3707837@noisy.programming.kicks-ass.net
parent 70406964
Loading
Loading
Loading
Loading
+17 −16
Original line number Diff line number Diff line
@@ -10833,23 +10833,24 @@ void sched_change_end(struct sched_change_ctx *ctx)
		if (p->sched_class->switched_to)
			p->sched_class->switched_to(rq, p);

		if (ctx->running) {
			/*
		 * If this was a class promotion; let the old class know it
		 * got preempted. Note that none of the switch*_from() methods
		 * know the new class and none of the switch*_to() methods
		 * know the old class.
			 * If this was a class promotion; let the old class
			 * know it got preempted. Note that none of the
			 * switch*_from() methods know the new class and none
			 * of the switch*_to() methods know the old class.
			 */
		if (ctx->running && sched_class_above(p->sched_class, ctx->class)) {
			if (sched_class_above(p->sched_class, ctx->class)) {
				rq->next_class->wakeup_preempt(rq, p, 0);
				rq->next_class = p->sched_class;
			}

			/*
		 * If this was a degradation in class someone should have set
		 * need_resched by now.
			 * If this was a degradation in class; make sure to
			 * reschedule.
			 */
		WARN_ON_ONCE(sched_class_above(ctx->class, p->sched_class) &&
			     !test_tsk_need_resched(p));
			if (sched_class_above(ctx->class, p->sched_class))
				resched_curr(rq);
		}
	} else {
		p->sched_class->prio_changed(rq, p, ctx->prio);
	}