sched/fair: Task placement biasing using uclamp
Subsystems (2)
v2 cover sched/fair: Task placement biasing using uclamp
Hi,
While uclamp restrictions currently only impacts schedutil's frequency selection, it would make sense to also let it impact CPU selection in asymmetric topologies. This would let us steer specific tasks towards certain CPU capacities regardless of their actual utilization - I give a few examples in patch 3.
The first two patches are just cleanups/renames, the meat of the thing is in patches 3 and 4.
Note that this is in the same spirit as what Patrick had proposed for EAS on Android [1]
[1]: https://android.googlesource.com/kernel/common/+/b61876ed122f816660fe49e0de1b7ee4891deaa2%5E%21
Revisions
=========
Changed in v2:
- Collect Reviewed-by
- Make uclamp_task_util() unconditionally use util_est (Quentin)
- Because of the above, move uclamp_task_util() to fair.c
- Split v1's 3/3 into
- task_fits_capacity() tweak (v2's 3/4)
- find_energy_efficient_cpu() tweak (v2's 4/4).
Cheers,
Valentin
Valentin Schneider (4):
sched/uclamp: Make uclamp_util_*() helpers use and return UL values sched/uclamp: Rename uclamp_util_*() into uclamp_rq_util_*() sched/fair: Make task_fits_capacity() consider uclamp restrictions sched/fair: Make feec() consider uclamp restrictions
kernel/sched/cpufreq_schedutil.c | 2 +- kernel/sched/fair.c | 30 +++++++++++++++++++++++++++--- kernel/sched/sched.h | 22 +++++++++++----------- 3 files changed, 39 insertions(+), 15 deletions(-)
--
2.24.0
PATCH v2 1/4 sched/uclamp: Make uclamp_util_*() helpers use and return UL values
Vincent pointed out recently that the canonical type for utilization values is 'unsigned long'. Internally uclamp uses 'unsigned int' values for cache optimization, but this doesn't have to be exported to its users.
Make the uclamp helpers that deal with utilization use and return unsigned long values.
--- kernel/sched/sched.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
kernel/sched/sched.h +10 -10
@@ -2303,15 +2303,15 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id);static __always_inline -unsigned int uclamp_util_with(struct rq *rq, unsigned int util, -struct task_struct *p) +unsigned long uclamp_util_with (struct rq *rq,unsigned long util, +struct task_struct *p) { -unsigned int min_util =READ_ONCE (rq->uclamp[UCLAMP_MIN ].value); -unsigned int max_util =READ_ONCE (rq->uclamp[UCLAMP_MAX ].value); +unsigned long min_util =READ_ONCE (rq->uclamp[UCLAMP_MIN ].value); +unsigned long max_util =READ_ONCE (rq->uclamp[UCLAMP_MAX ].value);if (p) { - min_util =max (min_util,uclamp_eff_value (p,UCLAMP_MIN )); - max_util =max (max_util,uclamp_eff_value (p,UCLAMP_MAX )); + min_util = max_t(unsigned long, min_util, uclamp_eff_value(p, UCLAMP_MIN)); + max_util = max_t(unsigned long, max_util, uclamp_eff_value(p, UCLAMP_MAX)); }/*
@@ -2325,17 +2325,17 @@ unsigned int uclamp_util_with(struct rq *rq, unsigned int util, return clamp(util, min_util, max_util); } -static inline unsigned int uclamp_util (struct rq *rq,unsigned int util) +static inline unsigned long uclamp_util (struct rq *rq,unsigned long util) {return uclamp_util_with (rq, util,NULL ); }#else /* CONFIG_UCLAMP_TASK */ -static inline unsigned int uclamp_util_with (struct rq *rq,unsigned int util, -struct task_struct *p) +static inline unsigned long uclamp_util_with (struct rq *rq,unsigned long util, +struct task_struct *p) {return util; } -static inline unsigned int uclamp_util (struct rq *rq,unsigned int util) +static inline unsigned long uclamp_util (struct rq *rq,unsigned long util) {return util; }
Signature · 1 line
2.24.0
Vincent Guittot
maintainerRe: [PATCH v2 1/4] sched/uclamp: Make uclamp_util_*() helpers use and return UL values
Quoted 19 lines · Valentin Schneider
Vincent pointed out recently that the canonical type for utilization values is 'unsigned long'. Internally uclamp uses 'unsigned int' values for cache optimization, but this doesn't have to be exported to its users.
Make the uclamp helpers that deal with utilization use and return unsigned long values.
Reviewed-by Quentin Perret <[email protected]>Signed-off-by Valentin Schneider <[email protected]>--- kernel/sched/sched.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)kernel/sched/sched.h +0
-0
kernel/sched/sched.h static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {} · line 2303
Quoted 1 line
kernel/sched/sched.h +0
-0@@ -2303,15 +2303,15 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id);
Why not changing uclamp_eff_value to return unsigned long too ? The returned value represents a utilization to be compared with other utilization value
Quoted 6 lines
kernel/sched/sched.h +2
-2static __always_inline -unsigned int uclamp_util_with(struct rq *rq, unsigned int util, -struct task_struct *p) +unsigned long uclamp_util_with (struct rq *rq,unsigned long util, +struct task_struct *p)
kernel/sched/sched.h static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {} · line 2313
Quoted 10 lines
kernel/sched/sched.h +3
-4{ -unsigned int min_util =READ_ONCE (rq->uclamp[UCLAMP_MIN ].value); -unsigned int max_util =READ_ONCE (rq->uclamp[UCLAMP_MAX ].value); +unsigned long min_util =READ_ONCE (rq->uclamp[UCLAMP_MIN ].value); +unsigned long max_util =READ_ONCE (rq->uclamp[UCLAMP_MAX ].value);if (p) { - min_util =max (min_util,uclamp_eff_value (p,UCLAMP_MIN )); - max_util =max (max_util,uclamp_eff_value (p,UCLAMP_MAX )); + min_util = max_t(unsigned long, min_util, uclamp_eff_value(p, UCLAMP_MIN));
As mentioned above, uclamp_eff_value should return an unsigned long
Quoted 29 lines
kernel/sched/sched.h +5
-5+ max_util = max_t(unsigned long, max_util, uclamp_eff_value(p, UCLAMP_MAX)); }/* @@ -2325,17 +2325,17 @@ unsigned int uclamp_util_with(struct rq *rq, unsigned int util, return clamp(util, min_util, max_util); } -static inline unsigned int uclamp_util (struct rq *rq,unsigned int util) +static inline unsigned long uclamp_util (struct rq *rq,unsigned long util) {return uclamp_util_with (rq, util,NULL ); }#else /* CONFIG_UCLAMP_TASK */ -static inline unsigned int uclamp_util_with (struct rq *rq,unsigned int util, -struct task_struct *p) +static inline unsigned long uclamp_util_with (struct rq *rq,unsigned long util, +struct task_struct *p) {return util; } -static inline unsigned int uclamp_util (struct rq *rq,unsigned int util) +static inline unsigned long uclamp_util (struct rq *rq,unsigned long util) {return util; } --2.24.0
Re: [PATCH v2 1/4] sched/uclamp: Make uclamp_util_*() helpers use and return UL values
Quoted 7 lines · Vincent Guittot
kernel/sched/sched.h static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {} · line 2303
Quoted 2 lines
kernel/sched/sched.h +0
-0@@ -2303,15 +2303,15 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id);Why not changing
uclamp_eff_valueto return unsigned long too ? The returned value represents a utilization to be compared with other utilization value
IMO uclamp_eff_value() is a simple accessor to uclamp_se.value (unsigned int), which is why I didn't want to change its return type. I see it as being the task equivalent of rq->uclamp[clamp_id].value, IOW "give me the uclamp value for that clamp index". It just happens to be a bit more intricate for tasks than for rqs.
uclamp_util() & uclamp_util_with() do explicitly return a utilization, so here it makes sense (in my mind, that is) to return UL.
Vincent Guittot
maintainerRe: [PATCH v2 1/4] sched/uclamp: Make uclamp_util_*() helpers use and return UL values
Quoted 10 lines · Valentin Schneider
Quoted 7 lines · Vincent Guittot
kernel/sched/sched.h static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {} · line 2303
Quoted 2 lines
kernel/sched/sched.h +0
-0@@ -2303,15 +2303,15 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id);Why not changing
uclamp_eff_valueto return unsigned long too ? The returned value represents a utilization to be compared with other utilization value
Quoted 5 lines
IMO
uclamp_eff_value()is a simple accessor to uclamp_se.value (unsigned int), which is why I didn't want to change its return type. I see it as being the task equivalent of rq->uclamp[clamp_id].value, IOW "give me the uclamp value for that clamp index". It just happens to be a bit more intricate for tasks than for rqs.
But then you have to take care of casting the returned value in several places here and in patch 3
Quoted 3 lines
uclamp_util()&uclamp_util_with()do explicitly return a utilization, so here it makes sense (in my mind, that is) to return UL.
Re: [PATCH v2 1/4] sched/uclamp: Make uclamp_util_*() helpers use and return UL values
You can just use Math.clamp for that!
Idiots.
RAINER
Am Mi., 4. Dez. 2019 um 17:13 Uhr schrieb Vincent Guittot <[email protected]>:
Quoted 25 lines
Quoted 10 lines · Valentin Schneider
Quoted 7 lines · Vincent Guittot
kernel/sched/sched.h static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {} · line 2303
Quoted 2 lines
kernel/sched/sched.h +0
-0@@ -2303,15 +2303,15 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id);Why not changing
uclamp_eff_valueto return unsigned long too ? The returned value represents a utilization to be compared with other utilization valueQuoted 5 lines
IMO
uclamp_eff_value()is a simple accessor to uclamp_se.value (unsigned int), which is why I didn't want to change its return type. I see it as being the task equivalent of rq->uclamp[clamp_id].value, IOW "give me the uclamp value for that clamp index". It just happens to be a bit more intricate for tasks than for rqs.But then you have to take care of casting the returned value in several places here and in patch 3
Quoted 3 lines
uclamp_util()&uclamp_util_with()do explicitly return a utilization, so here it makes sense (in my mind, that is) to return UL.
Re: [PATCH v2 1/4] sched/uclamp: Make uclamp_util_*() helpers use and return UL values
In reply to Vincent GuittotQuoted 12 lines · Vincent Guittot
Quoted 10 lines · Valentin Schneider
Quoted 7 lines · Vincent Guittot
kernel/sched/sched.h static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {} · line 2303
Quoted 2 lines
kernel/sched/sched.h +0
-0@@ -2303,15 +2303,15 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id);Why not changing
uclamp_eff_valueto return unsigned long too ? The returned value represents a utilization to be compared with other utilization value
Quoted 9 lines
Quoted 5 lines
IMO
uclamp_eff_value()is a simple accessor to uclamp_se.value (unsigned int), which is why I didn't want to change its return type. I see it as being the task equivalent of rq->uclamp[clamp_id].value, IOW "give me the uclamp value for that clamp index". It just happens to be a bit more intricate for tasks than for rqs.But then you have to take care of casting the returned value in several places here and in patch 3
True. I'm not too hot on having to handle rq clamp values (rq->uclamp[x].value) and task clamp values (uclamp_eff_value()) differently (cast one but not the other), but I don't feel *too* strongly about this, so if you want I can do that change for v3.
Quoted 3 lines
Quoted 3 lines
uclamp_util()&uclamp_util_with()do explicitly return a utilization, so here it makes sense (in my mind, that is) to return UL.
Re: [PATCH v2 1/4] sched/uclamp: Make uclamp_util_*() helpers use and return UL values
Quoted 20 lines · Valentin Schneider
Quoted 18 lines · Vincent Guittot
Quoted 15 lines · Valentin Schneider
Quoted 7 lines · Vincent Guittot
kernel/sched/sched.h static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {} · line 2303
Quoted 2 lines
kernel/sched/sched.h +0
-0@@ -2303,15 +2303,15 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id);Why not changing
uclamp_eff_valueto return unsigned long too ? The returned value represents a utilization to be compared with other utilization valueIMO
uclamp_eff_value()is a simple accessor to uclamp_se.value (unsigned int), which is why I didn't want to change its return type. I see it as being the task equivalent of rq->uclamp[clamp_id].value, IOW "give me the uclamp value for that clamp index". It just happens to be a bit more intricate for tasks than for rqs.
Quoted 8 lines
Quoted 3 lines
But then you have to take care of casting the returned value in several places here and in patch 3
True. I'm not too hot on having to handle rq clamp values (rq->uclamp[x].value) and task clamp values (
uclamp_eff_value()) differently (cast one but not the other), but I don't feel *too* strongly about this, so if you want I can do that change for v3.
Yes please. This makes the code easier to read and understand.
The rest of the patch series looks good to me. So feel free to add my reviewed by on the next version
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
uclamp_util()&uclamp_util_with()do explicitly return a utilization, so here it makes sense (in my mind, that is) to return UL.
Re: [PATCH v2 1/4] sched/uclamp: Make uclamp_util_*() helpers use and return UL values
Quoted 7 lines · Vincent Guittot
Quoted 4 lines
True. I'm not too hot on having to handle rq clamp values (rq->uclamp[x].value) and task clamp values (
uclamp_eff_value()) differently (cast one but not the other), but I don't feel *too* strongly about this, so if you want I can do that change for v3.Yes please. This makes the code easier to read and understand.
Will do.
Quoted 3 lines
The rest of the patch series looks good to me. So feel free to add my reviewed by on the next version
Reviewed-by Vincent Guittot <[email protected]>>
Thanks!
Dietmar Eggemann
reviewerRe: [PATCH v2 1/4] sched/uclamp: Make uclamp_util_*() helpers use and return UL values
In reply to Valentin SchneiderOn 03/12/2019 16:59, Valentin Schneider wrote:
[...]
Quoted 38 lines
kernel/sched/sched.h +7
-9@@ -2303,15 +2303,15 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id);static __always_inline -unsigned int uclamp_util_with(struct rq *rq, unsigned int util, -struct task_struct *p) +unsigned long uclamp_util_with (struct rq *rq,unsigned long util, +struct task_struct *p) { -unsigned int min_util =READ_ONCE (rq->uclamp[UCLAMP_MIN ].value); -unsigned int max_util =READ_ONCE (rq->uclamp[UCLAMP_MAX ].value); +unsigned long min_util =READ_ONCE (rq->uclamp[UCLAMP_MIN ].value); +unsigned long max_util =READ_ONCE (rq->uclamp[UCLAMP_MAX ].value);if (p) { - min_util =max (min_util,uclamp_eff_value (p,UCLAMP_MIN )); - max_util =max (max_util,uclamp_eff_value (p,UCLAMP_MAX )); + min_util = max_t(unsigned long, min_util, uclamp_eff_value(p, UCLAMP_MIN)); + max_util = max_t(unsigned long, max_util, uclamp_eff_value(p, UCLAMP_MAX)); }/* @@ -2325,17 +2325,17 @@ unsigned int uclamp_util_with(struct rq *rq, unsigned int util, return clamp(util, min_util, max_util); } -static inline unsigned int uclamp_util (struct rq *rq,unsigned int util) +static inline unsigned long uclamp_util (struct rq *rq,unsigned long util) {return uclamp_util_with (rq, util,NULL ); }#else /* CONFIG_UCLAMP_TASK */ -static inline unsigned int uclamp_util_with (struct rq *rq,unsigned int util, -struct task_struct *p)
kernel/sched/sched.h unsigned int uclamp_util_with(struct rq *rq, unsigned int util, · line 2341
Quoted 10 lines
kernel/sched/sched.h +3
-1+static inline unsigned long uclamp_util_with (struct rq *rq,unsigned long util, +struct task_struct *p) {return util; } -static inline unsigned int uclamp_util (struct rq *rq,unsigned int util) +static inline unsigned long uclamp_util (struct rq *rq,unsigned long util) {return util; }
There doesn't seem to be any user of uclamp_util(), only uclamp_util_with()?
Re: [PATCH v2 1/4] sched/uclamp: Make uclamp_util_*() helpers use and return UL values
Quoted 46 lines · Dietmar Eggemann
On 03/12/2019 16:59, Valentin Schneider wrote:
[...]
Quoted 42 lines
kernel/sched/sched.h +9
-9@@ -2303,15 +2303,15 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id);static __always_inline -unsigned int uclamp_util_with(struct rq *rq, unsigned int util, -struct task_struct *p) +unsigned long uclamp_util_with (struct rq *rq,unsigned long util, +struct task_struct *p) { -unsigned int min_util =READ_ONCE (rq->uclamp[UCLAMP_MIN ].value); -unsigned int max_util =READ_ONCE (rq->uclamp[UCLAMP_MAX ].value); +unsigned long min_util =READ_ONCE (rq->uclamp[UCLAMP_MIN ].value); +unsigned long max_util =READ_ONCE (rq->uclamp[UCLAMP_MAX ].value);if (p) { - min_util =max (min_util,uclamp_eff_value (p,UCLAMP_MIN )); - max_util =max (max_util,uclamp_eff_value (p,UCLAMP_MAX )); + min_util = max_t(unsigned long, min_util, uclamp_eff_value(p, UCLAMP_MIN)); + max_util = max_t(unsigned long, max_util, uclamp_eff_value(p, UCLAMP_MAX)); }/* @@ -2325,17 +2325,17 @@ unsigned int uclamp_util_with(struct rq *rq, unsigned int util, return clamp(util, min_util, max_util); } -static inline unsigned int uclamp_util (struct rq *rq,unsigned int util) +static inline unsigned long uclamp_util (struct rq *rq,unsigned long util) {return uclamp_util_with (rq, util,NULL ); }#else /* CONFIG_UCLAMP_TASK */ -static inline unsigned int uclamp_util_with (struct rq *rq,unsigned int util, -struct task_struct *p) +static inline unsigned long uclamp_util_with (struct rq *rq,unsigned long util, +struct task_struct *p) {return util;
Quoted 9 lines
kernel/sched/sched.h unsigned int uclamp_util_with(struct rq *rq, unsigned int util, · line 2337
Quoted 6 lines
kernel/sched/sched.h +1
-1} -static inline unsigned int uclamp_util (struct rq *rq,unsigned int util) +static inline unsigned long uclamp_util (struct rq *rq,unsigned long util) {return util; }There doesn't seem to be any user of
uclamp_util(), onlyuclamp_util_with()?
It was added in
982d9cdc22c9 ("sched/cpufreq, sched/uclamp: Add clamps for FAIR and RT tasks")
uclamp_util_with() followed closely in
9d20ad7dfc9a ("sched/uclamp: Add uclamp_util_with()")
and the sole uclamp_util() user (schedutil_cpu_util()) moved to the latter in
af24bde8df20 ("sched/uclamp: Add uclamp support to energy_compute()")
So it does seem like we could get rid of it - I could see it being useful later on, but it's useless right now.
PATCH v2 2/4 sched/uclamp: Rename uclamp_util_*() into uclamp_rq_util_*()
In reply to Valentin SchneiderThe current helpers return (CPU) rq utilization with uclamp restrictions taken into account. As I'm about to introduce a task clamped utilization variant, make it explicit that those deal with runqueues.
--- kernel/sched/cpufreq_schedutil.c | 2 +- kernel/sched/sched.h | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-)
kernel/sched/cpufreq_schedutil.c +1 -1
@@ -240,7 +240,7 @@ unsigned long schedutil_cpu_util(int cpu, unsigned long util_cfs,*/ util = util_cfs +cpu_util_rt (rq);if (type ==FREQUENCY_UTIL ) - util =uclamp_util_with (rq, util, p); + util =uclamp_rq_util_with (rq, util, p); dl_util =cpu_util_dl (rq);
kernel/sched/sched.h +7 -7
@@ -2303,8 +2303,8 @@ static inline void cpufreq_update_util(struct rq *rq, unsigned int flags) {}unsigned int uclamp_eff_value (struct task_struct *p,enum uclamp_id clamp_id);static __always_inline -unsigned long uclamp_util_with (struct rq *rq,unsigned long util, -struct task_struct *p) +unsigned long uclamp_rq_util_with (struct rq *rq,unsigned long util, +struct task_struct *p) {unsigned long min_util =READ_ONCE (rq->uclamp[UCLAMP_MIN ].value);unsigned long max_util =READ_ONCE (rq->uclamp[UCLAMP_MAX ].value);
@@ -2325,17 +2325,17 @@ unsigned long uclamp_util_with(struct rq *rq, unsigned long util, return clamp(util, min_util, max_util); } -static inline unsigned long uclamp_util (struct rq *rq,unsigned long util) +static inline unsigned long uclamp_rq_util (struct rq *rq,unsigned long util) { -return uclamp_util_with (rq, util,NULL ); +return uclamp_rq_util_with (rq, util,NULL ); }#else /* CONFIG_UCLAMP_TASK */ -static inline unsigned long uclamp_util_with (struct rq *rq,unsigned long util, -struct task_struct *p) +static inline unsigned long uclamp_rq_util_with (struct rq *rq,unsigned long util, +struct task_struct *p) {return util; } -static inline unsigned long uclamp_util (struct rq *rq,unsigned long util) +static inline unsigned long uclamp_rq_util (struct rq *rq,unsigned long util) {return util; }
Signature · 1 line
2.24.0
PATCH v2 3/4 sched/fair: Make task_fits_capacity() consider uclamp restrictions
In reply to Valentin Schneidertask_fits_capacity() drives CPU selection at wakeup time, and is also used to detect misfit tasks. Right now it does so by comparing task_util_est() with a CPU's capacity, but doesn't take into account uclamp restrictions.
There's a few interesting uses that can come out of doing this. For instance, a low uclamp.max value could prevent certain tasks from being flagged as misfit tasks, so they could merrily remain on low-capacity CPUs. Similarly, a high uclamp.min value would steer tasks towards high capacity CPU at wakeup (and, should that fail, later steered via misfit balancing), so such "boosted" tasks would favor CPUs of higher capacity.
Introduce uclamp_task_util() and make task_fits_capacity() use it.
--- kernel/sched/fair.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
kernel/sched/fair.c +17 -1
@@ -3711,6 +3711,22 @@ static inline unsigned long task_util_est(struct task_struct *p)return max (task_util (p),_task_util_est (p)); } +#ifdef CONFIG_UCLAMP_TASK +static inline +unsigned long uclamp_task_util (struct task_struct *p) +{ +return clamp (task_util_est (p), + (unsigned long )uclamp_eff_value (p,UCLAMP_MIN ), + (unsigned long )uclamp_eff_value (p,UCLAMP_MAX )); +} +#else +static inline +unsigned long uclamp_task_util (struct task_struct *p) +{ +return task_util_est (p); +} +#endif +static inline void util_est_enqueue (struct cfs_rq *cfs_rq,struct task_struct *p) {
@@ -3822,7 +3838,7 @@ util_est_dequeue(struct cfs_rq *cfs_rq, struct task_struct *p, bool task_sleep)static inline int task_fits_capacity (struct task_struct *p,long capacity) { -return fits_capacity (task_util_est (p), capacity); +return fits_capacity (uclamp_task_util (p), capacity); }static inline void update_misfit_status (struct task_struct *p,struct rq *rq)
Signature · 1 line
2.24.0
Dietmar Eggemann
reviewerRe: [PATCH v2 3/4] sched/fair: Make task_fits_capacity() consider uclamp restrictions
On 03/12/2019 16:59, Valentin Schneider wrote:
[...]
Quoted 9 lines
kernel/sched/fair.c +1
-0@@ -3711,6 +3711,22 @@ static inline unsigned long task_util_est(struct task_struct *p)return max (task_util (p),_task_util_est (p)); } +#ifdef CONFIG_UCLAMP_TASK
kernel/sched/fair.c static inline unsigned long task_util_est(struct task_struct *p) · line 3724
Quoted 10 lines
kernel/sched/fair.c +10
-0+static inline +unsigned long uclamp_task_util (struct task_struct *p) +{ +return clamp (task_util_est (p), + (unsigned long )uclamp_eff_value (p,UCLAMP_MIN ), + (unsigned long )uclamp_eff_value (p,UCLAMP_MAX )); +} +#else +static inline +unsigned long uclamp_task_util (struct task_struct *p)
[...]
Save some lines?
kernel/sched/fair.c +0 -0
@@ -3712,16 +3712,14 @@ static inline unsigned long task_util_est(struct
task_struct *p)
}
#ifdef CONFIG_UCLAMP_TASK
-static inline
-unsigned long uclamp_task_util(struct task_struct *p) +static inline unsigned long uclamp_task_util(struct task_struct *p)
{
return clamp(task_util_est(p),
(unsigned long)uclamp_eff_value(p, UCLAMP_MIN), (unsigned long)uclamp_eff_value(p, UCLAMP_MAX));
}
#else
-static inline
-unsigned long uclamp_task_util(struct task_struct *p) +static inline unsigned long uclamp_task_util(struct task_struct *p)
{
return task_util_est(p);}
[...]
Re: [PATCH v2 3/4] sched/fair: Make task_fits_capacity() consider uclamp restrictions
Quoted 26 lines · Dietmar Eggemann
On 03/12/2019 16:59, Valentin Schneider wrote:
[...]
Quoted 19 lines
kernel/sched/fair.c +11
-0@@ -3711,6 +3711,22 @@ static inline unsigned long task_util_est(struct task_struct *p)return max (task_util (p),_task_util_est (p)); } +#ifdef CONFIG_UCLAMP_TASK +static inline +unsigned long uclamp_task_util (struct task_struct *p) +{ +return clamp (task_util_est (p), + (unsigned long )uclamp_eff_value (p,UCLAMP_MIN ), + (unsigned long )uclamp_eff_value (p,UCLAMP_MAX )); +} +#else +static inline +unsigned long uclamp_task_util (struct task_struct *p)[...]
Quoted 2 lines
Save some lines?
Right! I went a bit overboard there.
Quoted 1 line
kernel/sched/fair.c +0
-0
<snip>
PATCH v2 4/4 sched/fair: Make feec() consider uclamp restrictions
In reply to Valentin SchneiderWe've just made task_fits_capacity() uclamp-aware, and find_energy_efficient_cpu() needs to go through the same treatment. Things are somewhat different here however - we can't directly use the now uclamp-aware task_fits_capacity(). Consider the following setup:
rq.cpu_capacity_orig = 512
rq.util_avg = 200
rq.uclamp.max = 768
p.util_est = 600
p.uclamp.max = 256
(p not yet enqueued on rq)
Using task_fits_capacity() here would tell us that p fits on the above CPU. However, enqueuing p on that CPU *will* cause it to become overutilized since rq clamp values are max-aggregated, so we'd remain with
rq.uclamp.max = 768
Thus we could reach a high enough frequency to reach beyond 0.8 * 512 utilization (== overutilized). What feec() needs here is uclamp_rq_util_with() which lets us peek at the future utilization landscape, including rq-wide uclamp values.
Make find_energy_efficient_cpu() use uclamp_rq_util_with() for its fits_capacity() check. This is in line with what compute_energy() ends up using for estimating utilization.
--- kernel/sched/fair.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
kernel/sched/fair.c +10 -2
@@ -6284,9 +6284,18 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)if (!cpumask_test_cpu (cpu, p->cpus_ptr))continue ; -/* Skip CPUs that will be overutilized. */ util =cpu_util_next (cpu, p, cpu); cpu_cap =capacity_of (cpu); + spare_cap = cpu_cap - util; + +/* +* Skip CPUs that cannot satisfy the capacity request. +* IOW, placing the task there would make the CPU +* overutilized. Take uclamp into account to see how +* much capacity we can get out of the CPU; this is +* aligned with schedutil_cpu_util(). +*/ + util =uclamp_rq_util_with (cpu_rq (cpu), util, p);if (!fits_capacity (util, cpu_cap))continue ;
@@ -6301,7 +6310,6 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)* Find the CPU with the maximum spare capacity in * the performance domain */ - spare_cap = cpu_cap - util;if (spare_cap > max_spare_cap) { max_spare_cap = spare_cap; max_spare_cap_cpu = cpu;
Signature · 1 line
2.24.0
Dietmar Eggemann
reviewerRe: [PATCH v2 4/4] sched/fair: Make feec() consider uclamp restrictions
On 03/12/2019 16:59, Valentin Schneider wrote:
Could you replace feec (find_energy_efficient_cpu) with EAS wakeup path in the subject line? The term EAS is described in Documentation/scheduler/sched-energy.rst so its probably easier to match the patch to functionality.
Quoted 9 lines
We've just made
task_fits_capacity()uclamp-aware, andfind_energy_efficient_cpu()needs to go through the same treatment. Things are somewhat different here however - we can't directly use the now uclamp-awaretask_fits_capacity(). Consider the following setup:rq.cpu_capacity_orig = 512
rq.util_avg = 200
rq.uclamp.max = 768
Quoted 8 lines
p.util_est = 600
p.uclamp.max = 256(p not yet enqueued on rq)
Using
task_fits_capacity()here would tell us that p fits on the above CPU. However, enqueuing p on that CPU *will* cause it to become overutilized since rq clamp values are max-aggregated, so we'd remain with
I assume it doesn't harm to explicitly mention that this rq.uclamp.max = 768 value comes from another task already enqueued on a cfs_rq of this rq. This gives same substance to the term max-aggregated here.
Quoted 4 lines
rq.uclamp.max = 768
Thus we could reach a high enough frequency to reach beyond 0.8 * 512 utilization (== overutilized). What
feec()needs here is
s/feec()/find_energy_efficient_cpu() ?
Quoted 6 lines
uclamp_rq_util_with()which lets us peek at the future utilization landscape, including rq-wide uclamp values.Make
find_energy_efficient_cpu()useuclamp_rq_util_with()for itsfits_capacity()check. This is in line with whatcompute_energy()ends up using for estimating utilization.
This is also aligned with schedutil_cpu_util() (you do mention this in the code later in this patch.
[...]
Re: [PATCH v2 4/4] sched/fair: Make feec() consider uclamp restrictions
Quoted 7 lines · Dietmar Eggemann
On 03/12/2019 16:59, Valentin Schneider wrote:
Could you replace feec (
find_energy_efficient_cpu) with EAS wakeup path in the subject line? The term EAS is described inDocumentation/scheduler/sched-energy.rstso its probably easier to match the patch to functionality.
Will do.
Quoted 14 lines
Quoted 14 lines
We've just made
task_fits_capacity()uclamp-aware, andfind_energy_efficient_cpu()needs to go through the same treatment. Things are somewhat different here however - we can't directly use the now uclamp-awaretask_fits_capacity(). Consider the following setup:rq.cpu_capacity_orig = 512
rq.util_avg = 200
rq.uclamp.max = 768p.util_est = 600
p.uclamp.max = 256(p not yet enqueued on rq)
Quoted 8 lines
Quoted 3 lines
Using
task_fits_capacity()here would tell us that p fits on the above CPU. However, enqueuing p on that CPU *will* cause it to become overutilized since rq clamp values are max-aggregated, so we'd remain withI assume it doesn't harm to explicitly mention that this rq.uclamp.max = 768 value comes from another task already enqueued on a
cfs_rqof this rq. This gives same substance to the term max-aggregated here.
I've changed the setup example to:
The target runqueue, rq:
rq.cpu_capacity_orig = 512
rq.cfs.avg.util_avg = 200
rq.uclamp.max = 768 // the max p.uclamp.max of all enqueued p's is 768The waking task, p (not yet enqueued on rq):
p.util_est = 600
p.uclamp.max = 100I'll also flesh out the rest.
Quoted 7 lines
Quoted 4 lines
rq.uclamp.max = 768
Thus we could reach a high enough frequency to reach beyond 0.8 * 512 utilization (== overutilized). What
feec()needs here iss/feec()/find_energy_efficient_cpu() ?
Will do.
Quoted 10 lines
Quoted 6 lines
uclamp_rq_util_with()which lets us peek at the future utilization landscape, including rq-wide uclamp values.Make
find_energy_efficient_cpu()useuclamp_rq_util_with()for itsfits_capacity()check. This is in line with whatcompute_energy()ends up using for estimating utilization.This is also aligned with
schedutil_cpu_util()(you do mention this in the code later in this patch.
That's what I imply with compute_energy() (which ends up calling schedutil_cpu_util()).
Quoted 2 lines
[...]