From: Tejun Heo Date: Tue, 28 Oct 2025 21:38:34 +0000 (-1000) Subject: sched_ext: Use SCX_TASK_READY test instead of tryget_task_struct() during class switch X-Git-Tag: v6.19-rc1~177^2~28 X-Git-Url: https://gentwo.org/gitweb/?a=commitdiff_plain;h=b7d4b28db7da89de1d03316c4e67b5a47390fcd3;p=linux%2F.git sched_ext: Use SCX_TASK_READY test instead of tryget_task_struct() during class switch ddf7233fcab6 ("sched/ext: Fix invalid task state transitions on class switch") added tryget_task_struct() test during scx_enable()'s class switching loop. The reason for the addition was to avoid enabling tasks which skipped prep in the previous loop due to being dead. While tryget_task_struct() does work for this purpose as tasks that fail tryget always will fail it, it's a bit roundabout. A more direct way is testing whether the task is in READY state. Switch to testing SCX_TASK_READY directly. Cc: Andrea Righi Acked-by: Andrea Righi Signed-off-by: Tejun Heo --- diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 1cfe4b43d31b..603de983a509 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -4753,7 +4753,7 @@ static int scx_enable(struct sched_ext_ops *ops, struct bpf_link *link) const struct sched_class *new_class = __setscheduler_class(p->policy, p->prio); - if (!tryget_task_struct(p)) + if (scx_get_task_state(p) != SCX_TASK_READY) continue; if (old_class != new_class) @@ -4763,8 +4763,6 @@ static int scx_enable(struct sched_ext_ops *ops, struct bpf_link *link) p->scx.slice = SCX_SLICE_DFL; p->sched_class = new_class; } - - put_task_struct(p); } scx_task_iter_stop(&sti); percpu_up_write(&scx_fork_rwsem);