linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal: power_allocator: using round the division when re-divvying up power
@ 2021-03-15  8:25 gao.yunxiao6
  2021-03-15  9:51 ` Lukasz Luba
  0 siblings, 1 reply; 5+ messages in thread
From: gao.yunxiao6 @ 2021-03-15  8:25 UTC (permalink / raw)
  To: lukasz.luba, rui.zhang, daniel.lezcano, amitk
  Cc: linux-pm, linux-kernel, orsonzhai, zhang.lyra, jeson.gao

From: "jeson.gao" <jeson.gao@unisoc.com>

The division is used directly in re-divvying up power, the decimal part will
be discarded, devices will get less than the extra_actor_power - 1.
if using round the division to make the calculation more accurate.

For example:
actor0 received more than it's max_power, it has the extra_power 759
actor1 received less than it's max_power, it require extra_actor_power 395
actor2 received less than it's max_power, it require extra_actor_power 365
actor1 and actor2 require the total capped_extra_power 760

using division in re-divvying up power
actor1 would actually get the extra_actor_power 394
actor2 would actually get the extra_actor_power 364

if using round the division in re-divvying up power
actor1 would actually get the extra_actor_power 394
actor2 would actually get the extra_actor_power 365

Signed-off-by: Jeson Gao <jeson.gao@unisoc.com>
---
 drivers/thermal/gov_power_allocator.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c
index 92acae53df49..2802a0e13c88 100644
--- a/drivers/thermal/gov_power_allocator.c
+++ b/drivers/thermal/gov_power_allocator.c
@@ -374,9 +374,11 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
 	 */
 	extra_power = min(extra_power, capped_extra_power);
 	if (capped_extra_power > 0)
-		for (i = 0; i < num_actors; i++)
-			granted_power[i] += (extra_actor_power[i] *
-					extra_power) / capped_extra_power;
+		for (i = 0; i < num_actors; i++) {
+			u64 extra_range = (u64)extra_actor_power[i] * extra_power;
+			granted_power[i] += DIV_ROUND_CLOSEST_ULL(extra_range,
+							 capped_extra_power);
+		}
 }
 
 static int allocate_power(struct thermal_zone_device *tz,
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] thermal: power_allocator: using round the division when re-divvying up power
  2021-03-15  8:25 [PATCH] thermal: power_allocator: using round the division when re-divvying up power gao.yunxiao6
@ 2021-03-15  9:51 ` Lukasz Luba
  2021-03-16 13:15   ` Daniel Lezcano
  0 siblings, 1 reply; 5+ messages in thread
From: Lukasz Luba @ 2021-03-15  9:51 UTC (permalink / raw)
  To: gao.yunxiao6, daniel.lezcano
  Cc: rui.zhang, amitk, linux-pm, linux-kernel, orsonzhai, zhang.lyra,
	jeson.gao



On 3/15/21 8:25 AM, gao.yunxiao6@gmail.com wrote:
> From: "jeson.gao" <jeson.gao@unisoc.com>
> 
> The division is used directly in re-divvying up power, the decimal part will
> be discarded, devices will get less than the extra_actor_power - 1.
> if using round the division to make the calculation more accurate.
> 
> For example:
> actor0 received more than it's max_power, it has the extra_power 759
> actor1 received less than it's max_power, it require extra_actor_power 395
> actor2 received less than it's max_power, it require extra_actor_power 365
> actor1 and actor2 require the total capped_extra_power 760
> 
> using division in re-divvying up power
> actor1 would actually get the extra_actor_power 394
> actor2 would actually get the extra_actor_power 364
> 
> if using round the division in re-divvying up power
> actor1 would actually get the extra_actor_power 394
> actor2 would actually get the extra_actor_power 365
> 
> Signed-off-by: Jeson Gao <jeson.gao@unisoc.com>
> ---
>   drivers/thermal/gov_power_allocator.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c
> index 92acae53df49..2802a0e13c88 100644
> --- a/drivers/thermal/gov_power_allocator.c
> +++ b/drivers/thermal/gov_power_allocator.c
> @@ -374,9 +374,11 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
>   	 */
>   	extra_power = min(extra_power, capped_extra_power);
>   	if (capped_extra_power > 0)
> -		for (i = 0; i < num_actors; i++)
> -			granted_power[i] += (extra_actor_power[i] *
> -					extra_power) / capped_extra_power;
> +		for (i = 0; i < num_actors; i++) {
> +			u64 extra_range = (u64)extra_actor_power[i] * extra_power;
> +			granted_power[i] += DIV_ROUND_CLOSEST_ULL(extra_range,
> +							 capped_extra_power);
> +		}
>   }
>   
>   static int allocate_power(struct thermal_zone_device *tz,
> 

Make sense. There is already DIV_ROUND_CLOSEST_ULL() in that function,
so let's align both. There might be a bit overhead on 32bit machines,
but IPA polling isn't so often there.

Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>

Regards,
Lukasz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] thermal: power_allocator: using round the division when re-divvying up power
  2021-03-15  9:51 ` Lukasz Luba
@ 2021-03-16 13:15   ` Daniel Lezcano
  2021-03-16 13:16     ` Lukasz Luba
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Lezcano @ 2021-03-16 13:15 UTC (permalink / raw)
  To: Lukasz Luba, gao.yunxiao6
  Cc: rui.zhang, amitk, linux-pm, linux-kernel, orsonzhai, zhang.lyra,
	jeson.gao

On 15/03/2021 10:51, Lukasz Luba wrote:
> 
> 
> On 3/15/21 8:25 AM, gao.yunxiao6@gmail.com wrote:
>> From: "jeson.gao" <jeson.gao@unisoc.com>
>>
>> The division is used directly in re-divvying up power, the decimal
>> part will
>> be discarded, devices will get less than the extra_actor_power - 1.
>> if using round the division to make the calculation more accurate.
>>
>> For example:
>> actor0 received more than it's max_power, it has the extra_power 759
>> actor1 received less than it's max_power, it require extra_actor_power
>> 395
>> actor2 received less than it's max_power, it require extra_actor_power
>> 365
>> actor1 and actor2 require the total capped_extra_power 760
>>
>> using division in re-divvying up power
>> actor1 would actually get the extra_actor_power 394
>> actor2 would actually get the extra_actor_power 364
>>
>> if using round the division in re-divvying up power
>> actor1 would actually get the extra_actor_power 394
>> actor2 would actually get the extra_actor_power 365
>>
>> Signed-off-by: Jeson Gao <jeson.gao@unisoc.com>
>> ---

Applied, thanks

-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] thermal: power_allocator: using round the division when re-divvying up power
  2021-03-16 13:15   ` Daniel Lezcano
@ 2021-03-16 13:16     ` Lukasz Luba
  2021-03-17 11:20       ` gao yunxiao
  0 siblings, 1 reply; 5+ messages in thread
From: Lukasz Luba @ 2021-03-16 13:16 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: gao.yunxiao6, rui.zhang, amitk, linux-pm, linux-kernel,
	orsonzhai, zhang.lyra, jeson.gao



On 3/16/21 1:15 PM, Daniel Lezcano wrote:
> On 15/03/2021 10:51, Lukasz Luba wrote:
>>
>>
>> On 3/15/21 8:25 AM, gao.yunxiao6@gmail.com wrote:
>>> From: "jeson.gao" <jeson.gao@unisoc.com>
>>>
>>> The division is used directly in re-divvying up power, the decimal
>>> part will
>>> be discarded, devices will get less than the extra_actor_power - 1.
>>> if using round the division to make the calculation more accurate.
>>>
>>> For example:
>>> actor0 received more than it's max_power, it has the extra_power 759
>>> actor1 received less than it's max_power, it require extra_actor_power
>>> 395
>>> actor2 received less than it's max_power, it require extra_actor_power
>>> 365
>>> actor1 and actor2 require the total capped_extra_power 760
>>>
>>> using division in re-divvying up power
>>> actor1 would actually get the extra_actor_power 394
>>> actor2 would actually get the extra_actor_power 364
>>>
>>> if using round the division in re-divvying up power
>>> actor1 would actually get the extra_actor_power 394
>>> actor2 would actually get the extra_actor_power 365
>>>
>>> Signed-off-by: Jeson Gao <jeson.gao@unisoc.com>
>>> ---
> 
> Applied, thanks
> 

thank you Daniel!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] thermal: power_allocator: using round the division when re-divvying up power
  2021-03-16 13:16     ` Lukasz Luba
@ 2021-03-17 11:20       ` gao yunxiao
  0 siblings, 0 replies; 5+ messages in thread
From: gao yunxiao @ 2021-03-17 11:20 UTC (permalink / raw)
  To: Lukasz Luba
  Cc: Daniel Lezcano, rui.zhang, amitk, linux-pm, linux-kernel,
	orsonzhai, zhang.lyra, jeson.gao

Lukasz,Daniel, Thank you for your review!

On 16/03/2021, Lukasz Luba <lukasz.luba@arm.com> wrote:
>
>
> On 3/16/21 1:15 PM, Daniel Lezcano wrote:
>> On 15/03/2021 10:51, Lukasz Luba wrote:
>>>
>>>
>>> On 3/15/21 8:25 AM, gao.yunxiao6@gmail.com wrote:
>>>> From: "jeson.gao" <jeson.gao@unisoc.com>
>>>>
>>>> The division is used directly in re-divvying up power, the decimal
>>>> part will
>>>> be discarded, devices will get less than the extra_actor_power - 1.
>>>> if using round the division to make the calculation more accurate.
>>>>
>>>> For example:
>>>> actor0 received more than it's max_power, it has the extra_power 759
>>>> actor1 received less than it's max_power, it require extra_actor_power
>>>> 395
>>>> actor2 received less than it's max_power, it require extra_actor_power
>>>> 365
>>>> actor1 and actor2 require the total capped_extra_power 760
>>>>
>>>> using division in re-divvying up power
>>>> actor1 would actually get the extra_actor_power 394
>>>> actor2 would actually get the extra_actor_power 364
>>>>
>>>> if using round the division in re-divvying up power
>>>> actor1 would actually get the extra_actor_power 394
>>>> actor2 would actually get the extra_actor_power 365
>>>>
>>>> Signed-off-by: Jeson Gao <jeson.gao@unisoc.com>
>>>> ---
>>
>> Applied, thanks
>>
>
> thank you Daniel!
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-17 11:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-15  8:25 [PATCH] thermal: power_allocator: using round the division when re-divvying up power gao.yunxiao6
2021-03-15  9:51 ` Lukasz Luba
2021-03-16 13:15   ` Daniel Lezcano
2021-03-16 13:16     ` Lukasz Luba
2021-03-17 11:20       ` gao yunxiao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).