Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ni Wade and committed by
Zhang Rui
25a0a5ce 74d33293

+34
+6
Documentation/thermal/sysfs-api.txt
··· 180 180 |---temp: Current temperature 181 181 |---mode: Working mode of the thermal zone 182 182 |---policy: Thermal governor used for this zone 183 + |---available_policies: Available thermal governors for this zone 183 184 |---trip_point_[0-*]_temp: Trip point temperature 184 185 |---trip_point_[0-*]_type: Trip point type 185 186 |---trip_point_[0-*]_hyst: Hysteresis value for this trip point ··· 256 255 policy 257 256 One of the various thermal governors used for a particular zone. 258 257 RW, Required 258 + 259 + available_policies 260 + Available thermal governors which can be used for a particular zone. 261 + RO, Required 259 262 260 263 trip_point_[0-*]_temp 261 264 The temperature above which trip point will be fired. ··· 422 417 |---temp: 37000 423 418 |---mode: enabled 424 419 |---policy: step_wise 420 + |---available_policies: step_wise fair_share 425 421 |---trip_point_0_temp: 100000 426 422 |---trip_point_0_type: critical 427 423 |---trip_point_1_temp: 80000
+28
drivers/thermal/thermal_core.c
··· 847 847 return sprintf(buf, "%s\n", tz->governor->name); 848 848 } 849 849 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 + 850 871 #ifdef CONFIG_THERMAL_EMULATION 851 872 static ssize_t 852 873 emul_temp_store(struct device *dev, struct device_attribute *attr, ··· 1053 1032 static DEVICE_ATTR(mode, 0644, mode_show, mode_store); 1054 1033 static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store); 1055 1034 static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show, policy_store); 1035 + static DEVICE_ATTR(available_policies, S_IRUGO, available_policies_show, NULL); 1056 1036 1057 1037 /* sys I/F for cooling device */ 1058 1038 #define to_cooling_device(_dev) \ ··· 1839 1817 if (result) 1840 1818 goto unregister; 1841 1819 1820 + /* Create available_policies attribute */ 1821 + result = device_create_file(&tz->device, &dev_attr_available_policies); 1822 + if (result) 1823 + goto unregister; 1824 + 1842 1825 /* Update 'this' zone's governor information */ 1843 1826 mutex_lock(&thermal_governor_lock); 1844 1827 ··· 1944 1917 if (tz->ops->get_mode) 1945 1918 device_remove_file(&tz->device, &dev_attr_mode); 1946 1919 device_remove_file(&tz->device, &dev_attr_policy); 1920 + device_remove_file(&tz->device, &dev_attr_available_policies); 1947 1921 remove_trip_attrs(tz); 1948 1922 thermal_set_governor(tz, NULL); 1949 1923