From: Peter Zijlstra <peterz@infradead.org>
To: Hongyan Xia <hongyan.xia@transsion.com>
Cc: Li kunyu <likunyu10@163.com>,
"mingo@redhat.com" <mingo@redhat.com>,
"juri.lelli@redhat.com" <juri.lelli@redhat.com>,
"vincent.guittot@linaro.org" <vincent.guittot@linaro.org>,
"dietmar.eggemann@arm.com" <dietmar.eggemann@arm.com>,
"rostedt@goodmis.org" <rostedt@goodmis.org>,
"bsegall@google.com" <bsegall@google.com>,
"mgorman@suse.de" <mgorman@suse.de>,
"vschneid@redhat.com" <vschneid@redhat.com>,
"kprateek.nayak@amd.com" <kprateek.nayak@amd.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kernel/sched/fair: Fix to not require calculation for the weight nice0
Date: Fri, 29 May 2026 14:01:51 +0200 [thread overview]
Message-ID: <20260529120151.GM3493090@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <edd47e8e-710c-4eec-9454-3266198a536d@transsion.com>
On Fri, May 29, 2026 at 07:37:07AM +0000, Hongyan Xia wrote:
> On 5/29/2026 10:34 AM, Li kunyu wrote:
> > Typically, the default priority for client tasks is nice0, and reducing
> > the conversion of virtual runtime to real time for nice0 tasks can
> > significantly reduce unnecessary computations.
> >
> > Signed-off-by: Li kunyu <likunyu10@163.com>
> > ---
> > kernel/sched/fair.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > index 69361c63353a..74d1c77a8bcf 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -7033,7 +7033,10 @@ static void hrtick_start_fair(struct rq *rq, struct task_struct *p)
> > resched_curr(rq);
> > return;
> > }
> > - delta = (se->load.weight * vdelta) / NICE_0_LOAD;
> > + if (unlikely(se->load.weight != NICE_0_LOAD))
> > + delta = (se->load.weight * vdelta) / NICE_0_LOAD;
> > + else
> > + delta = vdelta;
> >
> > /*
> > * Correct for instantaneous load of other classes.
>
> Given NICE_0_LOAD is a nice power-of-two which compiles down to just a
> bit shift, it seems interesting that you would find the multiplication
> to be 'significant unnecessary computations'. Do you have any data to
> support this?
Notably, branches can be many times more expensive than a mult on modern
deeply pipelined machines. Divisions are a bit of a mixed bag, but mult
is generally dirt cheap.
According to Gemini we have something like so:
+---------------------------------------------------------------------------------------------------+
| ARCHITECTURE | BRANCH MISPREDICT PENALTY | 64-BIT INTEGER MULTIPLY | 64-BIT INTEGER DIVIDE |
| (Modern Cores) | (Clock Cycles) | (Latency / Throughput) | (Latency / Throughput) |
+-------------------+----------------------------+-------------------------+------------------------+
| | | | |
| Apple M-Series | 16 to 20 cycles | 3 to 4 cycles | 7 to 9 cycles |
| (M1 through M5) | | 0.5 cycle thr. (2/clk) | 2 cycles throughput |
| | | | |
+-------------------+----------------------------+-------------------------+------------------------+
| | | | |
| Intel Core | 14 to 15 cycles * | 3 cycles | 18 to 25 cycles |
| (Panther / Arrow) | | 1 cycle thr. (1/clk) | 10 to 15 cycles thr. |
| | | | |
+-------------------+----------------------------+-------------------------+------------------------+
| | | | |
| AMD Zen | 17 to 20 cycles | 3 cycles | 12 to 14 cycles |
| (Zen 4 / Zen 5) | | 1 cycle thr. (1/clk) | 3 to 4 cycles thr. |
| | | | |
+-------------------+----------------------------+-------------------------+------------------------+
So the branch in calc_delta_fair() might still be justified, esp. if it
is predicted well. But like Hongyan noted, not in this case.
prev parent reply other threads:[~2026-05-29 12:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-29 2:34 Li kunyu
2026-05-29 7:37 ` Hongyan Xia
2026-05-29 8:13 ` Li kunyu
2026-05-29 12:01 ` Peter Zijlstra [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=20260529120151.GM3493090@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=hongyan.xia@transsion.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=likunyu10@163.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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®