Skip to content

Commit 4b26cfd

Browse files
joelagnelPeter Zijlstra
authored andcommitted
sched/core: Fix priority checking for DL server picks
In core scheduling, a DL server pick (which is CFS task) should be given higher priority than tasks in other classes. Not doing so causes CFS starvation. A kselftest is added later to demonstrate this. A CFS task that is competing with RT tasks can be completely starved without this and the DL server's boosting completely ignored. Fix these problems. Reported-by: Suleiman Souhlal <[email protected]> Signed-off-by: "Joel Fernandes (Google)" <[email protected]> Signed-off-by: Daniel Bristot de Oliveira <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Vineeth Pillai <[email protected]> Tested-by: Juri Lelli <[email protected]> Link: https://lore.kernel.org/r/48b78521d86f3b33c24994d843c1aad6b987dda9.1716811044.git.bristot@kernel.org
1 parent d741f29 commit 4b26cfd

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

kernel/sched/core.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ static inline int __task_prio(const struct task_struct *p)
163163
if (p->sched_class == &stop_sched_class) /* trumps deadline */
164164
return -2;
165165

166+
if (p->dl_server)
167+
return -1; /* deadline */
168+
166169
if (rt_prio(p->prio)) /* includes deadline */
167170
return p->prio; /* [-1, 99] */
168171

@@ -192,8 +195,24 @@ static inline bool prio_less(const struct task_struct *a,
192195
if (-pb < -pa)
193196
return false;
194197

195-
if (pa == -1) /* dl_prio() doesn't work because of stop_class above */
196-
return !dl_time_before(a->dl.deadline, b->dl.deadline);
198+
if (pa == -1) { /* dl_prio() doesn't work because of stop_class above */
199+
const struct sched_dl_entity *a_dl, *b_dl;
200+
201+
a_dl = &a->dl;
202+
/*
203+
* Since,'a' and 'b' can be CFS tasks served by DL server,
204+
* __task_prio() can return -1 (for DL) even for those. In that
205+
* case, get to the dl_server's DL entity.
206+
*/
207+
if (a->dl_server)
208+
a_dl = a->dl_server;
209+
210+
b_dl = &b->dl;
211+
if (b->dl_server)
212+
b_dl = b->dl_server;
213+
214+
return !dl_time_before(a_dl->deadline, b_dl->deadline);
215+
}
197216

198217
if (pa == MAX_RT_PRIO + MAX_NICE) /* fair */
199218
return cfs_prio_less(a, b, in_fi);

0 commit comments

Comments
 (0)