Skip to contentSkip to conversation

sched/fair: Let minimally loaded cpu balance the group

tip:sched/core tip-bot for Peter Zijlstra 1 participant 2 messages May 9, 2012 Scheduler

lore
Share & tools
lore
#0 lore raw
Commit-ID:  c22402a2f76e88b04b7a8b6c0597ad9ba6fd71de
Gitweb:     http://git.kernel.org/tip/c22402a2f76e88b04b7a8b6c0597ad9ba6fd71de
Author:     Peter Zijlstra <[email protected]>
AuthorDate: Fri, 20 Apr 2012 16:57:22 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 9 May 2012 15:00:51 +0200

sched/fair: Let minimally loaded cpu balance the group

Currently we let the leftmost (or first idle) cpu ascend the sched_domain tree and perform load-balancing. The result is that the busiest cpu in the group might be performing this function and pull more load to itself. The next load balance pass will then try to equalize this again.

Change this to pick the least loaded cpu to perform higher domain balancing.

---
 kernel/sched/fair.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
kernel/sched/fair.c +5 -5
index 678966c..968ffee 100644
@@ -3781,7 +3781,8 @@ static inline void update_sg_lb_stats(struct sched_domain *sd,
 {
 	unsigned long load, max_cpu_load, min_cpu_load, max_nr_running;
 	int i;
-	unsigned int balance_cpu = -1, first_idle_cpu = 0;
+	unsigned int balance_cpu = -1;
+	unsigned long balance_load = ~0UL;
 	unsigned long avg_load_per_task = 0;
 
 	if (local_group)
@@ -3797,12 +3798,11 @@ static inline void update_sg_lb_stats(struct sched_domain *sd,
 
 		/* Bias balancing toward cpus of our domain */
 		if (local_group) {
-			if (idle_cpu(i) && !first_idle_cpu) {
-				first_idle_cpu = 1;
+			load = target_load(i, load_idx);
+			if (load < balance_load || idle_cpu(i)) {
+				balance_load = load;
 				balance_cpu = i;
 			}
-
-			load = target_load(i, load_idx);
 		} else {
 			load = source_load(i, load_idx);
 			if (load > max_cpu_load) {
#1 lore raw
Quoted 10 lines · tip-bot for Peter Zijlstra

sched/fair: Let minimally loaded cpu balance the group

Currently we let the leftmost (or first idle) cpu ascend the sched_domain tree and perform load-balancing. The result is that the busiest cpu in the group might be performing this function and pull more load to itself. The next load balance pass will then try to equalize this again.

Change this to pick the least loaded cpu to perform higher domain balancing.

OK, so while this all sounds great its horrible broken.. there's no guarantee the selected cpu actually gets to balance the domain for it might never reach as high in its own balance pass since by then it might not be the least loaded anymore.

Will have to poke at this more tomorrow, but from what my tired brain makes of it there's nothing but a straight revert (and probably similar for the next patch).