linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Zhang, Rui" <rui.zhang@intel.com>
To: "linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
	"Valentin, Eduardo" <eduval@amazon.com>,
	"rafael@kernel.org" <rafael@kernel.org>,
	"evalenti@kernel.org" <evalenti@kernel.org>,
	"daniel.lezcano@linaro.org" <daniel.lezcano@linaro.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "amitk@kernel.org" <amitk@kernel.org>
Subject: Re: [PATCH 1/1] thermal: sysfs: avoid actual readings from sysfs
Date: Wed, 7 Jun 2023 06:32:46 +0000	[thread overview]
Message-ID: <27c8bd5ddea62391f9573ea77cfcebb4fa88ff66.camel@intel.com> (raw)
In-Reply-To: <20230607003721.834038-1-evalenti@kernel.org>

On Tue, 2023-06-06 at 17:37 -0700, Eduardo Valentin wrote:
> 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*/

what is the expected behavior of a disabled zone?

IMO, the hardware may not be functional at this point, and reading the
temperature should be avoided, as we do in
__thermal_zone_device_update().

should we just return failure in this case?

userspace should poke the temp attribute for enabled zones only.

thanks,
rui
> +               if (r)
> +                       return r;
> +       } else {
> +               mutex_lock(&tz->lock);
> +               temperature = tz->temperature;
> +               mutex_unlock(&tz->lock);
> +       }
>  
>         return sprintf(buf, "%d\n", temperature);
>  }


  reply	other threads:[~2023-06-07  6:33 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-07  0:37 [PATCH 1/1] thermal: sysfs: avoid actual readings from sysfs Eduardo Valentin
2023-06-07  6:32 ` Zhang, Rui [this message]
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=27c8bd5ddea62391f9573ea77cfcebb4fa88ff66.camel@intel.com \
    --to=rui.zhang@intel.com \
    --cc=amitk@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=eduval@amazon.com \
    --cc=evalenti@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    /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).