From e02f1d718a967adaebc9098f6207e529a50a253b Mon Sep 17 00:00:00 2001
From: Joel Fernandes <joelaf@google.com>
Date: Wed, 21 Jun 2017 13:09:15 -0700
Subject: [PATCH] sched: honor sync only if CPU is about to goto idle

sync is causing excessive latencies during binder replies as its causing
migration of important tasks to busy CPU. Incase the CPU has a lot of
tasks running, prevent sync from happening

bug: 62806392

Change-Id: I4731bd9fdbf278c4ba55f3abc8c9ed4fa54a31cf
Signed-off-by: Joel Fernandes <joelaf@google.com>
---
 kernel/sched/fair.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 035e3864e046..6a25aa14d067 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5675,8 +5675,10 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f
 
 	if (!sd) {
 		int sync_used = 0;
+		bool about_to_idle = (cpu_rq(cpu)->nr_running < 2);
 
-		if (sysctl_sched_sync_hint_enable && sync) {
+		if (sysctl_sched_sync_hint_enable && sync
+				&& about_to_idle) {
 			cpumask_t search_cpus;
 			cpumask_and(&search_cpus, tsk_cpus_allowed(p),
 				    cpu_online_mask);
-- 
GitLab