sched: rt: Avoid CPUs running top apps if possible

If an RT task was running on a CPU some time back and a top-app happen
to be running later, then when the RT task wakes up, we will blindly
wake up the RT task on its previous CPU thus preventing the top-app from
running until the RT task sleeps. RT tasks can run on any available CPU
that's lower in priority than itself so we should look at all possible
options under this condition. Incase no option is available, it will
fallback to preempting the top-app as before.

Tests:
* Improvement in UiBench GLTextureView seen which gets us to the N levels.
  Other benchmarks show good or better performance.
* No energy increases seen with UiBench GLTextureView and Camera preview.

bug: 62806392

Change-Id: Ifea9157c23decc34f64ce8ab87df8ac4d1bcb3c3
Signed-off-by: Joel Fernandes <joelaf@google.com>
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index 4d25a1f..d1c0952 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -1488,6 +1488,20 @@
 	return !!((pc & SOFTIRQ_MASK)>= SOFTIRQ_DISABLE_OFFSET);
 }
 
+static bool is_top_app_cpu(int cpu)
+{
+	bool boosted = (schedtune_cpu_boost(cpu) > 0);
+
+	return boosted;
+}
+
+static bool is_top_app(struct task_struct *cur)
+{
+	bool boosted = (schedtune_task_boost(cur) > 0);
+
+	return boosted;
+}
+
 /*
  * Return whether the task on the given cpu is currently non-preemptible
  * while handling a potentially long softint, or if the task is likely
@@ -1502,8 +1516,14 @@
 	struct task_struct *cpu_ksoftirqd = per_cpu(ksoftirqd, cpu);
 	int task_pc = 0;
 
-	if (task)
+	if (task) {
+		if (is_top_app(task))
+			return true;
 		task_pc = task_preempt_count(task);
+	}
+
+	if (is_top_app_cpu(cpu))
+		return true;
 
 	if (softirq_masked(task_pc))
 		return true;