]> git.ipfire.org Git - thirdparty/linux.git/commit
sched_ext: add p->scx.tid and SCX_OPS_TID_TO_TASK lookup
authorTejun Heo <tj@kernel.org>
Sun, 19 Apr 2026 18:36:45 +0000 (08:36 -1000)
committerTejun Heo <tj@kernel.org>
Mon, 20 Apr 2026 16:55:33 +0000 (06:55 -1000)
commit41e3312861eafba171d9620150aaf2e99165d044
tree0f22d2d6af12df3f4f39c7c203171df3eaae79d1
parented859d4319863263665b239cd2c62c3aad1664ce
sched_ext: add p->scx.tid and SCX_OPS_TID_TO_TASK lookup

BPF schedulers that can't hold task_struct pointers (arena-backed ones in
particular) key tasks by pid. During exit, pid is released before the
task finishes passing through scheduler callbacks, so a dying task
becomes invisible to the BPF side mid-schedule. scx_qmap hits this: an
exiting task's dispatch callback can't recover its queue entry, stalling
dispatch until SCX_EXIT_ERROR_STALL.

Add a unique non-zero u64 p->scx.tid assigned at fork that survives the
full task lifetime including exit. scx_bpf_tid_to_task() looks up the
task; unlike bpf_task_from_pid(), it handles exiting tasks.

The lookup costs an rhashtable insert/remove under scx_tasks_lock, so
root schedulers opt in via SCX_OPS_TID_TO_TASK. Sub-schedulers that set
the flag to declare a dependency are rejected at attach if root didn't
opt in.

scx_qmap converted: keys tasks by tid and enables SCX_OPS_ENQ_EXITING.
Pre-patch it stalls within seconds under a non-leader-exec workload;
with the patch it runs cleanly.

v3: Warn on rhashtable_lookup_insert_fast() failure via new
    scx_tid_hash_insert() helper (Cheng-Yang Chou).

v2: Guard scx_root deref in scx_bpf_tid_to_task() error path. The kfunc
    is registered via scx_kfunc_set_any and reachable from tracing and
    syscall programs when no scheduler is attached (Cheng-Yang Chou).

Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
include/linux/sched/ext.h
kernel/sched/ext.c
kernel/sched/ext_internal.h
tools/sched_ext/include/scx/common.bpf.h
tools/sched_ext/scx_qmap.bpf.c