From: Christian Loehle <christian.loehle@arm.com>
To: Vincent Guittot <vincent.guittot@linaro.org>
Cc: 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>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Beata Michalska <beata.michalska@arm.com>,
Elif Topuz <elif.topuz@arm.com>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@kernel.org>,
Shubhang Kaushik <sh@gentwo.org>,
Christoph Lameter <cl@gentwo.org>,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH 2/2] sched/fair: Randomize equally shallow slow-path candidates
Date: Thu, 17 Sep 2026 16:17:58 +0100 [thread overview]
Message-ID: <cd1a09fb-17e0-4d3b-9720-cdc28e90c030@arm.com> (raw)
In-Reply-To: <CAKfTPtAexsLhEb3hEnWvhFo3Z0+CsN41WQ8gfW+waLvxJQrb+A@mail.gmail.com>
On 9/17/26 16:08, Vincent Guittot wrote:
> On Thu, 17 Sept 2026 at 16:22, Christian Loehle
> <christian.loehle@arm.com> wrote:
>>
>> On 9/17/26 15:08, Vincent Guittot wrote:
>>> On Wed, 16 Sept 2026 at 12:01, Christian Loehle
>>> <christian.loehle@arm.com> wrote:
>>>>
>>>> Picking the first eligible idle CPU leaves a scan-order bias. Concurrent
>>>> slow-path selectors can choose the same CPU before either task is enqueued.
>>>>
>>>> Use reservoir sampling in the tie branch, resetting the candidate count
>>>> when a lower advertised exit latency is found. Use the per-CPU scheduler
>>>> PRNG and reciprocal_scale() to avoid variable division or a second scan.
>>>>
>>>> This reduces deterministic convergence without reserving the chosen CPU.
>>>>
>>>> Signed-off-by: Christian Loehle <christian.loehle@arm.com>
>>>> ---
>>>> kernel/sched/fair.c | 11 ++++++++---
>>>> 1 file changed, 8 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
>>>> index ff5793bddc35..6836a8364440 100644
>>>> --- a/kernel/sched/fair.c
>>>> +++ b/kernel/sched/fair.c
>>>> @@ -24,6 +24,7 @@
>>>> #include <linux/mmap_lock.h>
>>>> #include <linux/hugetlb_inline.h>
>>>> #include <linux/jiffies.h>
>>>> +#include <linux/math.h>
>>>> #include <linux/mm_api.h>
>>>> #include <linux/highmem.h>
>>>> #include <linux/hrtimer.h>
>>>> @@ -8459,6 +8460,7 @@ sched_balance_find_dst_group_cpu(struct sched_group *group, struct task_struct *
>>>> {
>>>> unsigned long load, min_load = ULONG_MAX;
>>>> unsigned int min_exit_latency = UINT_MAX;
>>>> + unsigned int nr_candidates = 0;
>>>> int least_loaded_cpu = this_cpu;
>>>> int shallowest_idle_cpu = -1;
>>>> int i;
>>>> @@ -8482,9 +8484,12 @@ sched_balance_find_dst_group_cpu(struct sched_group *group, struct task_struct *
>>>> if (idle && idle->exit_latency < min_exit_latency) {
>>>> min_exit_latency = idle->exit_latency;
>>>> shallowest_idle_cpu = i;
>>>> + nr_candidates = 1;
>>>
>>> You clear the number of candidate when you find a lower exit_latency
>>> but !idle CPUs that have already been checked will be cleared whereas
>>> they still get a chance if they are checked later.
>> That is correct. Is this a problem?
>
> I would say we should try to be consistent
Ack
>
>> (Again, mirroring what upstream currently does, let's say exit_latency(CPU0)=100, exit_latency(CPU2)=1
>> !idle at CPU3 trumps CPU2 (assuming recent idle_stamp), !idle at CPU1 doesn't trump CPU2, i.e.
>> the inconsistency around !idle is already there?)
>
> Fair enough but the idle_stamp was also in the party
>
>> And I'm assuming we really don't wanna keep a cpumask of !idle CPUs, if anything we may just ignore
>> them completely, given how unlikely it they are to be observed.
>
> We must keep them when there is no cpuidle driver, i.e. until we find
> a CPU with an idle state
Alright let me make a it a U64_MAX reservoir.
Thanks for reviewing Vincent!
prev parent reply other threads:[~2026-09-17 15:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-16 10:01 [PATCH 0/2] sched/fair: Randomize equally shallow idle CPU picks Christian Loehle
2026-09-16 10:01 ` [PATCH 1/2] sched/fair: Drop idle recency from slow-path CPU selection Christian Loehle
2026-09-17 13:28 ` Vincent Guittot
2026-09-16 10:01 ` [PATCH 2/2] sched/fair: Randomize equally shallow slow-path candidates Christian Loehle
2026-09-16 11:06 ` Kayra Cizmeci
2026-09-16 11:10 ` Christian Loehle
2026-09-16 11:12 ` Christian Loehle
2026-09-16 11:46 ` Kayra Cizmeci
2026-09-16 19:43 ` Shubhang
2026-09-17 7:47 ` Christian Loehle
2026-09-17 9:58 ` Christian Loehle
2026-09-17 14:02 ` Vincent Guittot
2026-09-17 14:16 ` Kayra Cizmeci
2026-09-17 14:08 ` Vincent Guittot
2026-09-17 14:22 ` Christian Loehle
2026-09-17 15:08 ` Vincent Guittot
2026-09-17 15:17 ` Christian Loehle [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=cd1a09fb-17e0-4d3b-9720-cdc28e90c030@arm.com \
--to=christian.loehle@arm.com \
--cc=beata.michalska@arm.com \
--cc=cl@gentwo.org \
--cc=daniel.lezcano@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=elif.topuz@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=rostedt@goodmis.org \
--cc=sh@gentwo.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®