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

Commit 116f3444 authored by Joonwoo Park's avatar Joonwoo Park
Browse files

sched: fix overflow in scaled execution time calculation



Task execution time in nanoseconds and CPU cycle counters are large
enough to cause overflow when we multiply both.  Avoid overflow by
calculating frequency separately.

Change-Id: I076d9ecd27cb1c1f11578f009ebe1a19c1619454
Signed-off-by: default avatarJoonwoo Park <joonwoop@codeaurora.org>
parent 7d2dfd06
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1866,9 +1866,10 @@ static inline u64 scale_exec_time(u64 delta, struct rq *rq)
{
	int cpu = cpu_of(rq);
	int sf;
	u32 freq;

	delta = DIV64_U64_ROUNDUP(delta * rq->cc.cycles,
				  max_possible_freq * rq->cc.time);
	freq = cpu_cycles_to_freq(rq->cc.cycles, rq->cc.time);
	delta = DIV64_U64_ROUNDUP(delta * freq, max_possible_freq);
	sf = DIV_ROUND_UP(cpu_efficiency(cpu) * 1024, max_possible_efficiency);

	delta *= sf;