Skip to contentSkip to conversation

thermal/core: Make the userspace governor deprecated

PATCH Superseded Daniel Lezcano 2 participants 4 messages Oct 19, 2021 Thermal

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 thermal/core: Make the userspace governor deprecated

The userspace governor is sending temperature when polling is active and trip point crossed events. Nothing else.

AFAICT, this governor is used with custom kernels making the userspace governor co-existing with another governor on the same thermal zone because there was no notification mechanism.

The new netlink thermal notification is able to provide more information than the userspace governor and give the opportunity to the users of this governor to replace it by a dedicated notification framework.

The userspace governor will be removed as its usage is no longer needed.

Add a warning message to tell the userspace governor is deprecated.

---
 drivers/thermal/gov_user_space.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/thermal/gov_user_space.c +9 -0
index 82a7198bbe71..95d6d3d6b8f7 100644
@@ -15,6 +15,14 @@
 
 #include "thermal_core.h"
 
+static int user_space_bind(struct thermal_zone_device *tz)
+{
+	WARN(1, "Userspace governor deprecated: use thermal netlink "	\
+	     "notification instead\n");
+
+	return 0;
+}
+
 /**
  * notify_user_space - Notifies user space about thermal events
  * @tz: thermal_zone_device
@@ -43,5 +51,6 @@ static int notify_user_space(struct thermal_zone_device *tz, int trip)
 static struct thermal_governor thermal_gov_user_space = {
 	.name		= "user_space",
 	.throttle	= notify_user_space,
+	.bind_to_tz	= user_space_bind,
 };
 THERMAL_GOVERNOR_DECLARE(thermal_gov_user_space);
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 thermal/core: Make deprecated cooling device state change from userspace

The cooling devices have their cooling device set_cur_state read-writable all the time in the sysfs directory, thus allowing the userspace to act on it.

The thermal framework is wrongly used by userspace as a power capping framework by acting on the cooling device opaque state. This one then competes with the in-kernel governor decision.

We have seen in out-of-tree kernels, a big number of devices which are abusely declaring themselves as cooling device just to act on their power.

The role of the thermal framework is to protect the junction temperature of the silicon. Letting the userspace to play with a cooling device is wrong and potentially dangerous.

The powercap framework is the right framework to do power capping and moreover it deals with the aggregation via the dev pm qos.

As the userspace governor is marked deprecated and about to be removed, there is no point to keep this file writable also in the future.

Emit a warning and deprecate the interface.

---
 drivers/thermal/thermal_sysfs.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/thermal/thermal_sysfs.c +2 -0
index 1c4aac8464a7..3f4ea3a283ae 100644
@@ -610,6 +610,8 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
 	unsigned long state;
 	int result;
 
+	WARN_ON_ONCE(1, "Setting cooling device state is deprecated\n");
+	
 	if (sscanf(buf, "%ld\n", &state) != 1)
 		return -EINVAL;
 
Signature · 1 line
2.25.1
#3 lore raw
In reply to Daniel Lezcano
Quoted 28 lines · Daniel Lezcano

The userspace governor is sending temperature when polling is active and trip point crossed events. Nothing else.

AFAICT, this governor is used with custom kernels making the userspace governor co-existing with another governor on the same thermal zone because there was no notification mechanism.

The new netlink thermal notification is able to provide more information than the userspace governor and give the opportunity to the users of this governor to replace it by a dedicated notification framework.

The userspace governor will be removed as its usage is no longer needed.

Add a warning message to tell the userspace governor is deprecated.

---
 drivers/thermal/gov_user_space.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/thermal/gov_user_space.c +0 -0
index 82a7198bbe71..95d6d3d6b8f7 100644

drivers/thermal/gov_user_space.c line 21

Quoted 7 lines
drivers/thermal/gov_user_space.c +4 -0
@@ -15,6 +15,14 @@
 
 #include "thermal_core.h"
 
+static int user_space_bind(struct thermal_zone_device *tz)
+{
+       WARN(1, "Userspace governor deprecated: use thermal netlink "   \
+            "notification instead\n");

This is really aggressive, because this becomes BUG() in certain kernel configurations.

pr_warn() should be sufficient IMO.

Quoted 15 lines
drivers/thermal/gov_user_space.c +5 -1
+
+       return 0;
+}
+
 /**
  * notify_user_space - Notifies user space about thermal events
  * @tz: thermal_zone_device
@@ -43,5 +51,6 @@ static int notify_user_space(struct thermal_zone_device *tz, int trip)
 static struct thermal_governor thermal_gov_user_space = {
        .name           = "user_space",
        .throttle       = notify_user_space,
+       .bind_to_tz     = user_space_bind,
 };
 THERMAL_GOVERNOR_DECLARE(thermal_gov_user_space);
--
#2 lore raw

Re: [PATCH 2/2] thermal/core: Make deprecated cooling device state change from userspace

In reply to Daniel Lezcano
Quoted 9 lines · Daniel Lezcano

The cooling devices have their cooling device set_cur_state read-writable all the time in the sysfs directory, thus allowing the userspace to act on it.

The thermal framework is wrongly used by userspace as a power capping framework by acting on the cooling device opaque state. This one then competes with the in-kernel governor decision.

Quoted 6 lines

We have seen in out-of-tree kernels, a big number of devices which are abusely declaring themselves as cooling device just to act on their power.

The role of the thermal framework is to protect the junction temperature of the silicon.

It's more than that. You also don't want to let the system's skin temperature get too high, for example.

I would just say that the role of the thermal framework is thermal control.

Quoted 2 lines

Letting the userspace to play with a cooling device is wrong and potentially dangerous.

Agreed, although I would say "invalid" instead of "wrong".

Quoted 19 lines

The powercap framework is the right framework to do power capping and moreover it deals with the aggregation via the dev pm qos.

As the userspace governor is marked deprecated and about to be removed, there is no point to keep this file writable also in the future.

Emit a warning and deprecate the interface.

---
 drivers/thermal/thermal_sysfs.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/thermal/thermal_sysfs.c +0 -0
index 1c4aac8464a7..3f4ea3a283ae 100644

drivers/thermal/thermal_sysfs.c cur_state_store(struct device *dev, struct device_attribute *attr, · line 614

Quoted 5 lines
drivers/thermal/thermal_sysfs.c +2 -0
@@ -610,6 +610,8 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
        unsigned long state;
        int result;
 
+       WARN_ON_ONCE(1, "Setting cooling device state is deprecated\n");
+

I would use pr_warn_once() instead.

Quoted 4 lines
drivers/thermal/thermal_sysfs.c +0 -1
        if (sscanf(buf, "%ld\n", &state) != 1)
                return -EINVAL;
 
--