Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Javi Merino <javi.merino@arm.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>

authored by

Javi Merino and committed by
Eduardo Valentin
ea54cac9 488c7455

+2 -1
+2 -1
drivers/thermal/power_allocator.c
··· 196 196 for (i = 0; i < num_actors; i++) { 197 197 u64 req_range = req_power[i] * power_range; 198 198 199 - granted_power[i] = div_u64(req_range, total_req_power); 199 + granted_power[i] = DIV_ROUND_CLOSEST_ULL(req_range, 200 + total_req_power); 200 201 201 202 if (granted_power[i] > max_power[i]) { 202 203 extra_power += granted_power[i] - max_power[i];