Skip to content

Commit 9abb897

Browse files
posk-ioPeter Zijlstra
authored andcommitted
sched/fair: Tweak pick_next_entity()
Currently, pick_next_entity(...) has the following structure (simplified): [...] if (last_buddy_ok()) result = last_buddy; if (next_buddy_ok()) result = next_buddy; [...] The intended behavior is to prefer next buddy over last buddy; the current code somewhat obfuscates this, and also wastes cycles checking the last buddy when eventually the next buddy is picked up. So this patch refactors two 'ifs' above into [...] if (next_buddy_ok()) result = next_buddy; else if (last_buddy_ok()) result = last_buddy; [...] Signed-off-by: Peter Oskolkov <posk@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Vincent Guittot <vincent.guitttot@linaro.org> Link: https://lkml.kernel.org/r/20200930173532.1069092-1-posk@google.com
1 parent f166b11 commit 9abb897

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

kernel/sched/fair.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4465,17 +4465,17 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr)
44654465
se = second;
44664466
}
44674467

4468-
/*
4469-
* Prefer last buddy, try to return the CPU to a preempted task.
4470-
*/
4471-
if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1)
4472-
se = cfs_rq->last;
4473-
4474-
/*
4475-
* Someone really wants this to run. If it's not unfair, run it.
4476-
*/
4477-
if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1)
4468+
if (cfs_rq->next && wakeup_preempt_entity(cfs_rq->next, left) < 1) {
4469+
/*
4470+
* Someone really wants this to run. If it's not unfair, run it.
4471+
*/
44784472
se = cfs_rq->next;
4473+
} else if (cfs_rq->last && wakeup_preempt_entity(cfs_rq->last, left) < 1) {
4474+
/*
4475+
* Prefer last buddy, try to return the CPU to a preempted task.
4476+
*/
4477+
se = cfs_rq->last;
4478+
}
44794479

44804480
clear_buddies(cfs_rq, se);
44814481

0 commit comments

Comments
 (0)