linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] thermal: sysfs: avoid actual readings from sysfs
@ 2023-06-07  0:37 Eduardo Valentin
  2023-06-07  6:32 ` Zhang, Rui
  2023-06-07  9:24 ` Daniel Lezcano
  0 siblings, 2 replies; 27+ messages in thread
From: Eduardo Valentin @ 2023-06-07  0:37 UTC (permalink / raw)
  To: evalenti, eduval, rafael, daniel.lezcano, linux-pm, linux-kernel
  Cc: Amit Kucheria, Zhang Rui

From: Eduardo Valentin <eduval@amazon.com>

As the thermal zone caches the current and last temperature
value, the sysfs interface can use that instead of
forcing an actual update or read from the device.
This way, if multiple userspace requests are coming
in, we avoid storming the device with multiple reads
and potentially clogging the timing requirement
for the governors.

Cc: "Rafael J. Wysocki" <rafael@kernel.org> (supporter:THERMAL)
Cc: Daniel Lezcano <daniel.lezcano@linaro.org> (supporter:THERMAL)
Cc: Amit Kucheria <amitk@kernel.org> (reviewer:THERMAL)
Cc: Zhang Rui <rui.zhang@intel.com> (reviewer:THERMAL)
Cc: linux-pm@vger.kernel.org (open list:THERMAL)
Cc: linux-kernel@vger.kernel.org (open list)

Signed-off-by: Eduardo Valentin <eduval@amazon.com>
---
 drivers/thermal/thermal_sysfs.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index b6daea2398da..a240c58d9e08 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -35,12 +35,23 @@ static ssize_t
 temp_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct thermal_zone_device *tz = to_thermal_zone(dev);
-	int temperature, ret;
-
-	ret = thermal_zone_get_temp(tz, &temperature);
+	int temperature;
 
-	if (ret)
-		return ret;
+	/*
+	 * don't force new update from external reads
+	 * This way we avoid messing up with time constraints.
+	 */
+	if (tz->mode == THERMAL_DEVICE_DISABLED) {
+		int r;
+
+		r = thermal_zone_get_temp(tz, &temperature); /* holds tz->lock*/
+		if (r)
+			return r;
+	} else {
+		mutex_lock(&tz->lock);
+		temperature = tz->temperature;
+		mutex_unlock(&tz->lock);
+	}
 
 	return sprintf(buf, "%d\n", temperature);
 }
-- 
2.34.1


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

end of thread, other threads:[~2023-07-07 17:14 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-07  0:37 [PATCH 1/1] thermal: sysfs: avoid actual readings from sysfs Eduardo Valentin
2023-06-07  6:32 ` Zhang, Rui
2023-06-07 16:28   ` Eduardo Valentin
2023-06-07  9:24 ` Daniel Lezcano
2023-06-07 16:38   ` Eduardo Valentin
2023-06-07 18:23     ` Daniel Lezcano
2023-06-08 17:44       ` Eduardo Valentin
2023-06-12  8:17         ` Daniel Lezcano
2023-06-21  5:06           ` Eduardo Valentin
2023-06-21 11:43             ` Daniel Lezcano
2023-06-22  4:56               ` Eduardo Valentin
2023-06-23 17:31                 ` Rafael J. Wysocki
2023-06-28 21:10                   ` Eduardo Valentin
2023-06-30  8:16                     ` Rafael J. Wysocki
2023-06-30 10:11                       ` Daniel Lezcano
2023-06-30 10:46                         ` Rafael J. Wysocki
2023-06-30 12:09                           ` Daniel Lezcano
2023-07-01  1:49                             ` Eduardo Valentin
2023-07-01  7:28                               ` Daniel Lezcano
2023-07-05 22:49                                 ` Eduardo Valentin
2023-07-06 13:22                                   ` Rafael J. Wysocki
2023-07-07 17:14                                     ` Eduardo Valentin
2023-07-01  1:38                         ` Eduardo Valentin
2023-07-01 14:20                           ` Daniel Lezcano
2023-07-01  1:37                       ` Eduardo Valentin
2023-07-06 13:02                         ` Rafael J. Wysocki
2023-06-10 17:24     ` Russell Haley

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