[PATCH 2/2] sched:fix: Signed overflow prevention for vacancycalculation

From: Lukasz Majewski
Date: Thu May 23 2013 - 04:36:05 EST


Nasty bug with vacancy calculation has been fixed.
In the if statement the FULL_UTIL is a large constant, max_cfs_util()
returns unsigned and putil is also defined as unsigned. The outcome
is that this condition is always true.

As observed, this was the reason for frequent jumps of processes between
CPUs.

Signed-off-by: Lukasz Majewski <l.majewski@xxxxxxxxxxx>
Signed-off-by: Kyungmin Park <kyungmin.park@xxxxxxxxxxx>
---
This patch was developed on top of the following Alex's repository:
https://github.com/alexshi/power-scheduling/commits/power-scheduling
---
kernel/sched/fair.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 14d29b3..8b07f6c 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3476,9 +3476,10 @@ find_leader_cpu(struct sched_group *group, struct task_struct *p, int this_cpu,
do_div(tmp, (p->se.avg.runnable_avg_period + 1));
putil = (unsigned) tmp;

+ vacancy = (int) (FULL_UTIL - max_cfs_util(this_cpu, wakeup) -
+ (putil << 2));
/* bias toward local cpu */
- if (cpumask_test_cpu(this_cpu, tsk_cpus_allowed(p)) &&
- FULL_UTIL - max_cfs_util(this_cpu, wakeup) - (putil << 2) > 0)
+ if (cpumask_test_cpu(this_cpu, tsk_cpus_allowed(p)) && vacancy > 0)
return this_cpu;

/* Traverse only the allowed CPUs */
--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/