From: Qing Wang <wangqing7171@gmail.com>
To: peterz@infradead.org
Cc: bsegall@google.com, davichazbh@gmail.com,
dietmar.eggemann@arm.com, juri.lelli@redhat.com,
kprateek.nayak@amd.com, linux-kernel@vger.kernel.org,
mgorman@suse.de, mingo@redhat.com, rostedt@goodmis.org,
tim.c.chen@linux.intel.com, vincent.guittot@linaro.org,
vschneid@redhat.com, wangqing7171@gmail.com, yu.c.chen@intel.com
Subject: Re: [PATCH v4] sched/fair: Replace random newidle_balance with Bresenham accumulator
Date: Thu, 5 Nov 2026 14:02:31 +0800 [thread overview]
Message-ID: <20261105060231.2701208-1-wangqing7171@gmail.com> (raw)
In-Reply-To: <20261030103916.GV2668564@noisy.programming.kicks-ass.net>
On Fri, 30 Oct 2026 at 18:39, Peter Zijlstra <peterz@infradead.org> wrote:
> On Fri, Oct 30, 2026 at 06:22:26PM +0800, Qing Wang wrote:
> > On Fri, 30 Oct 2026 at 17:56, Peter Zijlstra <peterz@infradead.org> wrote:
> > > Funnily enough, treating this as an independent variable and using a
> > > random number works and 'fixes' the slope change problems.
> >
> > Hi Peter,
> >
> > I explained this in the v3 thread: on a slope change, carrying
> > newidle_window_pos over from the previous window only shifts the
> > first allowed balance in the new-slope window (512 calls) earlier or
> > later; subsequent balances are still uniformly spaced. So the
> > initial value can be anything — it doesn't matter.
>
> It does matter; you're rounding down. If you discard two fractions that
> sum up to more than a whole, you've lost a call.
>
> Let '/' be the integer division; then (3/2 + 3/2) = 2, but (3+3)/2 = 3.
>
> IOW integer division (flooring) does not distribute.
>
> The result here is less newidle calls than should have happened.
>
> You cannot argue they are equal, you can argue the difference is
> irrelevant. But so far you seem unable to see this distinction :-(
Thanks again for your patience.
I think we talked past each other: the lost-calls problem from repeated
rounding down is already fixed in v4 by not clearing newidle_window_pos.
The position is never reset, so the total number of balances is
floor((initial_pos + total accumulated weight) / 1024) -- the long-run
count is exact.
My last mail was only about the initial value of newidle_window_pos in
sd_init(): it shifts the timing of first balance call.
> Also, the uniformity isn't a feature per se, another thing I called out
> earlier. One reason why uniform distribution can be detrimental is if
> two CPUs end up in a synchronized pattern, then you increase contention.
>
> Now, again, there's plenty arguments to be had why that isn't a likely
> issue in this case, but you cannot blindly state that uniform is better.
You're right, and I'm sorry for that. I favored uniformity without a
strong argument, and I kept claiming "equivalent" where the honest claim
is "the difference is bounded" -- the distinction you point out.
Performance-wise, the uniform version should be on par with the random.
And it can indeed run into the synchronization problem you describe,
but that can be mitigated by giving each sd a different initial value.
e.g.:
.newidle_window_pos = (cpu * 1024) / cpumask_weight(cpu_map)
That leaves the per-window deviation as the only remaining advantage,
as described in v4: the call count stays within one call of the
expected value in every window (vs up to ~41 call for the random
dice in the simulation). I understand if that alone is not enough to justify
the patch -- I'm grateful for the rounds of discussion.
--
Best regards,
Qing
next prev parent reply other threads:[~2026-11-05 6:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 9:19 Qing Wang
2026-10-30 9:46 ` K Prateek Nayak
2026-10-30 9:56 ` Peter Zijlstra
2026-10-30 10:22 ` Qing Wang
2026-10-30 10:39 ` Peter Zijlstra
2026-11-05 6:02 ` Qing Wang [this message]
2026-10-30 10:09 ` Qing Wang
2026-10-30 14:47 ` Kayra Cizmeci
2026-11-05 9:03 ` Chengfeng Lin
2026-11-05 18:06 ` 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=20261105060231.2701208-1-wangqing7171@gmail.com \
--to=wangqing7171@gmail.com \
--cc=bsegall@google.com \
--cc=davichazbh@gmail.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.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=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®