Skip to content

Commit 25a0a5c

Browse files
wni-WeiNizhang-rui
authored andcommitted
thermal: add available policies sysfs attribute
The Linux thermal framework support to change thermal governor policy in userspace, but it can't show what available policies supported. This patch adds available_policies attribute to the thermal framework, it can list the thermal governors which can be used for a particular zone. This attribute is read only. Signed-off-by: Wei Ni <wni@nvidia.com> Reviewed-by: Javi Merino <javi.merino@arm.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
1 parent 74d3329 commit 25a0a5c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Documentation/thermal/sysfs-api.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ Thermal zone device sys I/F, created once it's registered:
180180
|---temp: Current temperature
181181
|---mode: Working mode of the thermal zone
182182
|---policy: Thermal governor used for this zone
183+
|---available_policies: Available thermal governors for this zone
183184
|---trip_point_[0-*]_temp: Trip point temperature
184185
|---trip_point_[0-*]_type: Trip point type
185186
|---trip_point_[0-*]_hyst: Hysteresis value for this trip point
@@ -256,6 +257,10 @@ policy
256257
One of the various thermal governors used for a particular zone.
257258
RW, Required
258259

260+
available_policies
261+
Available thermal governors which can be used for a particular zone.
262+
RO, Required
263+
259264
trip_point_[0-*]_temp
260265
The temperature above which trip point will be fired.
261266
Unit: millidegree Celsius
@@ -417,6 +422,7 @@ method, the sys I/F structure will be built like this:
417422
|---temp: 37000
418423
|---mode: enabled
419424
|---policy: step_wise
425+
|---available_policies: step_wise fair_share
420426
|---trip_point_0_temp: 100000
421427
|---trip_point_0_type: critical
422428
|---trip_point_1_temp: 80000

drivers/thermal/thermal_core.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,27 @@ policy_show(struct device *dev, struct device_attribute *devattr, char *buf)
847847
return sprintf(buf, "%s\n", tz->governor->name);
848848
}
849849

850+
static ssize_t
851+
available_policies_show(struct device *dev, struct device_attribute *devattr,
852+
char *buf)
853+
{
854+
struct thermal_governor *pos;
855+
ssize_t count = 0;
856+
ssize_t size = PAGE_SIZE;
857+
858+
mutex_lock(&thermal_governor_lock);
859+
860+
list_for_each_entry(pos, &thermal_governor_list, governor_list) {
861+
size = PAGE_SIZE - count;
862+
count += scnprintf(buf + count, size, "%s ", pos->name);
863+
}
864+
count += scnprintf(buf + count, size, "\n");
865+
866+
mutex_unlock(&thermal_governor_lock);
867+
868+
return count;
869+
}
870+
850871
#ifdef CONFIG_THERMAL_EMULATION
851872
static ssize_t
852873
emul_temp_store(struct device *dev, struct device_attribute *attr,
@@ -1032,6 +1053,7 @@ static DEVICE_ATTR(temp, 0444, temp_show, NULL);
10321053
static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
10331054
static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store);
10341055
static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show, policy_store);
1056+
static DEVICE_ATTR(available_policies, S_IRUGO, available_policies_show, NULL);
10351057

10361058
/* sys I/F for cooling device */
10371059
#define to_cooling_device(_dev) \
@@ -1817,6 +1839,11 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
18171839
if (result)
18181840
goto unregister;
18191841

1842+
/* Create available_policies attribute */
1843+
result = device_create_file(&tz->device, &dev_attr_available_policies);
1844+
if (result)
1845+
goto unregister;
1846+
18201847
/* Update 'this' zone's governor information */
18211848
mutex_lock(&thermal_governor_lock);
18221849

@@ -1917,6 +1944,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
19171944
if (tz->ops->get_mode)
19181945
device_remove_file(&tz->device, &dev_attr_mode);
19191946
device_remove_file(&tz->device, &dev_attr_policy);
1947+
device_remove_file(&tz->device, &dev_attr_available_policies);
19201948
remove_trip_attrs(tz);
19211949
thermal_set_governor(tz, NULL);
19221950

0 commit comments

Comments
 (0)