Skip to content

Commit bcdcbbc

Browse files
Javi MerinoEduardo Valentin
authored andcommitted
thermal: fair_share: generalize the weight concept
The fair share governor has the concept of weights, which is the influence of each cooling device in a thermal zone. The current implementation forces the weights of all cooling devices in a thermal zone to add up to a 100. This complicates setups, as you need to know in advance how many cooling devices you are going to have. If you bind a new cooling device, you have to modify all the other cooling devices weights, which is error prone. Furthermore, you can't specify a "default" weight for platforms since that default value depends on the number of cooling devices in the platform. This patch generalizes the concept of weight by allowing any number to be a "weight". Weights are now relative to each other. Platforms that don't specify weights get the same default value for all their cooling devices, so all their cdevs are considered to be equally influential. It's important to note that previous users of the weights don't need to alter the code: percentages continue to work as they used to. This patch just removes the constraint of all the weights in a thermal zone having to add up to a 100. If they do, you get the same behavior as before. If they don't, fair share now works for that platform. Cc: Zhang Rui <rui.zhang@intel.com> Cc: Eduardo Valentin <edubezval@gmail.com> Cc: Durgadoss R <durgadoss.r@intel.com> Acked-by: Durgadoss R <durgadoss.r@intel.com> Signed-off-by: Javi Merino <javi.merino@arm.com> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
1 parent db91651 commit bcdcbbc

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

Documentation/thermal/sysfs-api.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,15 @@ temperature) and throttle appropriate devices.
129129
This structure defines the following parameters that are used to bind
130130
a zone with a cooling device for a particular trip point.
131131
.cdev: The cooling device pointer
132-
.weight: The 'influence' of a particular cooling device on this zone.
133-
This is on a percentage scale. The sum of all these weights
134-
(for a particular zone) cannot exceed 100.
132+
.weight: The 'influence' of a particular cooling device on this
133+
zone. This is relative to the rest of the cooling
134+
devices. For example, if all cooling devices have a
135+
weight of 1, then they all contribute the same. You can
136+
use percentages if you want, but it's not mandatory. A
137+
weight of 0 means that this cooling device doesn't
138+
contribute to the cooling of this zone unless all cooling
139+
devices have a weight of 0. If all weights are 0, then
140+
they all contribute the same.
135141
.trip_mask:This is a bit mask that gives the binding relation between
136142
this thermal zone and cdev, for a particular trip point.
137143
If nth bit is set, then the cdev and thermal zone are bound

drivers/thermal/fair_share.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ static int get_trip_level(struct thermal_zone_device *tz)
5959
}
6060

6161
static long get_target_state(struct thermal_zone_device *tz,
62-
struct thermal_cooling_device *cdev, int weight, int level)
62+
struct thermal_cooling_device *cdev, int percentage, int level)
6363
{
6464
unsigned long max_state;
6565

6666
cdev->ops->get_max_state(cdev, &max_state);
6767

68-
return (long)(weight * level * max_state) / (100 * tz->trips);
68+
return (long)(percentage * level * max_state) / (100 * tz->trips);
6969
}
7070

7171
/**
@@ -77,7 +77,7 @@ static long get_target_state(struct thermal_zone_device *tz,
7777
*
7878
* Parameters used for Throttling:
7979
* P1. max_state: Maximum throttle state exposed by the cooling device.
80-
* P2. weight[i]/100:
80+
* P2. percentage[i]/100:
8181
* How 'effective' the 'i'th device is, in cooling the given zone.
8282
* P3. cur_trip_level/max_no_of_trips:
8383
* This describes the extent to which the devices should be throttled.
@@ -89,16 +89,32 @@ static long get_target_state(struct thermal_zone_device *tz,
8989
static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
9090
{
9191
struct thermal_instance *instance;
92+
int total_weight = 0;
93+
int total_instance = 0;
9294
int cur_trip_level = get_trip_level(tz);
9395

9496
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
97+
if (instance->trip != trip)
98+
continue;
99+
100+
total_weight += instance->weight;
101+
total_instance++;
102+
}
103+
104+
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
105+
int percentage;
95106
struct thermal_cooling_device *cdev = instance->cdev;
96107

97108
if (instance->trip != trip)
98109
continue;
99110

100-
instance->target = get_target_state(tz, cdev,
101-
instance->weight, cur_trip_level);
111+
if (!total_weight)
112+
percentage = 100 / total_instance;
113+
else
114+
percentage = (instance->weight * 100) / total_weight;
115+
116+
instance->target = get_target_state(tz, cdev, percentage,
117+
cur_trip_level);
102118

103119
instance->cdev->updated = false;
104120
thermal_cdev_update(cdev);

include/linux/thermal.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,12 @@ struct thermal_bind_params {
217217

218218
/*
219219
* This is a measure of 'how effectively these devices can
220-
* cool 'this' thermal zone. The shall be determined by platform
221-
* characterization. This is on a 'percentage' scale.
222-
* See Documentation/thermal/sysfs-api.txt for more information.
220+
* cool 'this' thermal zone. It shall be determined by
221+
* platform characterization. This value is relative to the
222+
* rest of the weights so a cooling device whose weight is
223+
* double that of another cooling device is twice as
224+
* effective. See Documentation/thermal/sysfs-api.txt for more
225+
* information.
223226
*/
224227
int weight;
225228

0 commit comments

Comments
 (0)