Skip to contentSkip to conversation

thermal: core: fix emulation of subzero temps

PATCH In review Kevin DuBois 2 participants 2 messages Apr 23, 2018 – Apr 24, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: core: fix emulation of subzero temps

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

Change-Id: Iee1a4f0aacf7b4299b67c7f8f4effedf2d7a8425

---
 Documentation/thermal/sysfs-api.txt |  2 +-
 drivers/thermal/thermal_core.c      | 13 ++++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)
Documentation/thermal/sysfs-api.txt +1 -1
index 10f062ea6bc2..e240d9e165a0 100644
@@ -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
 
drivers/thermal/thermal_core.c +8 -5
index 768783ab3dac..650a6b124fc7 100644
@@ -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);
 
Signature · 6 lines
2.17.0.484.g0c8726318c-goog

--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
reviewer
#1 lore raw
Quoted 4 lines · Kevin DuBois

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.

Makes sense to me.

Quoted 9 lines

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

can you paste the bug link here?

Quoted 20 lines

Change-Id: Iee1a4f0aacf7b4299b67c7f8f4effedf2d7a8425
---
 Documentation/thermal/sysfs-api.txt |  2 +- drivers/thermal/thermal_core.c      | 13 ++++++++-----

 2 files changed, 9 insertions(+), 6 deletions(-)
Documentation/thermal/sysfs-api.txt +0 -0
index 10f062ea6bc2..e240d9e165a0 100644
@@ -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

Documentation/thermal/sysfs-api.txt emul_temp · line 315

Quoted 2 lines
Documentation/thermal/sysfs-api.txt +1 -1
-	and writing 0 on this node should disable emulation.
+	and writing -INT_MAX on this node should disable emulation.

This is an ABI change. I'm not sure if there is any userspace tool depends on this.
could you please resend the bug with a real bug link, and I will keep it in my tree for a longer period to see if there is any objections.

thanks,
rui

Quoted 64 lines

  Unit: millidegree Celsius
  WO, Optional

drivers/thermal/thermal_core.c +0 -0
index 768783ab3dac..650a6b124fc7 100644
@@ -636,8 +636,8 @@ int get_tz_trend(struct thermal_zone_device *tz,
 int trip)
  {
  	enum thermal_trend trend;

drivers/thermal/thermal_core.c +2 -2
-	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)

drivers/thermal/thermal_core.c +0 -0
@@ -904,7 +904,8 @@ int thermal_zone_get_temp(struct
 thermal_zone_device *tz, int *temp)


  ret = tz->ops->get_temp(tz, temp);

drivers/thermal/thermal_core.c +0 -1
-	if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz-
Quoted 1 line

emul_temperature) {

drivers/thermal/thermal_core.c +2 -0
+	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) {

drivers/thermal/thermal_core.c +0 -0
@@ -961,6 +962,7 @@ static void thermal_zone_device_reset(struct
 thermal_zone_device *tz)
  	struct thermal_instance *pos;


  tz->temperature = THERMAL_TEMP_INVALID;

drivers/thermal/thermal_core.c +1 -0
+	tz->emul_temperature = THERMAL_TEMP_INVALID;

  tz->passive = 0;
  list_for_each_entry(pos, &tz->thermal_instances, tz_node) pos->initialized = false;

drivers/thermal/thermal_core.c +1 -1
@@ -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;

drivers/thermal/thermal_core.c +1 -1
-	if (kstrtoul(buf, 10, &temperature))
+	if (kstrtoint(buf, 10, &temperature))

  return -EINVAL;

  if (!tz->ops->set_emul_temp) {

drivers/thermal/thermal_core.c +1 -0
@@ -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);
Quoted 1 line

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