Re: [PATCH 5/6] sched_ext: Add a kfunc to read a task's preferred NUMA node
From: K Prateek Nayak
Date: Tue Oct 27 2026 - 02:12:46 EST
Hello Andrea,
On 10/27/2026 9:43 AM, Andrea Righi wrote:
> +__bpf_kfunc s32 scx_bpf_task_numa_nid(const struct task_struct *p)
> +{
> +#ifdef CONFIG_NUMA_BALANCING
> + if (task_on_scx(p)) {
> + struct scx_sched *sch;
> +
> + guard(rcu)();
> + sch = scx_task_sched_rcu(p);
> + if (!sch || !SCX_HAS_OP(sch, set_numa_node))
> + return NUMA_NO_NODE;
> + }
> +
> + return READ_ONCE(p->numa_preferred_nid);
Would the ext scheduler need the raw numa_preferred_nid when
sched_numa_balancing is disabled?
It may just be pointing to some stale value if NUMA balancing
was disabled at runtime right?
> +#else
> + return NUMA_NO_NODE;
> +#endif
> +}
> +
> /**
> * scx_bpf_locked_rq - Return the rq currently locked by SCX
> * @aux: implicit BPF argument to access bpf_prog_aux hidden from BPF progs
> @@ -11836,6 +11877,7 @@ BTF_ID_FLAGS(func, scx_bpf_put_cpumask, KF_RELEASE)
> BTF_ID_FLAGS(func, scx_bpf_task_running, KF_RCU)
On a tangential note, scx_bpf_task_running() just does a
rcu_access_pointer() (resolves to a READ_ONCE()) and doesn't take a
rcu_read_lock() so does it really need KF_RCU?
> BTF_ID_FLAGS(func, scx_bpf_task_cpu, KF_RCU)
> BTF_ID_FLAGS(func, scx_bpf_task_cid, KF_RCU)
> +BTF_ID_FLAGS(func, scx_bpf_task_numa_nid, KF_RCU)
> BTF_ID_FLAGS(func, scx_bpf_locked_rq, KF_IMPLICIT_ARGS | KF_RET_NULL)
> BTF_ID_FLAGS(func, scx_bpf_cpu_curr, KF_IMPLICIT_ARGS | KF_RET_NULL | KF_RCU_PROTECTED)
> BTF_ID_FLAGS(func, scx_bpf_cid_curr, KF_IMPLICIT_ARGS | KF_RET_NULL | KF_RCU_PROTECTED)
--
Thanks and Regards,
Prateek