Skip to content

Commit aa93cd5

Browse files
tkhaiPeter Zijlstra
authored andcommitted
sched: Micro optimization in pick_next_task() and in check_preempt_curr()
This introduces an optimization based on xxx_sched_class addresses in two hot scheduler functions: pick_next_task() and check_preempt_curr(). It is possible to compare pointers to sched classes to check, which of them has a higher priority, instead of current iterations using for_each_class(). One more result of the patch is that size of object file becomes a little less (excluding added BUG_ON(), which goes in __init section): $size kernel/sched/core.o text data bss dec hex filename before: 66446 18957 676 86079 1503f kernel/sched/core.o after: 66398 18957 676 86031 1500f kernel/sched/core.o Signed-off-by: Kirill Tkhai <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: http://lkml.kernel.org/r/[email protected]
1 parent a87e749 commit aa93cd5

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

kernel/sched/core.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,20 +1412,10 @@ static inline void check_class_changed(struct rq *rq, struct task_struct *p,
14121412

14131413
void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags)
14141414
{
1415-
const struct sched_class *class;
1416-
1417-
if (p->sched_class == rq->curr->sched_class) {
1415+
if (p->sched_class == rq->curr->sched_class)
14181416
rq->curr->sched_class->check_preempt_curr(rq, p, flags);
1419-
} else {
1420-
for_each_class(class) {
1421-
if (class == rq->curr->sched_class)
1422-
break;
1423-
if (class == p->sched_class) {
1424-
resched_curr(rq);
1425-
break;
1426-
}
1427-
}
1428-
}
1417+
else if (p->sched_class > rq->curr->sched_class)
1418+
resched_curr(rq);
14291419

14301420
/*
14311421
* A queue event has occurred, and we're going to schedule. In
@@ -4003,8 +3993,7 @@ pick_next_task(struct rq *rq, struct task_struct *prev, struct rq_flags *rf)
40033993
* higher scheduling class, because otherwise those loose the
40043994
* opportunity to pull in more work from other CPUs.
40053995
*/
4006-
if (likely((prev->sched_class == &idle_sched_class ||
4007-
prev->sched_class == &fair_sched_class) &&
3996+
if (likely(prev->sched_class <= &fair_sched_class &&
40083997
rq->nr_running == rq->cfs.h_nr_running)) {
40093998

40103999
p = pick_next_task_fair(rq, prev, rf);

0 commit comments

Comments
 (0)