From: Tejun Heo <tj@kernel.org>
To: Cheng-Yang Chou <yphbchou0911@gmail.com>
Cc: Kuba Piecuch <jpiecuch@google.com>,
sched-ext@lists.linux.dev, David Vernet <void@manifault.com>,
Andrea Righi <arighi@nvidia.com>,
Changwoo Min <changwoo@igalia.com>,
Ching-Chun Huang <jserv@ccns.ncku.edu.tw>,
Chia-Ping Tsai <chia7712@gmail.com>
Subject: Re: [PATCH] tools/sched_ext: Handle pinned tasks in scx_central
Date: Tue, 14 Apr 2026 07:19:04 -1000 [thread overview]
Message-ID: <ad53CFXVxTha3EQu@slm.duckdns.org> (raw)
In-Reply-To: <s3khi4ec55rog6tgbgxip5skqjdhimcemhwzf3h7pbbvxslnu7@5r4v7jbv4w7z>
Hello,
On Tue, Apr 14, 2026 at 11:45:59AM +0800, Cheng-Yang Chou wrote:
> diff --git a/tools/sched_ext/scx_central.bpf.c b/tools/sched_ext/scx_central.bpf.c
> index 4efcce099bd5..67b160a7ce18 100644
> --- a/tools/sched_ext/scx_central.bpf.c
> +++ b/tools/sched_ext/scx_central.bpf.c
> @@ -96,7 +96,13 @@ s32 BPF_STRUCT_OPS(central_select_cpu, struct task_struct *p,
> * disturbing other CPUs. It's safe to blindly return the central cpu as
> * select_cpu() is a hint and if @p can't be on it, the kernel will
> * automatically pick a fallback CPU.
> + *
> + * For tasks pinned to a single CPU, return the current CPU to avoid
> + * an unnecessary fallback.
> */
> + if (p->nr_cpus_allowed == 1)
> + return scx_bpf_task_cpu(p);
> +
This isn't necessary. select_cpu() isn't called if nr_cpus_allowed == 1.
> @@ -107,12 +113,17 @@ void BPF_STRUCT_OPS(central_enqueue, struct task_struct *p, u64 enq_flags)
> __sync_fetch_and_add(&nr_total, 1);
>
> /*
> - * Push per-cpu kthreads at the head of local dsq's and preempt the
> - * corresponding CPU. This ensures that e.g. ksoftirqd isn't blocked
> - * behind other threads which is necessary for forward progress
> - * guarantee as we depend on the BPF timer which may run from ksoftirqd.
> + * Push tasks pinned to a single CPU or with migration disabled at
> + * the head of local dsq's and preempt the corresponding CPU. This
> + * ensures that e.g. ksoftirqd isn't blocked behind other threads
> + * which is necessary for forward progress guarantee as we depend on
> + * the BPF timer which may run from ksoftirqd.
> + *
> + * p->nr_cpus_allowed is not updated until migrate_disable_switch()
> + * runs during context switch, which happens after ops.enqueue(). Check
> + * is_migration_disabled() directly to catch tasks in this window.
> */
> - if ((p->flags & PF_KTHREAD) && p->nr_cpus_allowed == 1) {
> + if (p->nr_cpus_allowed == 1 || is_migration_disabled(p)) {
Let's not expand the condition here. This is to guarantee forward progress
of the scheduler itself.
> @@ -155,6 +166,13 @@ static bool dispatch_to_cpu(s32 cpu)
> if (!bpf_cpumask_test_cpu(cpu, p->cpus_ptr)) {
Instead, can you expand the condition above to "if this task can't run on
the target CPU for whatever reason"?
Thanks.
--
tejun
next prev parent reply other threads:[~2026-04-14 17:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-13 11:04 [PATCH] tools/sched_ext: Handle pinned tasks in scx_central Cheng-Yang Chou
2026-04-13 15:29 ` Kuba Piecuch
2026-04-14 3:45 ` Cheng-Yang Chou
2026-04-14 17:19 ` Tejun Heo [this message]
2026-04-15 6:17 ` Cheng-Yang Chou
2026-04-15 9:59 ` Kuba Piecuch
2026-04-15 10:07 ` Cheng-Yang Chou
2026-04-17 18:38 ` Tejun Heo
2026-04-14 21:01 ` Andrea Righi
2026-04-15 6:02 ` Cheng-Yang Chou
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=ad53CFXVxTha3EQu@slm.duckdns.org \
--to=tj@kernel.org \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=chia7712@gmail.com \
--cc=jpiecuch@google.com \
--cc=jserv@ccns.ncku.edu.tw \
--cc=sched-ext@lists.linux.dev \
--cc=void@manifault.com \
--cc=yphbchou0911@gmail.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