From f25741f0470a54cb43036e5e81f1df623df8ba78 Mon Sep 17 00:00:00 2001 From: Choonghoon Park Date: Mon, 22 Mar 2021 09:54:41 +0900 Subject: [PATCH] ANDROID: sched/fair: Do not sync task util with SD_BALANCE_FORK When android_rvh_select_task_rq_fair is enabled, the woken-up new fair task's utilization is always updated in a wakeup path (wake_up_new_task) although it doesn't have to be. It is because sync_entity_load_avg() is always called in select_task_rq_fair() with the hook enabled. Let's see what happened: The new task's sched_avg->last_update_time should be 0 unless it is updated in attach_entity_cfs_rq() in the wakeup path. But because sync_entity_load_avg() is called, sched_avg->last_update_time is updated with cfs_rq->avg.last_update_time before attach_entity_cfs_rq() is called. After updated, post_init_entity_util_avg() is called and the half of spare capacity of rq which the task is assigned to is set to the task's utilization. Finally, update_load_avg() is called and check the task's sched_avg->last_update_time, and update the task's utilization due to non-zero last_update_time. - wake_up_new_task() - select_task_rq() <-- task's sched_avg->last_update_time is set if android_rvh_select_task_rq_fair is enabled. - post_init_entity_util_avg() <-- task gets the half of spare cap. - attach_entity_cfs_rq() - update_load_avg <-- update task's utiliztion because task's sched_avg->last_update_time is not 0. Make sure not to call sync_entity_load_avg() in select_task_rq_fair() when SD_BALANCE_FORK is also set with the hook. Bug: 183306209 Signed-off-by: Choonghoon Park Change-Id: I1fd70bf3d8e5fe1548f2237afd2d3d81134a68ee --- kernel/sched/fair.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 9ed56b5d7efb..5268007d1ae1 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6801,7 +6801,8 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f int sync = (wake_flags & WF_SYNC) && !(current->flags & PF_EXITING); int target_cpu = -1; - if (trace_android_rvh_select_task_rq_fair_enabled()) + if (trace_android_rvh_select_task_rq_fair_enabled() && + !(sd_flag & SD_BALANCE_FORK)) sync_entity_load_avg(&p->se); trace_android_rvh_select_task_rq_fair(p, prev_cpu, sd_flag, wake_flags, &target_cpu);