From 5f9174b2f311714c258a6bcb49ef4dcfe03f538f Mon Sep 17 00:00:00 2001 From: Stephen Dickey Date: Tue, 27 Jul 2021 08:40:56 -0700 Subject: [PATCH] sched/walt: check next task state Validate that the task selected is in a good state. on_cpu must not be 1 when picking a task. on_cpu is only set in prepare_task() just before the task is switched in. on_rq must not be 0 or migrating when picking a task, because it must be active. Only active tasks are are enqueued on a runqueue, and a migrating task shouldn't be picked as the rq it is on should be locked doing the migration. cpu must be equal to the rq's cpu. pick_next_task must not be picking a task which is not enqueued in this rq's cpu. One exception to the above, is when the scheduler picks a task that is the same as the previous task. In this case the task might already be on_cpu. Change-Id: I07c94c3b2eab0a328222f29550e0515cdcd6e7ed Signed-off-by: Stephen Dickey --- kernel/sched/walt/walt_cfs.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kernel/sched/walt/walt_cfs.c b/kernel/sched/walt/walt_cfs.c index a08414829041..9a463143cb73 100644 --- a/kernel/sched/walt/walt_cfs.c +++ b/kernel/sched/walt/walt_cfs.c @@ -1210,6 +1210,15 @@ static void walt_cfs_replace_next_task_fair(void *unused, struct rq *rq, struct if (unlikely(walt_disabled)) return; + if ((*p) && (*p) != prev && ((*p)->on_cpu == 1 || (*p)->on_rq == 0 || + (*p)->on_rq == TASK_ON_RQ_MIGRATING || + (*p)->cpu != cpu_of(rq))) { + printk_deferred("WALT-BUG picked %s(%d) on_cpu=%d on_rq=%d p->cpu=%d cpu_of(rq)=%d kthread=%d\n", + (*p)->comm, (*p)->pid, (*p)->on_cpu, + (*p)->on_rq, (*p)->cpu, cpu_of(rq), ((*p)->flags & PF_KTHREAD)); + SCHED_BUG_ON(1); + } + /* We don't have MVP tasks queued */ if (list_empty(&wrq->mvp_tasks)) return; @@ -1222,6 +1231,15 @@ static void walt_cfs_replace_next_task_fair(void *unused, struct rq *rq, struct *se = &mvp->se; *repick = true; + if ((*p) && (*p) != prev && ((*p)->on_cpu == 1 || (*p)->on_rq == 0 || + (*p)->on_rq == TASK_ON_RQ_MIGRATING || + (*p)->cpu != cpu_of(rq))) { + printk_deferred("WALT-BUG picked %s(%d) on_cpu=%d on_rq=%d p->cpu=%d cpu_of(rq)=%d kthread=%d\n", + (*p)->comm, (*p)->pid, (*p)->on_cpu, + (*p)->on_rq, (*p)->cpu, cpu_of(rq), ((*p)->flags & PF_KTHREAD)); + SCHED_BUG_ON(1); + } + trace_walt_cfs_mvp_pick_next(mvp, wts, walt_cfs_mvp_task_limit(mvp)); }