Re: [PATCH v2 3/8] sched_ext: Add scx_bpf_sched_id() and scx_bpf_task_sched_id()
From: Changwoo Min
Date: Sun Dec 06 2026 - 00:38:45 EST
On 12/5/26 2:17 AM, Tejun Heo wrote:
Hello, Changwoo.Right. v3 replaces the kfunc with scx_task_sched_id(), a CO-RE helper in
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.
compat.bpf.h, following Andrea's suggestion. It returns 0 unless the
task is in INIT, READY or ENABLED, as a scheduler owns a task only after
ops.init_task(). So the !CONFIG_EXT_SUB_SCHED case reports the root's id
only for tasks the root owns.
Regards,
Changwoo