[PATCH 1/2] sched: fix cast on power utilization calculation and usediv_u64

From: Alex Shi
Date: Tue May 28 2013 - 23:09:39 EST


Now explicit casting is done when power usage variable (putil) is
calculated.
div_u64 is optimized on u32.

Signed-off-by: Lukasz Majewski <l.majewski@xxxxxxxxxxx>
Signed-off-by: Kyungmin Park <kyungmin.park@xxxxxxxxxxx>
Signed-off-by: Alex Shi <alex.shi@xxxxxxxxx>
---
kernel/sched/fair.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 09ae48a..3a4917c 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1504,8 +1504,8 @@ static inline void update_rq_runnable_avg(struct rq *rq, int runnable)
__update_tg_runnable_avg(&rq->avg, &rq->cfs);

period = rq->avg.runnable_avg_period ? rq->avg.runnable_avg_period : 1;
- rq->util = (u64)(rq->avg.runnable_avg_sum << SCHED_POWER_SHIFT)
- / period;
+ rq->util = div_u64(((u64)rq->avg.runnable_avg_sum << SCHED_POWER_SHIFT),
+ period);
}

/* Add the load generated by se into cfs_rq's child load-average */
@@ -3407,8 +3407,8 @@ static int is_sd_full(struct sched_domain *sd,
/* p maybe a new forked task */
putil = FULL_UTIL;
else
- putil = (u64)(p->se.avg.runnable_avg_sum << SCHED_POWER_SHIFT)
- / (p->se.avg.runnable_avg_period + 1);
+ putil = div_u64(((u64)p->se.avg.runnable_avg_sum << SCHED_POWER_SHIFT),
+ p->se.avg.runnable_avg_period + 1);

/* Try to collect the domain's utilization */
group = sd->groups;
@@ -3463,9 +3463,11 @@ find_leader_cpu(struct sched_group *group, struct task_struct *p, int this_cpu,
int vacancy, min_vacancy = INT_MAX;
int leader_cpu = -1;
int i;
+
/* percentage of the task's util */
- unsigned putil = (u64)(p->se.avg.runnable_avg_sum << SCHED_POWER_SHIFT)
- / (p->se.avg.runnable_avg_period + 1);
+ unsigned putil;
+ putil = div_u64(((u64)p->se.avg.runnable_avg_sum << SCHED_POWER_SHIFT),
+ p->se.avg.runnable_avg_period + 1);

/* bias toward local cpu */
if (cpumask_test_cpu(this_cpu, tsk_cpus_allowed(p)) &&
--
1.7.12


--
Thanks
Alex
--
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/