Commit b812fc97 authored by Vincent Donnefort's avatar Vincent Donnefort Committed by Peter Zijlstra

sched/fair: Remove the energy margin in feec()

find_energy_efficient_cpu() integrates a margin to protect tasks from
bouncing back and forth from a CPU to another. This margin is set as being
6% of the total current energy estimated on the system. This however does
not work for two reasons:

1. The energy estimation is not a good absolute value:

compute_energy() used in feec() is a good estimation for task placement as
it allows to compare the energy with and without a task. The computed
delta will give a good overview of the cost for a certain task placement.
It, however, doesn't work as an absolute estimation for the total energy
of the system. First it adds the contribution to idle CPUs into the
energy, second it mixes util_avg with util_est values. util_avg contains
the near history for a CPU usage, it doesn't tell at all what the current
utilization is. A system that has been quite busy in the near past will
hold a very high energy and then a high margin preventing any task
migration to a lower capacity CPU, wasting energy. It even creates a
negative feedback loop: by holding the tasks on a less efficient CPU, the
margin contributes in keeping the energy high.

2. The margin handicaps small tasks:

On a system where the workload is composed mostly of small tasks (which is
often the case on Android), the overall energy will be high enough to
create a margin none of those tasks can cross. On a Pixel4, a small
utilization of 5% on all the CPUs creates a global estimated energy of 140
joules, as per the Energy Model declaration of that same device. This
means, after applying the 6% margin that any migration must save more than
8 joules to happen. No task with a utilization lower than 40 would then be
able to migrate away from the biggest CPU of the system.

The 6% of the overall system energy was brought by the following patch:

 (eb92692b sched/fair: Speed-up energy-aware wake-ups)

It was previously 6% of the prev_cpu energy. Also, the following one
made this margin value conditional on the clusters where the task fits:

 (8d4c97c1 sched/fair: Only compute base_energy_pd if necessary)

We could simply revert that margin change to what it was, but the original
version didn't have strong grounds neither and as demonstrated in (1.) the
estimated energy isn't a good absolute value. Instead, removing it
completely. It is indeed, made possible by recent changes that improved
energy estimation comparison fairness (sched/fair: Remove task_util from
effective utilization in feec()) (PM: EM: Increase energy calculation
precision) and task utilization stabilization (sched/fair: Decay task
util_avg during migration)

Without a margin, we could have feared bouncing between CPUs. But running
LISA's eas_behaviour test coverage on three different platforms (Hikey960,
RB-5 and DB-845) showed no issue.

Removing the energy margin enables more energy-optimized placements for a
more energy efficient system.
Signed-off-by: default avatarVincent Donnefort <vincent.donnefort@arm.com>
Signed-off-by: default avatarVincent Donnefort <vdonnefort@google.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarDietmar Eggemann <dietmar.eggemann@arm.com>
Tested-by: default avatarLukasz Luba <lukasz.luba@arm.com>
Link: https://lkml.kernel.org/r/20220621090414.433602-8-vdonnefort@google.com
parent 3e8c6c9a
...@@ -6868,9 +6868,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) ...@@ -6868,9 +6868,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
{ {
struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_rq_mask); struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_rq_mask);
unsigned long prev_delta = ULONG_MAX, best_delta = ULONG_MAX; unsigned long prev_delta = ULONG_MAX, best_delta = ULONG_MAX;
int cpu, best_energy_cpu = prev_cpu, target = -1;
struct root_domain *rd = this_rq()->rd; struct root_domain *rd = this_rq()->rd;
unsigned long base_energy = 0; int cpu, best_energy_cpu, target = -1;
struct sched_domain *sd; struct sched_domain *sd;
struct perf_domain *pd; struct perf_domain *pd;
struct energy_env eenv; struct energy_env eenv;
...@@ -6902,8 +6901,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) ...@@ -6902,8 +6901,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
unsigned long cpu_cap, cpu_thermal_cap, util; unsigned long cpu_cap, cpu_thermal_cap, util;
unsigned long cur_delta, max_spare_cap = 0; unsigned long cur_delta, max_spare_cap = 0;
bool compute_prev_delta = false; bool compute_prev_delta = false;
unsigned long base_energy_pd;
int max_spare_cap_cpu = -1; int max_spare_cap_cpu = -1;
unsigned long base_energy;
cpumask_and(cpus, perf_domain_span(pd), cpu_online_mask); cpumask_and(cpus, perf_domain_span(pd), cpu_online_mask);
...@@ -6961,17 +6960,16 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) ...@@ -6961,17 +6960,16 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
eenv_pd_busy_time(&eenv, cpus, p); eenv_pd_busy_time(&eenv, cpus, p);
/* Compute the 'base' energy of the pd, without @p */ /* Compute the 'base' energy of the pd, without @p */
base_energy_pd = compute_energy(&eenv, pd, cpus, p, -1); base_energy = compute_energy(&eenv, pd, cpus, p, -1);
base_energy += base_energy_pd;
/* Evaluate the energy impact of using prev_cpu. */ /* Evaluate the energy impact of using prev_cpu. */
if (compute_prev_delta) { if (compute_prev_delta) {
prev_delta = compute_energy(&eenv, pd, cpus, p, prev_delta = compute_energy(&eenv, pd, cpus, p,
prev_cpu); prev_cpu);
/* CPU utilization has changed */ /* CPU utilization has changed */
if (prev_delta < base_energy_pd) if (prev_delta < base_energy)
goto unlock; goto unlock;
prev_delta -= base_energy_pd; prev_delta -= base_energy;
best_delta = min(best_delta, prev_delta); best_delta = min(best_delta, prev_delta);
} }
...@@ -6980,9 +6978,9 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) ...@@ -6980,9 +6978,9 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
cur_delta = compute_energy(&eenv, pd, cpus, p, cur_delta = compute_energy(&eenv, pd, cpus, p,
max_spare_cap_cpu); max_spare_cap_cpu);
/* CPU utilization has changed */ /* CPU utilization has changed */
if (cur_delta < base_energy_pd) if (cur_delta < base_energy)
goto unlock; goto unlock;
cur_delta -= base_energy_pd; cur_delta -= base_energy;
if (cur_delta < best_delta) { if (cur_delta < best_delta) {
best_delta = cur_delta; best_delta = cur_delta;
best_energy_cpu = max_spare_cap_cpu; best_energy_cpu = max_spare_cap_cpu;
...@@ -6991,12 +6989,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) ...@@ -6991,12 +6989,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
} }
rcu_read_unlock(); rcu_read_unlock();
/* if (best_delta < prev_delta)
* Pick the best CPU if prev_cpu cannot be used, or if it saves at
* least 6% of the energy used by prev_cpu.
*/
if ((prev_delta == ULONG_MAX) ||
(prev_delta - best_delta) > ((prev_delta + base_energy) >> 4))
target = best_energy_cpu; target = best_energy_cpu;
return target; return target;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment