LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Qais Yousef <qais.yousef@arm.com>,
	Valentin Schneider <valentin.schneider@arm.com>
Subject: Re: [PATCH V2] sched: fair: Use the earliest break even
Date: Thu, 12 Mar 2020 11:04:19 +0100	[thread overview]
Message-ID: <e6e8ff94-64f2-6404-e332-2e030fc7e332@linaro.org> (raw)
In-Reply-To: <CAKfTPtAqeHhVCeSgE1DsaGGkM6nY-9oAvGw_6zWvv1bKyE85JQ@mail.gmail.com>

On 12/03/2020 09:36, Vincent Guittot wrote:
> Hi Daniel,
> 
> On Wed, 11 Mar 2020 at 21:28, Daniel Lezcano <daniel.lezcano@linaro.org> wrote:
>>
>> In the idle CPU selection process occuring in the slow path via the
>> find_idlest_group_cpu() function, we pick up in priority an idle CPU
>> with the shallowest idle state otherwise we fall back to the least
>> loaded CPU.
> 
> The idea makes sense but this path is only used by fork and exec so
> I'm not sure about the real impact

I agree the fork / exec path is called much less often than the wake
path but it makes more sense for the decision.

>> In order to be more energy efficient but without impacting the
>> performances, let's use another criteria: the break even deadline.
>>
>> At idle time, when we store the idle state the CPU is entering in, we
>> compute the next deadline where the CPU could be woken up without
>> spending more energy to sleep.
>>
>> At the selection process, we use the shallowest CPU but in addition we
>> choose the one with the minimal break even deadline instead of relying
>> on the idle_timestamp. When the CPU is idle, the timestamp has less
>> meaning because the CPU could have wake up and sleep again several times
>> without exiting the idle loop. In this case the break even deadline is
>> more relevant as it increases the probability of choosing a CPU which
>> reached its break even.
>>
>> Tested on:
>>  - a synquacer 24 cores, 6 sched domains
>>  - a hikey960 HMP 8 cores, 2 sched domains, with the EAS and energy probe
>>
>> sched/perf and messaging does not show a performance regression. Ran
>> 50 times schbench, adrestia and forkbench.
>>
>> The tools described at https://lwn.net/Articles/724935/
>>
>>  --------------------------------------------------------------
>> | Synquacer             | With break even | Without break even |
>>  --------------------------------------------------------------
>> | schbench *99.0th      |      14844.8    |         15017.6    |
>> | adrestia / periodic   |        57.95    |              57    |
>> | adrestia / single     |         49.3    |            55.4    |
>>  --------------------------------------------------------------
> 
> Have you got some figures or cpuidle statistics for the syncquacer ?

No, and we just noticed the syncquacer has a bug in the firmware and
does not actually go to the idle states.


>> | Hikey960              | With break even | Without break even |
>>  --------------------------------------------------------------
>> | schbench *99.0th      |      56140.8    |           56256    |
>> | schbench energy       |      153.575    |         152.676    |
>> | adrestia / periodic   |         4.98    |             5.2    |
>> | adrestia / single     |         9.02    |            9.12    |
>> | adrestia energy       |         1.18    |           1.233    |
>> | forkbench             |        7.971    |            8.05    |
>> | forkbench energy      |         9.37    |            9.42    |
>>  --------------------------------------------------------------
>>
>> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
>> ---
>>  kernel/sched/fair.c  | 18 ++++++++++++++++--
>>  kernel/sched/idle.c  |  8 +++++++-
>>  kernel/sched/sched.h | 20 ++++++++++++++++++++
>>  3 files changed, 43 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>> index 4b5d5e5e701e..8bd6ea148db7 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -5793,6 +5793,7 @@ find_idlest_group_cpu(struct sched_group *group, struct task_struct *p, int this
>>  {
>>         unsigned long load, min_load = ULONG_MAX;
>>         unsigned int min_exit_latency = UINT_MAX;
>> +       s64 min_break_even = S64_MAX;
>>         u64 latest_idle_timestamp = 0;
>>         int least_loaded_cpu = this_cpu;
>>         int shallowest_idle_cpu = -1;
>> @@ -5810,6 +5811,8 @@ find_idlest_group_cpu(struct sched_group *group, struct task_struct *p, int this
>>                 if (available_idle_cpu(i)) {
>>                         struct rq *rq = cpu_rq(i);
>>                         struct cpuidle_state *idle = idle_get_state(rq);
>> +                       s64 break_even = idle_get_break_even(rq);
>> +
>>                         if (idle && idle->exit_latency < min_exit_latency) {
>>                                 /*
>>                                  * We give priority to a CPU whose idle state
>> @@ -5817,10 +5820,21 @@ find_idlest_group_cpu(struct sched_group *group, struct task_struct *p, int this
>>                                  * of any idle timestamp.
>>                                  */
>>                                 min_exit_latency = idle->exit_latency;
>> +                               min_break_even = break_even;
>>                                 latest_idle_timestamp = rq->idle_stamp;
>>                                 shallowest_idle_cpu = i;
>> -                       } else if ((!idle || idle->exit_latency == min_exit_latency) &&
>> -                                  rq->idle_stamp > latest_idle_timestamp) {
>> +                       } else if ((idle && idle->exit_latency == min_exit_latency) &&
>> +                                  break_even < min_break_even) {
>> +                               /*
>> +                                * We give priority to the shallowest
>> +                                * idle states with the minimal break
>> +                                * even deadline to decrease the
>> +                                * probability to choose a CPU which
>> +                                * did not reach its break even yet
>> +                                */
>> +                               min_break_even = break_even;
>> +                               shallowest_idle_cpu = i;
>> +                       } else if (!idle && rq->idle_stamp > latest_idle_timestamp) {
>>                                 /*
>>                                  * If equal or no active idle state, then
>>                                  * the most recently idled CPU might have
>> diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
>> index b743bf38f08f..3342e7bae072 100644
>> --- a/kernel/sched/idle.c
>> +++ b/kernel/sched/idle.c
>> @@ -19,7 +19,13 @@ extern char __cpuidle_text_start[], __cpuidle_text_end[];
>>   */
>>  void sched_idle_set_state(struct cpuidle_state *idle_state)
>>  {
>> -       idle_set_state(this_rq(), idle_state);
>> +       struct rq *rq = this_rq();
>> +
>> +       idle_set_state(rq, idle_state);
> 
> Shouldn't the state be set after setting break even otherwise you will
> have a time window with an idle_state != null but the break_even still
> set to the previous value

IIUC we are protected in this section. Otherwise the routine above would
be also wrong [if (idle && idle->exit_latency)], no?

>> +
>> +       if (idle_state)
>> +               idle_set_break_even(rq, ktime_get_ns() +
> 
> What worries me a bit is that it adds one ktime_get call each time a
> cpu enters idle

Right, we can improve this in the future by folding the local_clock() in
cpuidle when entering idle with this ktime_get.

>> +                                   idle_state->exit_latency_ns);
>>  }

[ ... ]


-- 
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


  reply	other threads:[~2020-03-12 10:04 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-11 20:26 Daniel Lezcano
2020-03-12  8:36 ` Vincent Guittot
2020-03-12 10:04   ` Daniel Lezcano [this message]
2020-03-12 12:27     ` Vincent Guittot
2020-03-13 12:15       ` Daniel Lezcano
2020-03-13 13:15         ` Vincent Guittot
2020-03-13 13:17           ` Daniel Lezcano
2020-03-13 13:21             ` Vincent Guittot
2020-03-17  7:56     ` Morten Rasmussen
2020-03-17 13:48       ` Daniel Lezcano
2020-03-17 14:30         ` Morten Rasmussen
2020-03-17 17:07           ` Daniel Lezcano
2020-03-18  8:24             ` Morten Rasmussen
2020-03-18 10:17               ` Daniel Lezcano
2020-03-18 14:38                 ` Morten Rasmussen
2020-03-18  7:51           ` Vincent Guittot
2020-03-18  8:33             ` Morten Rasmussen
2020-03-17 10:56 ` Valentin Schneider
2020-03-17 13:59   ` Daniel Lezcano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e6e8ff94-64f2-6404-e332-2e030fc7e332@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=qais.yousef@arm.com \
    --cc=rostedt@goodmis.org \
    --cc=valentin.schneider@arm.com \
    --cc=vincent.guittot@linaro.org \
    --subject='Re: [PATCH V2] sched: fair: Use the earliest break even' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).