summaryrefslogtreecommitdiff
path: root/drivers/thermal/gov_fair_share.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2024-04-10 20:00:10 +0300
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2024-04-24 11:15:08 +0300
commitc98e24795e8b53ff68b317ed31ddcc37cf8b6a26 (patch)
tree0a07856f501a6efc4bd7f8d6ce6b19ea0351e1b0 /drivers/thermal/gov_fair_share.c
parent0292991ce46c75c28d6ccfe7a7f8ac962a824291 (diff)
downloadlinux-c98e24795e8b53ff68b317ed31ddcc37cf8b6a26.tar.xz
thermal: gov_fair_share: Eliminate unnecessary integer divisions
The computations carried out by fair_share_throttle() for each trip point include at least one redundant integer division which introduces superfluous rounding errors. Also the multiplications by 100 in it are not really necessary and can be eliminated. Rearrange fair_share_throttle() to carry out only one integer division per trip and only as many integer multiplications as necessary and rename one variable in it (while at it). Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Diffstat (limited to 'drivers/thermal/gov_fair_share.c')
-rw-r--r--drivers/thermal/gov_fair_share.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/drivers/thermal/gov_fair_share.c b/drivers/thermal/gov_fair_share.c
index ca6d6152ccf2..ce0ea571ed67 100644
--- a/drivers/thermal/gov_fair_share.c
+++ b/drivers/thermal/gov_fair_share.c
@@ -41,12 +41,6 @@ static int get_trip_level(struct thermal_zone_device *tz)
return trip_level;
}
-static long get_target_state(struct thermal_zone_device *tz,
- struct thermal_cooling_device *cdev, int percentage, int level)
-{
- return (long)(percentage * level * cdev->max_state) / (100 * tz->num_trips);
-}
-
/**
* fair_share_throttle - throttles devices associated with the given zone
* @tz: thermal_zone_device
@@ -58,7 +52,7 @@ static long get_target_state(struct thermal_zone_device *tz,
*
* Parameters used for Throttling:
* P1. max_state: Maximum throttle state exposed by the cooling device.
- * P2. percentage[i]/100:
+ * P2. weight[i]/total_weight:
* How 'effective' the 'i'th device is, in cooling the given zone.
* P3. trip_level/max_no_of_trips:
* This describes the extent to which the devices should be throttled.
@@ -72,30 +66,34 @@ static void fair_share_throttle(struct thermal_zone_device *tz,
{
struct thermal_instance *instance;
int total_weight = 0;
- int total_instance = 0;
+ int nr_instances = 0;
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
if (instance->trip != trip)
continue;
total_weight += instance->weight;
- total_instance++;
+ nr_instances++;
}
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
- int percentage;
struct thermal_cooling_device *cdev = instance->cdev;
+ u64 dividend;
+ u32 divisor;
if (instance->trip != trip)
continue;
- if (!total_weight)
- percentage = 100 / total_instance;
- else
- percentage = (instance->weight * 100) / total_weight;
-
- instance->target = get_target_state(tz, cdev, percentage,
- trip_level);
+ dividend = trip_level;
+ dividend *= cdev->max_state;
+ divisor = tz->num_trips;
+ if (total_weight) {
+ dividend *= instance->weight;
+ divisor *= total_weight;
+ } else {
+ divisor *= nr_instances;
+ }
+ instance->target = div_u64(dividend, divisor);
mutex_lock(&cdev->lock);
__thermal_cdev_update(cdev);