From 6dc3ebb376bfdb33d06b370b3c2caa62e67284fb Mon Sep 17 00:00:00 2001
From: Pavankumar Kondeti <pkondeti@codeaurora.org>
Date: Mon, 7 Sep 2020 09:35:49 +0530
Subject: [PATCH] sched/walt: Improve the scheduler

This change is for general scheduler improvement.

Change-Id: Id1692f724f2efd22ada3365cebd154f1999930b5
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
[clingutla@codeaurora.org: Resolved trivial merge conflicts]
Signed-off-by: Lingutla Chandrasekhar <clingutla@codeaurora.org>
---
 include/linux/sched/sysctl.h | 2 +-
 include/trace/events/sched.h | 2 +-
 kernel/sched/fair.c          | 2 +-
 kernel/sched/sched.h         | 3 ++-
 kernel/sysctl.c              | 6 +++---
 5 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
index 73eb9b462153..023c4824af37 100644
--- a/include/linux/sched/sysctl.h
+++ b/include/linux/sched/sysctl.h
@@ -59,7 +59,7 @@ extern unsigned int sysctl_sched_ravg_window_nr_ticks;
 extern unsigned int sysctl_sched_dynamic_ravg_window_enable;
 extern unsigned int sysctl_sched_prefer_spread;
 extern unsigned int sysctl_walt_rtg_cfs_boost_prio;
-extern unsigned int sysctl_walt_low_latency_task_boost;
+extern unsigned int sysctl_walt_low_latency_task_threshold;
 
 extern int
 walt_proc_group_thresholds_handler(struct ctl_table *table, int write,
diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h
index ae6480afb01c..f00fe85e6997 100644
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -1267,7 +1267,7 @@ TRACE_EVENT(sched_task_util,
 		__entry->start_cpu		= start_cpu;
 #ifdef CONFIG_SCHED_WALT
 		__entry->unfilter		= p->unfilter;
-		__entry->low_latency		= p->low_latency;
+		__entry->low_latency		= walt_low_latency_task(p);
 #else
 		__entry->unfilter		= 0;
 		__entry->low_latency		= 0;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index f2920f604abf..0f48f00cd752 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -177,7 +177,7 @@ unsigned int sysctl_sched_min_task_util_for_boost = 51;
 unsigned int sysctl_sched_min_task_util_for_colocation = 35;
 __read_mostly unsigned int sysctl_sched_prefer_spread;
 unsigned int sysctl_walt_rtg_cfs_boost_prio = 99; /* disabled by default */
-unsigned int sysctl_walt_low_latency_task_boost; /* disabled by default */
+unsigned int sysctl_walt_low_latency_task_threshold; /* disabled by default */
 #endif
 unsigned int sched_small_task_threshold = 102;
 __read_mostly unsigned int sysctl_sched_force_lb_enable = 1;
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 6b9d42bbc775..3aa2efdf6791 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -2911,7 +2911,8 @@ static inline bool task_rtg_high_prio(struct task_struct *p)
 
 static inline bool walt_low_latency_task(struct task_struct *p)
 {
-	return sysctl_walt_low_latency_task_boost && p->low_latency;
+	return p->low_latency &&
+		(task_util(p) < sysctl_walt_low_latency_task_threshold);
 }
 
 /* Is frequency of two cpus synchronized with each other? */
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index edd4ee102072..61e40b7c5d75 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -580,13 +580,13 @@ static struct ctl_table kern_table[] = {
 		.extra2		= &max_cfs_boost_prio,
 	},
 	{
-		.procname	= "walt_low_latency_task_boost",
-		.data		= &sysctl_walt_low_latency_task_boost,
+		.procname	= "walt_low_latency_task_threshold",
+		.data		= &sysctl_walt_low_latency_task_threshold,
 		.maxlen		= sizeof(unsigned int),
 		.mode		= 0644,
 		.proc_handler   = proc_dointvec_minmax,
 		.extra1		= &zero,
-		.extra2		= &one,
+		.extra2		= &one_thousand,
 	},
 #endif
 	{