sched/fair: micro-optimize pick_next_entity()
PATCH RESEND 1/1 sched/fair: micro-optimize pick_next_entity()
Only check the skip buddy when next buddy and last buddy are not picked up, this can save the cycles of checking the skip buddy and computation of the second buddy, when next and last buddy will be picked up
for example, yield_to_task_fair() set both next and skip buddy
--- kernel/sched/fair.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
kernel/sched/fair.c +16 -17
@@ -4503,11 +4503,22 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr) se = left;/* ideally we run the leftmost entity */ -/* -* Avoid running the skip buddy, if running something else can -* be done without getting too unfair. -*/ -if (cfs_rq->skip && cfs_rq->skip == se) { + +if (cfs_rq->next &&wakeup_preempt_entity (cfs_rq->next, left) <1 ) { +/* +* Someone really wants this to run. If it's not unfair, run it. +*/ + se = cfs_rq->next; + }else if (cfs_rq->last &&wakeup_preempt_entity (cfs_rq->last, left) <1 ) { +/* +* Prefer last buddy, try to return the CPU to a preempted task. +*/ + se = cfs_rq->last; + }else if (cfs_rq->skip && cfs_rq->skip == se) { +/* +* Avoid running the skip buddy, if running something else can +* be done without getting too unfair. +*/ struct sched_entity *second;if (se == curr) {
@@ -4522,18 +4533,6 @@ pick_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *curr) se = second; } -if (cfs_rq->next &&wakeup_preempt_entity (cfs_rq->next, left) <1 ) { -/* -* Someone really wants this to run. If it's not unfair, run it. -*/ - se = cfs_rq->next; - }else if (cfs_rq->last &&wakeup_preempt_entity (cfs_rq->last, left) <1 ) { -/* -* Prefer last buddy, try to return the CPU to a preempted task. -*/ - se = cfs_rq->last; - } -return se; }
Signature · 1 line
2.33.0.69.gc420321.dirty
Peter Zijlstra
maintainerQuoted 6 lines · Li RongQing
Only check the skip buddy when next buddy and last buddy are not picked up, this can save the cycles of checking the skip buddy and computation of the second buddy, when next and last buddy will be picked up
for example,yield_to_task_fair()set both next and skip buddy
Is that actually measurable?
But looking at it, should we not, instead, move the whole ->skip thing to the bottom, so we unconditionally check it vs the result of ->next/->last ?
Imagine ->next == ->skip, then we want to avoid running it and not have ->next win.
Quoted 11 lines
-----邮件原件-----
发件人: Peter Zijlstra <[email protected]>
发送时间: 2021年8月31日 22:10
收件人: Li,Rongqing <[email protected]>
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected] 主题: Re: [Resend][PATCH] sched/fair: micro-optimizepick_next_entity()
Quoted 9 lines
Quoted 5 lines · Li RongQing
Only check the skip buddy when next buddy and last buddy are not picked up, this can save the cycles of checking the skip buddy and computation of the second buddy, when next and last buddy will be picked up for example,
yield_to_task_fair()set both next and skip buddyIs that actually measurable?
No measurable
Quoted 6 lines
But looking at it, should we not, instead, move the whole ->skip thing to the bottom, so we unconditionally check it vs the result of ->next/->last ?
Imagine ->next == ->skip, then we want to avoid running it and not have ->next win.
True, next/last may be equal to skip
-Li
Quoted 18 lines
-----邮件原件-----
发件人: Peter Zijlstra <[email protected]>
发送时间: 2021年8月31日 22:10
收件人: Li,Rongqing <[email protected]>
抄送: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected] 主题: Re: [Resend][PATCH] sched/fair: micro-optimizepick_next_entity()Quoted 5 lines · Li RongQing
Only check the skip buddy when next buddy and last buddy are not picked up, this can save the cycles of checking the skip buddy and computation of the second buddy, when next and last buddy will be picked up for example,
yield_to_task_fair()set both next and skip buddy
Quoted 8 lines
Is that actually measurable?
But looking at it, should we not, instead, move the whole ->skip thing to the bottom, so we unconditionally check it vs the result of ->next/->last ?
Imagine ->next == ->skip, then we want to avoid running it and not have ->next win.
skip means this task is running on cpu, next is the blocked task and will be running.
I donot know how they can be same.
-Li