lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191216140622.25467-4-lukasz.luba@arm.com>
Date:   Mon, 16 Dec 2019 14:06:22 +0000
From:   lukasz.luba@....com
To:     linux-kernel@...r.kernel.org, rui.zhang@...el.com,
        daniel.lezcano@...aro.org, linux-pm@...r.kernel.org,
        linux-doc@...r.kernel.org
Cc:     amit.kucheria@...durent.com, corbet@....net, lukasz.luba@....com,
        dietmar.eggemann@....com
Subject: [PATCH  3/3] thermal: Add sysfs binding for cooling device and thermal zone

From: Lukasz Luba <lukasz.luba@....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@....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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ