Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools/sched_ext: scx_qmap: Silence task_ctx lookup miss

scx_fork() dispatches ops.init_task to exactly one scheduler - the one
owning the forking task's cgroup. A task forked inside a sub-scheduler's
cgroup is init'd into the sub only; the root scheduler has no task_ctx
entry for it. When that task later appears as @prev in the root's
qmap_dispatch() (or flows through core-sched comparison via task_qdist),
the bpf_task_storage_get() legitimately misses.

qmap treated those misses as fatal via scx_bpf_error("task_ctx lookup
failed") and aborted the scheduler as soon as the first cross-sched
task hit the root. Drop the error in the sites where the miss is
legitimate: lookup_task_ctx() (helper; callers already check for NULL),
qmap_dispatch()'s @prev branch (bookkeeping-only), task_qdist()
(returns 0 which makes the comparison a no-op), and qmap_select_cpu()
(returns prev_cpu as a no-op fallback instead of -ESRCH). The existing
scx_error was a paranoid guard from the pre-sub-sched world where every
task was owned by the one and only scheduler.

v2: qmap_select_cpu() returns prev_cpu on NULL instead of -ESRCH, so
the root scheduler doesn't error on cross-sched tasks that pass
through it (Andrea Righi).

Fixes: 4f8b122848db ("sched_ext: Add basic building blocks for nested sub-scheduler dispatching")
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Reviewed-by: Zhao Mengmeng <zhaomengmeng@kylinos.cn>

+6 -18
+6 -18
tools/sched_ext/scx_qmap.bpf.c
··· 159 159 160 160 static struct task_ctx *lookup_task_ctx(struct task_struct *p) 161 161 { 162 - struct task_ctx *tctx; 163 - 164 - if (!(tctx = bpf_task_storage_get(&task_ctx_stor, p, 0, 0))) { 165 - scx_bpf_error("task_ctx lookup failed"); 166 - return NULL; 167 - } 168 - return tctx; 162 + return bpf_task_storage_get(&task_ctx_stor, p, 0, 0); 169 163 } 170 164 171 165 s32 BPF_STRUCT_OPS(qmap_select_cpu, struct task_struct *p, ··· 169 175 s32 cpu; 170 176 171 177 if (!(tctx = lookup_task_ctx(p))) 172 - return -ESRCH; 178 + return prev_cpu; 173 179 174 180 if (p->scx.weight < 2 && !(p->flags & PF_KTHREAD)) 175 181 return prev_cpu; ··· 534 540 */ 535 541 if (prev) { 536 542 tctx = bpf_task_storage_get(&task_ctx_stor, prev, 0, 0); 537 - if (!tctx) { 538 - scx_bpf_error("task_ctx lookup failed"); 539 - return; 540 - } 541 - 542 - tctx->core_sched_seq = 543 - core_sched_tail_seqs[weight_to_idx(prev->scx.weight)]++; 543 + if (tctx) 544 + tctx->core_sched_seq = 545 + core_sched_tail_seqs[weight_to_idx(prev->scx.weight)]++; 544 546 } 545 547 } 546 548 ··· 574 584 s64 qdist; 575 585 576 586 tctx = bpf_task_storage_get(&task_ctx_stor, p, 0, 0); 577 - if (!tctx) { 578 - scx_bpf_error("task_ctx lookup failed"); 587 + if (!tctx) 579 588 return 0; 580 - } 581 589 582 590 qdist = tctx->core_sched_seq - core_sched_head_seqs[idx]; 583 591