Linux Documentation
 help / color / mirror / Atom feed
From: Kevin DuBois <kevindubois@google.com>
To: linux-pm@vger.kernel.org, linux-doc@vger.kernel.org,
	corbet@lwn.net, rui.zhang@intel.com, edubezval@gmail.com,
	kevindubois@google.com
Subject: [PATCH] thermal: core: fix emulation of subzero temps
Date: Mon, 23 Apr 2018 10:53:40 -0700	[thread overview]
Message-ID: <20180423175340.32598-1-kevindubois@google.com> (raw)

The current implementation casted away its sign.
It was also using '0' to disable emulation, but 0C is a valid
thermal reading. A large negative value (below absolute zero) now
disables the emulation.

Test: Build kernel with CONFIG_THERMAL_EMULATION=y, then write negative
values to the emul_temp sysfs entry. Check the temp entry, and see the
negative value. Write -INT_MAX to emul_temp, and see the proper sensor
reading appear.
Bug: 77599739
Signed-off-by: Kevin DuBois <kevindubois@google.com>

Change-Id: Iee1a4f0aacf7b4299b67c7f8f4effedf2d7a8425
---
 Documentation/thermal/sysfs-api.txt |  2 +-
 drivers/thermal/thermal_core.c      | 13 ++++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt
index 10f062ea6bc2..e240d9e165a0 100644
--- a/Documentation/thermal/sysfs-api.txt
+++ b/Documentation/thermal/sysfs-api.txt
@@ -312,7 +312,7 @@ emul_temp
 	this temperature to platform emulation function if registered or
 	cache it locally. This is useful in debugging different temperature
 	threshold and its associated cooling action. This is write only node
-	and writing 0 on this node should disable emulation.
+	and writing -INT_MAX on this node should disable emulation.
 	Unit: millidegree Celsius
 	WO, Optional
 
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 768783ab3dac..650a6b124fc7 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -636,8 +636,8 @@ int get_tz_trend(struct thermal_zone_device *tz, int trip)
 {
 	enum thermal_trend trend;
 
-	if (tz->emul_temperature || !tz->ops->get_trend ||
-	    tz->ops->get_trend(tz, trip, &trend)) {
+	if ((tz->emul_temperature > THERMAL_TEMP_INVALID) ||
+		!tz->ops->get_trend || tz->ops->get_trend(tz, trip, &trend)) {
 		if (tz->temperature > tz->last_temperature)
 			trend = THERMAL_TREND_RAISING;
 		else if (tz->temperature < tz->last_temperature)
@@ -904,7 +904,8 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
 
 	ret = tz->ops->get_temp(tz, temp);
 
-	if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) {
+	if (IS_ENABLED(CONFIG_THERMAL_EMULATION) &&
+		(tz->emul_temperature > THERMAL_TEMP_INVALID)) {
 		for (count = 0; count < tz->trips; count++) {
 			ret = tz->ops->get_trip_type(tz, count, &type);
 			if (!ret && type == THERMAL_TRIP_CRITICAL) {
@@ -961,6 +962,7 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz)
 	struct thermal_instance *pos;
 
 	tz->temperature = THERMAL_TEMP_INVALID;
+	tz->emul_temperature = THERMAL_TEMP_INVALID;
 	tz->passive = 0;
 	list_for_each_entry(pos, &tz->thermal_instances, tz_node)
 		pos->initialized = false;
@@ -1351,9 +1353,9 @@ emul_temp_store(struct device *dev, struct device_attribute *attr,
 {
 	struct thermal_zone_device *tz = to_thermal_zone(dev);
 	int ret = 0;
-	unsigned long temperature;
+	int temperature;
 
-	if (kstrtoul(buf, 10, &temperature))
+	if (kstrtoint(buf, 10, &temperature))
 		return -EINVAL;
 
 	if (!tz->ops->set_emul_temp) {
@@ -2296,6 +2298,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
 	tz->trips = trips;
 	tz->passive_delay = passive_delay;
 	tz->polling_delay = polling_delay;
+	tz->emul_temperature = THERMAL_TEMP_INVALID;
 	/* A new thermal zone needs to be updated anyway. */
 	atomic_set(&tz->need_update, 1);
 
-- 
2.17.0.484.g0c8726318c-goog

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2018-04-23 17:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-23 17:53 Kevin DuBois [this message]
2018-04-24 13:01 ` [PATCH] thermal: core: fix emulation of subzero temps Zhang Rui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180423175340.32598-1-kevindubois@google.com \
    --to=kevindubois@google.com \
    --cc=corbet@lwn.net \
    --cc=edubezval@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox