@@ -6297,6 +6297,15 @@ void __init init_sched_ext_class(void)
6297
6297
6298
6298
__bpf_kfunc_start_defs ();
6299
6299
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
+
6300
6309
/**
6301
6310
* scx_bpf_select_cpu_dfl - The default implementation of ops.select_cpu()
6302
6311
* @p: task_struct to select a CPU for
@@ -6314,10 +6323,8 @@ __bpf_kfunc_start_defs();
6314
6323
__bpf_kfunc s32 scx_bpf_select_cpu_dfl (struct task_struct * p , s32 prev_cpu ,
6315
6324
u64 wake_flags , bool * is_idle )
6316
6325
{
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 ())
6319
6327
goto prev_cpu ;
6320
- }
6321
6328
6322
6329
if (!scx_kf_allowed (SCX_KF_SELECT_CPU ))
6323
6330
goto prev_cpu ;
@@ -7411,10 +7418,8 @@ __bpf_kfunc void scx_bpf_put_cpumask(const struct cpumask *cpumask)
7411
7418
*/
7412
7419
__bpf_kfunc const struct cpumask * scx_bpf_get_idle_cpumask (void )
7413
7420
{
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 ())
7416
7422
return cpu_none_mask ;
7417
- }
7418
7423
7419
7424
#ifdef CONFIG_SMP
7420
7425
return idle_masks .cpu ;
@@ -7432,10 +7437,8 @@ __bpf_kfunc const struct cpumask *scx_bpf_get_idle_cpumask(void)
7432
7437
*/
7433
7438
__bpf_kfunc const struct cpumask * scx_bpf_get_idle_smtmask (void )
7434
7439
{
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 ())
7437
7441
return cpu_none_mask ;
7438
- }
7439
7442
7440
7443
#ifdef CONFIG_SMP
7441
7444
if (sched_smt_active ())
@@ -7473,10 +7476,8 @@ __bpf_kfunc void scx_bpf_put_idle_cpumask(const struct cpumask *idle_mask)
7473
7476
*/
7474
7477
__bpf_kfunc bool scx_bpf_test_and_clear_cpu_idle (s32 cpu )
7475
7478
{
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 ())
7478
7480
return false;
7479
- }
7480
7481
7481
7482
if (ops_cpu_valid (cpu , NULL ))
7482
7483
return test_and_clear_cpu_idle (cpu );
@@ -7506,10 +7507,8 @@ __bpf_kfunc bool scx_bpf_test_and_clear_cpu_idle(s32 cpu)
7506
7507
__bpf_kfunc s32 scx_bpf_pick_idle_cpu (const struct cpumask * cpus_allowed ,
7507
7508
u64 flags )
7508
7509
{
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 ())
7511
7511
return - EBUSY ;
7512
- }
7513
7512
7514
7513
return scx_pick_idle_cpu (cpus_allowed , flags );
7515
7514
}
0 commit comments