From: Shrikanth Hegde <sshegde@linux.vnet.ibm.com>
To: Tim Chen <tim.c.chen@linux.intel.com>
Cc: dietmar.eggemann@arm.com, vschneid@redhat.com,
linux-kernel@vger.kernel.org, srikar@linux.vnet.ibm.com,
mgorman@techsingularity.net, mingo@kernel.org,
yu.c.chen@intel.com, ricardo.neri-calderon@linux.intel.com,
iamjoonsoo.kim@lge.com, juri.lelli@redhat.com,
rocking@linux.alibaba.com, joshdon@google.com, mingo@redhat.com,
peterz@infradead.org, vincent.guittot@linaro.org
Subject: Re: [PATCH] sched/fair: optimize should_we_balance for higher SMT systems
Date: Wed, 6 Sep 2023 07:36:32 +0530 [thread overview]
Message-ID: <6d958bf0-d0e9-ab6f-944f-62a123adf98d@linux.vnet.ibm.com> (raw)
In-Reply-To: <925bbda25461035fdec1bebf8487f84f9a3852a7.camel@linux.intel.com>
On 9/6/23 1:00 AM, Tim Chen wrote:
> On Sat, 2023-09-02 at 13:42 +0530, Shrikanth Hegde wrote:
>>
>>
>> Fixes: b1bfeab9b002 ("sched/fair: Consider the idle state of the whole core for load balance")
>> Signed-off-by: Shrikanth Hegde <sshegde@linux.vnet.ibm.com>
>> ---
>> kernel/sched/fair.c | 15 ++++++++++++++-
>> 1 file changed, 14 insertions(+), 1 deletion(-)
>>
>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>> index 0b7445cd5af9..6e31923293bb 100644
>> --- a/kernel/sched/fair.c
>> +++ b/kernel/sched/fair.c
>> @@ -6619,6 +6619,7 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
>> /* Working cpumask for: load_balance, load_balance_newidle. */
>> static DEFINE_PER_CPU(cpumask_var_t, load_balance_mask);
>> static DEFINE_PER_CPU(cpumask_var_t, select_rq_mask);
>> +static DEFINE_PER_CPU(cpumask_var_t, should_we_balance_tmpmask);
>>
>> #ifdef CONFIG_NO_HZ_COMMON
>>
>> @@ -10913,6 +10914,7 @@ static int active_load_balance_cpu_stop(void *data);
>>
>> static int should_we_balance(struct lb_env *env)
>> {
>> + struct cpumask *swb_cpus = this_cpu_cpumask_var_ptr(should_we_balance_tmpmask);
>> struct sched_group *sg = env->sd->groups;
>> int cpu, idle_smt = -1;
>>
>> @@ -10936,8 +10938,9 @@ static int should_we_balance(struct lb_env *env)
>> return 1;
>> }
>>
>> + cpumask_copy(swb_cpus, group_balance_mask(sg));
>> /* Try to find first idle CPU */
>> - for_each_cpu_and(cpu, group_balance_mask(sg), env->cpus) {
>> + for_each_cpu_and(cpu, swb_cpus, env->cpus) {
>> if (!idle_cpu(cpu))
>> continue;
>>
>> @@ -10949,6 +10952,14 @@ static int should_we_balance(struct lb_env *env)
>> if (!(env->sd->flags & SD_SHARE_CPUCAPACITY) && !is_core_idle(cpu)) {
>> if (idle_smt == -1)
>> idle_smt = cpu;
>> + /*
>> + * If the core is not idle, and first SMT sibling which is
>> + * idle has been found, then its not needed to check other
>> + * SMT siblings for idleness
>> + */
>> +#ifdef CONFIG_SCHED_SMT
>> + cpumask_andnot(swb_cpus, swb_cpus, cpu_smt_mask(cpu));
>> +#endif
>> continue;
>> }
>>
>> @@ -12914,6 +12925,8 @@ __init void init_sched_fair_class(void)
>> for_each_possible_cpu(i) {
>> zalloc_cpumask_var_node(&per_cpu(load_balance_mask, i), GFP_KERNEL, cpu_to_node(i));
>> zalloc_cpumask_var_node(&per_cpu(select_rq_mask, i), GFP_KERNEL, cpu_to_node(i));
>> + zalloc_cpumask_var_node(&per_cpu(should_we_balance_tmpmask, i),
>> + GFP_KERNEL, cpu_to_node(i));
>
> Shrianth,
>
Hi Tim,
Thanks for taking a look at this patch.
> Wonder if we can avoid allocating the
> should_we_balance_tmpmask for SMT2 case to save memory
> for system with large number of cores.
>
> The new mask and logic I think is only needed for more than 2 threads in a core.
Code would have to be refactored quite a bit if one needs to take
different approach for specific SMT setting.
I think there would some cases in SMT2 that will benefit as well.
Lets say 1 cpu in each core is busy. the busy CPU happens to be second
CPU in the core. In that case, this approach would skip that instead of
checking if that is idle or not.
>
> Tim
>>
>> #ifdef CONFIG_CFS_BANDWIDTH
>> INIT_CSD(&cpu_rq(i)->cfsb_csd, __cfsb_csd_unthrottle, cpu_rq(i));
>> --
>> 2.31.1
>>
>
next prev parent reply other threads:[~2023-09-06 2:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-02 8:12 Shrikanth Hegde
2023-09-02 10:58 ` Ingo Molnar
2023-09-06 1:48 ` Shrikanth Hegde
2023-09-02 16:17 ` [tip: sched/urgent] sched/fair: Optimize should_we_balance() for large " tip-bot2 for Shrikanth Hegde
2023-09-05 19:30 ` [PATCH] sched/fair: optimize should_we_balance for higher " Tim Chen
2023-09-06 2:06 ` Shrikanth Hegde [this message]
2023-09-06 15:56 ` Tim Chen
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=6d958bf0-d0e9-ab6f-944f-62a123adf98d@linux.vnet.ibm.com \
--to=sshegde@linux.vnet.ibm.com \
--cc=dietmar.eggemann@arm.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=joshdon@google.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@techsingularity.net \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=ricardo.neri-calderon@linux.intel.com \
--cc=rocking@linux.alibaba.com \
--cc=srikar@linux.vnet.ibm.com \
--cc=tim.c.chen@linux.intel.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=yu.c.chen@intel.com \
/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
all inboxes | Powered by JetHome®