sched/fair: Sync task util before slow-path wakeup
PATCH 1/1 sched/fair: Sync task util before slow-path wakeup
We use task_util in find_idlest_group via capacity_spare_wake. This task_util is updated in wake_cap. However wake_cap is not the only reason for ending up in find_idlest_group - we could have been sent there by wake_wide. So explicitly sync the task util with prev_cpu when we are about to head to find_idlest_group.
We could simply do this at the beginning of select_task_rq_fair (i.e. irrespective of whether we're heading to select_idle_sibling or find_idlest_group & co), but I didn't want to slow down the select_idle_sibling path more than necessary.
Don't do this during fork balancing, we won't need the task_util and we'd just clobber the last_update_time, which is supposed to be 0.
--- kernel/sched/fair.c | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/sched/fair.c +8 -0
@@ -5913,6 +5913,14 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f new_cpu = cpu; } +if (sd && !(sd_flag &SD_BALANCE_FORK )) +/* +* We're going to need the task's util for capacity_spare_wake +* in select_idlest_group. Sync it up to prev_cpu's +* last_update_time. +*/ +sync_entity_load_avg (&p->se); +if (!sd) { pick_cpu:if (sd_flag &SD_BALANCE_WAKE )/* XXX always ? */
Signature · 1 line
2.13.0
Peter Zijlstra
maintainerQuoted 6 lines · Brendan Jackman
We use
task_utilinfind_idlest_groupviacapacity_spare_wake. Thistask_utilis updated inwake_cap. Howeverwake_capis not the only reason for ending up infind_idlest_group- we could have been sent there bywake_wide. So explicitly sync the task util withprev_cpuwhen we are about to head tofind_idlest_group.
Quoted 7 lines
We could simply do this at the beginning of
select_task_rq_fair(i.e. irrespective of whether we're heading toselect_idle_siblingorfind_idlest_group& co), but I didn't want to slow down theselect_idle_siblingpath more than necessary.Don't do this during fork balancing, we won't need the
task_utiland we'd just clobber thelast_update_time, which is supposed to be 0.
So I remember Morten explicitly not aging util of tasks on wakeup because the old util was higher and better representative of what the new util would be, or something along those lines.
Morten?
Quoted 17 lines
Signed-off-by Brendan Jackman <[email protected]>Cc Dietmar Eggemann <[email protected]>Cc Vincent Guittot <[email protected]>Cc Josef Bacik <[email protected]>Cc Ingo Molnar <[email protected]>Cc Morten Rasmussen <[email protected]>Cc Peter Zijlstra <[email protected]>--- kernel/sched/fair.c | 8 ++++++++ 1 file changed, 8 insertions(+)kernel/sched/fair.c +0
-0@@ -5913,6 +5913,14 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f new_cpu = cpu;
kernel/sched/fair.c select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f · line 5923
Quoted 10 lines
kernel/sched/fair.c +8
-0} +if (sd && !(sd_flag &SD_BALANCE_FORK )) +/* +* We're going to need the task's util for capacity_spare_wake +* in select_idlest_group. Sync it up to prev_cpu's +* last_update_time. +*/ +sync_entity_load_avg (&p->se); +
That has missing {}
kernel/sched/fair.c select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f · line 5925
Quoted 2 lines
kernel/sched/fair.c +0
-0if (!sd) { pick_cpu:
And if this patch lives, can you please fix up that broken label indent?
Quoted 1 line
kernel/sched/fair.c +0
-0if (sd_flag &SD_BALANCE_WAKE )/* XXX always ? */
Quoted 40 lines · Peter Zijlstra
Quoted 6 lines · Brendan Jackman
We use
task_utilinfind_idlest_groupviacapacity_spare_wake. Thistask_utilis updated inwake_cap. Howeverwake_capis not the only reason for ending up infind_idlest_group- we could have been sent there bywake_wide. So explicitly sync the task util withprev_cpuwhen we are about to head tofind_idlest_group.Quoted 7 lines
We could simply do this at the beginning of
select_task_rq_fair(i.e. irrespective of whether we're heading toselect_idle_siblingorfind_idlest_group& co), but I didn't want to slow down theselect_idle_siblingpath more than necessary.Don't do this during fork balancing, we won't need the
task_utiland we'd just clobber thelast_update_time, which is supposed to be 0.So I remember Morten explicitly not aging util of tasks on wakeup because the old util was higher and better representative of what the new util would be, or something along those lines.
Morten?
Quoted 19 lines
Signed-off-by Brendan Jackman <[email protected]>Cc Dietmar Eggemann <[email protected]>Cc Vincent Guittot <[email protected]>Cc Josef Bacik <[email protected]>Cc Ingo Molnar <[email protected]>Cc Morten Rasmussen <[email protected]>Cc Peter Zijlstra <[email protected]>--- kernel/sched/fair.c | 8 ++++++++ 1 file changed, 8 insertions(+)kernel/sched/fair.c +0
-0@@ -5913,6 +5913,14 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f new_cpu = cpu; }
Quoted 10 lines
kernel/sched/fair.c select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f · line 5923
Quoted 8 lines
kernel/sched/fair.c +8
-0+if (sd && !(sd_flag &SD_BALANCE_FORK )) +/* +* We're going to need the task's util for capacity_spare_wake +* in select_idlest_group. Sync it up to prev_cpu's +* last_update_time. +*/ +sync_entity_load_avg (&p->se); +That has missing {}
OK. Also just noticed it refers to "select_idlest_group", will change to "find_idlest_group".
Quoted 6 lines
kernel/sched/fair.c select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f · line 5925
Quoted 4 lines
kernel/sched/fair.c +0
-0if (!sd) { pick_cpu:And if this patch lives, can you please fix up that broken label indent?
Sure.
Quoted 1 line
kernel/sched/fair.c select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f · line 5926
Quoted 1 line
kernel/sched/fair.c +0
-0if (sd_flag &SD_BALANCE_WAKE )/* XXX always ? */
Cheers,
Brendan
Quoted 12 lines · Peter Zijlstra
Quoted 11 lines · Brendan Jackman
We use
task_utilinfind_idlest_groupviacapacity_spare_wake. Thistask_utilis updated inwake_cap. Howeverwake_capis not the only reason for ending up infind_idlest_group- we could have been sent there bywake_wide. So explicitly sync the task util withprev_cpuwhen we are about to head tofind_idlest_group.We could simply do this at the beginning of
select_task_rq_fair(i.e. irrespective of whether we're heading toselect_idle_siblingorfind_idlest_group& co), but I didn't want to slow down theselect_idle_siblingpath more than necessary.
Quoted 8 lines
Quoted 2 lines
Don't do this during fork balancing, we won't need the
task_utiland we'd just clobber thelast_update_time, which is supposed to be 0.So I remember Morten explicitly not aging util of tasks on wakeup because the old util was higher and better representative of what the new util would be, or something along those lines.
Morten?
That was the intention, but when we discussed the wake_cap() stuff we decided to drop that hoping that decay clamping or some other magic would be added on top later. So this patch is in line with current behaviour.
Using non-aged util is causing trouble when comparing prev_cpu to other cpus. In cpu_util_wake() we compensate for the fact that the aged task util is already included in the cpu util on the prev_cpu. For that to work, we need to age the task util so we know how much is already accounted for. In the original wake_cap() series I think I had a patch that store the non-aged version so we could calculate the potential cpu util as:
predicted_cpu_util(prev_cpu) =
cpu_util(prev_cpu) - task_util_aged(task) + task_util_nonaged(task)
predicted_cpu_util(other_cpu) =
cpu_util(other_cpu) + task_util_nonaged(task)
This would be better always under-estimating the task util by using the aged util as we currently do:
predicted_cpu_util(prev_cpu) =
cpu_util(prev_cpu) - task_util_aged(task) + task_util_aged(task)
predicted_cpu_util(other_cpu) =
cpu_util(other_cpu) + task_util_aged(task)
but at least it gives us a fair comparison between prev_cpu and other cpus.
The Android kernel carries additional patches that tracks the max (peak) utilization and uses that as the non aged util for wake-up placement. I'm hoping we can discuss this topic again at LPC, as last years idea of clamping decay didn't work very well to solve this issue.