diff mbox series

[v2,5/8] thermal: gov_power_allocator: Refactor checks in divvy_up_power()

Message ID 20231212134844.1213381-6-lukasz.luba@arm.com (mailing list archive)
State Changes Requested, archived
Headers show
Series Add callback for cooling list update to speed-up IPA | expand

Commit Message

Lukasz Luba Dec. 12, 2023, 1:48 p.m. UTC
Simplify the code and remove one extra 'if' block.

No intentional functional impact.

Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
 drivers/thermal/gov_power_allocator.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

Comments

Rafael J. Wysocki Dec. 20, 2023, 2:41 p.m. UTC | #1
On Tue, Dec 12, 2023 at 2:48 PM Lukasz Luba <lukasz.luba@arm.com> wrote:
>
> Simplify the code and remove one extra 'if' block.
>
> No intentional functional impact.
>
> Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
> ---
>  drivers/thermal/gov_power_allocator.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c
> index 1a605fd9c8c6..574aa5822112 100644
> --- a/drivers/thermal/gov_power_allocator.c
> +++ b/drivers/thermal/gov_power_allocator.c
> @@ -349,7 +349,8 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
>                            u32 total_req_power, u32 power_range,
>                            u32 *granted_power, u32 *extra_actor_power)
>  {
> -       u32 extra_power, capped_extra_power;
> +       u32 capped_extra_power = 0;
> +       u32 extra_power = 0;
>         int i;
>
>         /*
> @@ -358,8 +359,6 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
>         if (!total_req_power)
>                 total_req_power = 1;
>
> -       capped_extra_power = 0;
> -       extra_power = 0;
>         for (i = 0; i < num_actors; i++) {
>                 u64 req_range = (u64)req_power[i] * power_range;
>
> @@ -375,7 +374,7 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
>                 capped_extra_power += extra_actor_power[i];
>         }
>
> -       if (!extra_power)
> +       if (!extra_power || !capped_extra_power)
>                 return;
>
>         /*
> @@ -383,12 +382,13 @@ static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
>          * how far they are from the max
>          */
>         extra_power = min(extra_power, capped_extra_power);
> -       if (capped_extra_power > 0)
> -               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);
> -               }
> +
> +       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, int control_temp)
> --

Looks good to me.
diff mbox series

Patch

diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c
index 1a605fd9c8c6..574aa5822112 100644
--- a/drivers/thermal/gov_power_allocator.c
+++ b/drivers/thermal/gov_power_allocator.c
@@ -349,7 +349,8 @@  static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
 			   u32 total_req_power, u32 power_range,
 			   u32 *granted_power, u32 *extra_actor_power)
 {
-	u32 extra_power, capped_extra_power;
+	u32 capped_extra_power = 0;
+	u32 extra_power = 0;
 	int i;
 
 	/*
@@ -358,8 +359,6 @@  static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
 	if (!total_req_power)
 		total_req_power = 1;
 
-	capped_extra_power = 0;
-	extra_power = 0;
 	for (i = 0; i < num_actors; i++) {
 		u64 req_range = (u64)req_power[i] * power_range;
 
@@ -375,7 +374,7 @@  static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
 		capped_extra_power += extra_actor_power[i];
 	}
 
-	if (!extra_power)
+	if (!extra_power || !capped_extra_power)
 		return;
 
 	/*
@@ -383,12 +382,13 @@  static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors,
 	 * how far they are from the max
 	 */
 	extra_power = min(extra_power, capped_extra_power);
-	if (capped_extra_power > 0)
-		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);
-		}
+
+	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, int control_temp)