Skip to content

Commit bec5533

Browse files
committed
thermal: gov_fair_share: Use .manage() callback instead of .throttle()
The Fair Share governor tries very hard to be stateless and so it calls get_trip_level() from fair_share_throttle() every time, even though the number produced by this function for all of the trips during a given thermal zone update is actually the same. Since get_trip_level() walks all of the trips in the thermal zone every time it is called, doing this may generate quite a bit of completely useless overhead. For this reason, make the governor use the new .manage() callback instead of .throttle() which allows it to call get_trip_level() just once and use the value computed by it to handle all of the trips. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Lukasz Luba <[email protected]>
1 parent fe03626 commit bec5533

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

drivers/thermal/gov_fair_share.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static long get_target_state(struct thermal_zone_device *tz,
5353
* fair_share_throttle - throttles devices associated with the given zone
5454
* @tz: thermal_zone_device
5555
* @trip: trip point
56+
* @trip_level: number of trips crossed by the zone temperature
5657
*
5758
* Throttling Logic: This uses three parameters to calculate the new
5859
* throttle state of the cooling devices associated with the given zone.
@@ -61,22 +62,19 @@ static long get_target_state(struct thermal_zone_device *tz,
6162
* P1. max_state: Maximum throttle state exposed by the cooling device.
6263
* P2. percentage[i]/100:
6364
* How 'effective' the 'i'th device is, in cooling the given zone.
64-
* P3. cur_trip_level/max_no_of_trips:
65+
* P3. trip_level/max_no_of_trips:
6566
* This describes the extent to which the devices should be throttled.
6667
* We do not want to throttle too much when we trip a lower temperature,
6768
* whereas the throttling is at full swing if we trip critical levels.
68-
* (Heavily assumes the trip points are in ascending order)
6969
* new_state of cooling device = P3 * P2 * P1
7070
*/
71-
static int fair_share_throttle(struct thermal_zone_device *tz,
72-
const struct thermal_trip *trip)
71+
static void fair_share_throttle(struct thermal_zone_device *tz,
72+
const struct thermal_trip *trip,
73+
int trip_level)
7374
{
7475
struct thermal_instance *instance;
7576
int total_weight = 0;
7677
int total_instance = 0;
77-
int cur_trip_level = get_trip_level(tz);
78-
79-
lockdep_assert_held(&tz->lock);
8078

8179
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
8280
if (instance->trip != trip)
@@ -99,18 +97,35 @@ static int fair_share_throttle(struct thermal_zone_device *tz,
9997
percentage = (instance->weight * 100) / total_weight;
10098

10199
instance->target = get_target_state(tz, cdev, percentage,
102-
cur_trip_level);
100+
trip_level);
103101

104102
mutex_lock(&cdev->lock);
105103
__thermal_cdev_update(cdev);
106104
mutex_unlock(&cdev->lock);
107105
}
106+
}
107+
108+
static void fair_share_manage(struct thermal_zone_device *tz)
109+
{
110+
int trip_level = get_trip_level(tz);
111+
const struct thermal_trip_desc *td;
112+
113+
lockdep_assert_held(&tz->lock);
114+
115+
for_each_trip_desc(tz, td) {
116+
const struct thermal_trip *trip = &td->trip;
108117

109-
return 0;
118+
if (trip->temperature == THERMAL_TEMP_INVALID ||
119+
trip->type == THERMAL_TRIP_CRITICAL ||
120+
trip->type == THERMAL_TRIP_HOT)
121+
continue;
122+
123+
fair_share_throttle(tz, trip, trip_level);
124+
}
110125
}
111126

112127
static struct thermal_governor thermal_gov_fair_share = {
113-
.name = "fair_share",
114-
.throttle = fair_share_throttle,
128+
.name = "fair_share",
129+
.manage = fair_share_manage,
115130
};
116131
THERMAL_GOVERNOR_DECLARE(thermal_gov_fair_share);

0 commit comments

Comments
 (0)