From: Eduardo Valentin <evalenti@kernel.org>
To: evalenti@kernel.org, eduval@amazon.com, rafael@kernel.org,
daniel.lezcano@linaro.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Amit Kucheria <amitk@kernel.org>, Zhang Rui <rui.zhang@intel.com>
Subject: [PATCH 1/1] thermal: sysfs: avoid actual readings from sysfs
Date: Tue, 6 Jun 2023 17:37:21 -0700 [thread overview]
Message-ID: <20230607003721.834038-1-evalenti@kernel.org> (raw)
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
next reply other threads:[~2023-06-07 0:37 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-07 0:37 Eduardo Valentin [this message]
2023-06-07 6:32 ` [PATCH 1/1] thermal: sysfs: avoid actual readings from sysfs 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
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=20230607003721.834038-1-evalenti@kernel.org \
--to=evalenti@kernel.org \
--cc=amitk@kernel.org \
--cc=daniel.lezcano@linaro.org \
--cc=eduval@amazon.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@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;
as well as URLs for NNTP newsgroup(s).