From 8c2844c02537b021aa04f58e32b24370dfc8d21b Mon Sep 17 00:00:00 2001 From: Abhijeet Dharmapurikar Date: Fri, 24 Jun 2022 14:37:13 -0700 Subject: [PATCH] sched/walt: fix busy time accounting for tasks moving between groups Currently the code subtracts busy time when a task is being migrated. IOW migrate_busy_time_subtraction is called in set_task_cpu hook. And the code adds busy time in an after-migration enqueue IOW enqueue_after_migration is seen set in enqueue hook. Both the above operations happen under the prev_cpu and next cpu rq lock respt. Now a task could exit or enter group after the migration and before the enqueue i.e. transfer_busy_time could be called when enqueue_after_migration is set. This could lead to -ve load bugs as we have only subtracted the load and not added it. To address this, complete the addition step in transfer_busy_time() itself, prior to moving the busy time, if a task is found to be migrating. Change-Id: Ifa7a2b017763392431dfa5407ec9dbde76d90019 Signed-off-by: Abhijeet Dharmapurikar --- kernel/sched/walt/walt.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/sched/walt/walt.c b/kernel/sched/walt/walt.c index 702e6a492269..18dd18f34135 100644 --- a/kernel/sched/walt/walt.c +++ b/kernel/sched/walt/walt.c @@ -1237,7 +1237,6 @@ static void migrate_busy_time_addition(struct task_struct *p, int new_cpu, u64 w if (is_ed_enabled() && is_ed_task(p, wallclock)) dest_wrq->ed_task = p; - wts->enqueue_after_migration = 0; wts->new_cpu = -1; } @@ -3406,6 +3405,12 @@ static void transfer_busy_time(struct rq *rq, new_task = is_new_task(p); + if (wts->enqueue_after_migration != 0) { + wallclock = walt_sched_clock(); + migrate_busy_time_addition(p, cpu_of(rq), wallclock); + wts->enqueue_after_migration = 0; + } + cpu_time = &wrq->grp_time; if (event == ADD_TASK) { migrate_type = RQ_TO_GROUP; @@ -4232,6 +4237,7 @@ static void android_rvh_enqueue_task(void *unused, struct rq *rq, struct task_st if (wts->enqueue_after_migration != 0) { wallclock = walt_sched_clock(); migrate_busy_time_addition(p, cpu_of(rq), wallclock); + wts->enqueue_after_migration = 0; } wts->prev_on_rq = 1;