Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a734c2b authored by Abhijeet Dharmapurikar's avatar Abhijeet Dharmapurikar Committed by Gerrit - the friendly Code Review server
Browse files

sched/fair: dont run energy calculation unless necessary



The placement code calls find_best_target() to find the next cpu,
and if possible a backup cpu. After that it does an energy
evaluation between next, backup and prev cpu.

When find_best_target() finds the next or backup the same
as prev, we unnecessarily account for the same cpu twice
in energy evaluation.

So, drop the backup if its same as prev. If the next cpu
is same as the prev, make backup the next candidate.

Also replace task_cpu() with stack prev_cpu variable.

Change-Id: Ia2dc0c1b059ad515d99e7d66556795b24d30629c
Signed-off-by: default avatarAbhijeet Dharmapurikar <adharmap@codeaurora.org>
[clingutla@codeaurora.org: Resolved merge conflicts, and include
 backup cpu check with target cpu.]
Signed-off-by: default avatarLingutla Chandrasekhar <clingutla@codeaurora.org>
parent 2dba40ba
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -6930,6 +6930,7 @@ static inline int find_best_target(struct task_struct *p, int *backup_cpu,
	int cpu, i;
	unsigned int active_cpus_count = 0;
	int isolated_candidate = -1;
	int prev_cpu = task_cpu(p);

	*backup_cpu = -1;

@@ -6982,7 +6983,7 @@ static inline int find_best_target(struct task_struct *p, int *backup_cpu,

			isolated_candidate = i;

			if (avoid_prev_cpu && i == task_cpu(p))
			if (avoid_prev_cpu && i == prev_cpu)
				continue;

			if (walt_cpu_high_irqload(i) || is_reserved(i))
@@ -7234,7 +7235,7 @@ static inline int find_best_target(struct task_struct *p, int *backup_cpu,

	if (best_idle_cpu != -1 && !is_packing_eligible(p, target_cpu, fbt_env,
					active_cpus_count, best_idle_cstate)) {
		if (target_cpu == task_cpu(p))
		if (target_cpu == prev_cpu)
			fbt_env->avoid_prev_cpu = true;

		target_cpu = best_idle_cpu;
@@ -7270,12 +7271,28 @@ static inline int find_best_target(struct task_struct *p, int *backup_cpu,
		? best_active_cpu
		: best_idle_cpu;

	if (target_cpu == -1 && cpu_isolated(task_cpu(p)) &&
	if (target_cpu == -1 && cpu_isolated(prev_cpu) &&
			isolated_candidate != -1) {
		target_cpu = isolated_candidate;
		fbt_env->avoid_prev_cpu = true;
	}

	/*
	 * - It is possible for target and backup
	 *   to select same CPU - if so, drop backup
	 *
	 * - The next step of energy evaluation includes
	 *   prev_cpu. Drop target or backup if it is
	 *   same as prev_cpu.
	 */
	if (*backup_cpu == target_cpu || *backup_cpu == prev_cpu)
		*backup_cpu = -1;

	if (target_cpu == prev_cpu) {
		target_cpu = *backup_cpu;
		*backup_cpu = -1;
	}

	trace_sched_find_best_target(p, prefer_idle, min_util, cpu,
				     best_idle_cpu, best_active_cpu,
				     target_cpu, *backup_cpu);