Re: [PATCH v2 3/8] sched_ext: Add scx_bpf_sched_id() and scx_bpf_task_sched_id()

From: Tejun Heo

Date: Fri Dec 04 2026 - 12:17:39 EST


Hello, Changwoo.

On Thu, Dec 03, 2026 at 01:56:13PM +0900, Changwoo Min wrote:
> + * Return the instance id of the scheduler @p is on, see scx_bpf_sched_id(), 0
> + * if @p is not on any. Without the rq lock of @p, @p may move to another
> + * scheduler right after.
> + */
> +__bpf_kfunc u64 scx_bpf_task_sched_id(struct task_struct *p)
> +{
> + struct scx_sched *sch;
> +
> + guard(rcu)();
> + sch = scx_task_sched_rcu(p);
> + return sch ? sch->id : 0;

AFAICS, without CONFIG_EXT_SUB_SCHED, scx_task_sched_rcu() returns scx_root
whatever @p is, so this returns the root's id for a task which isn't on any
scheduler too, e.g. one which is already dead.

Thanks.

--
tejun