From: Tejun Heo <tj@kernel.org> mainline inclusion from mainline-v6.19-rc1 commit b7d4b28db7da89de1d03316c4e67b5a47390fcd3 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/IDC9YK Reference: https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commi... -------------------------------- 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 <arighi@nvidia.com> Acked-by: Andrea Righi <arighi@nvidia.com> Signed-off-by: Tejun Heo <tj@kernel.org> Conflicts: kernel/sched/ext.c [Context difference, only pick the code modified by this mainline patch.] Signed-off-by: Zicheng Qu <quzicheng@huawei.com> --- kernel/sched/ext.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c index 092fcc092ea8..1c8805d9215d 100644 --- a/kernel/sched/ext.c +++ b/kernel/sched/ext.c @@ -5311,7 +5311,7 @@ static int scx_ops_enable(struct sched_ext_ops *ops) const struct sched_class *old_class = p->sched_class; struct sched_enq_and_set_ctx ctx; - if (!tryget_task_struct(p)) + if (scx_get_task_state(p) != SCX_TASK_READY) continue; sched_deq_and_put_task(p, DEQUEUE_SAVE | DEQUEUE_MOVE, &ctx); @@ -5330,7 +5330,6 @@ static int scx_ops_enable(struct sched_ext_ops *ops) sched_enq_and_set_task(&ctx); check_class_changed(task_rq(p), p, old_class, p->prio); - put_task_struct(p); } scx_task_iter_stop(&sti); percpu_up_write(&scx_fork_rwsem); -- 2.34.1