Skip to contentSkip to conversation

thermal: Default OF created trip points to writable

PATCH In review Punit Agrawal 3 participants 10 messages Feb 10, 2015 – Feb 26, 2015 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: Default OF created trip points to writable

When registering a thermal zone from device tree, default the trip points to writable. By default, only the root user can change these.

This allows the trip points to be tweaked after the system has booted.

---
Hi Eduardo,

We've been using this patch internally and haven't run into any
issues. Without these changes there is no way to change trip points from a running system.

Comments welcome.

Cheers,
Punit

 drivers/thermal/of-thermal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/thermal/of-thermal.c +5 -1
index 668fb1b..b7ad5c0 100644
@@ -865,6 +865,7 @@ int __init of_parse_thermal_zones(void)
 	for_each_child_of_node(np, child) {
 		struct thermal_zone_device *zone;
 		struct thermal_zone_params *tzp;
+		int i, mask = 0;
 
 		/* Check whether child is enabled or not */
 		if (!of_device_is_available(child))
@@ -891,8 +892,11 @@ int __init of_parse_thermal_zones(void)
 		/* No hwmon because there might be hwmon drivers registering */
 		tzp->no_hwmon = true;
 
+		for (i = 0; i < tz->ntrips; i++)
+			mask |= 1 << i;
+
 		zone = thermal_zone_device_register(child->name, tz->ntrips,
-						    0, tz,
+						    mask, tz,
 						    ops, tzp,
 						    tz->passive_delay,
 						    tz->polling_delay);
Signature · 1 line
2.1.4
#1 lore raw

Hey Punit,

Quoted 5 lines · Punit Agrawal

When registering a thermal zone from device tree, default the trip points to writable. By default, only the root user can change these.

This allows the trip points to be tweaked after the system has booted.

Can you please elaborate more on why having default writable makes sense against having default read only? The purpose of this patch seams to be targeted to development/debugging systems, not productions systems. The default has to make sense for production systems.

Quoted 8 lines

---
Hi Eduardo,

We've been using this patch internally and haven't run into any
issues. Without these changes there is no way to change trip points from a running system.

Ok. I see.

So, the problem statement here is to be able to change the trip points from a running system. What is the purpose? Do you have something in userland that is benefiting of having these trips writable? Or is it just for development fun?

BR,

Eduardo Valentin

Quoted 37 lines

Comments welcome.

Cheers,
Punit

 drivers/thermal/of-thermal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/thermal/of-thermal.c +5 -1
index 668fb1b..b7ad5c0 100644
@@ -865,6 +865,7 @@ int __init of_parse_thermal_zones(void)
 	for_each_child_of_node(np, child) {
 		struct thermal_zone_device *zone;
 		struct thermal_zone_params *tzp;
+		int i, mask = 0;
 
 		/* Check whether child is enabled or not */
 		if (!of_device_is_available(child))
@@ -891,8 +892,11 @@ int __init of_parse_thermal_zones(void)
 		/* No hwmon because there might be hwmon drivers registering */
 		tzp->no_hwmon = true;
 
+		for (i = 0; i < tz->ntrips; i++)
+			mask |= 1 << i;
+
 		zone = thermal_zone_device_register(child->name, tz->ntrips,
-						    0, tz,
+						    mask, tz,
 						    ops, tzp,
 						    tz->passive_delay,
 						    tz->polling_delay);
Signature · 1 line
2.1.4
#2 lore raw
Quoted 6 lines · Eduardo Valentin

Hey Punit,

Quoted 3 lines · Punit Agrawal

When registering a thermal zone from device tree, default the trip points to writable. By default, only the root user can change these.

Quoted 7 lines
Quoted 2 lines

This allows the trip points to be tweaked after the system has booted.

Can you please elaborate more on why having default writable makes sense against having default read only? The purpose of this patch seams to be targeted to development/debugging systems, not productions systems. The default has to make sense for production systems.

Agreed about the default making sense for production systems.

We've seen deployments in the field where the default value of the trip temperatures are modulated by a userspace component that has contextual knowledge about workloads and device margins. Using OF for thermal setup, it is not possible to get this functionality.

I guess you are worried about safety - as you still need root privileges to be able to change the trip temperatures so it's not by-passing the security setup of the system.

Quoted 10 lines
Quoted 9 lines

---
Hi Eduardo,

We've been using this patch internally and haven't run into any
issues. Without these changes there is no way to change trip points from a running system.

Quoted 6 lines

Ok. I see.

So, the problem statement here is to be able to change the trip points from a running system. What is the purpose? Do you have something in userland that is benefiting of having these trips writable? Or is it just for development fun?

Sure it helps with development too. In a workflow where the development of the drivers and the tuning are separate activities, and not necessarily done by the same people, it is very helpful to be able to evaluate different parameters for power-performance-thermal tuning without having to rebuild the dtb and reboot the system.

I think it makes it easier for folks to get up and running with OF and thermals. But I'll defer to your judgement here.

Cheers,
Punit

Quoted 43 lines

BR,

Eduardo Valentin

Quoted 37 lines

Comments welcome.

Cheers,
Punit

 drivers/thermal/of-thermal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/thermal/of-thermal.c +5 -1
index 668fb1b..b7ad5c0 100644
@@ -865,6 +865,7 @@ int __init of_parse_thermal_zones(void)
 	for_each_child_of_node(np, child) {
 		struct thermal_zone_device *zone;
 		struct thermal_zone_params *tzp;
+		int i, mask = 0;
 
 		/* Check whether child is enabled or not */
 		if (!of_device_is_available(child))
@@ -891,8 +892,11 @@ int __init of_parse_thermal_zones(void)
 		/* No hwmon because there might be hwmon drivers registering */
 		tzp->no_hwmon = true;
 
+		for (i = 0; i < tz->ntrips; i++)
+			mask |= 1 << i;
+
 		zone = thermal_zone_device_register(child->name, tz->ntrips,
-						    0, tz,
+						    mask, tz,
 						    ops, tzp,
 						    tz->passive_delay,
 						    tz->polling_delay);
Signature · 1 line
2.1.4
#3 lore raw
Quoted 44 lines · Punit Agrawal
Quoted 6 lines · Eduardo Valentin

Hey Punit,

Quoted 3 lines · Punit Agrawal

When registering a thermal zone from device tree, default the trip points to writable. By default, only the root user can change these.

Quoted 7 lines
Quoted 2 lines

This allows the trip points to be tweaked after the system has booted.

Can you please elaborate more on why having default writable makes sense against having default read only? The purpose of this patch seams to be targeted to development/debugging systems, not productions systems. The default has to make sense for production systems.

Agreed about the default making sense for production systems.

We've seen deployments in the field where the default value of the trip temperatures are modulated by a userspace component that has contextual knowledge about workloads and device margins. Using OF for thermal setup, it is not possible to get this functionality.

I guess you are worried about safety - as you still need root privileges to be able to change the trip temperatures so it's not by-passing the security setup of the system.

Quoted 10 lines
Quoted 9 lines

---
Hi Eduardo,

We've been using this patch internally and haven't run into any
issues. Without these changes there is no way to change trip points from a running system.

Quoted 6 lines

Ok. I see.

So, the problem statement here is to be able to change the trip points from a running system. What is the purpose? Do you have something in userland that is benefiting of having these trips writable? Or is it just for development fun?

Quoted 8 lines

Sure it helps with development too. In a workflow where the development of the drivers and the tuning are separate activities, and not necessarily done by the same people, it is very helpful to be able to evaluate different parameters for power-performance-thermal tuning without having to rebuild the dtb and reboot the system.

I think it makes it easier for folks to get up and running with OF and thermals. But I'll defer to your judgement here.

Punit,

I understand your concerns and thoughts. Let me make a counterproposal. Instead of making the trip points populated by of-thermal writable by default, how about if we do the following?

(1) - Change thermal core to have a Kconfig option to allow system integrator to choose if trip points are writable or not. So, on top of the mask index flags for each trip, the Kconfig must be enabled at compilation time. If the Kconfig option is disable, no trip points will get write access, regardless the mask provided by the thermal drivers. Here, I would prefer to have the default behavior as readonly.

(2) - Change of-thermal to provide writable trip points by default (essentially, this present patch).

Although no changes in this patch are required, I would prefer to merge first number (1) above.

In this way, we allow an option to system engineers that do not want user space to mess with their kernel thermal policy. And we also allow people who has userspace thermal policy to work properly. And, by grant, we have an option to make development easier.

What is your optionion?

I am copying Srinivas here too. Srinivas, do you think that option (1) above will break things in userspace on your side?

Quoted 47 lines

Cheers,
Punit

Quoted 43 lines

BR,

Eduardo Valentin

Quoted 37 lines

Comments welcome.

Cheers,
Punit

 drivers/thermal/of-thermal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/thermal/of-thermal.c +5 -1
index 668fb1b..b7ad5c0 100644
@@ -865,6 +865,7 @@ int __init of_parse_thermal_zones(void)
 	for_each_child_of_node(np, child) {
 		struct thermal_zone_device *zone;
 		struct thermal_zone_params *tzp;
+		int i, mask = 0;
 
 		/* Check whether child is enabled or not */
 		if (!of_device_is_available(child))
@@ -891,8 +892,11 @@ int __init of_parse_thermal_zones(void)
 		/* No hwmon because there might be hwmon drivers registering */
 		tzp->no_hwmon = true;
 
+		for (i = 0; i < tz->ntrips; i++)
+			mask |= 1 << i;
+
 		zone = thermal_zone_device_register(child->name, tz->ntrips,
-						    0, tz,
+						    mask, tz,
 						    ops, tzp,
 						    tz->passive_delay,
 						    tz->polling_delay);
Signature · 1 line
2.1.4
#4 lore raw
Quoted 74 lines · Eduardo Valentin
Quoted 44 lines · Punit Agrawal
Quoted 6 lines · Eduardo Valentin

Hey Punit,

Quoted 3 lines · Punit Agrawal

When registering a thermal zone from device tree, default the trip points to writable. By default, only the root user can change these.

Quoted 7 lines
Quoted 2 lines

This allows the trip points to be tweaked after the system has booted.

Can you please elaborate more on why having default writable makes sense against having default read only? The purpose of this patch seams to be targeted to development/debugging systems, not productions systems. The default has to make sense for production systems.

Agreed about the default making sense for production systems.

We've seen deployments in the field where the default value of the trip temperatures are modulated by a userspace component that has contextual knowledge about workloads and device margins. Using OF for thermal setup, it is not possible to get this functionality.

I guess you are worried about safety - as you still need root privileges to be able to change the trip temperatures so it's not by-passing the security setup of the system.

Quoted 10 lines
Quoted 9 lines

---
Hi Eduardo,

We've been using this patch internally and haven't run into any
issues. Without these changes there is no way to change trip points from a running system.

Quoted 6 lines

Ok. I see.

So, the problem statement here is to be able to change the trip points from a running system. What is the purpose? Do you have something in userland that is benefiting of having these trips writable? Or is it just for development fun?

Quoted 8 lines

Sure it helps with development too. In a workflow where the development of the drivers and the tuning are separate activities, and not necessarily done by the same people, it is very helpful to be able to evaluate different parameters for power-performance-thermal tuning without having to rebuild the dtb and reboot the system.

I think it makes it easier for folks to get up and running with OF and thermals. But I'll defer to your judgement here.

Punit,

I understand your concerns and thoughts. Let me make a counterproposal. Instead of making the trip points populated by of-thermal writable by default, how about if we do the following?

(1) - Change thermal core to have a Kconfig option to allow system integrator to choose if trip points are writable or not. So, on top of the mask index flags for each trip, the Kconfig must be enabled at compilation time. If the Kconfig option is disable, no trip points will get write access, regardless the mask provided by the thermal drivers. Here, I would prefer to have the default behavior as readonly.

(2) - Change of-thermal to provide writable trip points by default (essentially, this present patch).

Although no changes in this patch are required, I would prefer to merge first number (1) above.

Quoted 6 lines

In this way, we allow an option to system engineers that do not want user space to mess with their kernel thermal policy. And we also allow people who has userspace thermal policy to work properly. And, by grant, we have an option to make development easier.

What is your optionion?

Although I understand your motivation for suggesting (1), I am not sure this will work in practice. As soon as one platform enables the option in the defconfig (arm64) or multi_v7_defconfig (arm), all platforms will have it enabled.

But if you think it's worth merging, something like below should do it.

Quoted 20 lines

I am copying Srinivas here too. Srinivas, do you think that option (1) above will break things in userspace on your side?

Quoted 16 lines

Cheers,
Punit

Quoted 12 lines

BR,

Eduardo Valentin

Quoted 6 lines

Comments welcome.

Cheers,
Punit

-- >8 --

Subject: [PATCH] thermal: core: Add Kconfig option to enable writable trips

Add a Kconfig option to allow system integrators to control whether userspace tools can change trip temperatures. This option overrides the thermal zone setup in the driver code and must be enabled for platform specified writable trips to come into effect.

The original behaviour of requiring root privileges to change trip temperatures remains unchanged.

---
 drivers/thermal/Kconfig        | 11 +++++++++++
 drivers/thermal/thermal_core.c |  3 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/thermal/Kconfig +11 -0
index af40db0..5d2d39b 100644
@@ -42,6 +42,17 @@ config THERMAL_OF
 	  Say 'Y' here if you need to build thermal infrastructure
 	  based on device tree.
 
+config THERMAL_WRITABLE_TRIPS
+	bool "Enable writable trip points"
+	help
+	  This option allows the system integrator to choose whether
+	  trip temperatures can be changed from userspace. The
+	  writable trips need to be specified when setting up the
+	  thermal zone but the choice here takes precedence.
+
+	  Say 'Y' here if you would like to allow userspace tools to
+	  change trip temperatures.
+
 choice
 	prompt "Default Thermal governor"
 	default THERMAL_DEFAULT_GOV_STEP_WISE
drivers/thermal/thermal_core.c +2 -1
index 48491d1..15111c1 100644
@@ -1378,7 +1378,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 						tz->trip_temp_attrs[indx].name;
 		tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO;
 		tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show;
-		if (mask & (1 << indx)) {
+		if (IS_ENABLED(CONFIG_THERMAL_WRITABLE_TRIPS) &&
+		    mask & (1 << indx)) {
 			tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR;
 			tz->trip_temp_attrs[indx].attr.store =
 							trip_point_temp_store;
Signature · 1 line
2.1.4
#7 lore raw
In reply to Eduardo Valentin
Quoted 61 lines · Eduardo Valentin
Quoted 44 lines · Punit Agrawal
Quoted 6 lines · Eduardo Valentin

Hey Punit,

Quoted 3 lines · Punit Agrawal

When registering a thermal zone from device tree, default the trip points to writable. By default, only the root user can change these.

Quoted 7 lines
Quoted 2 lines

This allows the trip points to be tweaked after the system has booted.

Can you please elaborate more on why having default writable makes sense against having default read only? The purpose of this patch seams to be targeted to development/debugging systems, not productions systems. The default has to make sense for production systems.

Agreed about the default making sense for production systems.

We've seen deployments in the field where the default value of the trip temperatures are modulated by a userspace component that has contextual knowledge about workloads and device margins. Using OF for thermal setup, it is not possible to get this functionality.

I guess you are worried about safety - as you still need root privileges to be able to change the trip temperatures so it's not by-passing the security setup of the system.

Quoted 10 lines
Quoted 9 lines

---
Hi Eduardo,

We've been using this patch internally and haven't run into any
issues. Without these changes there is no way to change trip points from a running system.

Quoted 6 lines

Ok. I see.

So, the problem statement here is to be able to change the trip points from a running system. What is the purpose? Do you have something in userland that is benefiting of having these trips writable? Or is it just for development fun?

Quoted 8 lines

Sure it helps with development too. In a workflow where the development of the drivers and the tuning are separate activities, and not necessarily done by the same people, it is very helpful to be able to evaluate different parameters for power-performance-thermal tuning without having to rebuild the dtb and reboot the system.

I think it makes it easier for folks to get up and running with OF and thermals. But I'll defer to your judgement here.

Punit,

I understand your concerns and thoughts. Let me make a counterproposal. Instead of making the trip points populated by of-thermal writable by default, how about if we do the following?

Quoted 6 lines

(1) - Change thermal core to have a Kconfig option to allow system integrator to choose if trip points are writable or not. So, on top of the mask index flags for each trip, the Kconfig must be enabled at compilation time. If the Kconfig option is disable, no trip points will get write access, regardless the mask provided by the thermal drivers. Here, I would prefer to have the default behavior as readonly.

On x86 system the parameters provided through ACPI, shouldn't be modified, as this voids warranty from manufacturer and will not pass security review. So they have to be read only.

Quoted 3 lines

(2) - Change of-thermal to provide writable trip points by default (essentially, this present patch).

I understand this change is only for tuning trip point. May be you should use debugfs to specify +/- offsets from default trip. In one of my driver I provided debugfs to specify offset from trip for tuning. Once tuned the ACPI config can change to reflect correct settings.

Quoted 9 lines

Al though no changes in this patch are required, I would prefer to merge first number (1) above.

In this way, we allow an option to system engineers that do not want user space to mess with their kernel thermal policy. And we also allow people who has userspace thermal policy to work properly. And, by grant, we have an option to make development easier.

Quoted 4 lines

What is your optionion?

I am copying Srinivas here too. Srinivas, do you think that option (1) above will break things in userspace on your side?

I am not sure distros like ubuntu starts Linux Thermal Daemon on ARM systems. This has option to take over thermal control from kernel by changing governor to user space. I take writable trips as a way to get threshold temp notification for users space governor by setting offset from a read only passive/active/critical trips. This way we get notified before, to monitor an do proactive control. For example if there is a critical trip at X, take action at X-a to avoid shutdown. Thanks,
Srinivas

Quoted 48 lines
Quoted 48 lines

Cheers,
Punit

Quoted 43 lines

BR,

Eduardo Valentin

Quoted 37 lines

Comments welcome.

Cheers,
Punit

 drivers/thermal/of-thermal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/thermal/of-thermal.c +5 -1
index 668fb1b..b7ad5c0 100644
@@ -865,6 +865,7 @@ int __init of_parse_thermal_zones(void)
 	for_each_child_of_node(np, child) {
 		struct thermal_zone_device *zone;
 		struct thermal_zone_params *tzp;
+		int i, mask = 0;
 
 		/* Check whether child is enabled or not */
 		if (!of_device_is_available(child))
@@ -891,8 +892,11 @@ int __init of_parse_thermal_zones(void)
 		/* No hwmon because there might be hwmon drivers registering */
 		tzp->no_hwmon = true;
 
+		for (i = 0; i < tz->ntrips; i++)
+			mask |= 1 << i;
+
 		zone = thermal_zone_device_register(child->name, tz->ntrips,
-						    0, tz,
+						    mask, tz,
 						    ops, tzp,
 						    tz->passive_delay,
 						    tz->polling_delay);
Signature · 1 line
2.1.4
#5 lore raw
In reply to Punit Agrawal

Punit,

Quoted 2 lines · Punit Agrawal

Eduardo Valentin <[email protected]> writes:

<cut>

Quoted 6 lines
Quoted 1 line

What is your optionion?

Although I understand your motivation for suggesting (1), I am not sure this will work in practice. As soon as one platform enables the option in the defconfig (arm64) or multi_v7_defconfig (arm), all platforms will have it enabled.

Well, just because it is enabled by default, it does not mean that everybody has to follow what is in defconfig. In practice, when building production kernels, defconfigs are changed.

My concern now is more about allowing people to have the possibility to change the expected behavior. Only with the original patch, it will always be writable.

Quoted 33 lines

But if you think it's worth merging, something like below should do it.

Quoted 20 lines

I am copying Srinivas here too. Srinivas, do you think that option (1) above will break things in userspace on your side?

Quoted 16 lines

Cheers,
Punit

Quoted 12 lines

BR,

Eduardo Valentin

Quoted 6 lines

Comments welcome.

Cheers,
Punit

-- >8 --

Subject: [PATCH] thermal: core: Add Kconfig option to enable writable trips

Add a Kconfig option to allow system integrators to control whether userspace tools can change trip temperatures. This option overrides the thermal zone setup in the driver code and must be enabled for platform specified writable trips to come into effect.

Quoted 4 lines

The original behaviour of requiring root privileges to change trip temperatures remains unchanged.

Yes, something like this is what I was suggesting.

Thanks.

Quoted 43 lines
---
 drivers/thermal/Kconfig        | 11 +++++++++++
 drivers/thermal/thermal_core.c |  3 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/thermal/Kconfig +11 -0
index af40db0..5d2d39b 100644
@@ -42,6 +42,17 @@ config THERMAL_OF
 	  Say 'Y' here if you need to build thermal infrastructure
 	  based on device tree.
 
+config THERMAL_WRITABLE_TRIPS
+	bool "Enable writable trip points"
+	help
+	  This option allows the system integrator to choose whether
+	  trip temperatures can be changed from userspace. The
+	  writable trips need to be specified when setting up the
+	  thermal zone but the choice here takes precedence.
+
+	  Say 'Y' here if you would like to allow userspace tools to
+	  change trip temperatures.
+
 choice
 	prompt "Default Thermal governor"
 	default THERMAL_DEFAULT_GOV_STEP_WISE
drivers/thermal/thermal_core.c +2 -1
index 48491d1..15111c1 100644
@@ -1378,7 +1378,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 						tz->trip_temp_attrs[indx].name;
 		tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO;
 		tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show;
-		if (mask & (1 << indx)) {
+		if (IS_ENABLED(CONFIG_THERMAL_WRITABLE_TRIPS) &&
+		    mask & (1 << indx)) {
 			tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR;
 			tz->trip_temp_attrs[indx].attr.store =
 							trip_point_temp_store;
Signature · 1 line
2.1.4
#8 lore raw
In reply to Srinivas Pandruvada

Srinivas,

Quoted 10 lines
Quoted 3 lines

I am copying Srinivas here too. Srinivas, do you think that option (1) above will break things in userspace on your side?

I am not sure distros like ubuntu starts Linux Thermal Daemon on ARM systems. This has option to take over thermal control from kernel by changing governor to user space. I take writable trips as a way to get threshold temp notification for users space governor by setting offset from a read only passive/active/critical trips. This way we get notified before, to monitor an do proactive control. For example if there is a critical trip at X, take action at X-a to avoid shutdown.

Let me ask differently. If the trip points are read only, would the daemon still work?

If not, the change needs to make writable in x86 builds, right?

BR,

Quoted 52 lines

Thanks,
Srinivas

Quoted 48 lines
Quoted 48 lines

Cheers,
Punit

Quoted 43 lines

BR,

Eduardo Valentin

Quoted 37 lines

Comments welcome.

Cheers,
Punit

 drivers/thermal/of-thermal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/thermal/of-thermal.c +5 -1
index 668fb1b..b7ad5c0 100644
@@ -865,6 +865,7 @@ int __init of_parse_thermal_zones(void)
 	for_each_child_of_node(np, child) {
 		struct thermal_zone_device *zone;
 		struct thermal_zone_params *tzp;
+		int i, mask = 0;
 
 		/* Check whether child is enabled or not */
 		if (!of_device_is_available(child))
@@ -891,8 +892,11 @@ int __init of_parse_thermal_zones(void)
 		/* No hwmon because there might be hwmon drivers registering */
 		tzp->no_hwmon = true;
 
+		for (i = 0; i < tz->ntrips; i++)
+			mask |= 1 << i;
+
 		zone = thermal_zone_device_register(child->name, tz->ntrips,
-						    0, tz,
+						    mask, tz,
 						    ops, tzp,
 						    tz->passive_delay,
 						    tz->polling_delay);
Signature · 1 line
2.1.4
#9 lore raw

Hi Eduardo,

Quoted 13 lines · Eduardo Valentin

Srinivas,

Quoted 10 lines
Quoted 3 lines

I am copying Srinivas here too. Srinivas, do you think that option (1) above will break things in userspace on your side?

I am not sure distros like ubuntu starts Linux Thermal Daemon on ARM systems. This has option to take over thermal control from kernel by changing governor to user space. I take writable trips as a way to get threshold temp notification for users space governor by setting offset from a read only passive/active/critical trips. This way we get notified before, to monitor an do proactive control. For example if there is a critical trip at X, take action at X-a to avoid shutdown.

Quoted 2 lines

Let me ask differently. If the trip points are read only, would the daemon still work?

Yes.

Thanks,
Srinivas

Quoted 57 lines

If not, the change needs to make writable in x86 builds, right?

BR,

Quoted 52 lines

Thanks,
Srinivas

Quoted 48 lines
Quoted 48 lines

Cheers,
Punit

Quoted 43 lines

BR,

Eduardo Valentin

Quoted 37 lines

Comments welcome.

Cheers,
Punit

 drivers/thermal/of-thermal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/thermal/of-thermal.c +5 -1
index 668fb1b..b7ad5c0 100644
@@ -865,6 +865,7 @@ int __init of_parse_thermal_zones(void)
 	for_each_child_of_node(np, child) {
 		struct thermal_zone_device *zone;
 		struct thermal_zone_params *tzp;
+		int i, mask = 0;
 
 		/* Check whether child is enabled or not */
 		if (!of_device_is_available(child))
@@ -891,8 +892,11 @@ int __init of_parse_thermal_zones(void)
 		/* No hwmon because there might be hwmon drivers registering */
 		tzp->no_hwmon = true;
 
+		for (i = 0; i < tz->ntrips; i++)
+			mask |= 1 << i;
+
 		zone = thermal_zone_device_register(child->name, tz->ntrips,
-						    0, tz,
+						    mask, tz,
 						    ops, tzp,
 						    tz->passive_delay,
 						    tz->polling_delay);
Signature · 1 line
2.1.4
#6 lore raw
In reply to Eduardo Valentin
Quoted 15 lines · Eduardo Valentin

Punit,

Quoted 2 lines · Punit Agrawal

Eduardo Valentin <[email protected]> writes:

<cut>

Quoted 6 lines
Quoted 1 line

What is your optionion?

Although I understand your motivation for suggesting (1), I am not sure this will work in practice. As soon as one platform enables the option in the defconfig (arm64) or multi_v7_defconfig (arm), all platforms will have it enabled.

Quoted 7 lines

Well, just because it is enabled by default, it does not mean that everybody has to follow what is in defconfig. In practice, when building production kernels, defconfigs are changed.

My concern now is more about allowing people to have the possibility to change the expected behavior. Only with the original patch, it will always be writable.

Makes sense. With the patch below, where required the Kconfig can be turned off.

[...]

Quoted 10 lines
Quoted 10 lines

-- >8 --

Subject: [PATCH] thermal: core: Add Kconfig option to enable writable trips

Add a Kconfig option to allow system integrators to control whether userspace tools can change trip temperatures. This option overrides the thermal zone setup in the driver code and must be enabled for platform specified writable trips to come into effect.

Quoted 6 lines
Quoted 4 lines

The original behaviour of requiring root privileges to change trip temperatures remains unchanged.

Yes, something like this is what I was suggesting.

Can you pick it up from here, or do you prefer for me to re-send the two patches?

Cheers,
Punit

Quoted 47 lines

Thanks.

Quoted 43 lines
---
 drivers/thermal/Kconfig        | 11 +++++++++++
 drivers/thermal/thermal_core.c |  3 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/thermal/Kconfig +11 -0
index af40db0..5d2d39b 100644
@@ -42,6 +42,17 @@ config THERMAL_OF
 	  Say 'Y' here if you need to build thermal infrastructure
 	  based on device tree.
 
+config THERMAL_WRITABLE_TRIPS
+	bool "Enable writable trip points"
+	help
+	  This option allows the system integrator to choose whether
+	  trip temperatures can be changed from userspace. The
+	  writable trips need to be specified when setting up the
+	  thermal zone but the choice here takes precedence.
+
+	  Say 'Y' here if you would like to allow userspace tools to
+	  change trip temperatures.
+
 choice
 	prompt "Default Thermal governor"
 	default THERMAL_DEFAULT_GOV_STEP_WISE
drivers/thermal/thermal_core.c +2 -1
index 48491d1..15111c1 100644
@@ -1378,7 +1378,8 @@ static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
 						tz->trip_temp_attrs[indx].name;
 		tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO;
 		tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show;
-		if (mask & (1 << indx)) {
+		if (IS_ENABLED(CONFIG_THERMAL_WRITABLE_TRIPS) &&
+		    mask & (1 << indx)) {
 			tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR;
 			tz->trip_temp_attrs[indx].attr.store =
 							trip_point_temp_store;
Signature · 1 line
2.1.4