thermal: Add new mechanism to get thermal notification
cover thermal: Add new mechanism to get thermal notification
I presented this idea during LPC 2018.
Refer to the following link:
https://linuxplumbersconf.org/event/2/contributions/182/attachments/38/45/LPC_2018_Thermal-Srinivas-Rui.pdf
There was broad agreement about this.
At that time, there was no use case for non x86 systems. But now there is interest from Linaro community. But this doesn't meet all the requirement for Linaro use cases. So I think, Daniel Lezcano <[email protected]> is working on a follow up series.
Thermal actions can be categorized in three types:
1. Urgent actions in micro to less than milli second range
2. Actions at milli seconds scale
3. Non urgent actions but improves thermal management, which improves long term reliability of the system and also allow to meet safety standards
The first category of actions usually handled by the hardware and firmware to meet the time scale. Some examples are sudden spike of CPU temperature which needs immediate action.
Second category of actions are done at OS kernel level. Like graceful shutdown of a system, when a critical temperature is reached. Also a good place to take takes actions where there is a direct correlation from a thermal source to a cooling action (one to one relationship). The Linux thermal subsystem has in built governors to bind thermal zones to cooling devices.
The third category acts at a scale of several seconds. This types of actions primarily focused for non CPU components, which takes time to heat up but once hot will take long time to cool. Like skin temperature or board temperature. Also there is no one to one relationship. For example skin can be hot, not only by CPU processing, but GPU, displays, networking, charger and ambient temperature etc. There are some thermally constraint laptops with 15+ sensors and complex thermal relationship tables tying thermal hotspots to groups of devices. Also these relationships and threshold changes are context aware. This is done primary from user space thermal management programs. These programs primarily relies on the thermal sysfs for getting temperature samples and to get other notifications of change.
There are several limitations of the thermal subsystem, which makes the user space management inefficient and complex.
- Temperature needs to be polled from sysfs
There is no way to set thermal thresholds and get notifications. We are getting around by using the passive trips as threshold and using user space governor to send uevents. The uevent is used for other non thermal events also. We have special strings to notify temperature samples.
- We have platforms with 15+ zones, where we need to traverse each directory read "temp" string and convert to integer to process every second in some cases
- For hotpluggable devices the zones can appear and disappear on fly. We have to again listen to uevents to find out that.
- Based on the context, firmware updates temperature trips, again combination of user space governor and uevents are used as workaround.
To be more flexible here /dev/thermal_notify device is created, where user space can wait for notifications and read events and data. A standard structure for notifications is defined. Based on the zone, additional thermal sysfs attributes are added to specify thresholds. More events and attributes can be added in future based on need. If the kernel config is not defined, there are are no additional thermal sysfs attributes.
This patchset contains
- A new config for creation of the /dev interface
- Use of the new interface in the core for zone creation, deletion and temperature samples
- Use of the framework in int340x drivers. More will be added in the next series
This series is based on 4.7-rc1
Srinivas Pandruvada (5):
thermal: Add support for /dev/thermal_notify
thermal: Add notification for zone creation and deletion
thermal: Add support for setting notification thresholds
thermal: Add support for setting polling interval
thermal: int340x: Use new device interface
drivers/thermal/Kconfig | 9 + drivers/thermal/Makefile | 3 + .../intel/int340x_thermal/int3403_thermal.c | 3 + .../int340x_thermal/int340x_thermal_zone.c | 29 +++ .../int340x_thermal/int340x_thermal_zone.h | 7 + .../processor_thermal_device.c | 1 + drivers/thermal/thermal_core.c | 11 + drivers/thermal/thermal_dev_if.c | 195 ++++++++++++++++++ drivers/thermal/thermal_sysfs.c | 168 ++++++++++++++- include/linux/thermal.h | 33 +++ 10 files changed, 457 insertions(+), 2 deletions(-) create mode 100644 drivers/thermal/thermal_dev_if.c
Signature · 1 line
2.25.4
RFC PATCH 1/5 thermal: Add support for /dev/thermal_notify
This change adds an optional feature to add a new device entry /dev/thermal_notify.
When config CONFIG_THERMAL_USER_EVENT_INTERFACE is selected, this new device entry is created.
Thermal core or any thermal driver can use thermal_dev_send_event() interface to send events. Each user events follows a standard format:
- zone_id
- event_id
- event_data
- reserved for future, currently 0s
User space can basically:
fd = open ("/dev/thermal_notify")
In a loop
read (fd)
read and process event
or
fd = open ("/dev/thermal_notify")
Set the fs as non blocking
In a loop
Use poll() and wait
read and process event
There are predefined events added to thermal.h. Based on need they can be extended.
--- drivers/thermal/Kconfig | 9 ++ drivers/thermal/Makefile | 3 + drivers/thermal/thermal_dev_if.c | 195 +++++++++++++++++++++++++++++++ include/linux/thermal.h | 24 ++++ 4 files changed, 231 insertions(+) create mode 100644 drivers/thermal/thermal_dev_if.c
drivers/thermal/Kconfig +9 -0
@@ -78,6 +78,15 @@ config THERMAL_WRITABLE_TRIPS Say 'Y' here if you would like to allow userspace tools to change trip temperatures. +config THERMAL_USER_EVENT_INTERFACE + bool "Allow user space to read thermal events from a dev file" + help + This option allows a user space program to read thermal events + via /dev/thermal_notify file. + + Say 'Y' here if you would like to allow userspace programs to + read thermal events. + choice prompt "Default Thermal governor" default THERMAL_DEFAULT_GOV_STEP_WISE
drivers/thermal/Makefile +3 -0
@@ -11,6 +11,9 @@ thermal_sys-y += thermal_core.o thermal_sysfs.o \ thermal_sys-$(CONFIG_THERMAL_HWMON) += thermal_hwmon.o thermal_sys-$(CONFIG_THERMAL_OF) += of-thermal.o +# Thermal user space events +obj-$(CONFIG_THERMAL_USER_EVENT_INTERFACE) += thermal_dev_if.o + # governors thermal_sys-$(CONFIG_THERMAL_GOV_FAIR_SHARE) += fair_share.o thermal_sys-$(CONFIG_THERMAL_GOV_BANG_BANG) += gov_bang_bang.o
drivers/thermal/thermal_dev_if.c new file +195 -0
195 lines not on this page · raw message
include/linux/thermal.h +24 -0
@@ -543,4 +543,28 @@ static inline void thermal_notify_framework(struct thermal_zone_device *tz, { }#endif /* CONFIG_THERMAL */ +enum thermal_device_events { +THERMAL_TEMP_SAMPLE =0 , +THERMAL_ZONE_CREATE , +THERMAL_ZONE_DELETE , +THERMAL_ZONE_DISABLED , +THERMAL_ZONE_ENABLED , +THERMAL_TEMP_LOW_THRES , +THERMAL_TEMP_HIGH_THRES , +THERMAL_TRIP_ADD , +THERMAL_TRIP_DELETE , +THERMAL_TRIP_UPDATE , +THERMAL_TRIP_REACHED , +THERMAL_PERF_CHANGED , +}; + +#ifdef CONFIG_THERMAL_USER_EVENT_INTERFACE +int thermal_dev_send_event (int zone_id,enum thermal_device_events event,u64 event_data); +#else +int thermal_dev_send_event (int zone_id,enum thermal_device_events event,u64 event_data) +{ +return 0 ; +} +#endif +#endif /* __THERMAL_H__ */
Signature · 1 line
2.25.4
kbuild test robot
build botRe: [RFC][PATCH 1/5] thermal: Add support for /dev/thermal_notify
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…
Hi Srinivas,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linus/master]
[also build test ERROR on v5.7-rc4 next-20200505]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Srinivas-Pandruvada/thermal-Add-new-mechanism-to-get-thermal-notification/20200505-135412 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 47cf1b422e6093aee2a3e55d5e162112a2c69870 config: ia64-allnoconfig (attached as .config) compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=ia64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
ia64-linux-ld: drivers/acpi/acpi_processor.o: in function `thermal_dev_send_event':
>> acpi_processor.c:(.text+0xda0): multiple definition of `thermal_dev_send_event'; arch/ia64/kernel/acpi.o:acpi.c:(.text+0x2e0): first defined here
ia64-linux-ld: drivers/acpi/processor_core.o: in function `thermal_dev_send_event':
processor_core.c:(.text+0x5a0): multiple definition of `thermal_dev_send_event'; arch/ia64/kernel/acpi.o:acpi.c:(.text+0x2e0): first defined here
ia64-linux-ld: drivers/acpi/processor_pdc.o: in function `thermal_dev_send_event':
processor_pdc.c:(.text+0x0): multiple definition of `thermal_dev_send_event'; arch/ia64/kernel/acpi.o:acpi.c:(.text+0x2e0): first defined here
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kbuild test robot
build botRe: [RFC][PATCH 1/5] thermal: Add support for /dev/thermal_notify
In reply to Srinivas Pandruvada[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…
Hi Srinivas,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on linus/master]
[also build test ERROR on v5.7-rc4 next-20200505]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Srinivas-Pandruvada/thermal-Add-new-mechanism-to-get-thermal-notification/20200505-135412 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 47cf1b422e6093aee2a3e55d5e162112a2c69870 config: powerpc-adder875_defconfig (attached as .config) compiler: powerpc-linux-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=powerpc
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
powerpc-linux-ld: drivers/thermal/thermal_sysfs.o: in function `thermal_dev_send_event':
>> thermal_sysfs.c:(.text+0x1424): multiple definition of `thermal_dev_send_event'; drivers/thermal/thermal_core.o:thermal_core.c:(.text+0x7f8): first defined here
powerpc-linux-ld: drivers/thermal/thermal_helpers.o: in function `thermal_dev_send_event':
thermal_helpers.c:(.text+0x0): multiple definition of `thermal_dev_send_event'; drivers/thermal/thermal_core.o:thermal_core.c:(.text+0x7f8): first defined here
powerpc-linux-ld: drivers/thermal/of-thermal.o: in function `thermal_dev_send_event':
of-thermal.c:(.text+0x71c): multiple definition of `thermal_dev_send_event'; drivers/thermal/thermal_core.o:thermal_core.c:(.text+0x7f8): first defined here
powerpc-linux-ld: drivers/thermal/step_wise.o: in function `thermal_dev_send_event':
step_wise.c:(.text+0x430): multiple definition of `thermal_dev_send_event'; drivers/thermal/thermal_core.o:thermal_core.c:(.text+0x7f8): first defined here
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [RFC][PATCH 1/5] thermal: Add support for /dev/thermal_notify
In reply to Srinivas PandruvadaQuoted 8 lines · Srinivas Pandruvada
This change adds an optional feature to add a new device entry
/dev/thermal_notify.When config
CONFIG_THERMAL_USER_EVENT_INTERFACEis selected, this new device entry is created.Thermal core or any thermal driver can use
thermal_dev_send_event()interface
Do you have any particular use case in mind where a platform driver will use this interface to send platform-specific events?
IMO, we should probably try to keep this restricted to messages from thermal core if we are to have any hope of having a standard library in userspace capable of parsing these thermal events.
Quoted 302 lines
to send events. Each user events follows a standard format:
-zone_id
-event_id
-event_data
- reserved for future, currently 0sUser space can basically:
fd = open ("/dev/thermal_notify")
In a loop
read (fd)
read and process eventor
fd = open ("/dev/thermal_notify")
Set the fs as non blocking
In a loop
Usepoll()and wait
read and process eventThere are predefined events added to
thermal.h. Based on need they can be extended.Signed-off-by Srinivas Pandruvada <[email protected]>--- drivers/thermal/Kconfig | 9 ++ drivers/thermal/Makefile | 3 + drivers/thermal/thermal_dev_if.c | 195 +++++++++++++++++++++++++++++++ include/linux/thermal.h | 24 ++++ 4 files changed, 231 insertions(+) create mode 100644 drivers/thermal/thermal_dev_if.cdrivers/thermal/Kconfig +9
-0@@ -78,6 +78,15 @@ config THERMAL_WRITABLE_TRIPS Say 'Y' here if you would like to allow userspace tools to change trip temperatures. +config THERMAL_USER_EVENT_INTERFACE + bool "Allow user space to read thermal events from a dev file" + help + This option allows a user space program to read thermal events + via /dev/thermal_notify file. + + Say 'Y' here if you would like to allow userspace programs to + read thermal events. + choice prompt "Default Thermal governor" default THERMAL_DEFAULT_GOV_STEP_WISEdrivers/thermal/Makefile +3
-0@@ -11,6 +11,9 @@ thermal_sys-y += thermal_core.o thermal_sysfs.o \ thermal_sys-$(CONFIG_THERMAL_HWMON) += thermal_hwmon.o thermal_sys-$(CONFIG_THERMAL_OF) += of-thermal.o +# Thermal user space events +obj-$(CONFIG_THERMAL_USER_EVENT_INTERFACE) += thermal_dev_if.o + # governors thermal_sys-$(CONFIG_THERMAL_GOV_FAIR_SHARE) += fair_share.o thermal_sys-$(CONFIG_THERMAL_GOV_BANG_BANG) += gov_bang_bang.odrivers/thermal/thermal_dev_if.c new file +195
-0@@ -0,0 +1,195 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Thermal device file interface +* Copyright (c) 2020, Intel Corporation. +* All rights reserved. +* +* Author: Srinivas Pandruvada <[email protected]> +*/ + +#include <linux/init.h> +#include <linux/kfifo.h> +#include <linux/miscdevice.h> +#include <linux/poll.h> +#include <linux/slab.h> +#include <linux/thermal.h> +#include <linux/wait.h> + +#define THERMAL_DEV_FIFO_SIZE 1024 + +struct thermal_chdev_sample { +int zone_id; +int event; +u64 event_data; +u64 reserved; +}; + +struct thermal_chdev { +struct miscdevice therm_dev; +struct kfifo data_fifo; +unsigned long misc_opened; +wait_queue_head_t wait; +}; + +static DEFINE_MUTEX (thermal_chdev_mutex); +static struct thermal_chdev *thermal_chdev; + +static int thermal_chdev_open (struct inode *inode,struct file *file) +{ +struct thermal_chdev *chdev; + + chdev = container_of(file->private_data, struct thermal_chdev, therm_dev); + +/* We essentially have single reader and writer */ +if (test_and_set_bit (0 , &chdev->misc_opened)) +return -EBUSY ; + +return stream_open (inode, file); +} + +static int thermal_chdev_release (struct inode *inode,struct file *file) +{ +struct thermal_chdev *chdev; + + chdev = container_of(file->private_data, struct thermal_chdev, therm_dev); + +clear_bit (0 , &chdev->misc_opened); + +return 0 ; +} + +static __poll_t thermal_chdev_poll (struct file *file,struct poll_table_struct *wait) +{ +struct thermal_chdev *chdev; +__poll_t mask =0 ; + + chdev = container_of(file->private_data, struct thermal_chdev, therm_dev); + +poll_wait (file, &chdev->wait, wait); + +if (!kfifo_is_empty (&chdev->data_fifo)) + mask =EPOLLIN |EPOLLRDNORM ; + +return mask; +} + +static ssize_t thermal_chdev_read (struct file *file,char __user *buf,size_t count,loff_t *f_ps) +{ +struct thermal_chdev *chdev; +unsigned int copied; +int ret; + + chdev = container_of(file->private_data, struct thermal_chdev, therm_dev); + +if (count <sizeof (struct thermal_chdev_sample )) +return -EINVAL ; + +do { +if (kfifo_is_empty (&chdev->data_fifo)) { +if (file->f_flags &O_NONBLOCK ) +return -EAGAIN ; + + ret =wait_event_interruptible (chdev->wait, !kfifo_is_empty (&chdev->data_fifo)); +if (ret) +return ret; + } + ret =kfifo_to_user (&chdev->data_fifo, buf, count, &copied); +if (ret) +return ret; + + }while (copied ==0 ); + +return copied; +} + +static int thermal_chdev_capture_sample (struct thermal_chdev *chdev,struct thermal_chdev_sample *sample) +{ +int ret =0 ; + +if (!test_bit (0 , &chdev->misc_opened)) +return 0 ; + +mutex_lock (&thermal_chdev_mutex); +if (kfifo_avail (&chdev->data_fifo) >=sizeof (*sample)) { +kfifo_in (&chdev->data_fifo, (unsigned char *)sample,sizeof (*sample)); +wake_up (&chdev->wait); + }else { + ret = -ENOMEM ; + } +mutex_unlock (&thermal_chdev_mutex); + +return ret; +} + +static const struct file_operations thermal_chdev_fops = { + .open = thermal_chdev_open, + .read = thermal_chdev_read, + .release = thermal_chdev_release, + .poll = thermal_chdev_poll, + .llseek = noop_llseek, +}; + +static int thermal_dev_if_add (void ) +{ +int ret; + +if (thermal_chdev) +return 0 ; + + thermal_chdev =kzalloc (sizeof (*thermal_chdev),GFP_KERNEL ); +if (!thermal_chdev) +return -ENOMEM ; + + ret =kfifo_alloc (&thermal_chdev->data_fifo,THERMAL_DEV_FIFO_SIZE ,GFP_KERNEL ); +if (ret) + goto free_mem; + +init_waitqueue_head (&thermal_chdev->wait); + + thermal_chdev->therm_dev.minor =MISC_DYNAMIC_MINOR ; + thermal_chdev->therm_dev.name ="thermal_notify" ; + thermal_chdev->therm_dev.fops = &thermal_chdev_fops; + ret =misc_register (&thermal_chdev->therm_dev); +if (ret) { +kfifo_free (&thermal_chdev->data_fifo); + goto free_mem; + } + +return 0 ; + +free_mem: +kfree (thermal_chdev); + thermal_chdev =NULL ; +return ret; +} + +/** +* thermal_dev_send_event() - Send thermal event to user space +* @zone_id: Zone id of the caller +* @event: A predefined thermal event +* @event_data: Event specific data +* +* An interface to send event to user space with an optional associated +* data. +* +* Return: 0 on success, other values on error. +*/ +int thermal_dev_send_event (int zone_id,enum thermal_device_events event,u64 event_data) +{ +struct thermal_chdev_sample sample; + +if (!thermal_chdev) { +int ret; + + ret =thermal_dev_if_add (); +if (ret) +return ret; + } + + sample.zone_id = zone_id; + sample.event = event; + sample.event_data = event_data; + sample.reserved =0 ; +return thermal_chdev_capture_sample (thermal_chdev, &sample); +} +EXPORT_SYMBOL_GPL (thermal_dev_send_event);include/linux/thermal.h +24
-1@@ -543,4 +543,28 @@ static inline void thermal_notify_framework(struct thermal_zone_device *tz, { }#endif /* CONFIG_THERMAL */ +enum thermal_device_events { +THERMAL_TEMP_SAMPLE =0 , +THERMAL_ZONE_CREATE , +THERMAL_ZONE_DELETE , +THERMAL_ZONE_DISABLED , +THERMAL_ZONE_ENABLED , +THERMAL_TEMP_LOW_THRES , +THERMAL_TEMP_HIGH_THRES , +THERMAL_TRIP_ADD , +THERMAL_TRIP_DELETE , +THERMAL_TRIP_UPDATE , +THERMAL_TRIP_REACHED , +THERMAL_PERF_CHANGED , +}; + +#ifdef CONFIG_THERMAL_USER_EVENT_INTERFACE +int thermal_dev_send_event (int zone_id,enum thermal_device_events event,u64 event_data); +#else +int thermal_dev_send_event (int zone_id,enum thermal_device_events event,u64 event_data) +{ +return 0 ; +} +#endif +#endif /* __THERMAL_H__ */ --2.25.4
RFC PATCH 2/5 thermal: Add notification for zone creation and deletion
In reply to Srinivas PandruvadaWhenever thermal_zone_device_register() is called and zone is created successfully, send a notification "THERMAL_ZONE_CREATE". Similarly send "THERMAL_ZONE_DELETE" when thermal_zone_device_unregister is called.
--- drivers/thermal/thermal_core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/thermal/thermal_core.c +4 -0
@@ -1350,6 +1350,8 @@ thermal_zone_device_register(const char *type, int trips, int mask,if (atomic_cmpxchg (&tz->need_update,1 ,0 ))thermal_zone_device_update (tz,THERMAL_EVENT_UNSPECIFIED ); +thermal_dev_send_event (tz->id,THERMAL_ZONE_CREATE ,0 ); +return tz; unregister:
@@ -1379,6 +1381,8 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)if (!tz)return ; +thermal_dev_send_event (tz->id,THERMAL_ZONE_DELETE ,0 ); + tzp = tz->tzp;mutex_lock (&thermal_list_lock);
Signature · 1 line
2.25.4
RFC PATCH 3/5 thermal: Add support for setting notification thresholds
In reply to Srinivas PandruvadaAdd new attributes in thermal syfs when a thermal drivers provides callbacks for them and CONFIG_THERMAL_USER_EVENT_INTERFACE is defined.
These attribute allow user space to stop polling for temperature.
These attributes are:
- temp_thres_low: Specify a notification temperature for a low temperature threshold event.temp_thres_high: Specify a notification temperature for a high temperature threshold event.temp_thres_hyst: Specify a change in temperature to send notification again.
This is implemented by adding additional sysfs attribute group. The changes in this patch are trivial to add new attributes in thermal sysfs as done for other attributes.
--- drivers/thermal/thermal_sysfs.c | 136 +++++++++++++++++++++++++++++++- include/linux/thermal.h | 10 ++- 2 files changed, 143 insertions(+), 3 deletions(-)
drivers/thermal/thermal_sysfs.c +134 -2
@@ -215,6 +215,125 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,return ret ? ret :sprintf (buf,"%d\n" , temperature); } +#if IS_ENABLED (CONFIG_THERMAL_USER_EVENT_INTERFACE ) + +#define create_thres_attr (name) \ + static ssize_t \ + name##_show(struct device *dev, struct device_attribute *devattr, \ + char *buf) \ + { \ + struct thermal_zone_device *tz = to_thermal_zone(dev); \ + int temperature, ret; \ + \ + ret = tz->ops->get_##name(tz, &temperature); \ + \ + return ret ? ret : sprintf(buf, "%d\n", temperature); \ + } \ + \ + static ssize_t \ + name##_store(struct device *dev, struct device_attribute *devattr, \ + const char *buf, size_t count) \ + { \ + struct thermal_zone_device *tz = to_thermal_zone(dev); \ + int temperature, ret; \ + \ + if (kstrtoint(buf, 10, &temperature)) \ + return -EINVAL; \ + \ + ret = tz->ops->set_##name(tz, temperature); \ + return ret ? ret : count; \ + } + +create_thres_attr (temp_thres_low); +create_thres_attr (temp_thres_high); +create_thres_attr (temp_thres_hyst); + +static int create_user_events_attrs (struct thermal_zone_device *tz) +{ +struct attribute **attrs; +int index =0 ; + +if (tz->ops->get_temp_thres_low) + ++index; +if (tz->ops->get_temp_thres_high) + ++index; +if (tz->ops->get_temp_thres_high) + ++index; + +/* One additional space for NULL */ + attrs =kcalloc (index +1 ,sizeof (*attrs),GFP_KERNEL ); +if (!attrs) +return -ENOMEM ; + + tz->threshold_attrs =kcalloc (index,sizeof (*tz->threshold_attrs),GFP_KERNEL ); +if (!tz->threshold_attrs) { +kfree (attrs); +return -ENOMEM ; + } + + index =0 ; + +if (tz->ops->get_temp_thres_low) { +snprintf (tz->threshold_attrs[index].name,THERMAL_NAME_LENGTH , +"temp_thres_low" ); + +sysfs_attr_init (&tz->threshold_attrs[index].attr.attr); + tz->threshold_attrs[index].attr.attr.name = + tz->threshold_attrs[index].name; + tz->threshold_attrs[index].attr.attr.mode =S_IWUSR |S_IRUGO ; + tz->threshold_attrs[index].attr.show = temp_thres_low_show; + tz->threshold_attrs[index].attr.store = temp_thres_low_store; + attrs[index] = &tz->threshold_attrs[index].attr.attr; + ++index; + } +if (tz->ops->get_temp_thres_high) { +snprintf (tz->threshold_attrs[index].name,THERMAL_NAME_LENGTH , +"temp_thres_high" ); + +sysfs_attr_init (&tz->threshold_attrs[index].attr.attr); + tz->threshold_attrs[index].attr.attr.name = + tz->threshold_attrs[index].name; + tz->threshold_attrs[index].attr.attr.mode =S_IWUSR |S_IRUGO ; + tz->threshold_attrs[index].attr.show = temp_thres_high_show; + tz->threshold_attrs[index].attr.store = temp_thres_high_store; + attrs[index] = &tz->threshold_attrs[index].attr.attr; + ++index; + } +if (tz->ops->get_temp_thres_hyst) { +snprintf (tz->threshold_attrs[index].name,THERMAL_NAME_LENGTH , +"temp_thres_hyst" ); + +sysfs_attr_init (&tz->threshold_attrs[index].attr.attr); + tz->threshold_attrs[index].attr.attr.name = + tz->threshold_attrs[index].name; + tz->threshold_attrs[index].attr.attr.mode =S_IWUSR |S_IRUGO ; + tz->threshold_attrs[index].attr.show = temp_thres_hyst_show; + tz->threshold_attrs[index].attr.store = temp_thres_hyst_store; + attrs[index] = &tz->threshold_attrs[index].attr.attr; + ++index; + } + attrs[index] =NULL ; + tz->threshold_attribute_group.attrs = attrs; + +return 0 ; +} + +static void delete_user_events_attrs (struct thermal_zone_device *tz) +{ +kfree (tz->threshold_attrs); +kfree (tz->threshold_attribute_group.attrs); +} +#else +static int create_user_events_attrs (struct thermal_zone_device *tz) +{ +return -EINVAL ; +} + +static void delete_user_events_attrs (struct thermal_zone_device *tz) +{ +} +#endif +static ssize_t passive_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count)
@@ -625,16 +744,27 @@ int thermal_zone_create_device_groups(struct thermal_zone_device *tz, {const struct attribute_group **groups;int i, size, result; +int start =0 ;/* we need one extra for trips and the NULL to terminate the array */ size =ARRAY_SIZE (thermal_zone_attribute_groups) +2 ; + + result =create_user_events_attrs (tz); +if (!result) { + ++size; + ++start; + } +/* This also takes care of API requirement to be NULL terminated */ groups =kcalloc (size,sizeof (*groups),GFP_KERNEL );if (!groups)return -ENOMEM ; -for (i =0 ; i < size -2 ; i++) - groups[i] = thermal_zone_attribute_groups[i]; +if (start) + groups[0 ] = &tz->threshold_attribute_group; + +for (i =0 ; i < size -2 - start; i++) + groups[i + start] = thermal_zone_attribute_groups[i];if (tz->trips) { result =create_trip_attrs (tz, mask);
@@ -660,6 +790,8 @@ void thermal_zone_destroy_device_groups(struct thermal_zone_device *tz)if (tz->trips)destroy_trip_attrs (tz); +delete_user_events_attrs (tz); +kfree (tz->device.groups); }
include/linux/thermal.h +9 -1
@@ -102,6 +102,12 @@ struct thermal_zone_device_ops { enum thermal_trend *);int (*notify) (struct thermal_zone_device *,int ,enum thermal_trip_type ); +int (*set_temp_thres_low)(struct thermal_zone_device *,int ); +int (*set_temp_thres_high)(struct thermal_zone_device *,int ); +int (*set_temp_thres_hyst)(struct thermal_zone_device *,int ); +int (*get_temp_thres_low)(struct thermal_zone_device *,int *); +int (*get_temp_thres_high)(struct thermal_zone_device *,int *); +int (*get_temp_thres_hyst)(struct thermal_zone_device *,int *); };struct thermal_cooling_device_ops {
@@ -208,6 +214,8 @@ struct thermal_zone_device {struct list_head node;struct delayed_work poll_queue;enum thermal_notify_event notify_event; +struct attribute_group threshold_attribute_group; +struct thermal_attr *threshold_attrs; };/**
@@ -558,7 +566,7 @@ enum thermal_device_events { THERMAL_PERF_CHANGED, }; -#ifdef CONFIG_THERMAL_USER_EVENT_INTERFACE +#if IS_ENABLED (CONFIG_THERMAL_USER_EVENT_INTERFACE )int thermal_dev_send_event (int zone_id,enum thermal_device_events event,u64 event_data);#else int thermal_dev_send_event (int zone_id,enum thermal_device_events event,u64 event_data)
Signature · 1 line
2.25.4
Re: [RFC][PATCH 3/5] thermal: Add support for setting notification thresholds
Quoted 13 lines · Srinivas Pandruvada
Add new attributes in thermal syfs when a thermal drivers provides callbacks for them and
CONFIG_THERMAL_USER_EVENT_INTERFACEis defined.These attribute allow user space to stop polling for temperature.
These attributes are:
-temp_thres_low: Specify a notification temperature for a low temperature threshold event.temp_thres_high: Specify a notification temperature for a high temperature threshold event.temp_thres_hyst: Specify a change in temperature to send notification again.
Quoted 3 lines
This is implemented by adding additional sysfs attribute group. The changes in this patch are trivial to add new attributes in thermal sysfs as done for other attributes.
Isn't it duplicate with the trip point?
Quoted 211 lines
Signed-off-by Srinivas Pandruvada <[email protected]>--- drivers/thermal/thermal_sysfs.c | 136 +++++++++++++++++++++++++++++++- include/linux/thermal.h | 10 ++- 2 files changed, 143 insertions(+), 3 deletions(-)drivers/thermal/thermal_sysfs.c +134
-2@@ -215,6 +215,125 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,return ret ? ret :sprintf (buf,"%d\n" , temperature); } +#if IS_ENABLED (CONFIG_THERMAL_USER_EVENT_INTERFACE ) + +#define create_thres_attr (name) \ + static ssize_t \ + name##_show(struct device *dev, struct device_attribute *devattr, \ + char *buf) \ + { \ + struct thermal_zone_device *tz = to_thermal_zone(dev); \ + int temperature, ret; \ + \ + ret = tz->ops->get_##name(tz, &temperature); \ + \ + return ret ? ret : sprintf(buf, "%d\n", temperature); \ + } \ + \ + static ssize_t \ + name##_store(struct device *dev, struct device_attribute *devattr, \ + const char *buf, size_t count) \ + { \ + struct thermal_zone_device *tz = to_thermal_zone(dev); \ + int temperature, ret; \ + \ + if (kstrtoint(buf, 10, &temperature)) \ + return -EINVAL; \ + \ + ret = tz->ops->set_##name(tz, temperature); \ + return ret ? ret : count; \ + } + +create_thres_attr (temp_thres_low); +create_thres_attr (temp_thres_high); +create_thres_attr (temp_thres_hyst); + +static int create_user_events_attrs (struct thermal_zone_device *tz) +{ +struct attribute **attrs; +int index =0 ; + +if (tz->ops->get_temp_thres_low) + ++index; +if (tz->ops->get_temp_thres_high) + ++index; +if (tz->ops->get_temp_thres_high) + ++index; + +/* One additional space for NULL */ + attrs =kcalloc (index +1 ,sizeof (*attrs),GFP_KERNEL ); +if (!attrs) +return -ENOMEM ; + + tz->threshold_attrs =kcalloc (index,sizeof (*tz->threshold_attrs),GFP_KERNEL ); +if (!tz->threshold_attrs) { +kfree (attrs); +return -ENOMEM ; + } + + index =0 ; + +if (tz->ops->get_temp_thres_low) { +snprintf (tz->threshold_attrs[index].name,THERMAL_NAME_LENGTH , +"temp_thres_low" ); + +sysfs_attr_init (&tz->threshold_attrs[index].attr.attr); + tz->threshold_attrs[index].attr.attr.name = + tz->threshold_attrs[index].name; + tz->threshold_attrs[index].attr.attr.mode =S_IWUSR |S_IRUGO ; + tz->threshold_attrs[index].attr.show = temp_thres_low_show; + tz->threshold_attrs[index].attr.store = temp_thres_low_store; + attrs[index] = &tz->threshold_attrs[index].attr.attr; + ++index; + } +if (tz->ops->get_temp_thres_high) { +snprintf (tz->threshold_attrs[index].name,THERMAL_NAME_LENGTH , +"temp_thres_high" ); + +sysfs_attr_init (&tz->threshold_attrs[index].attr.attr); + tz->threshold_attrs[index].attr.attr.name = + tz->threshold_attrs[index].name; + tz->threshold_attrs[index].attr.attr.mode =S_IWUSR |S_IRUGO ; + tz->threshold_attrs[index].attr.show = temp_thres_high_show; + tz->threshold_attrs[index].attr.store = temp_thres_high_store; + attrs[index] = &tz->threshold_attrs[index].attr.attr; + ++index; + } +if (tz->ops->get_temp_thres_hyst) { +snprintf (tz->threshold_attrs[index].name,THERMAL_NAME_LENGTH , +"temp_thres_hyst" ); + +sysfs_attr_init (&tz->threshold_attrs[index].attr.attr); + tz->threshold_attrs[index].attr.attr.name = + tz->threshold_attrs[index].name; + tz->threshold_attrs[index].attr.attr.mode =S_IWUSR |S_IRUGO ; + tz->threshold_attrs[index].attr.show = temp_thres_hyst_show; + tz->threshold_attrs[index].attr.store = temp_thres_hyst_store; + attrs[index] = &tz->threshold_attrs[index].attr.attr; + ++index; + } + attrs[index] =NULL ; + tz->threshold_attribute_group.attrs = attrs; + +return 0 ; +} + +static void delete_user_events_attrs (struct thermal_zone_device *tz) +{ +kfree (tz->threshold_attrs); +kfree (tz->threshold_attribute_group.attrs); +} +#else +static int create_user_events_attrs (struct thermal_zone_device *tz) +{ +return -EINVAL ; +} + +static void delete_user_events_attrs (struct thermal_zone_device *tz) +{ +} +#endif +static ssize_t passive_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count)@@ -625,16 +744,27 @@ int thermal_zone_create_device_groups(struct thermal_zone_device *tz, {const struct attribute_group **groups;int i, size, result; +int start =0 ;/* we need one extra for trips and the NULL to terminate the array */ size =ARRAY_SIZE (thermal_zone_attribute_groups) +2 ; + + result =create_user_events_attrs (tz); +if (!result) { + ++size; + ++start; + } +/* This also takes care of API requirement to be NULL terminated */ groups =kcalloc (size,sizeof (*groups),GFP_KERNEL );if (!groups)return -ENOMEM ; -for (i =0 ; i < size -2 ; i++) - groups[i] = thermal_zone_attribute_groups[i]; +if (start) + groups[0 ] = &tz->threshold_attribute_group; + +for (i =0 ; i < size -2 - start; i++) + groups[i + start] = thermal_zone_attribute_groups[i];if (tz->trips) { result =create_trip_attrs (tz, mask);@@ -660,6 +790,8 @@ void thermal_zone_destroy_device_groups(struct thermal_zone_device *tz)if (tz->trips)destroy_trip_attrs (tz); +delete_user_events_attrs (tz); +kfree (tz->device.groups); }include/linux/thermal.h +9
-1@@ -102,6 +102,12 @@ struct thermal_zone_device_ops { enum thermal_trend *);int (*notify) (struct thermal_zone_device *,int ,enum thermal_trip_type ); +int (*set_temp_thres_low)(struct thermal_zone_device *,int ); +int (*set_temp_thres_high)(struct thermal_zone_device *,int ); +int (*set_temp_thres_hyst)(struct thermal_zone_device *,int ); +int (*get_temp_thres_low)(struct thermal_zone_device *,int *); +int (*get_temp_thres_high)(struct thermal_zone_device *,int *); +int (*get_temp_thres_hyst)(struct thermal_zone_device *,int *); };struct thermal_cooling_device_ops {@@ -208,6 +214,8 @@ struct thermal_zone_device {struct list_head node;struct delayed_work poll_queue;enum thermal_notify_event notify_event; +struct attribute_group threshold_attribute_group; +struct thermal_attr *threshold_attrs; };/** @@ -558,7 +566,7 @@ enum thermal_device_events { THERMAL_PERF_CHANGED, }; -#ifdef CONFIG_THERMAL_USER_EVENT_INTERFACE +#if IS_ENABLED (CONFIG_THERMAL_USER_EVENT_INTERFACE )int thermal_dev_send_event (int zone_id,enum thermal_device_events event,u64 event_data);#else int thermal_dev_send_event (int zone_id,enum thermal_device_events event,u64 event_data)
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Re: [RFC][PATCH 3/5] thermal: Add support for setting notification thresholds
Quoted 16 lines · Daniel Lezcano
Quoted 15 lines · Srinivas Pandruvada
Add new attributes in thermal syfs when a thermal drivers provides callbacks for them and
CONFIG_THERMAL_USER_EVENT_INTERFACEis defined.These attribute allow user space to stop polling for temperature.
These attributes are:
-temp_thres_low: Specify a notification temperature for a low temperature threshold event.temp_thres_high: Specify a notification temperature for a high temperature threshold event.temp_thres_hyst: Specify a change in temperature to send notification
again.
Quoted 5 lines
Quoted 3 lines
This is implemented by adding additional sysfs attribute group. The changes in this patch are trivial to add new attributes in thermal sysfs as done for other attributes.
Isn't it duplicate with the trip point?
A trip point is where an in-kernel governor takes some action. This is not same as a notification temperature. For example at trip point configured by ACPI at 85C, the thermal governor may start aggressive throttling.
But a user space can set a notification threshold at 80C and start some active controls like activate some fan to reduce the impact of passive control on performance.
We need a way to distinguish between temperature notification threshold and actual trip point. Changing a trip point means that user wants kernel to throttle at temperature.
Thanks,
Srinivas
Quoted 265 lines
Quoted 263 lines
Signed-off-by: Srinivas Pandruvada <
[email protected]>--- drivers/thermal/thermal_sysfs.c | 136 +++++++++++++++++++++++++++++++- include/linux/thermal.h | 10 ++- 2 files changed, 143 insertions(+), 3 deletions(-)drivers/thermal/thermal_sysfs.c +5
-0@@ -215,6 +215,125 @@ trip_point_hyst_show(struct device *dev,struct device_attribute *attr, return ret ? ret : sprintf(buf, "%d\n", temperature); } +#if IS_ENABLED (CONFIG_THERMAL_USER_EVENT_INTERFACE ) + +#define create_thres_attr (name) \ + static ssize_t \ + name##_show(struct device *dev, struct device_attribute*devattr, \
drivers/thermal/thermal_sysfs.c +4
-0+ char *buf) \ + { \ +struct thermal_zone_device *tz =to_thermal_zone (dev); \ +int temperature, ret;\
drivers/thermal/thermal_sysfs.c +1
-0+\
drivers/thermal/thermal_sysfs.c +1
-0+ ret = tz->ops->get_##name(tz, &temperature);\
drivers/thermal/thermal_sysfs.c +1
-0+\
drivers/thermal/thermal_sysfs.c +3
-0+return ret ? ret :sprintf (buf,"%d\n" , temperature); \ + } \ +\
drivers/thermal/thermal_sysfs.c +1
-0+ static ssize_t\
drivers/thermal/thermal_sysfs.c +1
-0+ name##_store(struct device *dev, struct device_attribute*devattr, \
drivers/thermal/thermal_sysfs.c +1
-0+ const char *buf, size_t count)\
drivers/thermal/thermal_sysfs.c +2
-0+ { \ +struct thermal_zone_device *tz =to_thermal_zone (dev);\
drivers/thermal/thermal_sysfs.c +1
-0+int temperature, ret;\
drivers/thermal/thermal_sysfs.c +1
-0+\
drivers/thermal/thermal_sysfs.c +1
-0+if (kstrtoint (buf,10 , &temperature))\
drivers/thermal/thermal_sysfs.c +2
-0+return -EINVAL ; \ +\
drivers/thermal/thermal_sysfs.c +9
-0+ ret = tz->ops->set_##name(tz, temperature); \ + return ret ? ret : count; \ + } + +create_thres_attr (temp_thres_low); +create_thres_attr (temp_thres_high); +create_thres_attr (temp_thres_hyst); + +static int create_user_events_attrs(struct thermal_zone_device*tz)
drivers/thermal/thermal_sysfs.c +17
-0+{ +struct attribute **attrs; +int index =0 ; + +if (tz->ops->get_temp_thres_low) + ++index; +if (tz->ops->get_temp_thres_high) + ++index; +if (tz->ops->get_temp_thres_high) + ++index; + +/* One additional space for NULL */ + attrs =kcalloc (index +1 ,sizeof (*attrs),GFP_KERNEL ); +if (!attrs) +return -ENOMEM ; + + tz->threshold_attrs = kcalloc(index, sizeof(*tz-Quoted 1 line
threshold_attrs),GFP_KERNEL);drivers/thermal/thermal_sysfs.c +9
-0+if (!tz->threshold_attrs) { +kfree (attrs); +return -ENOMEM ; + } + + index =0 ; + +if (tz->ops->get_temp_thres_low) { + snprintf(tz->threshold_attrs[index].name,
THERMAL_NAME_LENGTH,drivers/thermal/thermal_sysfs.c +5
-0+ "temp_thres_low"); + +sysfs_attr_init (&tz->threshold_attrs[index].attr.attr); + tz->threshold_attrs[index].attr.attr.name = + tz-Quoted 1 line
threshold_attrs[index].name;
drivers/thermal/thermal_sysfs.c +1
-0+ tz->threshold_attrs[index].attr.attr.mode = S_IWUSR |
S_IRUGO;drivers/thermal/thermal_sysfs.c +1
-0+ tz->threshold_attrs[index].attr.show =
temp_thres_low_show;drivers/thermal/thermal_sysfs.c +1
-0+ tz->threshold_attrs[index].attr.store =
temp_thres_low_store;drivers/thermal/thermal_sysfs.c +5
-0+ attrs[index] = &tz->threshold_attrs[index].attr.attr; + ++index; + } +if (tz->ops->get_temp_thres_high) { + snprintf(tz->threshold_attrs[index].name,
THERMAL_NAME_LENGTH,drivers/thermal/thermal_sysfs.c +5
-0+ "temp_thres_high"); + +sysfs_attr_init (&tz->threshold_attrs[index].attr.attr); + tz->threshold_attrs[index].attr.attr.name = + tz-Quoted 1 line
threshold_attrs[index].name;
drivers/thermal/thermal_sysfs.c +1
-0+ tz->threshold_attrs[index].attr.attr.mode = S_IWUSR |
S_IRUGO;drivers/thermal/thermal_sysfs.c +1
-0+ tz->threshold_attrs[index].attr.show =
temp_thres_high_show;drivers/thermal/thermal_sysfs.c +1
-0+ tz->threshold_attrs[index].attr.store =
temp_thres_high_store;drivers/thermal/thermal_sysfs.c +5
-0+ attrs[index] = &tz->threshold_attrs[index].attr.attr; + ++index; + } +if (tz->ops->get_temp_thres_hyst) { + snprintf(tz->threshold_attrs[index].name,
THERMAL_NAME_LENGTH,drivers/thermal/thermal_sysfs.c +5
-0+ "temp_thres_hyst"); + +sysfs_attr_init (&tz->threshold_attrs[index].attr.attr); + tz->threshold_attrs[index].attr.attr.name = + tz-Quoted 1 line
threshold_attrs[index].name;
drivers/thermal/thermal_sysfs.c +1
-0+ tz->threshold_attrs[index].attr.attr.mode = S_IWUSR |
S_IRUGO;drivers/thermal/thermal_sysfs.c +1
-0+ tz->threshold_attrs[index].attr.show =
temp_thres_hyst_show;drivers/thermal/thermal_sysfs.c +1
-0+ tz->threshold_attrs[index].attr.store =
temp_thres_hyst_store;drivers/thermal/thermal_sysfs.c +10
-0+ attrs[index] = &tz->threshold_attrs[index].attr.attr; + ++index; + } + attrs[index] =NULL ; + tz->threshold_attribute_group.attrs = attrs; + +return 0 ; +} + +static void delete_user_events_attrs(struct thermal_zone_device*tz)
drivers/thermal/thermal_sysfs.c +6
-0+{ +kfree (tz->threshold_attrs); +kfree (tz->threshold_attribute_group.attrs); +} +#else +static int create_user_events_attrs(struct thermal_zone_device*tz)
drivers/thermal/thermal_sysfs.c +5
-0+{ +return -EINVAL ; +} + +static void delete_user_events_attrs(struct thermal_zone_device*tz)
drivers/thermal/thermal_sysfs.c +5
-0+{ +} +#endif +static ssize_t passive_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count)@@ -625,16 +744,27 @@ int thermal_zone_create_device_groups(struct thermal_zone_device *tz, {const struct attribute_group **groups;int i, size, result; +int start =0 ;/* we need one extra for trips and the NULL to terminate the array */
drivers/thermal/thermal_sysfs.c +7
-0size =ARRAY_SIZE (thermal_zone_attribute_groups) +2 ; + + result =create_user_events_attrs (tz); +if (!result) { + ++size; + ++start; + } +/* This also takes care of API requirement to be NULL terminated */
drivers/thermal/thermal_sysfs.c +7
-2groups =kcalloc (size,sizeof (*groups),GFP_KERNEL );if (!groups)return -ENOMEM ; -for (i =0 ; i < size -2 ; i++) - groups[i] = thermal_zone_attribute_groups[i]; +if (start) + groups[0 ] = &tz->threshold_attribute_group; + +for (i =0 ; i < size -2 - start; i++) + groups[i + start] = thermal_zone_attribute_groups[i];if (tz->trips) { result =create_trip_attrs (tz, mask);@@ -660,6 +790,8 @@ void thermal_zone_destroy_device_groups(struct thermal_zone_device *tz)if (tz->trips)destroy_trip_attrs (tz); +delete_user_events_attrs (tz); +kfree (tz->device.groups); }include/linux/thermal.h +6
-0@@ -102,6 +102,12 @@ struct thermal_zone_device_ops { enum thermal_trend *);int (*notify) (struct thermal_zone_device *,int ,enum thermal_trip_type ); +int (*set_temp_thres_low)(struct thermal_zone_device *,int ); +int (*set_temp_thres_high)(struct thermal_zone_device *,int ); +int (*set_temp_thres_hyst)(struct thermal_zone_device *,int ); +int (*get_temp_thres_low)(struct thermal_zone_device *,int *); +int (*get_temp_thres_high)(struct thermal_zone_device *,int *); +int (*get_temp_thres_hyst)(struct thermal_zone_device *,int *); };struct
thermal_cooling_device_ops{include/linux/thermal.h +3
-1@@ -208,6 +214,8 @@ struct thermal_zone_device {struct list_head node;struct delayed_work poll_queue;enum thermal_notify_event notify_event; +struct attribute_group threshold_attribute_group; +struct thermal_attr *threshold_attrs; };/** @@ -558,7 +566,7 @@ enum thermal_device_events { THERMAL_PERF_CHANGED, }; -#ifdef CONFIG_THERMAL_USER_EVENT_INTERFACE +#if IS_ENABLED (CONFIG_THERMAL_USER_EVENT_INTERFACE )int thermal_dev_send_event (int zone_id,enum thermal_device_events event,u64 event_data);#else int thermal_dev_send_event(int
zone_id, enumthermal_device_events
event, u64event_data)
Re: [RFC][PATCH 3/5] thermal: Add support for setting notification thresholds
Quoted 22 lines · Srinivas Pandruvada
Quoted 20 lines · Daniel Lezcano
Quoted 18 lines · Srinivas Pandruvada
Add new attributes in thermal syfs when a thermal drivers provides callbacks for them and
CONFIG_THERMAL_USER_EVENT_INTERFACEis defined.These attribute allow user space to stop polling for temperature.
These attributes are:
-temp_thres_low: Specify a notification temperature for a low temperature threshold event.temp_thres_high: Specify a notification temperature for a high temperature threshold event.temp_thres_hyst: Specify a change in temperature to send notification
again.This is implemented by adding additional sysfs attribute group. The changes in this patch are trivial to add new attributes in thermal sysfs as done for other attributes.
Quoted 8 lines
Quoted 1 line
Isn't it duplicate with the trip point?
A trip point is where an in-kernel governor takes some action. This is not same as a notification temperature. For example at trip point configured by ACPI at 85C, the thermal governor may start aggressive throttling.
But a user space can set a notification threshold at 80C and start some active controls like activate some fan to reduce the impact of passive control on performance.
Then what is the use of thermal trip type "ACTIVE" ?
Quoted 3 lines
We need a way to distinguish between temperature notification threshold and actual trip point. Changing a trip point means that user wants kernel to throttle at temperature.
Re: [RFC][PATCH 3/5] thermal: Add support for setting notification thresholds
Quoted 40 lines · Amit Kucheria
Quoted 26 lines · Srinivas Pandruvada
Quoted 18 lines · Daniel Lezcano
Quoted 17 lines · Srinivas Pandruvada
Add new attributes in thermal syfs when a thermal drivers provides
callbacks for them andCONFIG_THERMAL_USER_EVENT_INTERFACEis defined.These attribute allow user space to stop polling for temperature.
These attributes are:
-temp_thres_low: Specify a notification temperature for a low temperature threshold event.temp_thres_high: Specify a notification temperature for a high temperature threshold event.temp_thres_hyst: Specify a change in temperature to send notification
again.Quoted 7 lines
Quoted 5 lines
This is implemented by adding additional sysfs attribute group. The
changes in this patch are trivial to add new attributes in thermal
sysfs as done for other attributes.Isn't it duplicate with the trip point?
Quoted 11 lines
A trip point is where an in-kernel governor takes some action. This is
not same as a notification temperature. For example at trip point configured by ACPI at 85C, the thermal governor may start aggressive
throttling.
But a user space can set a notification threshold at 80C and start some
active controls like activate some fan to reduce the impact of passive
control on performance.
Quoted 1 line
Then what is the use of thermal trip type "ACTIVE" ?
This is an example.
The defaults are set by the OEMs via ACPI. User can't modify that if they want to optimize for their usage on Linux. There are fan control daemon's which user use on top.
Thanks,
Srinivas
Quoted 5 lines
Quoted 5 lines
We need a way to distinguish between temperature notification threshold
and actual trip point. Changing a trip point means that user wants kernel to throttle at temperature.
Re: [RFC][PATCH 3/5] thermal: Add support for setting notification thresholds
Hi Srinivas,
Quoted 42 lines · Srinivas Pandruvada
Quoted 40 lines · Amit Kucheria
Quoted 37 lines · Srinivas Pandruvada
Quoted 18 lines · Daniel Lezcano
Quoted 17 lines · Srinivas Pandruvada
Add new attributes in thermal syfs when a thermal drivers provides
callbacks for them andCONFIG_THERMAL_USER_EVENT_INTERFACEis defined.These attribute allow user space to stop polling for temperature.
These attributes are:
-temp_thres_low: Specify a notification temperature for a low temperature threshold event.temp_thres_high: Specify a notification temperature for a high temperature threshold event.temp_thres_hyst: Specify a change in temperature to send notification
again.Quoted 7 lines
Quoted 5 lines
This is implemented by adding additional sysfs attribute group. The
changes in this patch are trivial to add new attributes in thermal
sysfs as done for other attributes.Isn't it duplicate with the trip point?
A trip point is where an in-kernel governor takes some action. This is
not same as a notification temperature. For example at trip point configured by ACPI at 85C, the thermal governor may start aggressive
throttling.
But a user space can set a notification threshold at 80C and start some
active controls like activate some fan to reduce the impact of passive
control on performance.
Quoted 5 lines
Quoted 1 line
Then what is the use of thermal trip type "ACTIVE" ?
This is an example.
The defaults are set by the OEMs via ACPI. User can't modify that if they want to optimize for their usage on Linux. There are fan control daemon's which user use on top.
-ENOPARSE. Are you saying users "can" modify these?
In any case, how is what you described earlier not possible with an ACTIVE trip point directly wired to the fan as a cooling device or with a HOT trip point that causes the platform driver to send notification to userspace where a fan control daemon can do what it needs to?
Basically, I think the issue of polling is orthogonal to the introduction of the new attributes introduced in this patch and I don't understand the reason for these attributes from your commit description.
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
We need a way to distinguish between temperature notification threshold
and actual trip point. Changing a trip point means that user wants kernel to throttle at temperature.
Re: [RFC][PATCH 3/5] thermal: Add support for setting notification thresholds
Hi Amit,
Quoted 53 lines · Amit Kucheria
Hi Srinivas,
Quoted 49 lines · Srinivas Pandruvada
Quoted 48 lines · Amit Kucheria
Quoted 30 lines · Srinivas Pandruvada
Quoted 21 lines · Daniel Lezcano
Quoted 20 lines · Srinivas Pandruvada
Add new attributes in thermal syfs when a thermal drivers provides
callbacks for them andCONFIG_THERMAL_USER_EVENT_INTERFACEis
defined.These attribute allow user space to stop polling for temperature.
These attributes are:
-temp_thres_low: Specify a notification temperature for a low
temperature threshold event.temp_thres_high: Specify a notification temperature for a high
temperature threshold event.temp_thres_hyst: Specify a change in temperature to send notification
again.Quoted 8 lines
Quoted 6 lines
This is implemented by adding additional sysfs attribute group.
The
changes in this patch are trivial to add new attributes in thermal
sysfs as done for other attributes.Isn't it duplicate with the trip point?
Quoted 14 lines
A trip point is where an in-kernel governor takes some action. This
is
not same as a notification temperature. For example at trip point
configured by ACPI at 85C, the thermal governor may start aggressive
throttling.
But a user space can set a notification threshold at 80C and start
some
active controls like activate some fan to reduce the impact of passive
control on performance.Then what is the use of thermal trip type "ACTIVE" ?
Quoted 8 lines
Quoted 6 lines
This is an example.
The defaults are set by the OEMs via ACPI. User can't modify that if
they want to optimize for their usage on Linux. There are fan control
daemon's which user use on top.
-ENOPARSE. Are you saying users "can" modify these?
Most of the x86 laptops will not have an active trip as the fan control is done by embedded controller. This is a safety and regulatory issue. Even when you have an active trip it will be read only and also ACPI fan cooling device will have few fix states to control.
There are fine grain controls on top are available outside of thermal drivers via hwmon or others.
https://wiki.archlinux.org/index.php/Fan_speed_control#ThinkPad_laptops
Like in thermald we have XML config, which can be used to set different speed levels at different temperatures. Instead of polling of temperature, these attributes allow notification of temperature threshold. We currently mimic this behavior via adding a RW passive trip (The RW passive trips has a well defined usage different than what we are using for).
There can be already existing RO passive/active trips in that zone already bound to some cooling device. So from user space we search for some RW passive trip and hope this is will give notifications. This I believe is a hack to use a fake trip point for notifications for temperature thresholds.
Thanks,
Srinivas
Quoted 17 lines
In any case, how is what you described earlier not possible with an ACTIVE trip point directly wired to the fan as a cooling device or with a HOT trip point that causes the platform driver to send notification to userspace where a fan control daemon can do what it needs to?
Basically, I think the issue of polling is orthogonal to the introduction of the new attributes introduced in this patch and I don't understand the reason for these attributes from your commit description.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
We need a way to distinguish between temperature notification threshold
and actual trip point. Changing a trip point means that user wants
kernel to throttle at temperature.
RFC PATCH 4/5 thermal: Add support for setting polling interval
In reply to Srinivas PandruvadaAdd new attribute in the thermal syfs for setting temperature sampling interval when CONFIG_THERMAL_USER_EVENT_INTERFACE is defined. The default value is 0, which means no polling.
At this interval user space will get an event THERMAL_TEMP_SAMPLE with temperature sample. This reuses existing polling mecahnism when polling or passive delay is specified during zone registry. To avoid interference with passive and polling delay, this new polling attribute can't be used for those zones.
--- drivers/thermal/thermal_core.c | 7 +++++++ drivers/thermal/thermal_sysfs.c | 36 +++++++++++++++++++++++++++++++-- include/linux/thermal.h | 1 + 3 files changed, 42 insertions(+), 2 deletions(-)
drivers/thermal/thermal_core.c +7 -0
@@ -313,6 +313,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)thermal_zone_device_set_polling (tz, tz->passive_delay); else if (tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); + else if (tz->temp_polling_delay) + thermal_zone_device_set_polling(tz, tz->temp_polling_delay); else thermal_zone_device_set_polling(tz, 0);
@@ -446,6 +448,11 @@ static void update_temperature(struct thermal_zone_device *tz) tz->temperature = temp;mutex_unlock (&tz->lock); +if (tz->temp_polling_delay) { +thermal_dev_send_event (tz->id,THERMAL_TEMP_SAMPLE , temp); +monitor_thermal_zone (tz); + } +trace_thermal_temperature (tz);if (tz->last_temperature ==THERMAL_TEMP_INVALID ) dev_dbg(&tz->device, "last_temperature N/A, current_temperature=%d\n",
drivers/thermal/thermal_sysfs.c +34 -2
@@ -248,6 +248,36 @@ create_thres_attr(temp_thres_low);create_thres_attr (temp_thres_high);create_thres_attr (temp_thres_hyst); +static ssize_t +temp_polling_delay_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct thermal_zone_device *tz =to_thermal_zone (dev); +int val; + +if (kstrtoint (buf,10 , &val)) +return -EINVAL ; + +if (val && val <1000 ) +return -EINVAL ; + + tz->temp_polling_delay = val; +thermal_zone_device_update (tz,THERMAL_EVENT_UNSPECIFIED ); + +return count; +} + +static ssize_t +temp_polling_delay_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct thermal_zone_device *tz =to_thermal_zone (dev); + +return sprintf (buf,"%d\n" , tz->temp_polling_delay); +} + +static DEVICE_ATTR_RW (temp_polling_delay); +static int create_user_events_attrs (struct thermal_zone_device *tz) {struct attribute **attrs;
@@ -260,8 +290,8 @@ static int create_user_events_attrs(struct thermal_zone_device *tz)if (tz->ops->get_temp_thres_high) ++index; -/* One additional space for NULL */ - attrs =kcalloc (index +1 ,sizeof (*attrs),GFP_KERNEL ); +/* One additional space for NULL and temp_pollling_delay */ + attrs =kcalloc (index +2 ,sizeof (*attrs),GFP_KERNEL );if (!attrs)return -ENOMEM ;
@@ -312,6 +342,8 @@ static int create_user_events_attrs(struct thermal_zone_device *tz) attrs[index] = &tz->threshold_attrs[index].attr.attr; ++index; } +if (!tz->polling_delay && !tz->passive_delay) + attrs[index++] = &dev_attr_temp_polling_delay.attr; attrs[index] =NULL ; tz->threshold_attribute_group.attrs = attrs;
include/linux/thermal.h +1 -0
@@ -216,6 +216,7 @@ struct thermal_zone_device {enum thermal_notify_event notify_event;struct attribute_group threshold_attribute_group;struct thermal_attr *threshold_attrs; +int temp_polling_delay; };/**
Signature · 1 line
2.25.4
Re: [RFC][PATCH 4/5] thermal: Add support for setting polling interval
Quoted 9 lines · Srinivas Pandruvada
Add new attribute in the thermal syfs for setting temperature sampling interval when
CONFIG_THERMAL_USER_EVENT_INTERFACEis defined. The default value is 0, which means no polling.At this interval user space will get an event
THERMAL_TEMP_SAMPLEwith temperature sample. This reuses existing polling mecahnism when polling or passive delay is specified during zone registry. To avoid interference with passive and polling delay, this new polling attribute can't be used for those zones.
The userspace can get the temperature whenever it wants via the temperature file. The polling is designed for a specific hardware and the slope of the temperature graphic.
The userspace has the alternative of reading the temperature based on its own timer or wait for (and stick to) the thermal framework sampling rate. Adding a notification in the update is enough IMO.
Quoted 106 lines
Signed-off-by Srinivas Pandruvada <[email protected]>--- drivers/thermal/thermal_core.c | 7 +++++++ drivers/thermal/thermal_sysfs.c | 36 +++++++++++++++++++++++++++++++-- include/linux/thermal.h | 1 + 3 files changed, 42 insertions(+), 2 deletions(-)drivers/thermal/thermal_core.c +7
-0@@ -313,6 +313,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)thermal_zone_device_set_polling (tz, tz->passive_delay); else if (tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); + else if (tz->temp_polling_delay) + thermal_zone_device_set_polling(tz, tz->temp_polling_delay); else thermal_zone_device_set_polling(tz, 0);@@ -446,6 +448,11 @@ static void update_temperature(struct thermal_zone_device *tz) tz->temperature = temp;mutex_unlock (&tz->lock); +if (tz->temp_polling_delay) { +thermal_dev_send_event (tz->id,THERMAL_TEMP_SAMPLE , temp); +monitor_thermal_zone (tz); + } +trace_thermal_temperature (tz);if (tz->last_temperature ==THERMAL_TEMP_INVALID ) dev_dbg(&tz->device, "last_temperature N/A, current_temperature=%d\n",drivers/thermal/thermal_sysfs.c +34
-2@@ -248,6 +248,36 @@ create_thres_attr(temp_thres_low);create_thres_attr (temp_thres_high);create_thres_attr (temp_thres_hyst); +static ssize_t +temp_polling_delay_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct thermal_zone_device *tz =to_thermal_zone (dev); +int val; + +if (kstrtoint (buf,10 , &val)) +return -EINVAL ; + +if (val && val <1000 ) +return -EINVAL ; + + tz->temp_polling_delay = val; +thermal_zone_device_update (tz,THERMAL_EVENT_UNSPECIFIED ); + +return count; +} + +static ssize_t +temp_polling_delay_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct thermal_zone_device *tz =to_thermal_zone (dev); + +return sprintf (buf,"%d\n" , tz->temp_polling_delay); +} + +static DEVICE_ATTR_RW (temp_polling_delay); +static int create_user_events_attrs (struct thermal_zone_device *tz) {struct attribute **attrs;@@ -260,8 +290,8 @@ static int create_user_events_attrs(struct thermal_zone_device *tz)if (tz->ops->get_temp_thres_high) ++index; -/* One additional space for NULL */ - attrs =kcalloc (index +1 ,sizeof (*attrs),GFP_KERNEL ); +/* One additional space for NULL and temp_pollling_delay */ + attrs =kcalloc (index +2 ,sizeof (*attrs),GFP_KERNEL );if (!attrs)return -ENOMEM ;@@ -312,6 +342,8 @@ static int create_user_events_attrs(struct thermal_zone_device *tz) attrs[index] = &tz->threshold_attrs[index].attr.attr; ++index; } +if (!tz->polling_delay && !tz->passive_delay) + attrs[index++] = &dev_attr_temp_polling_delay.attr; attrs[index] =NULL ; tz->threshold_attribute_group.attrs = attrs;include/linux/thermal.h +1
-0@@ -216,6 +216,7 @@ struct thermal_zone_device {enum thermal_notify_event notify_event;struct attribute_group threshold_attribute_group;struct thermal_attr *threshold_attrs; +int temp_polling_delay; };/**
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Re: [RFC][PATCH 4/5] thermal: Add support for setting polling interval
Quoted 17 lines · Daniel Lezcano
Quoted 6 lines · Srinivas Pandruvada
Add new attribute in the thermal syfs for setting temperature sampling
interval whenCONFIG_THERMAL_USER_EVENT_INTERFACEis defined. The default
value is 0, which means no polling.Quoted 9 lines
At this interval user space will get an event
THERMAL_TEMP_SAMPLEwith
temperature sample. This reuses existing polling mecahnism when polling
or passive delay is specified during zone registry. To avoid interference
with passive and polling delay, this new polling attribute can't be used
for those zones.
Quoted 9 lines
The userspace can get the temperature whenever it wants via the temperature file. The polling is designed for a specific hardware and the slope of the temperature graphic.
The userspace has the alternative of reading the temperature based on its own timer or wait for (and stick to) the thermal framework sampling
rate. Adding a notification in the update is enough IMO.
The problem with this approach is that the user can't change sampling interval. Those polling intervals are fixed during thermal-zone register. Is there any way to change those defaults from user space?
Kernel can start with some long polling interval and user space can change close to some trip.
Thanks,
Srinivas
Quoted 123 lines
Quoted 121 lines
Signed-off-by: Srinivas Pandruvada <
[email protected]>--- drivers/thermal/thermal_core.c | 7 +++++++ drivers/thermal/thermal_sysfs.c | 36 +++++++++++++++++++++++++++++++-- include/linux/thermal.h | 1 + 3 files changed, 42 insertions(+), 2 deletions(-)drivers/thermal/thermal_core.c +2
-0@@ -313,6 +313,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz) thermal_zone_device_set_polling(tz, tz->passive_delay); else if (tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); + else if (tz->temp_polling_delay) + thermal_zone_device_set_polling(tz, tz- >temp_polling_delay); elsedrivers/thermal/thermal_core.c +5
-0thermal_zone_device_set_polling (tz,0 );@@ -446,6 +448,11 @@ static void update_temperature(struct thermal_zone_device *tz) tz->temperature = temp;mutex_unlock (&tz->lock); +if (tz->temp_polling_delay) { +thermal_dev_send_event (tz->id,THERMAL_TEMP_SAMPLE , temp); +monitor_thermal_zone (tz); + } +trace_thermal_temperature (tz);drivers/thermal/thermal_core.c +0
-0if (tz->last_temperature ==THERMAL_TEMP_INVALID ) dev_dbg(&tz->device, "last_temperature N/A,current_temperature=%d\n",
drivers/thermal/thermal_sysfs.c +30
-0@@ -248,6 +248,36 @@ create_thres_attr(temp_thres_low);create_thres_attr (temp_thres_high);create_thres_attr (temp_thres_hyst); +static ssize_t +temp_polling_delay_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct thermal_zone_device *tz =to_thermal_zone (dev); +int val; + +if (kstrtoint (buf,10 , &val)) +return -EINVAL ; + +if (val && val <1000 ) +return -EINVAL ; + + tz->temp_polling_delay = val; +thermal_zone_device_update (tz,THERMAL_EVENT_UNSPECIFIED ); + +return count; +} + +static ssize_t +temp_polling_delay_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct thermal_zone_device *tz =to_thermal_zone (dev); + +return sprintf (buf,"%d\n" , tz->temp_polling_delay); +} + +static DEVICE_ATTR_RW (temp_polling_delay); + static int create_user_events_attrs(struct thermal_zone_device*tz)
{drivers/thermal/thermal_sysfs.c +4
-2struct attribute **attrs;@@ -260,8 +290,8 @@ static int create_user_events_attrs(struct thermal_zone_device *tz)if (tz->ops->get_temp_thres_high) ++index; -/* One additional space for NULL */ - attrs =kcalloc (index +1 ,sizeof (*attrs),GFP_KERNEL ); +/* One additional space for NULL and temp_pollling_delay */ + attrs =kcalloc (index +2 ,sizeof (*attrs),GFP_KERNEL );if (!attrs)return -ENOMEM ;@@ -312,6 +342,8 @@ static int create_user_events_attrs(struct thermal_zone_device *tz) attrs[index] = &tz->threshold_attrs[index].attr.attr; ++index; } +if (!tz->polling_delay && !tz->passive_delay) + attrs[index++] = &dev_attr_temp_polling_delay.attr; attrs[index] =NULL ; tz->threshold_attribute_group.attrs = attrs;include/linux/thermal.h +1
-0@@ -216,6 +216,7 @@ struct thermal_zone_device {enum thermal_notify_event notify_event;struct attribute_group threshold_attribute_group;struct thermal_attr *threshold_attrs; +int temp_polling_delay; };/**
Re: [RFC][PATCH 4/5] thermal: Add support for setting polling interval
Quoted 22 lines · Srinivas Pandruvada
Quoted 21 lines · Daniel Lezcano
Quoted 6 lines · Srinivas Pandruvada
Add new attribute in the thermal syfs for setting temperature sampling
interval whenCONFIG_THERMAL_USER_EVENT_INTERFACEis defined. The default
value is 0, which means no polling.Quoted 9 lines
At this interval user space will get an event
THERMAL_TEMP_SAMPLEwith
temperature sample. This reuses existing polling mecahnism when polling
or passive delay is specified during zone registry. To avoid interference
with passive and polling delay, this new polling attribute can't be used
for those zones.The userspace can get the temperature whenever it wants via the temperature file. The polling is designed for a specific hardware and the slope of the temperature graphic.
Quoted 8 lines
Quoted 5 lines
The userspace has the alternative of reading the temperature based on its own timer or wait for (and stick to) the thermal framework sampling
rate. Adding a notification in the update is enough IMO.The problem with this approach is that the user can't change sampling interval. Those polling intervals are fixed during thermal-zone register. Is there any way to change those defaults from user space?
No, we can't but the userspace can decide when to read the temperature (via sysfs or netlink) and thus decide its own sampling rate.
Otherwise, we are talking about an userspace governor, so the platform is setup with the desired sampling rate + userspace governor.
Quoted 2 lines
Kernel can start with some long polling interval and user space can change close to some trip.
Ok, let me rephrase it. This (big) comment encompass also patch 3/5.
I understood now the initial need of adding user trip points.
There are platforms where the interrupt mode does not exist so setting an user trip point does not set the interrupt for the closer temperature, hence we end up with a kernel sampling rate and in this case adding a trip point + new user sampling rate is pointless as the userspace can poll the temperature at its convenient rate.
If we summarize the different combinations we have:
1. monitoring : interrupt mode, mitigation : interrupt mode
There are no thermal zone update until an interrupt fires. The mitigation is based on trip point crossed.
2. monitoring : interrupt mode, mitigation : polling
There are no thermal zone update until an interrupt fires. The mitigation happens with a sampling rate specified with the polling rate.
3. monitoring : polling, mitigation : polling
The thermal zone is updated at the polling rate, the mitigation occurs with an update at the second polling rate.
IIUC, the RFC proposes to add a new type of temperature threshold, followed a new polling rate to update the userspace.
IMHO, it is not a good thing to delegate to the kernel what the userspace can handle easily.
I suggest:
- Not add another polling rate. If the thermal zone has a polling rate
or supports the interrupt mode, then the user trip point setup succeed otherwise it fails and up to the userspace to read the temperature at its convenient rate. (Note multiple process may want to get temperature, so one should not set the rate of others).
- Not add another temp threshold structure but add a new trip type
"user" and keep using the existing trip structures, so the notification can happen in the handle_trip_point function. The sysfs only reflects the setup via the "trip_point_x_hyst", "trip_point_0_temp", "trip_point_x_type"
- Do not use sysfs for setup but rely on the genetlink for one message
setup instead of multiple sysfs file writing. Adding a trip point will be straighforward.
What do you think?
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook | <http://twitter.com/#!/linaroorg> Twitter | <http://www.linaro.org/linaro-blog/> Blog
Re: [RFC][PATCH 4/5] thermal: Add support for setting polling interval
Quoted 39 lines · Daniel Lezcano
Quoted 32 lines · Srinivas Pandruvada
Quoted 25 lines · Daniel Lezcano
Quoted 7 lines · Srinivas Pandruvada
Add new attribute in the thermal syfs for setting temperature sampling
interval whenCONFIG_THERMAL_USER_EVENT_INTERFACEis defined. The
default
value is 0, which means no polling.Quoted 11 lines
At this interval user space will get an event
THERMAL_TEMP_SAMPLE
with
temperature sample. This reuses existing polling mecahnism when polling
or passive delay is specified during zone registry. To avoid interference
with passive and polling delay, this new polling attribute can't be
used
for those zones.The userspace can get the temperature whenever it wants via the temperature file. The polling is designed for a specific hardware and
the slope of the temperature graphic.Quoted 6 lines
The userspace has the alternative of reading the temperature based on
its own timer or wait for (and stick to) the thermal framework sampling
rate. Adding a notification in the update is enough IMO.Quoted 5 lines
The problem with this approach is that the user can't change sampling
interval. Those polling intervals are fixed during thermal-zone register. Is there any way to change those defaults from user space?
Quoted 3 lines
No, we can't but the userspace can decide when to read the temperature
(via sysfs or netlink) and thus decide its own sampling rate.
Yes, if we poll for temperature from user space, no change is required neighter netlink nor kfifo.
The average time to read CPU temperature and convert to int from sysfs takes 45us vs 7us for push via Kfifo. I haven't looked at your patches and checked this time. If it is comparable then netlink is better.
Quoted 19 lines
Otherwise, we are talking about an userspace governor, so the platform
is setup with the desired sampling rate + userspace governor.Quoted 2 lines
Kernel can start with some long polling interval and user space can change close to some trip.
Ok, let me rephrase it. This (big) comment encompass also patch 3/5.
I understood now the initial need of adding user trip points.
There are platforms where the interrupt mode does not exist so setting
an user trip point does not set the interrupt for the closer temperature, hence we end up with a kernel sampling rate and in this case adding a trip point + new user sampling rate is pointless as the userspace can poll the temperature at its convenient rate.
Quoted 6 lines
If we summarize the different combinations we have:
1. monitoring : interrupt mode, mitigation : interrupt mode
There are no thermal zone update until an interrupt fires. The mitigation is based on trip point crossed.
Yes. Basically daemon sleeps, till it gets a netlink notification currently.
Quoted 7 lines
2. monitoring : interrupt mode, mitigation : polling
There are no thermal zone update until an interrupt fires. The mitigation happens with a sampling rate specified with the polling rate.
More complex than this. interrupt fires but it will fire flood for any change (+/- around threshold) so after the first trigger, just disable interrupt for an interval and start polling from user space as this is more efficient.
Quoted 6 lines
3. monitoring : polling, mitigation : polling
The thermal zone is updated at the polling rate, the mitigation occurs
with an update at the second polling rate.
Yes.
Quoted 8 lines
IIUC, the RFC proposes to add a new type of temperature threshold, followed a new polling rate to update the userspace.
IMHO, it is not a good thing to delegate to the kernel what the userspace can handle easily.
I suggest:
Quoted 8 lines
- Not add another polling rate. If the thermal zone has a polling
rate
or supports the interrupt mode, then the user trip point setup succeed
otherwise it fails and up to the userspace to read the temperature at its convenient rate. (Note multiple process may want to get temperature,
so one should not set the rate of others).
Fine.
Quoted 7 lines
- Not add another temp threshold structure but add a new trip type
"user" and keep using the existing trip structures, so the notification
can happen in thehandle_trip_pointfunction. The sysfs only reflects the setup via the "trip_point_x_hyst", "trip_point_0_temp", "trip_point_x_type"
Fine. It is better than what we re-purpose a passive trip currently.
Quoted 5 lines
- Do not use sysfs for setup but rely on the genetlink for one
message
setup instead of multiple sysfs file writing. Adding a trip point will
Fine.
Quoted 3 lines
What do you think?
Looks good.
Thanks,
Srinivas
Quoted 2 lines
Re: [RFC][PATCH 4/5] thermal: Add support for setting polling interval
In reply to Srinivas PandruvadaQuoted 10 lines · Srinivas Pandruvada
Add new attribute in the thermal syfs for setting temperature sampling interval when
CONFIG_THERMAL_USER_EVENT_INTERFACEis defined. The default value is 0, which means no polling.At this interval user space will get an event
THERMAL_TEMP_SAMPLEwith temperature sample. This reuses existing polling mecahnism when polling or passive delay is specified during zone registry. To avoid interference with passive and polling delay, this new polling attribute can't be used for those zones.
Why should the kernel periodically emit events for userspace when the userspace is perfectly capable of deciding how frequently it wants to poll a file for changes?
Quoted 109 lines
Signed-off-by Srinivas Pandruvada <[email protected]>--- drivers/thermal/thermal_core.c | 7 +++++++ drivers/thermal/thermal_sysfs.c | 36 +++++++++++++++++++++++++++++++-- include/linux/thermal.h | 1 + 3 files changed, 42 insertions(+), 2 deletions(-)drivers/thermal/thermal_core.c +7
-0@@ -313,6 +313,8 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)thermal_zone_device_set_polling (tz, tz->passive_delay); else if (tz->polling_delay) thermal_zone_device_set_polling(tz, tz->polling_delay); + else if (tz->temp_polling_delay) + thermal_zone_device_set_polling(tz, tz->temp_polling_delay); else thermal_zone_device_set_polling(tz, 0);@@ -446,6 +448,11 @@ static void update_temperature(struct thermal_zone_device *tz) tz->temperature = temp;mutex_unlock (&tz->lock); +if (tz->temp_polling_delay) { +thermal_dev_send_event (tz->id,THERMAL_TEMP_SAMPLE , temp); +monitor_thermal_zone (tz); + } +trace_thermal_temperature (tz);if (tz->last_temperature ==THERMAL_TEMP_INVALID ) dev_dbg(&tz->device, "last_temperature N/A, current_temperature=%d\n",drivers/thermal/thermal_sysfs.c +34
-2@@ -248,6 +248,36 @@ create_thres_attr(temp_thres_low);create_thres_attr (temp_thres_high);create_thres_attr (temp_thres_hyst); +static ssize_t +temp_polling_delay_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct thermal_zone_device *tz =to_thermal_zone (dev); +int val; + +if (kstrtoint (buf,10 , &val)) +return -EINVAL ; + +if (val && val <1000 ) +return -EINVAL ; + + tz->temp_polling_delay = val; +thermal_zone_device_update (tz,THERMAL_EVENT_UNSPECIFIED ); + +return count; +} + +static ssize_t +temp_polling_delay_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct thermal_zone_device *tz =to_thermal_zone (dev); + +return sprintf (buf,"%d\n" , tz->temp_polling_delay); +} + +static DEVICE_ATTR_RW (temp_polling_delay); +static int create_user_events_attrs (struct thermal_zone_device *tz) {struct attribute **attrs;@@ -260,8 +290,8 @@ static int create_user_events_attrs(struct thermal_zone_device *tz)if (tz->ops->get_temp_thres_high) ++index; -/* One additional space for NULL */ - attrs =kcalloc (index +1 ,sizeof (*attrs),GFP_KERNEL ); +/* One additional space for NULL and temp_pollling_delay */ + attrs =kcalloc (index +2 ,sizeof (*attrs),GFP_KERNEL );if (!attrs)return -ENOMEM ;@@ -312,6 +342,8 @@ static int create_user_events_attrs(struct thermal_zone_device *tz) attrs[index] = &tz->threshold_attrs[index].attr.attr; ++index; } +if (!tz->polling_delay && !tz->passive_delay) + attrs[index++] = &dev_attr_temp_polling_delay.attr; attrs[index] =NULL ; tz->threshold_attribute_group.attrs = attrs;include/linux/thermal.h +1
-1@@ -216,6 +216,7 @@ struct thermal_zone_device {enum thermal_notify_event notify_event;struct attribute_group threshold_attribute_group;struct thermal_attr *threshold_attrs; +int temp_polling_delay; };/** -- 2.25.4
RFC PATCH 5/5 thermal: int340x: Use new device interface
In reply to Srinivas PandruvadaUse the new framework to send notifications for:
- Setting temperature threshold for notification to avoid polling
- Send THERMAL_TRIP_REACHED event on reaching threshold
- Send THERMAL_TRIP_UPDATE when firmware change the the existing trip temperature
--- .../intel/int340x_thermal/int3403_thermal.c | 3 ++ .../int340x_thermal/int340x_thermal_zone.c | 29 +++++++++++++++++++ .../int340x_thermal/int340x_thermal_zone.h | 7 +++++ .../processor_thermal_device.c | 1 + 4 files changed, 40 insertions(+)
drivers/thermal/intel/int340x_thermal/int3403_thermal.c +3 -0
@@ -63,15 +63,18 @@ static void int3403_notify(acpi_handle handle,switch (event) {case INT3403_PERF_CHANGED_EVENT : +int340x_thermal_send_user_event (obj->int340x_zone,THERMAL_PERF_CHANGED ,0 );break ;case INT3403_THERMAL_EVENT :int340x_thermal_zone_device_update (obj->int340x_zone,THERMAL_TRIP_VIOLATED ); +int340x_thermal_send_user_event (obj->int340x_zone,THERMAL_TRIP_REACHED ,0 );break ;case INT3403_PERF_TRIP_POINT_CHANGED :int340x_thermal_read_trips (obj->int340x_zone);int340x_thermal_zone_device_update (obj->int340x_zone,THERMAL_TRIP_CHANGED ); +int340x_thermal_send_user_event (obj->int340x_zone,THERMAL_TRIP_UPDATE ,0 );break ;default :dev_err (&priv->pdev->dev,"Unsupported event [0x%x]\n" , event);
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +29 -0
@@ -146,12 +146,41 @@ static int int340x_thermal_get_trip_hyst(struct thermal_zone_device *zone,return 0 ; } +static int int340x_thermal_get_thres_low (struct thermal_zone_device *zone,int *temp) +{ +struct int34x_thermal_zone *d = zone->devdata; + + *temp = d->aux_trips[0 ]; + +return 0 ; +} + +static int int340x_thermal_set_thres_low (struct thermal_zone_device *zone,int temp) +{ +struct int34x_thermal_zone *d = zone->devdata; +acpi_status status; + +if (d->override_ops && d->override_ops->set_trip_temp) +return d->override_ops->set_trip_temp (zone,0 , temp); + + status =acpi_execute_simple_method (d->adev->handle,"PAT0" , +millicelsius_to_deci_kelvin (temp)); +if (ACPI_FAILURE (status)) +return -EIO ; + + d->aux_trips[0 ] = temp; + +return 0 ; +} +static struct thermal_zone_device_ops int340x_thermal_zone_ops = { .get_temp = int340x_thermal_get_zone_temp, .get_trip_temp = int340x_thermal_get_trip_temp, .get_trip_type = int340x_thermal_get_trip_type, .set_trip_temp = int340x_thermal_set_trip_temp, .get_trip_hyst = int340x_thermal_get_trip_hyst, + .set_temp_thres_low = int340x_thermal_set_thres_low, + .get_temp_thres_low = int340x_thermal_get_thres_low, }; static int int340x_thermal_get_trip_config(acpi_handle handle, char *name,
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h +7 -0
@@ -58,4 +58,11 @@ static inline void int340x_thermal_zone_device_update( thermal_zone_device_update(tzone->zone, event); } +static inline void int340x_thermal_send_user_event ( +struct int34x_thermal_zone *tzone, +enum thermal_device_events event, +u64 data) +{ +thermal_dev_send_event (tzone->zone->id, event, data); +}#endif
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +1 -0
@@ -340,6 +340,7 @@ static void proc_thermal_notify(acpi_handle handle, u32 event, void *data)proc_thermal_read_ppcc (proc_priv);int340x_thermal_zone_device_update (proc_priv->int340x_zone,THERMAL_DEVICE_POWER_CAPABILITY_CHANGED ); +int340x_thermal_send_user_event (proc_priv->int340x_zone,THERMAL_PERF_CHANGED ,0 );break ;default :dev_dbg (proc_priv->dev,"Unsupported event [0x%x]\n" , event);
Signature · 1 line
2.25.4
Re: [RFC][PATCH 5/5] thermal: int340x: Use new device interface
Quoted 6 lines · Srinivas Pandruvada
Use the new framework to send notifications for:
- Setting temperature threshold for notification to avoid polling
- SendTHERMAL_TRIP_REACHEDevent on reaching threshold
- SendTHERMAL_TRIP_UPDATEwhen firmware change the the existing trip temperature
I am a little confused here. I would've expected the thermal core to send the THERMAL_TRIP_* notifications, not platform drivers. Why shouldn't this be done in thermal core?
Quoted 109 lines
Signed-off-by Srinivas Pandruvada <[email protected]>--- .../intel/int340x_thermal/int3403_thermal.c | 3 ++ .../int340x_thermal/int340x_thermal_zone.c | 29 +++++++++++++++++++ .../int340x_thermal/int340x_thermal_zone.h | 7 +++++ .../processor_thermal_device.c | 1 + 4 files changed, 40 insertions(+)drivers/thermal/intel/int340x_thermal/int3403_thermal.c +3
-0@@ -63,15 +63,18 @@ static void int3403_notify(acpi_handle handle,switch (event) {case INT3403_PERF_CHANGED_EVENT : +int340x_thermal_send_user_event (obj->int340x_zone,THERMAL_PERF_CHANGED ,0 );break ;case INT3403_THERMAL_EVENT :int340x_thermal_zone_device_update (obj->int340x_zone,THERMAL_TRIP_VIOLATED ); +int340x_thermal_send_user_event (obj->int340x_zone,THERMAL_TRIP_REACHED ,0 );break ;case INT3403_PERF_TRIP_POINT_CHANGED :int340x_thermal_read_trips (obj->int340x_zone);int340x_thermal_zone_device_update (obj->int340x_zone,THERMAL_TRIP_CHANGED ); +int340x_thermal_send_user_event (obj->int340x_zone,THERMAL_TRIP_UPDATE ,0 );break ;default :dev_err (&priv->pdev->dev,"Unsupported event [0x%x]\n" , event);drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c +29
-0@@ -146,12 +146,41 @@ static int int340x_thermal_get_trip_hyst(struct thermal_zone_device *zone,return 0 ; } +static int int340x_thermal_get_thres_low (struct thermal_zone_device *zone,int *temp) +{ +struct int34x_thermal_zone *d = zone->devdata; + + *temp = d->aux_trips[0 ]; + +return 0 ; +} + +static int int340x_thermal_set_thres_low (struct thermal_zone_device *zone,int temp) +{ +struct int34x_thermal_zone *d = zone->devdata; +acpi_status status; + +if (d->override_ops && d->override_ops->set_trip_temp) +return d->override_ops->set_trip_temp (zone,0 , temp); + + status =acpi_execute_simple_method (d->adev->handle,"PAT0" , +millicelsius_to_deci_kelvin (temp)); +if (ACPI_FAILURE (status)) +return -EIO ; + + d->aux_trips[0 ] = temp; + +return 0 ; +} +static struct thermal_zone_device_ops int340x_thermal_zone_ops = { .get_temp = int340x_thermal_get_zone_temp, .get_trip_temp = int340x_thermal_get_trip_temp, .get_trip_type = int340x_thermal_get_trip_type, .set_trip_temp = int340x_thermal_set_trip_temp, .get_trip_hyst = int340x_thermal_get_trip_hyst, + .set_temp_thres_low = int340x_thermal_set_thres_low, + .get_temp_thres_low = int340x_thermal_get_thres_low, }; static int int340x_thermal_get_trip_config(acpi_handle handle, char *name,drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.h +7
-0@@ -58,4 +58,11 @@ static inline void int340x_thermal_zone_device_update( thermal_zone_device_update(tzone->zone, event); } +static inline void int340x_thermal_send_user_event ( +struct int34x_thermal_zone *tzone, +enum thermal_device_events event, +u64 data) +{ +thermal_dev_send_event (tzone->zone->id, event, data); +}#endif drivers/thermal/intel/int340x_thermal/processor_thermal_device.c +1
-1@@ -340,6 +340,7 @@ static void proc_thermal_notify(acpi_handle handle, u32 event, void *data)proc_thermal_read_ppcc (proc_priv);int340x_thermal_zone_device_update (proc_priv->int340x_zone,THERMAL_DEVICE_POWER_CAPABILITY_CHANGED ); +int340x_thermal_send_user_event (proc_priv->int340x_zone,THERMAL_PERF_CHANGED ,0 );break ;default :dev_dbg (proc_priv->dev,"Unsupported event [0x%x]\n" , event); --2.25.4