public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Brendan Jackman <brendan.jackman@arm.com>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	Joel Fernandes <joelaf@google.com>,
	Andres Oportus <andresoportus@google.com>,
	Ingo Molnar <mingo@redhat.com>,
	Morten Rasmussen <morten.rasmussen@arm.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>
Subject: Re: [PATCH 2/2] sched/fair: Fix use of NULL with find_idlest_group
Date: Tue, 22 Aug 2017 11:41:44 +0100	[thread overview]
Message-ID: <87d17n3mvr.fsf@arm.com> (raw)
In-Reply-To: <CAKfTPtB0phDR+m9E8p2Xnn8THhBK0-Ngu0syDzg-XUUPXmCrLA@mail.gmail.com>


On Tue, Aug 22 2017 at 07:48, Vincent Guittot wrote:
> On 21 August 2017 at 17:21, Brendan Jackman <brendan.jackman@arm.com> wrote:
>> The current use of returning NULL from find_idlest_group is broken in
> [snip]
>> ---
>>  kernel/sched/fair.c | 34 +++++++++++++++++++---------------
>>  1 file changed, 19 insertions(+), 15 deletions(-)
>>
>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>> index 64618d768546..7cb5ed719cf9 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -5382,26 +5382,29 @@ static unsigned long capacity_spare_wake(int cpu, struct task_struct *p)
>>   * domain.
>>   */
>>  static struct sched_group *
>> -find_idlest_group(struct sched_domain *sd, struct task_struct *p,
>> -                 int this_cpu, int sd_flag)
>> +find_idlest_group(struct sched_domain *sd, struct task_struct *p, int sd_flag)
>>  {
>>         struct sched_group *idlest = NULL, *group = sd->groups;
>> +       struct sched_group *local_group = sd->groups;
>>         struct sched_group *most_spare_sg = NULL;
>> -       unsigned long min_runnable_load = ULONG_MAX, this_runnable_load = 0;
>> -       unsigned long min_avg_load = ULONG_MAX, this_avg_load = 0;
>> +       unsigned long min_runnable_load = ULONG_MAX, this_runnable_load = ULONG_MAX;
>> +       unsigned long min_avg_load = ULONG_MAX, this_avg_load = ULONG_MAX;
>
> Good catch for this_runnable_load, indeed there is a problem is
> local_group is not allowed
>
>>         unsigned long most_spare = 0, this_spare = 0; >>         int load_idx = sd->forkexec_idx;
>>         int imbalance_scale = 100 + (sd->imbalance_pct-100)/2;
>>         unsigned long imbalance = scale_load_down(NICE_0_LOAD) *
>>                                 (sd->imbalance_pct-100) / 100;
>>
>> +       if (!cpumask_intersects(sched_domain_span(sd), &p->cpus_allowed))
>> +               return NULL;
>
> You should put that test above at upper level in the while (sd) loop
> or even before the while(sd) loop as there is even no need to start
> this while loop in this case. There is no need to call
> find_idlest_group if there is no cpu allowed and no group to find.
> Then, you can keep the current behavior of find_idlest_group() which
> return null if there no best group than the local one

True. I have to admit the reason I didn't do this is because due to the
current "else while", doing this outside the loop would have meant
another level of indentation. But actually if I break out a new function
as in Peter's proposal I can avoid that (plus I probably shouldn't let
code beauty overrule warm-path performance :| ).

>> +
>>         if (sd_flag & SD_BALANCE_WAKE)
>>                 load_idx = sd->wake_idx;
>>
>>         do {
>>                 unsigned long load, avg_load, runnable_load;
>>                 unsigned long spare_cap, max_spare_cap;
>> -               int local_group;
>> +               bool group_is_local = group == local_group;
>>                 int i;
>>
>>                 /* Skip over this group if it has no CPUs allowed */
>
> [snip]
>
>> @@ -5927,8 +5927,12 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f
>>                         continue;
>>                 }
>>
>> -               group = find_idlest_group(sd, p, cpu, sd_flag);
>> +               group = find_idlest_group(sd, p, sd_flag);
>>                 if (!group) {
>> +                       break;
>> +               } else if (group == sd->groups) {
>> +                       new_cpu = cpu;
>
> The " new_cpu = cpu" above should be put before the while(sd) loop
> like in Peter's proposal

I don't think that would work - I've responded along with Joel in the
other subthread.

>> +                       /* Now try balancing at a lower domain level of cpu */
>>                         sd = sd->child;
>>                         continue;
>>                 }
>> --
>> 2.14.1
>>

      reply	other threads:[~2017-08-22 10:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-21 15:21 [PATCH 0/2] sched/fair: Tweaks for select_task_rq_fair slowpath Brendan Jackman
2017-08-21 15:21 ` [PATCH 1/2] sched/fair: Remove unnecessary comparison with -1 Brendan Jackman
2017-08-21 17:30   ` Josef Bacik
2017-08-21 15:21 ` [PATCH 2/2] sched/fair: Fix use of NULL with find_idlest_group Brendan Jackman
2017-08-21 17:26   ` Josef Bacik
2017-08-21 17:59     ` Brendan Jackman
2017-08-21 20:22       ` Peter Zijlstra
2017-08-21 21:14   ` Peter Zijlstra
2017-08-21 21:23     ` Peter Zijlstra
2017-08-22  4:34     ` Joel Fernandes
2017-08-22 10:39       ` Brendan Jackman
2017-08-22 10:45         ` Brendan Jackman
2017-08-22 11:03         ` Peter Zijlstra
2017-08-22 12:46           ` Brendan Jackman
2017-08-22  7:48   ` Vincent Guittot
2017-08-22 10:41     ` Brendan Jackman [this message]

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=87d17n3mvr.fsf@arm.com \
    --to=brendan.jackman@arm.com \
    --cc=andresoportus@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=joelaf@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=morten.rasmussen@arm.com \
    --cc=peterz@infradead.org \
    --cc=vincent.guittot@linaro.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox