From: "Li, Aubrey" <aubrey.li@linux.intel.com>
To: Vincent Guittot <vincent.guittot@linaro.org>,
Jiang Biao <benbjiang@gmail.com>
Cc: Aubrey Li <aubrey.li@intel.com>, Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <valentin.schneider@arm.com>,
Tim Chen <tim.c.chen@linux.intel.com>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH v1 1/1] sched/fair: select idle cpu from idle cpumask in sched domain
Date: Tue, 15 Sep 2020 21:38:04 +0800 [thread overview]
Message-ID: <3c9c8db6-86c0-3f62-4a8e-a5df4cb03715@linux.intel.com> (raw)
In-Reply-To: <CAKfTPtC1DQOCmQRJYPO4zH99Nw622zx__a-4TKAJNHJJfLpvKg@mail.gmail.com>
On 2020/9/15 17:23, Vincent Guittot wrote:
> On Tue, 15 Sep 2020 at 10:47, Jiang Biao <benbjiang@gmail.com> wrote:
>>
>> Hi, Vincent
>>
>> On Mon, 14 Sep 2020 at 20:26, Vincent Guittot
>> <vincent.guittot@linaro.org> wrote:
>>>
>>> On Sun, 13 Sep 2020 at 05:59, Jiang Biao <benbjiang@gmail.com> wrote:
>>>>
>>>> Hi, Aubrey
>>>>
>>>> On Fri, 11 Sep 2020 at 23:48, Aubrey Li <aubrey.li@intel.com> wrote:
>>>>>
>>>>> Added idle cpumask to track idle cpus in sched domain. When a CPU
>>>>> enters idle, its corresponding bit in the idle cpumask will be set,
>>>>> and when the CPU exits idle, its bit will be cleared.
>>>>>
>>>>> When a task wakes up to select an idle cpu, scanning idle cpumask
>>>>> has low cost than scanning all the cpus in last level cache domain,
>>>>> especially when the system is heavily loaded.
>>>>>
>>>>> Signed-off-by: Aubrey Li <aubrey.li@linux.intel.com>
>>>>> ---
>>>>> include/linux/sched/topology.h | 13 +++++++++++++
>>>>> kernel/sched/fair.c | 4 +++-
>>>>> kernel/sched/topology.c | 2 +-
>>>>> 3 files changed, 17 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h
>>>>> index fb11091129b3..43a641d26154 100644
>>>>> --- a/include/linux/sched/topology.h
>>>>> +++ b/include/linux/sched/topology.h
>>>>> @@ -65,8 +65,21 @@ struct sched_domain_shared {
>>>>> atomic_t ref;
>>>>> atomic_t nr_busy_cpus;
>>>>> int has_idle_cores;
>>>>> + /*
>>>>> + * Span of all idle CPUs in this domain.
>>>>> + *
>>>>> + * NOTE: this field is variable length. (Allocated dynamically
>>>>> + * by attaching extra space to the end of the structure,
>>>>> + * depending on how many CPUs the kernel has booted up with)
>>>>> + */
>>>>> + unsigned long idle_cpus_span[];
>>>>> };
>>>>>
>>>>> +static inline struct cpumask *sds_idle_cpus(struct sched_domain_shared *sds)
>>>>> +{
>>>>> + return to_cpumask(sds->idle_cpus_span);
>>>>> +}
>>>>> +
>>>>> struct sched_domain {
>>>>> /* These fields must be setup */
>>>>> struct sched_domain __rcu *parent; /* top domain must be null terminated */
>>>>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>>>>> index 6b3b59cc51d6..3b6f8a3589be 100644
>>>>> --- a/kernel/sched/fair.c
>>>>> +++ b/kernel/sched/fair.c
>>>>> @@ -6136,7 +6136,7 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, int t
>>>>>
>>>>> time = cpu_clock(this);
>>>>>
>>>>> - cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr);
>>>>> + cpumask_and(cpus, sds_idle_cpus(sd->shared), p->cpus_ptr);
>>>> Is the sds_idle_cpus() always empty if nohz=off?
>>>
>>> Good point
>>>
>>>> Do we need to initialize the idle_cpus_span with sched_domain_span(sd)?
>>>>
>>>>>
>>>>> for_each_cpu_wrap(cpu, cpus, target) {
>>>>> if (!--nr)
>>>>> @@ -10182,6 +10182,7 @@ static void set_cpu_sd_state_busy(int cpu)
>>>>> sd->nohz_idle = 0;
>>>>>
>>>>> atomic_inc(&sd->shared->nr_busy_cpus);
>>>>> + cpumask_clear_cpu(cpu, sds_idle_cpus(sd->shared));
>>>>> unlock:
>>>>> rcu_read_unlock();
>>>>> }
>>>>> @@ -10212,6 +10213,7 @@ static void set_cpu_sd_state_idle(int cpu)
>>>>> sd->nohz_idle = 1;
>>>>>
>>>>> atomic_dec(&sd->shared->nr_busy_cpus);
>>>>> + cpumask_set_cpu(cpu, sds_idle_cpus(sd->shared));
>>>> This only works when entering/exiting tickless mode? :)
>>>> Why not update idle_cpus_span during tick_nohz_idle_enter()/exit()?
>>>
>>> set_cpu_sd_state_busy is only called during a tick in order to limit
>>> the rate of the update to once per tick per cpu at most and prevents
>>> any kind of storm of update if short running tasks wake/sleep all the
>>> time. We don't want to update a cpumask at each and every enter/leave
>>> idle.
>>>
>> Agree. But set_cpu_sd_state_busy seems not being reached when
>> nohz=off, which means it will not work for that case? :)
>
> Yes set_cpu_sd_state_idle/busy are nohz function
Thanks Biao to point this out.
If the shared idle cpumask is initialized with sched_domain_span(sd),
then nohz=off case will remain the previous behavior.
Thanks,
-Aubrey
next prev parent reply other threads:[~2020-09-16 0:34 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-10 5:42 [RFC PATCH v1 0/1] " Aubrey Li
2020-09-10 5:42 ` [RFC PATCH v1 1/1] sched/fair: " Aubrey Li
2020-09-11 16:28 ` Qais Yousef
2020-09-11 23:04 ` Li, Aubrey
2020-09-11 23:16 ` Li, Aubrey
2020-09-14 10:31 ` Valentin Schneider
2020-09-14 11:08 ` Qais Yousef
2020-09-14 11:26 ` Valentin Schneider
2020-09-14 11:31 ` Qais Yousef
2020-09-13 3:59 ` Jiang Biao
2020-09-14 12:26 ` Vincent Guittot
2020-09-15 8:47 ` Jiang Biao
2020-09-15 9:23 ` Vincent Guittot
2020-09-15 13:38 ` Li, Aubrey [this message]
2020-09-14 12:32 ` Vincent Guittot
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=3c9c8db6-86c0-3f62-4a8e-a5df4cb03715@linux.intel.com \
--to=aubrey.li@linux.intel.com \
--cc=aubrey.li@intel.com \
--cc=benbjiang@gmail.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tim.c.chen@linux.intel.com \
--cc=valentin.schneider@arm.com \
--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
Powered by JetHome