Improve schedutil integration for FAIR tasks
Subsystems (2)
v3 cover Improve schedutil integration for FAIR tasks
Here is the (hopefully) final update of:
https://lkml.org/lkml/2018/5/11/319
[email protected]
including only the first two patches of the original series, which have been already reviewed and acked by Viresh and Vincent.
The last patch has been removed from this series since, during the discussion, we agree that it's not completely fixing the problem it was addressing and we would like to explore a better and more complete solution. Thus, I'll follow up on a separated and dedicated series.
Cheers Patrick
Changes in v3:
- add "Tested-by" and "Acked-by" Vincent tags
Changes in v2:
- improve comment in enqueue_task_fair() (Peter)
- add "Fixes" tag
- add "Acked-by" Viresh tag
Patrick Bellasi (2):
sched/cpufreq: always consider blocked FAIR utilization sched/fair: util_est: update before schedutil
kernel/sched/cpufreq_schedutil.c | 17 ++++++++--------- kernel/sched/fair.c | 9 ++++++++- 2 files changed, 16 insertions(+), 10 deletions(-)
Signature · 1 line
2.15.1
PATCH v3 1/2 sched/cpufreq: always consider blocked FAIR utilization
Since the refactoring introduced by:
commit 8f111bc357aa ("cpufreq/schedutil: Rewrite CPUFREQ_RT support")
we aggregate FAIR utilization only if this class has runnable tasks. This was mainly due to avoid the risk to stay on an high frequency just because of the blocked utilization of a CPU not being properly decayed while the CPU was idle.
However, since:
commit 31e77c93e432 ("sched/fair: Update blocked load when newly idle")
the FAIR blocked utilization is properly decayed also for IDLE CPUs.
This allows us to use the FAIR blocked utilization as a safe mechanism to gracefully reduce the frequency only if no FAIR tasks show up on a CPU for a reasonable period of time.
Moreover, we also reduce the frequency drops of CPUs running periodic tasks which, depending on the task periodicity and the time required for a frequency switch, was increasing the chances to introduce some undesirable performance variations.
---
Changes in v3:
- add "Tested-by" and "Acked-by" Vincent tags
Changes in v2:
- add "Acked-by" Viresh tag
--- kernel/sched/cpufreq_schedutil.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
kernel/sched/cpufreq_schedutil.c +8 -9
@@ -183,22 +183,21 @@ static void sugov_get_util(struct sugov_cpu *sg_cpu)static unsigned long sugov_aggregate_util (struct sugov_cpu *sg_cpu) {struct rq *rq =cpu_rq (sg_cpu->cpu); -unsigned long util; -if (rq->rt.rt_nr_running) { - util = sg_cpu->max; - }else { - util = sg_cpu->util_dl; -if (rq->cfs.h_nr_running) - util += sg_cpu->util_cfs; - } +if (rq->rt.rt_nr_running) +return sg_cpu->max;/* +* Utilization required by DEADLINE must always be granted while, for +* FAIR, we use blocked utilization of IDLE CPUs as a mechanism to +* gracefully reduce the frequency when no tasks show up for longer +* periods of time. +* * Ideally we would like to set util_dl as min/guaranteed freq and * util_cfs + util_dl as requested freq. However, cpufreq is not yet * ready for such an interface. So, we only do the latter for now. */ -return min (util, sg_cpu->max); +return min (sg_cpu->max, (sg_cpu->util_dl + sg_cpu->util_cfs)); }static void sugov_set_iowait_boost (struct sugov_cpu *sg_cpu,u64 time,unsigned int flags)
Signature · 1 line
2.15.1
tip-bot for Patrick Bellasi
merge bot[tip:sched/core] sched/cpufreq: Modify aggregate utilization to always include blocked FAIR utilization
sched/cpufreq: Modify aggregate utilization to always include blocked FAIR utilization
Commit-ID: 8ecf04e11283a28ca88b8b8049ac93c3a99fcd2c Gitweb: https://git.kernel.org/tip/8ecf04e11283a28ca88b8b8049ac93c3a99fcd2c Author: Patrick Bellasi <[email protected]> AuthorDate: Thu, 24 May 2018 15:10:22 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 25 May 2018 08:04:52 +0200
sched/cpufreq: Modify aggregate utilization to always include blocked FAIR utilization
Since the refactoring introduced by:
commit 8f111bc357aa ("cpufreq/schedutil: Rewrite CPUFREQ_RT support")
we aggregate FAIR utilization only if this class has runnable tasks.
This was mainly due to avoid the risk to stay on an high frequency just because of the blocked utilization of a CPU not being properly decayed while the CPU was idle.
However, since:
commit 31e77c93e432 ("sched/fair: Update blocked load when newly idle")
the FAIR blocked utilization is properly decayed also for IDLE CPUs.
This allows us to use the FAIR blocked utilization as a safe mechanism to gracefully reduce the frequency only if no FAIR tasks show up on a CPU for a reasonable period of time.
Moreover, we also reduce the frequency drops of CPUs running periodic tasks which, depending on the task periodicity and the time required for a frequency switch, was increasing the chances to introduce some undesirable performance variations.
--- kernel/sched/cpufreq_schedutil.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
kernel/sched/cpufreq_schedutil.c +8 -9
@@ -183,22 +183,21 @@ static void sugov_get_util(struct sugov_cpu *sg_cpu)static unsigned long sugov_aggregate_util (struct sugov_cpu *sg_cpu) {struct rq *rq =cpu_rq (sg_cpu->cpu); -unsigned long util; -if (rq->rt.rt_nr_running) { - util = sg_cpu->max; - }else { - util = sg_cpu->util_dl; -if (rq->cfs.h_nr_running) - util += sg_cpu->util_cfs; - } +if (rq->rt.rt_nr_running) +return sg_cpu->max;/* +* Utilization required by DEADLINE must always be granted while, for +* FAIR, we use blocked utilization of IDLE CPUs as a mechanism to +* gracefully reduce the frequency when no tasks show up for longer +* periods of time. +* * Ideally we would like to set util_dl as min/guaranteed freq and * util_cfs + util_dl as requested freq. However, cpufreq is not yet * ready for such an interface. So, we only do the latter for now. */ -return min (util, sg_cpu->max); +return min (sg_cpu->max, (sg_cpu->util_dl + sg_cpu->util_cfs)); }static void sugov_set_iowait_boost (struct sugov_cpu *sg_cpu,u64 time,unsigned int flags)
Re: [PATCH v3 1/2] sched/cpufreq: always consider blocked FAIR utilization
In reply to Patrick BellasiQuoted 24 lines · Patrick Bellasi
Since the refactoring introduced by:
commit
8f111bc357aa("cpufreq/schedutil: RewriteCPUFREQ_RTsupport")we aggregate FAIR utilization only if this class has runnable tasks. This was mainly due to avoid the risk to stay on an high frequency just because of the blocked utilization of a CPU not being properly decayed while the CPU was idle.
However, since:
commit
31e77c93e432("sched/fair: Update blocked load when newly idle")the FAIR blocked utilization is properly decayed also for IDLE CPUs.
This allows us to use the FAIR blocked utilization as a safe mechanism to gracefully reduce the frequency only if no FAIR tasks show up on a CPU for a reasonable period of time.
Moreover, we also reduce the frequency drops of CPUs running periodic tasks which, depending on the task periodicity and the time required for a frequency switch, was increasing the chances to introduce some undesirable performance variations.
Quoted 13 lines
Reported-by Vincent Guittot <[email protected]>Signed-off-by Patrick Bellasi <[email protected]>Acked-by Viresh Kumar <[email protected]>Acked-by Vincent Guittot <[email protected]>Tested-by Vincent Guittot <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Rafael J. Wysocki <[email protected]>Cc Vincent Guittot <[email protected]>Cc Viresh Kumar <[email protected]>Cc Joel Fernandes <[email protected]>
Or please let me know if you want me to apply this one.
Quoted 48 lines
---
Changes in v3:
- add "Tested-by" and "Acked-by" Vincent tagsChanges in v2:
- add "Acked-by" Viresh tag--- kernel/sched/cpufreq_schedutil.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)kernel/sched/cpufreq_schedutil.c +8
-10@@ -183,22 +183,21 @@ static void sugov_get_util(struct sugov_cpu *sg_cpu)static unsigned long sugov_aggregate_util (struct sugov_cpu *sg_cpu) {struct rq *rq =cpu_rq (sg_cpu->cpu); -unsigned long util; -if (rq->rt.rt_nr_running) { - util = sg_cpu->max; - }else { - util = sg_cpu->util_dl; -if (rq->cfs.h_nr_running) - util += sg_cpu->util_cfs; - } +if (rq->rt.rt_nr_running) +return sg_cpu->max;/* +* Utilization required by DEADLINE must always be granted while, for +* FAIR, we use blocked utilization of IDLE CPUs as a mechanism to +* gracefully reduce the frequency when no tasks show up for longer +* periods of time. +* * Ideally we would like to set util_dl as min/guaranteed freq and * util_cfs + util_dl as requested freq. However, cpufreq is not yet * ready for such an interface. So, we only do the latter for now. */ -return min (util, sg_cpu->max); +return min (sg_cpu->max, (sg_cpu->util_dl + sg_cpu->util_cfs)); }static void sugov_set_iowait_boost (struct sugov_cpu *sg_cpu,u64 time,unsigned int flags) --2.15.1
Re: [PATCH v3 1/2] sched/cpufreq: always consider blocked FAIR utilization
Quoted 40 lines · Rafael J. Wysocki
Quoted 24 lines · Patrick Bellasi
Since the refactoring introduced by:
commit
8f111bc357aa("cpufreq/schedutil: RewriteCPUFREQ_RTsupport")we aggregate FAIR utilization only if this class has runnable tasks. This was mainly due to avoid the risk to stay on an high frequency just because of the blocked utilization of a CPU not being properly decayed while the CPU was idle.
However, since:
commit
31e77c93e432("sched/fair: Update blocked load when newly idle")the FAIR blocked utilization is properly decayed also for IDLE CPUs.
This allows us to use the FAIR blocked utilization as a safe mechanism to gracefully reduce the frequency only if no FAIR tasks show up on a CPU for a reasonable period of time.
Moreover, we also reduce the frequency drops of CPUs running periodic tasks which, depending on the task periodicity and the time required for a frequency switch, was increasing the chances to introduce some undesirable performance variations.
Quoted 13 lines
Reported-by Vincent Guittot <[email protected]>Signed-off-by Patrick Bellasi <[email protected]>Acked-by Viresh Kumar <[email protected]>Acked-by Vincent Guittot <[email protected]>Tested-by Vincent Guittot <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Rafael J. Wysocki <[email protected]>Cc Vincent Guittot <[email protected]>Cc Viresh Kumar <[email protected]>Cc Joel Fernandes <[email protected]>
Quoted 3 lines
Reviewed-by Rafael J. Wysocki <[email protected]>Or please let me know if you want me to apply this one.
Hi Rafael, seems this patch has already been applied in tip/sched/core. However is missing your tag above. :/
Dunno if I have / I can to do something about that.
Quoted 48 lines
Quoted 48 lines
---
Changes in v3:
- add "Tested-by" and "Acked-by" Vincent tagsChanges in v2:
- add "Acked-by" Viresh tag--- kernel/sched/cpufreq_schedutil.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)kernel/sched/cpufreq_schedutil.c +8
-10@@ -183,22 +183,21 @@ static void sugov_get_util(struct sugov_cpu *sg_cpu)static unsigned long sugov_aggregate_util (struct sugov_cpu *sg_cpu) {struct rq *rq =cpu_rq (sg_cpu->cpu); -unsigned long util; -if (rq->rt.rt_nr_running) { - util = sg_cpu->max; - }else { - util = sg_cpu->util_dl; -if (rq->cfs.h_nr_running) - util += sg_cpu->util_cfs; - } +if (rq->rt.rt_nr_running) +return sg_cpu->max;/* +* Utilization required by DEADLINE must always be granted while, for +* FAIR, we use blocked utilization of IDLE CPUs as a mechanism to +* gracefully reduce the frequency when no tasks show up for longer +* periods of time. +* * Ideally we would like to set util_dl as min/guaranteed freq and * util_cfs + util_dl as requested freq. However, cpufreq is not yet * ready for such an interface. So, we only do the latter for now. */ -return min (util, sg_cpu->max); +return min (sg_cpu->max, (sg_cpu->util_dl + sg_cpu->util_cfs)); }static void sugov_set_iowait_boost (struct sugov_cpu *sg_cpu,u64 time,unsigned int flags) --2.15.1
Signature · 3 lines
#include <best/regards.h> Patrick Bellasi
Re: [PATCH v3 1/2] sched/cpufreq: always consider blocked FAIR utilization
Quoted 41 lines · CEST Patrick Bellasi
Quoted 40 lines · Rafael J. Wysocki
Quoted 37 lines · Patrick Bellasi
Since the refactoring introduced by:
commit
8f111bc357aa("cpufreq/schedutil: RewriteCPUFREQ_RTsupport")we aggregate FAIR utilization only if this class has runnable tasks. This was mainly due to avoid the risk to stay on an high frequency just because of the blocked utilization of a CPU not being properly decayed while the CPU was idle.
However, since:
commit
31e77c93e432("sched/fair: Update blocked load when newly idle")the FAIR blocked utilization is properly decayed also for IDLE CPUs.
This allows us to use the FAIR blocked utilization as a safe mechanism to gracefully reduce the frequency only if no FAIR tasks show up on a CPU for a reasonable period of time.
Moreover, we also reduce the frequency drops of CPUs running periodic tasks which, depending on the task periodicity and the time required for a frequency switch, was increasing the chances to introduce some undesirable performance variations.
Reported-by Vincent Guittot <[email protected]>Signed-off-by Patrick Bellasi <[email protected]>Acked-by Viresh Kumar <[email protected]>Acked-by Vincent Guittot <[email protected]>Tested-by Vincent Guittot <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Rafael J. Wysocki <[email protected]>Cc Vincent Guittot <[email protected]>Cc Viresh Kumar <[email protected]>Cc Joel Fernandes <[email protected]>
Quoted 6 lines
Quoted 3 lines
Reviewed-by Rafael J. Wysocki <[email protected]>Or please let me know if you want me to apply this one.
Hi Rafael, seems this patch has already been applied in tip/sched/core. However is missing your tag above. :/
That's OK.
I just wanted to let people know my opinion. :-)
PATCH v3 2/2 sched/fair: util_est: update before schedutil
In reply to Patrick BellasiWhen a task is enqueue the estimated utilization of a CPU is updated to better support the selection of the required frequency. However, schedutil is (implicitly) updated by update_load_avg() which always happens before util_est_{en,de}queue(), thus potentially introducing a latency between estimated utilization updates and frequency selections.
Let's update util_est at the beginning of enqueue_task_fair(), which will ensure that all schedutil updates will see the most updated estimated utilization value for a CPU.
---
Changes in v3:
- add "Acked-by" Vincent tags
Changes in v2:
- improve comment in enqueue_task_fair() (Peter)
- add "Fixes" tag
- add "Acked-by" Viresh tag
--- kernel/sched/fair.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/sched/fair.c +8 -1
@@ -5385,6 +5385,14 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)struct cfs_rq *cfs_rq;struct sched_entity *se = &p->se; +/* +* The code below (indirectly) updates schedutil which looks at +* the cfs_rq utilization to select a frequency. +* Let's add the task's estimated utilization to the cfs_rq's +* estimated utilization, before we update schedutil. +*/ +util_est_enqueue (&rq->cfs, p); +/* * If in_iowait is set, the code below may not trigger any cpufreq * utilization updates, so do it here explicitly with the IOWAIT flag
@@ -5426,7 +5434,6 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)if (!se)add_nr_running (rq,1 ); -util_est_enqueue (&rq->cfs, p);hrtick_update (rq); }
Signature · 1 line
2.15.1
tip-bot for Patrick Bellasi
merge bot[tip:sched/core] sched/fair: Update util_est before updating schedutil
sched/fair: Update util_est before updating schedutil
Commit-ID: 2539fc82aa9b07d968cf9ba1ffeec3e0416ac721 Gitweb: https://git.kernel.org/tip/2539fc82aa9b07d968cf9ba1ffeec3e0416ac721 Author: Patrick Bellasi <[email protected]> AuthorDate: Thu, 24 May 2018 15:10:23 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 25 May 2018 08:04:56 +0200
sched/fair: Update util_est before updating schedutil
When a task is enqueued the estimated utilization of a CPU is updated to better support the selection of the required frequency.
However, schedutil is (implicitly) updated by update_load_avg() which always happens before util_est_{en,de}queue(), thus potentially introducing a latency between estimated utilization updates and frequency selections.
Let's update util_est at the beginning of enqueue_task_fair(), which will ensure that all schedutil updates will see the most updated estimated utilization value for a CPU.
--- kernel/sched/fair.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/sched/fair.c +8 -1
@@ -5385,6 +5385,14 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)struct cfs_rq *cfs_rq;struct sched_entity *se = &p->se; +/* +* The code below (indirectly) updates schedutil which looks at +* the cfs_rq utilization to select a frequency. +* Let's add the task's estimated utilization to the cfs_rq's +* estimated utilization, before we update schedutil. +*/ +util_est_enqueue (&rq->cfs, p); +/* * If in_iowait is set, the code below may not trigger any cpufreq * utilization updates, so do it here explicitly with the IOWAIT flag
@@ -5426,7 +5434,6 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)if (!se)add_nr_running (rq,1 ); -util_est_enqueue (&rq->cfs, p);hrtick_update (rq); }