linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings
@ 2019-12-16 14:06 lukasz.luba
  2019-12-16 14:06 ` [PATCH 1/3] docs: thermal: Add bind, unbind information together with trip point lukasz.luba
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: lukasz.luba @ 2019-12-16 14:06 UTC (permalink / raw)
  To: linux-kernel, rui.zhang, daniel.lezcano, linux-pm, linux-doc
  Cc: amit.kucheria, corbet, lukasz.luba, dietmar.eggemann

From: Lukasz Luba <lukasz.luba@arm.com>

Hi all,

This patch set adds extensions to existing thermal zones and cooling devices
binding. Currently they are pinned using static definitions e.g. DT cooling
maps. These changes enable userspace like trusted middleware to change the
layout of cooling maps unbinding and binding the cooling devices.
It might be helpful for drivers loaded as a modules. They can be added to
existing thermal zones to take part of the power split.
It is based on the current work in thermal branch thermal/linux-next
https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git/log/?h=thermal/linux-next

Regards,
Lukasz Luba

Lukasz Luba (3):
  docs: thermal: Add bind, unbind information together with trip point
  thermal: Make cooling device trip point writable from sysfs
  thermal: Add sysfs binding for cooling device and thermal zone

 .../driver-api/thermal/sysfs-api.rst          | 30 +++++++-
 drivers/thermal/thermal_core.c                |  3 +-
 drivers/thermal/thermal_core.h                |  2 +
 drivers/thermal/thermal_sysfs.c               | 77 +++++++++++++++++++
 4 files changed, 109 insertions(+), 3 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH  1/3] docs: thermal: Add bind, unbind information together with trip point
  2019-12-16 14:06 [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings lukasz.luba
@ 2019-12-16 14:06 ` lukasz.luba
  2019-12-16 14:06 ` [PATCH 2/3] thermal: Make cooling device trip point writable from sysfs lukasz.luba
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: lukasz.luba @ 2019-12-16 14:06 UTC (permalink / raw)
  To: linux-kernel, rui.zhang, daniel.lezcano, linux-pm, linux-doc
  Cc: amit.kucheria, corbet, lukasz.luba, dietmar.eggemann

From: Lukasz Luba <lukasz.luba@arm.com>

Update sysfs interface documentation about new attributes in the cooling
device folder: bind and unbind. It also updates the changed cooling device
associated trip point interface extending it by information about writable
values.

Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
 .../driver-api/thermal/sysfs-api.rst          | 30 +++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/Documentation/driver-api/thermal/sysfs-api.rst b/Documentation/driver-api/thermal/sysfs-api.rst
index b40b1f839148..605f0d9ffe71 100644
--- a/Documentation/driver-api/thermal/sysfs-api.rst
+++ b/Documentation/driver-api/thermal/sysfs-api.rst
@@ -407,6 +407,8 @@ Thermal cooling device sys I/F, created once it's registered::
     |---stats/time_in_state_ms:	Time (msec) spent in various cooling states
     |---stats/total_trans:	Total number of times cooling state is changed
     |---stats/trans_table:	Cooing state transition table
+    |---bind_tz:	Interface for binding cooling device to thermal zone
+    |---unbind_tz:	Interface for unbinding cooling device from thermal zone
 
 
 Then next two dynamic attributes are created/removed in pairs. They represent
@@ -507,9 +509,12 @@ available_policies
 `cdev[0-*]_trip_point`
 	The trip point in this thermal zone which `cdev[0-*]` is associated
 	with; -1 means the cooling device is not associated with any trip
-	point.
+	point. Writing a value (a proper integer) will set new trip point
+	to this cooling device. The value -1 will cause the cooling device
+	is not associated to any trip point and can be unbind from the
+	thermal zone.
 
-	RO, Optional
+	RW, Optional
 
 `cdev[0-*]_weight`
 	The influence of `cdev[0-*]` in this thermal zone. This value
@@ -637,6 +642,27 @@ max_state
 
 	RO, Required
 
+bind_tz
+	Writing the thermal zone name binds this cooling device with the
+	specified thermal zone. A new dynamic attributes 'cdev*' will be
+	created inside the thermal zone directory.
+	The proper thermal zone name can be from read the attribute:
+	/sys/class/thermal/thermal_zone*/type
+	The default (-1) trip point will be set into the cooling instance,
+	which should be updated later using 'cdev*_trip_point' interface.
+
+	WO, Required
+
+unbind_tz
+	Writing the thermal zone name unbinds this cooling device from
+	the specified thermal zone. The cooling instance needs to set -1
+	into the associated cooling device instance 'cdev*_trip_point'
+	first.
+	The proper thermal zone name can be read from the attribute:
+	/sys/class/thermal/thermal_zone*/type
+
+	WO, Required
+
 cur_state
 	The current cooling state of this cooling device.
 	The value can any integer numbers between 0 and max_state:
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH  2/3] thermal: Make cooling device trip point writable from sysfs
  2019-12-16 14:06 [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings lukasz.luba
  2019-12-16 14:06 ` [PATCH 1/3] docs: thermal: Add bind, unbind information together with trip point lukasz.luba
@ 2019-12-16 14:06 ` lukasz.luba
  2019-12-16 14:06 ` [PATCH 3/3] thermal: Add sysfs binding for cooling device and thermal zone lukasz.luba
  2020-03-13 13:33 ` [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings Daniel Lezcano
  3 siblings, 0 replies; 6+ messages in thread
From: lukasz.luba @ 2019-12-16 14:06 UTC (permalink / raw)
  To: linux-kernel, rui.zhang, daniel.lezcano, linux-pm, linux-doc
  Cc: amit.kucheria, corbet, lukasz.luba, dietmar.eggemann

From: Lukasz Luba <lukasz.luba@arm.com>

Make it possible to change trip point for the cooling device instance
in the thermal zone. It would be helpful in case when cooling devices can
by bind to thermal zones using sysfs interface.

A proper trip point can be chosen for a cooling device by:
echo 2 > /sys/class/thermal/thermal_zoneX/cdev_Z_trip_point

It is also possible to unpin cooling device from trip point:
echo -1 > /sys/class/thermal/thermal_zoneX/cdev_Z_trip_point

Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
 drivers/thermal/thermal_core.c  |  3 ++-
 drivers/thermal/thermal_core.h  |  2 ++
 drivers/thermal/thermal_sysfs.c | 20 ++++++++++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 9a321dc548c8..aa66a73e9fa5 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -740,8 +740,9 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
 	sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
 	sysfs_attr_init(&dev->attr.attr);
 	dev->attr.attr.name = dev->attr_name;
-	dev->attr.attr.mode = 0444;
+	dev->attr.attr.mode = 0644;
 	dev->attr.show = trip_point_show;
+	dev->attr.store = trip_point_store;
 	result = device_create_file(&tz->device, &dev->attr);
 	if (result)
 		goto remove_symbol_link;
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index 207b0cda70da..203cc7a63706 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -76,6 +76,8 @@ void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
 void thermal_cooling_device_destroy_sysfs(struct thermal_cooling_device *cdev);
 /* used only at binding time */
 ssize_t trip_point_show(struct device *, struct device_attribute *, char *);
+ssize_t trip_point_store(struct device *, struct device_attribute *,
+			 const char *, size_t);
 ssize_t weight_show(struct device *, struct device_attribute *, char *);
 ssize_t weight_store(struct device *, struct device_attribute *, const char *,
 		     size_t);
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index aa99edb4dff7..80c8bae6dd1c 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -977,6 +977,26 @@ trip_point_show(struct device *dev, struct device_attribute *attr, char *buf)
 		return sprintf(buf, "%d\n", instance->trip);
 }
 
+ssize_t trip_point_store(struct device *dev, struct device_attribute *attr,
+			 const char *buf, size_t count)
+{
+	struct thermal_instance *instance;
+	int ret, trip;
+
+	ret = kstrtoint(buf, 0, &trip);
+	if (ret)
+		return ret;
+
+	instance = container_of(attr, struct thermal_instance, attr);
+
+	if (trip >= instance->tz->trips || trip < THERMAL_TRIPS_NONE)
+		return -EINVAL;
+
+	instance->trip = trip;
+
+	return count;
+}
+
 ssize_t
 weight_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH  3/3] thermal: Add sysfs binding for cooling device and thermal zone
  2019-12-16 14:06 [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings lukasz.luba
  2019-12-16 14:06 ` [PATCH 1/3] docs: thermal: Add bind, unbind information together with trip point lukasz.luba
  2019-12-16 14:06 ` [PATCH 2/3] thermal: Make cooling device trip point writable from sysfs lukasz.luba
@ 2019-12-16 14:06 ` lukasz.luba
  2020-03-13 13:33 ` [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings Daniel Lezcano
  3 siblings, 0 replies; 6+ messages in thread
From: lukasz.luba @ 2019-12-16 14:06 UTC (permalink / raw)
  To: linux-kernel, rui.zhang, daniel.lezcano, linux-pm, linux-doc
  Cc: amit.kucheria, corbet, lukasz.luba, dietmar.eggemann

From: Lukasz Luba <lukasz.luba@arm.com>

Make it possible to bind from userspace a cooling device to an existing
thermal zone. It adds more flexibility in addition to static device tree
definitions. There is also a code for changing trip point connected to
cooling device instance in the thermal zone.

In order to bind a device to a zone, first the proper thermal zone name
must be checked from file:
cat /sys/class/thermal/thermal_zoneX/type
Then that name must be set into cooling device 'bind_tz' file:
echo 'gpu-thermal' > /sys/class/thermal/cooling_deviceY/bind_tz
Next a proper trip point must be chosen for this cooling device:
echo 2 > /sys/class/thermal/thermal_zoneX/cdev_Z_trip_point

To unbind, first set -1 to connected trip point:
echo -1 > /sys/class/thermal/thermal_zoneX/cdev_Z_trip_point
Then unbind the thermal zone from the cooling device:
echo 'gpu-thermal' > /sys/class/thermal/cooling_deviceY/unbind_tz

Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
 drivers/thermal/thermal_sysfs.c | 57 +++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index 80c8bae6dd1c..473449b41d55 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -722,15 +722,72 @@ cur_state_store(struct device *dev, struct device_attribute *attr,
 	return result ? result : count;
 }
 
+static ssize_t
+bind_tz_store(struct device *dev, struct device_attribute *attr,
+		const char *buf, size_t count)
+{
+	struct thermal_cooling_device *cdev = to_cooling_device(dev);
+	struct thermal_zone_device *tz;
+	char *orig, *name;
+	int res = 0;
+
+	orig = kstrndup(buf, count, GFP_KERNEL);
+	if (!orig)
+		return -ENOMEM;
+
+	name = strstrip(orig);
+
+	tz = thermal_zone_get_zone_by_name(name);
+	if (IS_ERR_OR_NULL(tz))
+		return -EINVAL;
+
+	res = thermal_zone_bind_cooling_device(tz, THERMAL_TRIPS_NONE, cdev,
+					       THERMAL_NO_LIMIT,
+					       THERMAL_NO_LIMIT,
+					       THERMAL_WEIGHT_DEFAULT);
+
+	kfree(orig);
+	return res ? res : count;
+}
+
+static ssize_t
+unbind_tz_store(struct device *dev, struct device_attribute *attr,
+		const char *buf, size_t count)
+{
+	struct thermal_cooling_device *cdev = to_cooling_device(dev);
+	struct thermal_zone_device *tz;
+	char *name, *orig;
+	int res = 0;
+
+	orig = kstrndup(buf, count, GFP_KERNEL);
+	if (!orig)
+		return -ENOMEM;
+
+	name = strstrip(orig);
+
+	tz = thermal_zone_get_zone_by_name(name);
+	if (IS_ERR_OR_NULL(tz))
+		return -EINVAL;
+
+	res = thermal_zone_unbind_cooling_device(tz, THERMAL_TRIPS_NONE, cdev);
+
+	kfree(orig);
+	return res ? res : count;
+}
+
 static struct device_attribute
 dev_attr_cdev_type = __ATTR(type, 0444, cdev_type_show, NULL);
 static DEVICE_ATTR_RO(max_state);
 static DEVICE_ATTR_RW(cur_state);
+static DEVICE_ATTR_WO(bind_tz);
+static DEVICE_ATTR_WO(unbind_tz);
 
 static struct attribute *cooling_device_attrs[] = {
 	&dev_attr_cdev_type.attr,
 	&dev_attr_max_state.attr,
 	&dev_attr_cur_state.attr,
+	&dev_attr_bind_tz.attr,
+	&dev_attr_unbind_tz.attr,
 	NULL,
 };
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings
  2019-12-16 14:06 [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings lukasz.luba
                   ` (2 preceding siblings ...)
  2019-12-16 14:06 ` [PATCH 3/3] thermal: Add sysfs binding for cooling device and thermal zone lukasz.luba
@ 2020-03-13 13:33 ` Daniel Lezcano
  2020-03-13 15:28   ` Lukasz Luba
  3 siblings, 1 reply; 6+ messages in thread
From: Daniel Lezcano @ 2020-03-13 13:33 UTC (permalink / raw)
  To: lukasz.luba, linux-kernel, rui.zhang, linux-pm, linux-doc
  Cc: amit.kucheria, corbet, dietmar.eggemann


Hi Lukasz,

On 16/12/2019 15:06, lukasz.luba@arm.com wrote:
> From: Lukasz Luba <lukasz.luba@arm.com>
> 
> Hi all,
> 
> This patch set adds extensions to existing thermal zones and cooling devices
> binding. Currently they are pinned using static definitions e.g. DT cooling
> maps. These changes enable userspace like trusted middleware to change the
> layout of cooling maps unbinding and binding the cooling devices.
> It might be helpful for drivers loaded as a modules. They can be added to
> existing thermal zones to take part of the power split.
> It is based on the current work in thermal branch thermal/linux-next
> https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git/log/?h=thermal/linux-next

I've been keeping this series out of the previous merge because it did
not raise any comments and we are touching the sysfs.

For this release, I still don't know what to do with it.

Anyone a comment on this series? Rui ?

> Lukasz Luba (3):
>   docs: thermal: Add bind, unbind information together with trip point
>   thermal: Make cooling device trip point writable from sysfs
>   thermal: Add sysfs binding for cooling device and thermal zone
> 
>  .../driver-api/thermal/sysfs-api.rst          | 30 +++++++-
>  drivers/thermal/thermal_core.c                |  3 +-
>  drivers/thermal/thermal_core.h                |  2 +
>  drivers/thermal/thermal_sysfs.c               | 77 +++++++++++++++++++
>  4 files changed, 109 insertions(+), 3 deletions(-)
> 


-- 
 <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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings
  2020-03-13 13:33 ` [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings Daniel Lezcano
@ 2020-03-13 15:28   ` Lukasz Luba
  0 siblings, 0 replies; 6+ messages in thread
From: Lukasz Luba @ 2020-03-13 15:28 UTC (permalink / raw)
  To: Daniel Lezcano, linux-kernel, rui.zhang, linux-pm, linux-doc
  Cc: amit.kucheria, corbet, dietmar.eggemann

Hi Daniel,

On 3/13/20 1:33 PM, Daniel Lezcano wrote:
> 
> Hi Lukasz,
> 
> On 16/12/2019 15:06, lukasz.luba@arm.com wrote:
>> From: Lukasz Luba <lukasz.luba@arm.com>
>>
>> Hi all,
>>
>> This patch set adds extensions to existing thermal zones and cooling devices
>> binding. Currently they are pinned using static definitions e.g. DT cooling
>> maps. These changes enable userspace like trusted middleware to change the
>> layout of cooling maps unbinding and binding the cooling devices.
>> It might be helpful for drivers loaded as a modules. They can be added to
>> existing thermal zones to take part of the power split.
>> It is based on the current work in thermal branch thermal/linux-next
>> https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git/log/?h=thermal/linux-next
> 
> I've been keeping this series out of the previous merge because it did
> not raise any comments and we are touching the sysfs.
> 
> For this release, I still don't know what to do with it.

Thank you for bringing this back.

> 
> Anyone a comment on this series? Rui ?
> 

Regards,
Lukasz

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-03-13 15:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-16 14:06 [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings lukasz.luba
2019-12-16 14:06 ` [PATCH 1/3] docs: thermal: Add bind, unbind information together with trip point lukasz.luba
2019-12-16 14:06 ` [PATCH 2/3] thermal: Make cooling device trip point writable from sysfs lukasz.luba
2019-12-16 14:06 ` [PATCH 3/3] thermal: Add sysfs binding for cooling device and thermal zone lukasz.luba
2020-03-13 13:33 ` [PATCH 0/3] Thermal extensions for flexibility in cooling device bindings Daniel Lezcano
2020-03-13 15:28   ` Lukasz Luba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).