From: Lukasz Luba <lukasz.luba@arm.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
Linux PM <linux-pm@vger.kernel.org>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>,
LKML <linux-kernel@vger.kernel.org>,
Thierry Reding <thierry.reding@gmail.com>,
Jonathan Hunter <jonathanh@nvidia.com>,
linux-tegra@vger.kernel.org
Subject: Re: [RESEND][PATCH v1 5/8] thermal: tegra: Use thermal_zone_for_each_trip() for walking trip points
Date: Fri, 2 Aug 2024 10:47:39 +0100 [thread overview]
Message-ID: <2fb8441b-d0bb-4e63-998d-cc764db30a23@arm.com> (raw)
In-Reply-To: <1819430.VLH7GnMWUR@rjwysocki.net>
On 7/29/24 17:05, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> It is generally inefficient to iterate over trip indices and call
> thermal_zone_get_trip() every time to get the struct thermal_trip
> corresponding to the given trip index, so modify the Tegra thermal
> drivers to use thermal_zone_for_each_trip() for walking trips.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>
> This patch does not depend on patches [1-3/8].
>
> ---
> drivers/thermal/tegra/soctherm.c | 38 ++++++++++++++++----------------
> drivers/thermal/tegra/tegra30-tsensor.c | 25 ++++++++++-----------
> 2 files changed, 33 insertions(+), 30 deletions(-)
>
> Index: linux-pm/drivers/thermal/tegra/soctherm.c
> ===================================================================
> --- linux-pm.orig/drivers/thermal/tegra/soctherm.c
> +++ linux-pm/drivers/thermal/tegra/soctherm.c
> @@ -682,24 +682,25 @@ static const struct thermal_zone_device_
> .set_trips = tegra_thermctl_set_trips,
> };
>
> -static int get_hot_temp(struct thermal_zone_device *tz, int *trip_id, int *temp)
> +static int get_hot_trip_cb(struct thermal_trip *trip, void *arg)
> {
> - int i, ret;
> - struct thermal_trip trip;
> + const struct thermal_trip **trip_ret = arg;
>
> - for (i = 0; i < thermal_zone_get_num_trips(tz); i++) {
> + if (trip->type != THERMAL_TRIP_HOT)
> + return 0;
>
> - ret = thermal_zone_get_trip(tz, i, &trip);
> - if (ret)
> - return -EINVAL;
> -
> - if (trip.type == THERMAL_TRIP_HOT) {
> - *trip_id = i;
> - return 0;
> - }
> - }
> + *trip_ret = trip;
> + /* Return nonzero to terminate the search. */
> + return 1;
> +}
>
> - return -EINVAL;
> +static const struct thermal_trip *get_hot_trip(struct thermal_zone_device *tz)
> +{
> + const struct thermal_trip *trip = NULL;
> +
> + thermal_zone_for_each_trip(tz, get_hot_trip_cb, &trip);
> +
> + return trip;
> }
>
> /**
> @@ -731,8 +732,9 @@ static int tegra_soctherm_set_hwtrips(st
> struct thermal_zone_device *tz)
> {
> struct tegra_soctherm *ts = dev_get_drvdata(dev);
> + const struct thermal_trip *hot_trip;
> struct soctherm_throt_cfg *stc;
> - int i, trip, temperature, ret;
> + int i, temperature, ret;
>
> /* Get thermtrips. If missing, try to get critical trips. */
> temperature = tsensor_group_thermtrip_get(ts, sg->id);
> @@ -749,8 +751,8 @@ static int tegra_soctherm_set_hwtrips(st
> dev_info(dev, "thermtrip: will shut down when %s reaches %d mC\n",
> sg->name, temperature);
>
> - ret = get_hot_temp(tz, &trip, &temperature);
> - if (ret) {
> + hot_trip = get_hot_trip(tz);
> + if (!hot_trip) {
> dev_info(dev, "throttrip: %s: missing hot temperature\n",
> sg->name);
> return 0;
> @@ -763,7 +765,7 @@ static int tegra_soctherm_set_hwtrips(st
> continue;
>
> cdev = ts->throt_cfgs[i].cdev;
> - if (get_thermal_instance(tz, cdev, trip))
> + if (thermal_trip_is_bound_to_cdev(tz, hot_trip, cdev))
> stc = find_throttle_cfg_by_name(ts, cdev->type);
> else
> continue;
> Index: linux-pm/drivers/thermal/tegra/tegra30-tsensor.c
> ===================================================================
> --- linux-pm.orig/drivers/thermal/tegra/tegra30-tsensor.c
> +++ linux-pm/drivers/thermal/tegra/tegra30-tsensor.c
> @@ -308,6 +308,18 @@ struct trip_temps {
> int crit_trip;
> };
>
> +static int tegra_tsensor_get_trips_cb(struct thermal_trip *trip, void *arg)
> +{
> + struct trip_temps *temps = arg;
> +
> + if (trip->type == THERMAL_TRIP_HOT)
> + temps->hot_trip = trip->temperature;
> + else if (trip->type == THERMAL_TRIP_CRITICAL)
> + temps->crit_trip = trip->temperature;
> +
> + return 0;
> +}
> +
> static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd,
> struct trip_temps *temps)
> {
> @@ -320,18 +332,7 @@ static void tegra_tsensor_get_hw_channel
> temps->hot_trip = 85000;
> temps->crit_trip = 90000;
>
> - for (i = 0; i < thermal_zone_get_num_trips(tzd); i++) {
> -
> - struct thermal_trip trip;
> -
> - thermal_zone_get_trip(tzd, i, &trip);
> -
> - if (trip.type == THERMAL_TRIP_HOT)
> - temps->hot_trip = trip.temperature;
> -
> - if (trip.type == THERMAL_TRIP_CRITICAL)
> - temps->crit_trip = trip.temperature;
> - }
> + thermal_zone_for_each_trip(tzd, tegra_tsensor_get_trips_cb, temps);
>
> /* clamp hardware trips to the calibration limits */
> temps->hot_trip = clamp(temps->hot_trip, 25000, 90000);
>
>
>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
next prev parent reply other threads:[~2024-08-02 9:47 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-29 15:50 [RESEND][PATCH v1 0/8] thermal: Use trip pointers in thermal driver interface Rafael J. Wysocki
2024-07-29 15:53 ` [RESEND][PATCH v1 1/8] thermal: broadcom: Use thermal_zone_get_crit_temp() in bcm2835_thermal_probe() Rafael J. Wysocki
2024-07-29 21:54 ` Florian Fainelli
2024-08-02 9:36 ` Lukasz Luba
2024-07-29 15:56 ` [RESEND][PATCH v1 2/8] thermal: hisi: Use thermal_zone_for_each_trip() in hisi_thermal_register_sensor() Rafael J. Wysocki
2024-08-02 9:35 ` Lukasz Luba
2024-07-29 15:58 ` [RESEND][PATCH v1 3/8] thermal: qcom: Use thermal_zone_get_crit_temp() in qpnp_tm_init() Rafael J. Wysocki
2024-08-02 9:37 ` Lukasz Luba
2024-08-14 5:09 ` Amit Kucheria
2024-07-29 16:02 ` [RESEND][PATCH v1 4/8] thermal: tegra: Introduce struct trip_temps for critical and hot trips Rafael J. Wysocki
2024-08-02 9:40 ` Lukasz Luba
2024-07-29 16:05 ` [RESEND][PATCH v1 5/8] thermal: tegra: Use thermal_zone_for_each_trip() for walking trip points Rafael J. Wysocki
2024-08-02 9:47 ` Lukasz Luba [this message]
2024-07-29 16:06 ` [RESEND][PATCH v1 6/8] thermal: helpers: Drop get_thermal_instance() Rafael J. Wysocki
2024-08-02 9:53 ` Lukasz Luba
2024-07-29 16:11 ` [PATCH v2 7/8] thermal: trip: Get rid of thermal_zone_get_num_trips() Rafael J. Wysocki
2024-07-30 10:37 ` Niklas Söderlund
2024-08-02 9:55 ` Lukasz Luba
2024-07-29 16:12 ` [RESEND][PATCH v1 8/8] thermal: trip: Drop thermal_zone_get_trip() Rafael J. Wysocki
2024-08-02 9:56 ` 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=2fb8441b-d0bb-4e63-998d-cc764db30a23@arm.com \
--to=lukasz.luba@arm.com \
--cc=daniel.lezcano@linaro.org \
--cc=jonathanh@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=rjw@rjwysocki.net \
--cc=thierry.reding@gmail.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