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

Commit 3a5a6747 authored by Pavankumar Kondeti's avatar Pavankumar Kondeti Committed by Gerrit - the friendly Code Review server
Browse files

sched/fair: Add fallback CPU selection



When all CPUs are overloaded, the task is placed on the previous
CPU during wakeup. This can result in packing high number of tasks
on a CPU. When no suitable CPU is found and previous CPU has more
than 32 runnable tasks, add a fallback CPU selection to find
the CPU with least number of runnable tasks.

When a CPU is isolated or hotplugged out, all tasks queued on
the CPU are migrated to CPU#0. This can result in packing high
number of tasks on CPU#0. Add the above fallback CPU selection
here also.

Change-Id: Ia9b959339692770b4cc594fa36cf42ca342cf2de
Signed-off-by: default avatarPavankumar Kondeti <pkondeti@codeaurora.org>
parent 3de6f27e
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -2092,6 +2092,8 @@ static int select_fallback_rq(int cpu, struct task_struct *p, bool allow_iso)
	enum { cpuset, possible, fail, bug } state = cpuset;
	int dest_cpu;
	int isolated_candidate = -1;
	int backup_cpu = -1;
	unsigned int max_nr = UINT_MAX;

	/*
	 * If the node that the CPU is on has been offlined, cpu_to_node()
@@ -2107,9 +2109,18 @@ static int select_fallback_rq(int cpu, struct task_struct *p, bool allow_iso)
				continue;
			if (cpu_isolated(dest_cpu))
				continue;
			if (cpumask_test_cpu(dest_cpu, &p->cpus_allowed))
			if (cpumask_test_cpu(dest_cpu, &p->cpus_allowed)) {
				if (cpu_rq(dest_cpu)->nr_running < 32)
					return dest_cpu;
				if (cpu_rq(dest_cpu)->nr_running > max_nr)
					continue;
				backup_cpu = dest_cpu;
				max_nr = cpu_rq(dest_cpu)->nr_running;
			}
		}

		if (backup_cpu != -1)
			return backup_cpu;
	}

	for (;;) {
+20 −1
Original line number Diff line number Diff line
@@ -7765,8 +7765,27 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu,

	/* Bail out if no candidate was found. */
	weight = cpumask_weight(candidates);
	if (!weight)
	if (!weight) {
		/*
		 * Don't overload the previous CPU if it had already
		 * more runnable tasks. Fallback to a CPU with lower
		 * number of tasks.
		 */
		if (cpu_rq(prev_cpu)->nr_running > 32) {
			int i;
			unsigned int best_nr = UINT_MAX;

			for_each_cpu(i, cpu_active_mask) {
				if (!cpumask_test_cpu(i, &p->cpus_allowed))
					continue;
				if (cpu_rq(i)->nr_running < best_nr) {
					best_nr = cpu_rq(i)->nr_running;
					best_energy_cpu = i;
				}
			}
		}
		goto unlock;
	}

	/* If there is only one sensible candidate, select it now. */
	cpu = cpumask_first(candidates);