* [PATCH] sched_ext: initialize built-in idle state before ops.init()
@ 2025-03-24 8:56 Andrea Righi
2025-03-24 9:18 ` Andrea Righi
0 siblings, 1 reply; 2+ messages in thread
From: Andrea Righi @ 2025-03-24 8:56 UTC (permalink / raw)
To: Tejun Heo, David Vernet, Changwoo Min; +Cc: Joel Fernandes, linux-kernel
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>
---
kernel/sched/ext.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 06561d6717c9a..1ba02755ae8ad 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.
--
2.49.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] sched_ext: initialize built-in idle state before ops.init()
2025-03-24 8:56 [PATCH] sched_ext: initialize built-in idle state before ops.init() Andrea Righi
@ 2025-03-24 9:18 ` Andrea Righi
0 siblings, 0 replies; 2+ messages in thread
From: Andrea Righi @ 2025-03-24 9:18 UTC (permalink / raw)
To: Tejun Heo, David Vernet, Changwoo Min; +Cc: Joel Fernandes, linux-kernel
On Mon, Mar 24, 2025 at 09:56:16AM +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>
Sorry for the duplicate email, please ignore this one.
This is the right one targeting sched_ext/for-6.15:
https://lore.kernel.org/all/20250324085753.27112-1-arighi@nvidia.com/
-Andrea
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-24 9:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-24 8:56 [PATCH] sched_ext: initialize built-in idle state before ops.init() Andrea Righi
2025-03-24 9:18 ` Andrea Righi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox