Commit ea54cac9 authored by Javi Merino's avatar Javi Merino Committed by Eduardo Valentin

thermal: power_allocator: round the division when divvying up power

In situations where there is an uneven number of cooling devices, the
division of power among them can lead to a milliwatt being dropped on
the floor due to rounding errors.  This doesn't sound like a lot, but
some devices only grant the lowest cooling device state for their
maximum power.  So for instance, if the granted_power is the maximum
power and all devices are getting their maximum power, one would get
max_power - 1, making it choose cooling device state 1, instead of 0.

Round the division to make the calculation more accurate.

Cc: Zhang Rui <rui.zhang@intel.com>
Cc: Eduardo Valentin <edubezval@gmail.com>
Signed-off-by: default avatarJavi Merino <javi.merino@arm.com>
Signed-off-by: default avatarEduardo Valentin <edubezval@gmail.com>
parent 488c7455
...@@ -196,7 +196,8 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors, ...@@ -196,7 +196,8 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
for (i = 0; i < num_actors; i++) { for (i = 0; i < num_actors; i++) {
u64 req_range = req_power[i] * power_range; u64 req_range = req_power[i] * power_range;
granted_power[i] = div_u64(req_range, total_req_power); granted_power[i] = DIV_ROUND_CLOSEST_ULL(req_range,
total_req_power);
if (granted_power[i] > max_power[i]) { if (granted_power[i] > max_power[i]) {
extra_power += granted_power[i] - max_power[i]; extra_power += granted_power[i] - max_power[i];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment