From: Peter Zijlstra <peterz@infradead.org>
To: Barry Song <21cnbao@gmail.com>
Cc: mingo@redhat.com, juri.lelli@redhat.com,
vincent.guittot@linaro.org, rostedt@goodmis.org,
linux-kernel@vger.kernel.org, dietmar.eggemann@arm.com,
bsegall@google.com, mgorman@suse.de, bristot@redhat.com,
Barry Song <song.bao.hua@hisilicon.com>
Subject: Re: [PATCH] sched/fair: Remove the cost of a redundant cpumask_next_wrap in select_idle_cpu
Date: Tue, 23 Nov 2021 22:07:05 +0100 [thread overview]
Message-ID: <20211123210705.GD721624@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <20211123112229.7812-1-21cnbao@gmail.com>
On Tue, Nov 23, 2021 at 07:22:29PM +0800, Barry Song wrote:
> From: Barry Song <song.bao.hua@hisilicon.com>
>
> This patch keeps the same scanning amount, but drops a redundant loop
> of cpumask_next_wrap.
> The original code did for_each_cpu_wrap(cpu, cpus, target + 1), then
> checked --nr; this patch does --nr before doing the next loop, thus,
> it can remove a cpumask_next_wrap() which costs a little bit.
>
> Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
> ---
> kernel/sched/fair.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index ff69f24..e2fb3e0 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -6298,9 +6298,9 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
>
> span_avg = sd->span_weight * avg_idle;
> if (span_avg > 4*avg_cost)
> - nr = div_u64(span_avg, avg_cost);
> + nr = div_u64(span_avg, avg_cost) - 1;
> else
> - nr = 4;
> + nr = 3;
>
> time = cpu_clock(this);
> }
> @@ -6312,11 +6312,11 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
> return i;
>
> } else {
> - if (!--nr)
> - return -1;
> idle_cpu = __select_idle_cpu(cpu, p);
> if ((unsigned int)idle_cpu < nr_cpumask_bits)
> break;
> + if (!--nr)
> + return -1;
> }
> }
That's just confusing code. Isn't it much clearer to write the whole
thing like so ?
nr--;
for_each_cpu_wrap(cpu, cpus, target+1) {
...
if (!nr--)
return -1;
}
next prev parent reply other threads:[~2021-11-23 21:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-23 11:22 [PATCH] sched/fair: Remove the cost of a redundant cpumask_next_wrap in select_idle_cpu Barry Song
2021-11-23 21:07 ` Peter Zijlstra [this message]
2021-11-24 0:07 ` Barry Song
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=20211123210705.GD721624@worktop.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=21cnbao@gmail.com \
--cc=bristot@redhat.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=rostedt@goodmis.org \
--cc=song.bao.hua@hisilicon.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