From: Joel Fernandes <joelagnelf@nvidia.com>
To: Andrea Righi <arighi@nvidia.com>
Cc: Tejun Heo <tj@kernel.org>, David Vernet <void@manifault.com>,
Changwoo Min <changwoo@igalia.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] sched_ext: initialize built-in idle state before ops.init()
Date: Tue, 25 Mar 2025 11:19:20 -0400 [thread overview]
Message-ID: <20250325151920.GA750298@joelnvbox> (raw)
In-Reply-To: <20250325093212.47188-1-arighi@nvidia.com>
On Tue, Mar 25, 2025 at 10:32:12AM +0100, Andrea Righi wrote:
> A BPF scheduler may want to use the built-in idle cpumasks in ops.init()
> before the scheduler is fully initialized, either directly or through a
> BPF timer for example.
>
> However, this would result in an error, since the idle state has not
> been properly initialized yet.
>
> This can be easily verified by modifying scx_simple to call
> scx_bpf_get_idle_cpumask() in ops.init():
>
> $ sudo scx_simple
>
> DEBUG DUMP
> ===========================================================================
>
> scx_simple[121] triggered exit kind 1024:
> runtime error (built-in idle tracking is disabled)
> ...
>
> Fix this by properly initializing the idle state before ops.init() is
> called. With this change applied:
>
> $ sudo scx_simple
> local=2 global=0
> local=19 global=11
> local=23 global=11
> ...
>
> Fixes: d73249f88743d ("sched_ext: idle: Make idle static keys private")
> Signed-off-by: Andrea Righi <arighi@nvidia.com>
Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
Makes sense, I think this is restriction is because static branch will use
IPIs in some architectures which requires to exclude hotplug operations.
thanks,
- Joel
> ---
> kernel/sched/ext.c | 4 ++--
> kernel/sched/ext_idle.c | 8 ++++----
> 2 files changed, 6 insertions(+), 6 deletions(-)
>
> ChangeLog v1 -> v2:
> - fix potential deadlock with cpu_hotplug_lock
>
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index d82e9d3cbc0dc..3d20228052217 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -5361,6 +5361,8 @@ static int scx_ops_enable(struct sched_ext_ops *ops, struct bpf_link *link)
> */
> cpus_read_lock();
>
> + scx_idle_enable(ops);
> +
> if (scx_ops.init) {
> ret = SCX_CALL_OP_RET(SCX_KF_UNLOCKED, init);
> if (ret) {
> @@ -5427,8 +5429,6 @@ static int scx_ops_enable(struct sched_ext_ops *ops, struct bpf_link *link)
> if (scx_ops.cpu_acquire || scx_ops.cpu_release)
> static_branch_enable(&scx_ops_cpu_preempt);
>
> - scx_idle_enable(ops);
> -
> /*
> * Lock out forks, cgroup on/offlining and moves before opening the
> * floodgate so that they don't wander into the operations prematurely.
> diff --git a/kernel/sched/ext_idle.c b/kernel/sched/ext_idle.c
> index 746fd36050045..811f8bff2ff02 100644
> --- a/kernel/sched/ext_idle.c
> +++ b/kernel/sched/ext_idle.c
> @@ -794,14 +794,14 @@ static void reset_idle_masks(struct sched_ext_ops *ops)
> void scx_idle_enable(struct sched_ext_ops *ops)
> {
> if (!ops->update_idle || (ops->flags & SCX_OPS_KEEP_BUILTIN_IDLE))
> - static_branch_enable(&scx_builtin_idle_enabled);
> + static_branch_enable_cpuslocked(&scx_builtin_idle_enabled);
> else
> - static_branch_disable(&scx_builtin_idle_enabled);
> + static_branch_disable_cpuslocked(&scx_builtin_idle_enabled);
>
> if (ops->flags & SCX_OPS_BUILTIN_IDLE_PER_NODE)
> - static_branch_enable(&scx_builtin_idle_per_node);
> + static_branch_enable_cpuslocked(&scx_builtin_idle_per_node);
> else
> - static_branch_disable(&scx_builtin_idle_per_node);
> + static_branch_disable_cpuslocked(&scx_builtin_idle_per_node);
>
> #ifdef CONFIG_SMP
> reset_idle_masks(ops);
> --
> 2.49.0
>
next prev parent reply other threads:[~2025-03-25 15:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-25 9:32 [PATCH v2] sched_ext: initialize built-in idle state before ops.init() Andrea Righi
2025-03-25 15:19 ` Joel Fernandes [this message]
2025-03-26 20:49 ` Tejun Heo
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=20250325151920.GA750298@joelnvbox \
--to=joelagnelf@nvidia.com \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@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