[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180321153518.GC13951@e110439-lin>
Date: Wed, 21 Mar 2018 15:35:18 +0000
From: Patrick Bellasi <patrick.bellasi@....com>
To: Dietmar Eggemann <dietmar.eggemann@....com>
Cc: linux-kernel@...r.kernel.org,
Peter Zijlstra <peterz@...radead.org>,
Quentin Perret <quentin.perret@....com>,
Thara Gopinath <thara.gopinath@...aro.org>,
linux-pm@...r.kernel.org,
Morten Rasmussen <morten.rasmussen@....com>,
Chris Redpath <chris.redpath@....com>,
Valentin Schneider <valentin.schneider@....com>,
"Rafael J . Wysocki" <rjw@...ysocki.net>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Vincent Guittot <vincent.guittot@...aro.org>,
Viresh Kumar <viresh.kumar@...aro.org>,
Todd Kjos <tkjos@...gle.com>,
Joel Fernandes <joelaf@...gle.com>
Subject: Re: [RFC PATCH 5/6] sched/fair: Select an energy-efficient CPU on
task wake-up
On 20-Mar 09:43, Dietmar Eggemann wrote:
> From: Quentin Perret <quentin.perret@....com>
[...]
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 76bd46502486..65a1bead0773 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -6513,6 +6513,60 @@ static unsigned long compute_energy(struct task_struct *p, int dst_cpu)
> return energy;
> }
>
> +static bool task_fits(struct task_struct *p, int cpu)
> +{
> + unsigned long next_util = cpu_util_next(cpu, p, cpu);
> +
> + return util_fits_capacity(next_util, capacity_orig_of(cpu));
^^^^^^^^^^^^^^^^^^^^^
Since here we are at scheduling CFS tasks, should we not better use
capacity_of() to account for RT/IRQ pressure ?
> +}
> +
> +static int find_energy_efficient_cpu(struct sched_domain *sd,
> + struct task_struct *p, int prev_cpu)
> +{
> + unsigned long cur_energy, prev_energy, best_energy;
> + int cpu, best_cpu = prev_cpu;
> +
> + if (!task_util(p))
We are still waking up a task... what if the task was previously
running on a big CPU which is now idle?
I understand that from a _relative_ energy_diff standpoint there is
not much to do for a 0 utilization task. However, for those tasks we
can still try to return the most energy efficient CPU among the ones
in their cpus_allowed mask.
It should be a relatively low overhead (maybe contained in a fallback
most_energy_efficient_cpu() kind of function) which allows, for
example on ARM big.LITTLE systems, to consolidate those tasks on
LITTLE CPUs instead for example keep running them on a big CPU.
> + return prev_cpu;
> +
> + /* Compute the energy impact of leaving the task on prev_cpu. */
> + prev_energy = best_energy = compute_energy(p, prev_cpu);
> +
> + /* Look for the CPU that minimizes the energy. */
^^^^^^^^^^
nit-pick: would say explicitly "best_energy" here, just to avoid
confusion about (non) possible overflows in the following if check ;)
> + for_each_cpu_and(cpu, &p->cpus_allowed, sched_domain_span(sd)) {
> + if (!task_fits(p, cpu) || cpu == prev_cpu)
nit-pick: to me it would read better as:
if (cpu == prev_cpu)
continue;
if (!task_fits(p, cpu))
continue;
but it's more matter of (personal) taste then efficiency.
> + continue;
> + cur_energy = compute_energy(p, cpu);
> + if (cur_energy < best_energy) {
> + best_energy = cur_energy;
> + best_cpu = cpu;
> + }
> + }
> +
> + /*
> + * We pick the best CPU only if it saves at least 1.5% of the
> + * energy used by prev_cpu.
> + */
> + if ((prev_energy - best_energy) > (prev_energy >> 6))
> + return best_cpu;
> +
> + return prev_cpu;
> +}
[...]
> @@ -6555,6 +6613,14 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f
> break;
> }
>
> + /*
> + * Energy-aware task placement is performed on the highest
> + * non-overutilized domain spanning over cpu and prev_cpu.
> + */
> + if (want_energy && !sd_overutilized(tmp) &&
> + cpumask_test_cpu(prev_cpu, sched_domain_span(tmp)))
> + energy_sd = tmp;
> +
Not entirely sure, but I was trying to understand if we can avoid to
modify the definition of want_affine (in the previous chunk) and move
this block before the previous "if (want_affine..." (in mainline but
not in this chunk), which will became an else, e.g.
if (want_energy && !sd_overutilized(tmp) &&
// ...
else if (want_energy && !sd_overutilized(tmp) &&
// ...
Isn't that the same?
Maybe there is a code path I'm missing... but otherwise it seems a
more self contained modification of select_task_rq_fair...
> if (tmp->flags & sd_flag)
> sd = tmp;
> else if (!want_affine)
> @@ -6586,6 +6652,8 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f
> if (want_affine)
> current->recent_used_cpu = cpu;
> }
> + } else if (energy_sd) {
> + new_cpu = find_energy_efficient_cpu(energy_sd, p, prev_cpu);
> } else {
> new_cpu = find_idlest_cpu(sd, p, cpu, prev_cpu, sd_flag);
> }
--
#include <best/regards.h>
Patrick Bellasi
Powered by blists - more mailing lists