From: Tejun Heo <tj@kernel.org>
To: Andrea Righi <arighi@nvidia.com>
Cc: David Vernet <void@manifault.com>,
Changwoo Min <changwoo@igalia.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sched_ext: idle: Properly handle invalid prev_cpu during idle selection
Date: Fri, 30 May 2025 14:42:52 -1000 [thread overview]
Message-ID: <aDpQjDsPGkwf3qRs@slm.duckdns.org> (raw)
In-Reply-To: <20250530154629.52651-1-arighi@nvidia.com>
On Fri, May 30, 2025 at 05:46:29PM +0200, Andrea Righi wrote:
> The default idle selection policy doesn't properly handle the case where
> @prev_cpu is not part of the task's allowed CPUs.
>
> In this situation, it may return an idle CPU that is not usable by the
> task, breaking the assumption that the returned CPU must always be
> within the allowed cpumask, causing inefficiencies or even stalls in
> certain cases.
>
> This issue can arise in the following cases:
>
> - The task's affinity may have changed by the time the function is
> invoked, especially now that the idle selection logic can be used
> from multiple contexts (i.e., BPF test_run call).
>
> - The BPF scheduler may provide a @prev_cpu that is not part of the
> allowed mask, either unintentionally or as a placement hint. In fact
> @prev_cpu may not necessarily refer to the CPU the task last ran on,
> but it can also be considered as a target CPU that the scheduler
> wishes to use for the task.
>
> Therefore, enforce the right behavior by always checking whether
> @prev_cpu is in the allowed mask, when using scx_bpf_select_cpu_and(),
> and it's also usable by the task (@p->cpus_ptr). If it is not, try to
> find a valid CPU nearby @prev_cpu, following the usual locality-aware
> fallback path (SMT, LLC, node, allowed CPUs).
>
> This ensures the returned CPU is always allowed, improving robustness to
> affinity changes and invalid scheduler hints, while preserving locality
> as much as possible.
>
> Fixes: a730e3f7a48bc ("sched_ext: idle: Consolidate default idle CPU selection kfuncs")
> Signed-off-by: Andrea Righi <arighi@nvidia.com>
Applied to sched_ext/for-6.16-fixes.
Thanks.
--
tejun
prev parent reply other threads:[~2025-05-31 0:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-30 15:46 Andrea Righi
2025-05-31 0:42 ` Tejun Heo [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=aDpQjDsPGkwf3qRs@slm.duckdns.org \
--to=tj@kernel.org \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=void@manifault.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®