Skip to content

Commit 7ea98df

Browse files
valschneiderPeter Zijlstra
authored andcommitted
sched/deadline: Add more reschedule cases to prio_changed_dl()
I've been tracking down an issue on a ~5.17ish kernel where: CPUx CPUy <DL task p0 owns an rtmutex M> <p0 depletes its runtime, gets throttled> <rq switches to the idle task> <DL task p1 blocks on M, boost/replenish p0> <No call to resched_curr() happens here> [idle task keeps running here until *something* accidentally sets TIF_NEED_RESCHED] On that kernel, it is quite easy to trigger using rt-tests's deadline_test [1] with the test running on isolated CPUs (this reduces the chance of something unrelated setting TIF_NEED_RESCHED on the idle tasks, making the issue even more obvious as the hung task detector chimes in). I haven't been able to reproduce this using a mainline kernel, even if I revert 2972e30 ("tracing: Make trace_marker{,_raw} stream-like") which gets rid of the lock involved in the above test, *but* I cannot convince myself the issue isn't there from looking at the code. Make prio_changed_dl() issue a reschedule if the current task isn't a deadline one. While at it, ensure a reschedule is emitted when a queued-but-not-current task gets boosted with an earlier deadline that current's. [1]: https://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git Signed-off-by: Valentin Schneider <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Juri Lelli <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 829c165 commit 7ea98df

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

kernel/sched/deadline.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,33 +2663,45 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p)
26632663
static void prio_changed_dl(struct rq *rq, struct task_struct *p,
26642664
int oldprio)
26652665
{
2666-
if (task_on_rq_queued(p) || task_current(rq, p)) {
2666+
if (!task_on_rq_queued(p))
2667+
return;
2668+
26672669
#ifdef CONFIG_SMP
2668-
/*
2669-
* This might be too much, but unfortunately
2670-
* we don't have the old deadline value, and
2671-
* we can't argue if the task is increasing
2672-
* or lowering its prio, so...
2673-
*/
2674-
if (!rq->dl.overloaded)
2675-
deadline_queue_pull_task(rq);
2670+
/*
2671+
* This might be too much, but unfortunately
2672+
* we don't have the old deadline value, and
2673+
* we can't argue if the task is increasing
2674+
* or lowering its prio, so...
2675+
*/
2676+
if (!rq->dl.overloaded)
2677+
deadline_queue_pull_task(rq);
26762678

2679+
if (task_current(rq, p)) {
26772680
/*
26782681
* If we now have a earlier deadline task than p,
26792682
* then reschedule, provided p is still on this
26802683
* runqueue.
26812684
*/
26822685
if (dl_time_before(rq->dl.earliest_dl.curr, p->dl.deadline))
26832686
resched_curr(rq);
2684-
#else
2687+
} else {
26852688
/*
2686-
* Again, we don't know if p has a earlier
2687-
* or later deadline, so let's blindly set a
2688-
* (maybe not needed) rescheduling point.
2689+
* Current may not be deadline in case p was throttled but we
2690+
* have just replenished it (e.g. rt_mutex_setprio()).
2691+
*
2692+
* Otherwise, if p was given an earlier deadline, reschedule.
26892693
*/
2690-
resched_curr(rq);
2691-
#endif /* CONFIG_SMP */
2694+
if (!dl_task(rq->curr) ||
2695+
dl_time_before(p->dl.deadline, rq->curr->dl.deadline))
2696+
resched_curr(rq);
26922697
}
2698+
#else
2699+
/*
2700+
* We don't know if p has a earlier or later deadline, so let's blindly
2701+
* set a (maybe not needed) rescheduling point.
2702+
*/
2703+
resched_curr(rq);
2704+
#endif
26932705
}
26942706

26952707
DEFINE_SCHED_CLASS(dl) = {

0 commit comments

Comments
 (0)