Skip to content

Commit f0c6eab

Browse files
arighihtejun
authored andcommitted
sched_ext: initialize built-in idle state before ops.init()
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: d73249f ("sched_ext: idle: Make idle static keys private") Signed-off-by: Andrea Righi <arighi@nvidia.com> Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent a8897ed commit f0c6eab

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

kernel/sched/ext.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5361,6 +5361,8 @@ static int scx_ops_enable(struct sched_ext_ops *ops, struct bpf_link *link)
53615361
*/
53625362
cpus_read_lock();
53635363

5364+
scx_idle_enable(ops);
5365+
53645366
if (scx_ops.init) {
53655367
ret = SCX_CALL_OP_RET(SCX_KF_UNLOCKED, init);
53665368
if (ret) {
@@ -5427,8 +5429,6 @@ static int scx_ops_enable(struct sched_ext_ops *ops, struct bpf_link *link)
54275429
if (scx_ops.cpu_acquire || scx_ops.cpu_release)
54285430
static_branch_enable(&scx_ops_cpu_preempt);
54295431

5430-
scx_idle_enable(ops);
5431-
54325432
/*
54335433
* Lock out forks, cgroup on/offlining and moves before opening the
54345434
* floodgate so that they don't wander into the operations prematurely.

kernel/sched/ext_idle.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,14 +721,14 @@ static void reset_idle_masks(struct sched_ext_ops *ops)
721721
void scx_idle_enable(struct sched_ext_ops *ops)
722722
{
723723
if (!ops->update_idle || (ops->flags & SCX_OPS_KEEP_BUILTIN_IDLE))
724-
static_branch_enable(&scx_builtin_idle_enabled);
724+
static_branch_enable_cpuslocked(&scx_builtin_idle_enabled);
725725
else
726-
static_branch_disable(&scx_builtin_idle_enabled);
726+
static_branch_disable_cpuslocked(&scx_builtin_idle_enabled);
727727

728728
if (ops->flags & SCX_OPS_BUILTIN_IDLE_PER_NODE)
729-
static_branch_enable(&scx_builtin_idle_per_node);
729+
static_branch_enable_cpuslocked(&scx_builtin_idle_per_node);
730730
else
731-
static_branch_disable(&scx_builtin_idle_per_node);
731+
static_branch_disable_cpuslocked(&scx_builtin_idle_per_node);
732732

733733
#ifdef CONFIG_SMP
734734
reset_idle_masks(ops);

0 commit comments

Comments
 (0)