Skip to contentSkip to conversation

sched/fair: fix update the nohz.next_balance even if we haven't done any load balance

PATCH In review Wanpeng Li 2 participants 2 messages Mar 27, 2015 Scheduler

lore
Share & tools
lore

Wanpeng Li

author
#0 lore raw

PATCH v2 1/1 sched/fair: fix update the nohz.next_balance even if we haven't done any load balance

As Srikar pointed out (https://lkml.org/lkml/2015/3/27/26):

| With the current code when the ilb cpus are not free:
| - We would be updating the nohz.next_balance even through we havent done
|   any load balance.
| - We might iterate thro the nohz.idle_cpus_mask()s to find balance_cpus.

This patch fix it by adding need_resched check with the idle check, and keep the need_resched check in for loop to catch ilb get busy.

---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
index 0576ce0..788e42f 100644
@@ -7638,7 +7638,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
 	struct rq *rq;
 	int balance_cpu;
 
-	if (idle != CPU_IDLE ||
+	if (idle != CPU_IDLE || need_resched() ||
 	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)))
 		goto end;
 
Signature · 1 line
1.9.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Wanpeng Li

As Srikar pointed out (https://lkml.org/lkml/2015/3/27/26):

| With the current code when the ilb cpus are not free:
| - We would be updating the nohz.next_balance even through we havent done
|   any load balance.
| - We might iterate thro the nohz.idle_cpus_mask()s to find balance_cpus.
Quoted 6 lines

This patch fix it by adding need_resched check with the idle check, and keep the need_resched check in for loop to catch ilb get busy.

Looks good to me.

Quoted 20 lines
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
index 0576ce0..788e42f 100644
@@ -7638,7 +7638,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle)
 	struct rq *rq;
 	int balance_cpu;
 
-	if (idle != CPU_IDLE ||
+	if (idle != CPU_IDLE || need_resched() ||
 	    !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)))
 		goto end;
 
Signature · 1 line
1.9.1
Signature · 2 lines
Thanks and Regards
Srikar Dronamraju