History

thermal: core: genetlink support for events/cmd/sampling

Initially the thermal framework had a very simple notification mechanism to send generic netlink messages to the userspace. The notification function was never called from anywhere and the corresponding dead code was removed. It was probably a first attempt to introduce the netlink notification. At LPC2018, the presentation "Linux thermal: User kernel interface", proposed to create the notifications to the userspace via a kfifo. The advantage of the kfifo is the performance. It is usually used from a 1:1 communication channel where a driver captures data and sends it as fast as possible to a userspace process. The drawback is that only one process uses the notification channel exclusively, thus no other process is allowed to use the channel to get temperature or notifications. This patch defines a generic netlink API to discover the current thermal setup and adds event notifications as well as temperature sampling. As any genetlink protocol, it can evolve and the versioning allows to keep the backward compatibility. In order to prevent the user from getting flooded with data on a single channel, there are two multicast channels, one for the temperature sampling when the thermal zone is updated and another one for the events, so the user can get the events only without the thermal zone temperature sampling. Also, a list of commands to discover the thermal setup is added and can be extended when needed.

Daniel Lezcano committed 6 years ago

Commit 1ce50e71 parent 329b0645 files · +739 −35Browse files

Showing the changes to include/uapi/linux (1 of 5 files). Show all

Unified · Split

include/uapi/linux/thermal.h+72−17
@@ -4,31 +4,86 @@ · 3 unmodified lines
4 4
5#define THERMAL_NAME_LENGTH 205#define THERMAL_NAME_LENGTH 20
6 6
7/* Adding event notification support elements */7enum thermal_device_mode {
8#define THERMAL_GENL_FAMILY_NAME "thermal_event"8 THERMAL_DEVICE_DISABLED = 0,
9#define THERMAL_GENL_VERSION 0x019 THERMAL_DEVICE_ENABLED,
10#define THERMAL_GENL_MCAST_GROUP_NAME "thermal_mc_grp"10};
11 11
12/* Events supported by Thermal Netlink */12enum thermal_trip_type {
13enum events {13 THERMAL_TRIP_ACTIVE = 0,
14 THERMAL_AUX0,14 THERMAL_TRIP_PASSIVE,
15 THERMAL_AUX1,15 THERMAL_TRIP_HOT,
16 THERMAL_CRITICAL,16 THERMAL_TRIP_CRITICAL,
17 THERMAL_DEV_FAULT,
18};17};
19 18
20/* attributes of thermal_genl_family */19/* Adding event notification support elements */
21enum {20#define THERMAL_GENL_FAMILY_NAME "thermal"
21#define THERMAL_GENL_VERSION 0x01
22#define THERMAL_GENL_SAMPLING_GROUP_NAME "sampling"
23#define THERMAL_GENL_EVENT_GROUP_NAME "event"
24
25/* Attributes of thermal_genl_family */
26enum thermal_genl_attr {
22 THERMAL_GENL_ATTR_UNSPEC,27 THERMAL_GENL_ATTR_UNSPEC,
23 THERMAL_GENL_ATTR_EVENT,28 THERMAL_GENL_ATTR_TZ,
29 THERMAL_GENL_ATTR_TZ_ID,
30 THERMAL_GENL_ATTR_TZ_TEMP,
31 THERMAL_GENL_ATTR_TZ_TRIP,
32 THERMAL_GENL_ATTR_TZ_TRIP_ID,
33 THERMAL_GENL_ATTR_TZ_TRIP_TYPE,
34 THERMAL_GENL_ATTR_TZ_TRIP_TEMP,
35 THERMAL_GENL_ATTR_TZ_TRIP_HYST,
36 THERMAL_GENL_ATTR_TZ_MODE,
37 THERMAL_GENL_ATTR_TZ_NAME,
38 THERMAL_GENL_ATTR_TZ_CDEV_WEIGHT,
39 THERMAL_GENL_ATTR_TZ_GOV,
40 THERMAL_GENL_ATTR_TZ_GOV_NAME,
41 THERMAL_GENL_ATTR_CDEV,
42 THERMAL_GENL_ATTR_CDEV_ID,
43 THERMAL_GENL_ATTR_CDEV_CUR_STATE,
44 THERMAL_GENL_ATTR_CDEV_MAX_STATE,
45 THERMAL_GENL_ATTR_CDEV_NAME,
46 THERMAL_GENL_ATTR_GOV_NAME,
47
24 __THERMAL_GENL_ATTR_MAX,48 __THERMAL_GENL_ATTR_MAX,
25};49};
26#define THERMAL_GENL_ATTR_MAX (__THERMAL_GENL_ATTR_MAX - 1)50#define THERMAL_GENL_ATTR_MAX (__THERMAL_GENL_ATTR_MAX - 1)
27 51
28/* commands supported by the thermal_genl_family */52enum thermal_genl_sampling {
29enum {53 THERMAL_GENL_SAMPLING_TEMP,
54 __THERMAL_GENL_SAMPLING_MAX,
55};
56#define THERMAL_GENL_SAMPLING_MAX (__THERMAL_GENL_SAMPLING_MAX - 1)
57
58/* Events of thermal_genl_family */
59enum thermal_genl_event {
60 THERMAL_GENL_EVENT_UNSPEC,
61 THERMAL_GENL_EVENT_TZ_CREATE, /* Thermal zone creation */
62 THERMAL_GENL_EVENT_TZ_DELETE, /* Thermal zone deletion */
63 THERMAL_GENL_EVENT_TZ_DISABLE, /* Thermal zone disabed */
64 THERMAL_GENL_EVENT_TZ_ENABLE, /* Thermal zone enabled */
65 THERMAL_GENL_EVENT_TZ_TRIP_UP, /* Trip point crossed the way up */
66 THERMAL_GENL_EVENT_TZ_TRIP_DOWN, /* Trip point crossed the way down */
67 THERMAL_GENL_EVENT_TZ_TRIP_CHANGE, /* Trip point changed */
68 THERMAL_GENL_EVENT_TZ_TRIP_ADD, /* Trip point added */
69 THERMAL_GENL_EVENT_TZ_TRIP_DELETE, /* Trip point deleted */
70 THERMAL_GENL_EVENT_CDEV_ADD, /* Cdev bound to the thermal zone */
71 THERMAL_GENL_EVENT_CDEV_DELETE, /* Cdev unbound */
72 THERMAL_GENL_EVENT_CDEV_STATE_UPDATE, /* Cdev state updated */
73 THERMAL_GENL_EVENT_TZ_GOV_CHANGE, /* Governor policy changed */
74 __THERMAL_GENL_EVENT_MAX,
75};
76#define THERMAL_GENL_EVENT_MAX (__THERMAL_GENL_EVENT_MAX - 1)
77
78/* Commands supported by the thermal_genl_family */
79enum thermal_genl_cmd {
30 THERMAL_GENL_CMD_UNSPEC,80 THERMAL_GENL_CMD_UNSPEC,
31 THERMAL_GENL_CMD_EVENT,81 THERMAL_GENL_CMD_TZ_GET_ID, /* List of thermal zones id */
82 THERMAL_GENL_CMD_TZ_GET_TRIP, /* List of thermal trips */
83 THERMAL_GENL_CMD_TZ_GET_TEMP, /* Get the thermal zone temperature */
84 THERMAL_GENL_CMD_TZ_GET_GOV, /* Get the thermal zone governor */
85 THERMAL_GENL_CMD_TZ_GET_MODE, /* Get the thermal zone mode */
86 THERMAL_GENL_CMD_CDEV_GET, /* List of cdev id */
32 __THERMAL_GENL_CMD_MAX,87 __THERMAL_GENL_CMD_MAX,
33};88};
34#define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1)89#define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1)