Skip to content

Commit c0cf353

Browse files
arighihtejun
authored andcommitted
sched_ext: idle: introduce check_builtin_idle_enabled() helper
Minor refactoring to add a helper function for checking if the built-in idle CPU selection policy is enabled. Signed-off-by: Andrea Righi <arighi@nvidia.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 02f034d commit c0cf353

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

kernel/sched/ext.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6297,6 +6297,15 @@ void __init init_sched_ext_class(void)
62976297

62986298
__bpf_kfunc_start_defs();
62996299

6300+
static bool check_builtin_idle_enabled(void)
6301+
{
6302+
if (static_branch_likely(&scx_builtin_idle_enabled))
6303+
return true;
6304+
6305+
scx_ops_error("built-in idle tracking is disabled");
6306+
return false;
6307+
}
6308+
63006309
/**
63016310
* scx_bpf_select_cpu_dfl - The default implementation of ops.select_cpu()
63026311
* @p: task_struct to select a CPU for
@@ -6314,10 +6323,8 @@ __bpf_kfunc_start_defs();
63146323
__bpf_kfunc s32 scx_bpf_select_cpu_dfl(struct task_struct *p, s32 prev_cpu,
63156324
u64 wake_flags, bool *is_idle)
63166325
{
6317-
if (!static_branch_likely(&scx_builtin_idle_enabled)) {
6318-
scx_ops_error("built-in idle tracking is disabled");
6326+
if (!check_builtin_idle_enabled())
63196327
goto prev_cpu;
6320-
}
63216328

63226329
if (!scx_kf_allowed(SCX_KF_SELECT_CPU))
63236330
goto prev_cpu;
@@ -7411,10 +7418,8 @@ __bpf_kfunc void scx_bpf_put_cpumask(const struct cpumask *cpumask)
74117418
*/
74127419
__bpf_kfunc const struct cpumask *scx_bpf_get_idle_cpumask(void)
74137420
{
7414-
if (!static_branch_likely(&scx_builtin_idle_enabled)) {
7415-
scx_ops_error("built-in idle tracking is disabled");
7421+
if (!check_builtin_idle_enabled())
74167422
return cpu_none_mask;
7417-
}
74187423

74197424
#ifdef CONFIG_SMP
74207425
return idle_masks.cpu;
@@ -7432,10 +7437,8 @@ __bpf_kfunc const struct cpumask *scx_bpf_get_idle_cpumask(void)
74327437
*/
74337438
__bpf_kfunc const struct cpumask *scx_bpf_get_idle_smtmask(void)
74347439
{
7435-
if (!static_branch_likely(&scx_builtin_idle_enabled)) {
7436-
scx_ops_error("built-in idle tracking is disabled");
7440+
if (!check_builtin_idle_enabled())
74377441
return cpu_none_mask;
7438-
}
74397442

74407443
#ifdef CONFIG_SMP
74417444
if (sched_smt_active())
@@ -7473,10 +7476,8 @@ __bpf_kfunc void scx_bpf_put_idle_cpumask(const struct cpumask *idle_mask)
74737476
*/
74747477
__bpf_kfunc bool scx_bpf_test_and_clear_cpu_idle(s32 cpu)
74757478
{
7476-
if (!static_branch_likely(&scx_builtin_idle_enabled)) {
7477-
scx_ops_error("built-in idle tracking is disabled");
7479+
if (!check_builtin_idle_enabled())
74787480
return false;
7479-
}
74807481

74817482
if (ops_cpu_valid(cpu, NULL))
74827483
return test_and_clear_cpu_idle(cpu);
@@ -7506,10 +7507,8 @@ __bpf_kfunc bool scx_bpf_test_and_clear_cpu_idle(s32 cpu)
75067507
__bpf_kfunc s32 scx_bpf_pick_idle_cpu(const struct cpumask *cpus_allowed,
75077508
u64 flags)
75087509
{
7509-
if (!static_branch_likely(&scx_builtin_idle_enabled)) {
7510-
scx_ops_error("built-in idle tracking is disabled");
7510+
if (!check_builtin_idle_enabled())
75117511
return -EBUSY;
7512-
}
75137512

75147513
return scx_pick_idle_cpu(cpus_allowed, flags);
75157514
}

0 commit comments

Comments
 (0)