From: Lukasz Luba <lukasz.luba@arm.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: LKML <linux-kernel@vger.kernel.org>,
Linux PM <linux-pm@vger.kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>
Subject: Re: [PATCH v1 2/3] thermal/debugfs: Clean up thermal_debug_update_temp()
Date: Mon, 22 Apr 2024 12:15:14 +0100 [thread overview]
Message-ID: <bf96cf30-3698-424d-8d6c-722514529005@arm.com> (raw)
In-Reply-To: <2185763.irdbgypaU6@kreacher>
On 4/17/24 14:10, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> Notice that it is not necessary to compute tze in every iteration of the
> for () loop in thermal_debug_update_temp() because it is the same for all
> trips, so compute it once before the loop starts.
>
> Also use a trip_stats local variable to make the code in that loop easier
> to follow and move the trip_id variable definition into that loop because
> it is not used elsewhere in the function.
>
> While at it, change to order of local variable definitions in the function
> to follow the reverse-xmas-tree pattern.
>
> No intentional functional impact.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> drivers/thermal/thermal_debugfs.c | 21 +++++++++++----------
> 1 file changed, 11 insertions(+), 10 deletions(-)
>
> Index: linux-pm/drivers/thermal/thermal_debugfs.c
> ===================================================================
> --- linux-pm.orig/drivers/thermal/thermal_debugfs.c
> +++ linux-pm/drivers/thermal/thermal_debugfs.c
> @@ -679,9 +679,9 @@ out:
> void thermal_debug_update_temp(struct thermal_zone_device *tz)
> {
> struct thermal_debugfs *thermal_dbg = tz->debugfs;
> - struct tz_episode *tze;
> struct tz_debugfs *tz_dbg;
> - int trip_id, i;
> + struct tz_episode *tze;
> + int i;
>
> if (!thermal_dbg)
> return;
> @@ -693,15 +693,16 @@ void thermal_debug_update_temp(struct th
> if (!tz_dbg->nr_trips)
> goto out;
>
> + tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node);
> +
> for (i = 0; i < tz_dbg->nr_trips; i++) {
> - trip_id = tz_dbg->trips_crossed[i];
> - tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node);
> - tze->trip_stats[trip_id].count++;
> - tze->trip_stats[trip_id].max = max(tze->trip_stats[trip_id].max, tz->temperature);
> - tze->trip_stats[trip_id].min = min(tze->trip_stats[trip_id].min, tz->temperature);
> - tze->trip_stats[trip_id].avg = tze->trip_stats[trip_id].avg +
> - (tz->temperature - tze->trip_stats[trip_id].avg) /
> - tze->trip_stats[trip_id].count;
> + int trip_id = tz_dbg->trips_crossed[i];
> + struct trip_stats *trip_stats = &tze->trip_stats[trip_id];
> +
> + trip_stats->max = max(trip_stats->max, tz->temperature);
> + trip_stats->min = min(trip_stats->min, tz->temperature);
> + trip_stats->avg += (tz->temperature - trip_stats->avg) /
> + ++trip_stats->count;
> }
> out:
> mutex_unlock(&thermal_dbg->lock);
>
>
>
>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
next prev parent reply other threads:[~2024-04-22 11:15 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-17 13:07 [PATCH v1 0/3] thermal/debugfs: Fix and clean up trip point statistics updates Rafael J. Wysocki
2024-04-17 13:09 ` [PATCH v1 1/3] thermal/debugfs: Avoid excessive updates of trip point statistics Rafael J. Wysocki
2024-04-22 11:14 ` Lukasz Luba
2024-04-23 15:54 ` Daniel Lezcano
2024-04-17 13:10 ` [PATCH v1 2/3] thermal/debugfs: Clean up thermal_debug_update_temp() Rafael J. Wysocki
2024-04-22 11:15 ` Lukasz Luba [this message]
2024-04-23 15:30 ` Daniel Lezcano
2024-04-17 13:11 ` [PATCH v1 3/3] thermal/debugfs: Rename thermal_debug_update_temp() to thermal_debug_update_trip_stats() Rafael J. Wysocki
2024-04-22 11:15 ` Lukasz Luba
2024-04-23 15:30 ` Daniel Lezcano
2024-04-22 11:37 ` [PATCH v1 0/3] thermal/debugfs: Fix and clean up trip point statistics updates Lukasz Luba
2024-04-22 14:20 ` Rafael J. Wysocki
2024-04-22 15:34 ` Daniel Lezcano
2024-04-22 15:48 ` Rafael J. Wysocki
2024-04-22 16:12 ` Daniel Lezcano
2024-04-23 12:26 ` Rafael J. Wysocki
2024-04-23 13:38 ` Lukasz Luba
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=bf96cf30-3698-424d-8d6c-722514529005@arm.com \
--to=lukasz.luba@arm.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rjw@rjwysocki.net \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).