Re: [PATCH sched_ext/for-7.2] sched_ext: add p->scx.tid and SCX_OPS_TID_TO_TASK lookup

From: Cheng-Yang Chou

Date: Sun Apr 19 2026 - 13:24:10 EST


Hi Tejun,

On Sun, Apr 19, 2026 at 06:18:46AM -1000, Tejun Heo wrote:
[snipped]
> + * scx_bpf_tid_to_task - Look up a task by its scx tid
> + * @tid: task ID previously read from p->scx.tid
> + *
> + * Returns the task with the given tid, or NULL if no such task exists. The
> + * returned pointer is valid until the end of the current RCU read section
> + * (KF_RCU_PROTECTED). Requires SCX_OPS_TID_TO_TASK to be set on the root
> + * scheduler; otherwise an error is raised and NULL returned.
> + */
> +__bpf_kfunc struct task_struct *scx_bpf_tid_to_task(u64 tid)
> +{
> + struct sched_ext_entity *scx;
> +
> + if (!scx_tid_to_task_enabled()) {

Should we need to add a NULL guard here?
Since scx_bpf_tid_to_task() is registered in scx_kfunc_ids_any.

> + scx_error(scx_root,
> + "scx_bpf_tid_to_task() called without SCX_OPS_TID_TO_TASK");
> + return NULL;
> + }
> +
> + scx = rhashtable_lookup(&scx_tid_hash, &tid, scx_tid_hash_params);
> + if (!scx)
> + return NULL;
> +
> + return container_of(scx, struct task_struct, scx);
> +}
> +
> +/**
> * scx_bpf_now - Returns a high-performance monotonically non-decreasing
> * clock for the current CPU. The clock returned is in nanoseconds.
> *
> @@ -9470,6 +9595,7 @@ BTF_ID_FLAGS(func, scx_bpf_task_cpu, KF_
> BTF_ID_FLAGS(func, scx_bpf_cpu_rq, KF_IMPLICIT_ARGS)
> 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_tid_to_task, KF_RET_NULL | KF_RCU_PROTECTED)
> BTF_ID_FLAGS(func, scx_bpf_now)

--
Cheers,
Cheng-Yang