thermal: core: Add user thresholds support
authorDaniel Lezcano <daniel.lezcano@linaro.org>
Mon, 23 Sep 2024 09:59:57 +0000 (11:59 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 10 Oct 2024 21:33:37 +0000 (23:33 +0200)
commit445936f9e258eca624c8239056bd8cd6e853b3fd
tree8613f6a964acd230ec6f7b75cad79ec6390be108
parent827a07525c099f54d3b15110408824541ec66b3c
thermal: core: Add user thresholds support

The user thresholds mechanism is a way to have the userspace to tell
the thermal framework to send a notification when a temperature limit
is crossed. There is no id, no hysteresis, just the temperature and
the direction of the limit crossing. That means we can be notified
when a threshold is crossed the way up only, or the way down only or
both ways. That allows to create hysteresis values if it is needed.

A threshold can be added, deleted or flushed. The latter means all
thresholds belonging to a thermal zone will be deleted.

When a threshold is added:

 - if the same threshold (temperature and direction) exists, an error
   is returned

 - if a threshold is specified with the same temperature but a
   different direction, the specified direction is added

 - if there is no threshold with the same temperature then it is
   created

When a threshold is deleted:

 - if the same threshold (temperature and direction) exists, it is
   deleted

 - if a threshold is specified with the same temperature but a
   different direction, the specified direction is removed

 - if there is no threshold with the same temperature, then an error
   is returned

When the threshold are flushed:

 - All thresholds related to a thermal zone are deleted

When a threshold is crossed:

 - the userspace does not need to know which threshold(s) have been
   crossed, it will be notified with the current temperature and the
   previous temperature

 - if multiple thresholds have been crossed between two updates only
   one notification will be send to the userspace, it is pointless to
   send a notification per thresholds crossed as the userspace can
   handle that easily when it has the temperature delta information

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://patch.msgid.link/20240923100005.2532430-2-daniel.lezcano@linaro.org
[ rjw: Subject edit, use BIT(0) and BIT(1) in symbol definitions ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/thermal/Makefile
drivers/thermal/thermal_core.h
drivers/thermal/thermal_thresholds.c [new file with mode: 0644]
drivers/thermal/thermal_thresholds.h [new file with mode: 0644]
include/linux/thermal.h
include/uapi/linux/thermal.h