Skip to content

Commit db91651

Browse files
Javi MerinoEduardo Valentin
Javi Merino
authored and
Eduardo Valentin
committed
thermal: export weight to sysfs
It's useful to have access to the weights for the cooling devices for thermal zones and change them if needed. Export them to sysfs. Cc: Zhang Rui <[email protected]> Cc: Eduardo Valentin <[email protected]> Signed-off-by: Javi Merino <[email protected]> Signed-off-by: Eduardo Valentin <[email protected]>
1 parent 80b8917 commit db91651

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

Documentation/thermal/sysfs-api.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device.
194194
/sys/class/thermal/thermal_zone[0-*]:
195195
|---cdev[0-*]: [0-*]th cooling device in current thermal zone
196196
|---cdev[0-*]_trip_point: Trip point that cdev[0-*] is associated with
197+
|---cdev[0-*]_weight: Influence of the cooling device in
198+
this thermal zone
197199

198200
Besides the thermal zone device sysfs I/F and cooling device sysfs I/F,
199201
the generic thermal driver also creates a hwmon sysfs I/F for each _type_
@@ -267,6 +269,14 @@ cdev[0-*]_trip_point
267269
point.
268270
RO, Optional
269271

272+
cdev[0-*]_weight
273+
The influence of cdev[0-*] in this thermal zone. This value
274+
is relative to the rest of cooling devices in the thermal
275+
zone. For example, if a cooling device has a weight double
276+
than that of other, it's twice as effective in cooling the
277+
thermal zone.
278+
RW, Optional
279+
270280
passive
271281
Attribute is only present for zones in which the passive cooling
272282
policy is not supported by native thermal driver. Default is zero
@@ -320,7 +330,8 @@ passive, active. If an ACPI thermal zone supports critical, passive,
320330
active[0] and active[1] at the same time, it may register itself as a
321331
thermal_zone_device (thermal_zone1) with 4 trip points in all.
322332
It has one processor and one fan, which are both registered as
323-
thermal_cooling_device.
333+
thermal_cooling_device. Both are considered to have the same
334+
effectiveness in cooling the thermal zone.
324335

325336
If the processor is listed in _PSL method, and the fan is listed in _AL0
326337
method, the sys I/F structure will be built like this:
@@ -342,8 +353,10 @@ method, the sys I/F structure will be built like this:
342353
|---trip_point_3_type: active1
343354
|---cdev0: --->/sys/class/thermal/cooling_device0
344355
|---cdev0_trip_point: 1 /* cdev0 can be used for passive */
356+
|---cdev0_weight: 1024
345357
|---cdev1: --->/sys/class/thermal/cooling_device3
346358
|---cdev1_trip_point: 2 /* cdev1 can be used for active[0]*/
359+
|---cdev1_weight: 1024
347360

348361
|cooling_device0:
349362
|---type: Processor

drivers/thermal/thermal_core.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,34 @@ static const struct attribute_group *cooling_device_attr_groups[] = {
922922
NULL,
923923
};
924924

925+
static ssize_t
926+
thermal_cooling_device_weight_show(struct device *dev,
927+
struct device_attribute *attr, char *buf)
928+
{
929+
struct thermal_instance *instance;
930+
931+
instance = container_of(attr, struct thermal_instance, weight_attr);
932+
933+
return sprintf(buf, "%d\n", instance->weight);
934+
}
935+
936+
static ssize_t
937+
thermal_cooling_device_weight_store(struct device *dev,
938+
struct device_attribute *attr,
939+
const char *buf, size_t count)
940+
{
941+
struct thermal_instance *instance;
942+
int ret, weight;
943+
944+
ret = kstrtoint(buf, 0, &weight);
945+
if (ret)
946+
return ret;
947+
948+
instance = container_of(attr, struct thermal_instance, weight_attr);
949+
instance->weight = weight;
950+
951+
return count;
952+
}
925953
/* Device management */
926954

927955
/**
@@ -1016,6 +1044,16 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
10161044
if (result)
10171045
goto remove_symbol_link;
10181046

1047+
sprintf(dev->weight_attr_name, "cdev%d_weight", dev->id);
1048+
sysfs_attr_init(&dev->weight_attr.attr);
1049+
dev->weight_attr.attr.name = dev->weight_attr_name;
1050+
dev->weight_attr.attr.mode = S_IWUSR | S_IRUGO;
1051+
dev->weight_attr.show = thermal_cooling_device_weight_show;
1052+
dev->weight_attr.store = thermal_cooling_device_weight_store;
1053+
result = device_create_file(&tz->device, &dev->weight_attr);
1054+
if (result)
1055+
goto remove_trip_file;
1056+
10191057
mutex_lock(&tz->lock);
10201058
mutex_lock(&cdev->lock);
10211059
list_for_each_entry(pos, &tz->thermal_instances, tz_node)
@@ -1033,6 +1071,8 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
10331071
if (!result)
10341072
return 0;
10351073

1074+
device_remove_file(&tz->device, &dev->weight_attr);
1075+
remove_trip_file:
10361076
device_remove_file(&tz->device, &dev->attr);
10371077
remove_symbol_link:
10381078
sysfs_remove_link(&tz->device.kobj, dev->name);

drivers/thermal/thermal_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ struct thermal_instance {
4646
unsigned long target; /* expected cooling state */
4747
char attr_name[THERMAL_NAME_LENGTH];
4848
struct device_attribute attr;
49+
char weight_attr_name[THERMAL_NAME_LENGTH];
50+
struct device_attribute weight_attr;
4951
struct list_head tz_node; /* node in tz->thermal_instances */
5052
struct list_head cdev_node; /* node in cdev->thermal_instances */
5153
unsigned int weight; /* The weight of the cooling device */

0 commit comments

Comments
 (0)