Re: [PATCH 4/6] sched_ext: idle: Introduce scx_bpf_select_cpu_and()

From: Tejun Heo
Date: Mon Mar 31 2025 - 18:00:41 EST


Hello,

On Fri, Mar 21, 2025 at 11:10:50PM +0100, Andrea Righi wrote:
...
> +__bpf_kfunc s32 scx_bpf_select_cpu_and(struct task_struct *p, s32 prev_cpu, u64 wake_flags,
> + const struct cpumask *cpus_allowed, u64 flags)
> +{
> + s32 cpu;
> +
> + if (!ops_cpu_valid(prev_cpu, NULL))
> + return -EINVAL;
> +
> + if (!check_builtin_idle_enabled())
> + return -EBUSY;
> +
> + if (!scx_kf_allowed(SCX_KF_SELECT_CPU | SCX_KF_ENQUEUE))
> + return -EPERM;
> +
> +#ifdef CONFIG_SMP
> + cpu = scx_select_cpu_dfl(p, prev_cpu, wake_flags, cpus_allowed, flags);
> +#else
> + cpu = -EBUSY;
> +#endif
> +
> + return cpu;
> +}

Later in the series, I find scx_bpf_select_cpu_and() being called with
p->cpus_ptr really confusing. scx_bpf_select_cpu_and() is always constrained
by p->cpus_ptr (except for the currently buggy case where p->nr_cpus_allowed
is used while p->cpus_ptr is overridden), so what does it mean to call
scx_bpf_select_cpu_and() with p->cpus_ptr as @cpus_allowed? I'd much prefer
if the convention in such cases is calling with NULL @cpus_allowed.
@cpus_allowed is the extra mask to and to p->cpus_ptr when searching for an
idle CPU. If we're going to use p->cpus_ptr, we just don't have the extra
cpumask to and.

Thanks.

--
tejun