public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Zhang, Rui" <rui.zhang@intel.com>
To: "rafael@kernel.org" <rafael@kernel.org>,
	"daniel.lezcano@linaro.org" <daniel.lezcano@linaro.org>
Cc: "linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"amitk@kernel.org" <amitk@kernel.org>
Subject: Re: [PATCH 5/5] thermal/core: Sort the trip points when registering a thermal zone
Date: Thu, 19 Jan 2023 07:22:59 +0000	[thread overview]
Message-ID: <f515876ea2e43e734b8d4ac7feda7f17ee04894f.camel@intel.com> (raw)
In-Reply-To: <20230118211123.111493-5-daniel.lezcano@linaro.org>

On Wed, 2023-01-18 at 22:11 +0100, Daniel Lezcano wrote:
> Most of the drivers are converted to use the generic thermal trip
> points. They register a thermal zone with an array of trip points.
> 
> However, we don't have the guarantee the trip points are ordered. The
> main goal of moving to the generic trip points is to provide a common
> structure, ordered, so we can fix sanely how the trip points are
> crossed. As a reminder, the detection is fuzzy when the trip points
> are defined with hysteresis values, we can have duplicated or
> inconsistent trip events.
> 
> This change sorts the trip points array when it is registered with
> the
> thermal zone. The direction of the ordering is descending because
> when
> we browse the trip points, we want to check the highest trip points
> first as they are higher in temperature, thus higher in priority.
> 
> A pr_info() trace tells the trip points have been ordered if it
> appears they are not sorted initially.
> 
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> ---
>  drivers/thermal/thermal_core.c |  3 +++
>  drivers/thermal/thermal_core.h |  1 +
>  drivers/thermal/thermal_trip.c | 28 ++++++++++++++++++++++++++++
>  3 files changed, 32 insertions(+)
> 
> diff --git a/drivers/thermal/thermal_core.c
> b/drivers/thermal/thermal_core.c
> index d0577685085a..394770591771 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -1255,6 +1255,9 @@ thermal_zone_device_register_with_trips(const
> char *type, struct thermal_trip *t
>  	if (num_trips > 0 && (!ops->get_trip_type || !ops-
> >get_trip_temp) && !trips)
>  		return ERR_PTR(-EINVAL);
>  
> +	if (trips && thermal_trip_sort(trips, num_trips))
> +		pr_info("Thermal trips sorted for thermal zone '%s'\n",
> type);
> +	
>  	tz = kzalloc(sizeof(*tz), GFP_KERNEL);
>  	if (!tz)
>  		return ERR_PTR(-ENOMEM);
> diff --git a/drivers/thermal/thermal_core.h
> b/drivers/thermal/thermal_core.h
> index 26350206a98d..4688107fda1d 100644
> --- a/drivers/thermal/thermal_core.h
> +++ b/drivers/thermal/thermal_core.h
> @@ -117,6 +117,7 @@ void __thermal_zone_set_trips(struct
> thermal_zone_device *tz);
>  int __thermal_zone_get_trip(struct thermal_zone_device *tz, int
> trip_id,
>  			    struct thermal_trip *trip);
>  int __thermal_zone_get_temp(struct thermal_zone_device *tz, int
> *temp);
> +int thermal_trip_sort(struct thermal_trip *trips, int num_trips);
>  
>  /* sysfs I/F */
>  int thermal_zone_create_device_groups(struct thermal_zone_device *,
> int);
> diff --git a/drivers/thermal/thermal_trip.c
> b/drivers/thermal/thermal_trip.c
> index 2ef61ff7ffc3..924998f09a5a 100644
> --- a/drivers/thermal/thermal_trip.c
> +++ b/drivers/thermal/thermal_trip.c
> @@ -9,6 +9,34 @@
>   */
>  #include "thermal_core.h"
>  
> +/*
> + * The trip points must be ordered in the descending order so when
> we
> + * browse the trip points we will hit the critical, hot and then the
> + * passive/active trip points. The critical trip point being the
> first
> + * one to be handled.
> + */
> +int thermal_trip_sort(struct thermal_trip *trips, int num_trips)
> +{
> +	struct thermal_trip tt;
> +	int sorted = 0;
> +	int i, j;
> +
> +	for (i = 0; i < num_trips; i++) {
> +
> +		for (j = i + 1; j < num_trips; j++) {
> +
> +			if (trips[i].temperature <
> trips[j].temperature) {
> +				tt = trips[i];
> +				trips[i] = trips[j];
> +				trips[j] = tt;
> +				sorted++;
> +			}
> +		}
> + 	}
> +
> +	return sorted;
> +}
> +
When this happens, the index(trip_id) of each trip is changed, but we
pass the new trip_id to .get_trip_temp()/.set_trip_temp() callbacks.

This will confuse the drivers and update the wrong trips, right?

IMO, we need a map between thermal core trips and unsorted driver
trips.

thanks,
rui

>  int __for_each_thermal_trip(struct thermal_zone_device *tz,
>  			    int (*cb)(struct thermal_trip *,
>  				      int trip_id, void *),

  reply	other threads:[~2023-01-19  7:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-18 21:11 [PATCH 1/5] thermal/core: Fix unregistering netlink at thermal init time Daniel Lezcano
2023-01-18 21:11 ` [PATCH 2/5] thermal/core: Remove unneeded ida_destroy() Daniel Lezcano
2023-01-18 21:11 ` [PATCH 3/5] thermal/core: Remove unneeded mutex_destroy() Daniel Lezcano
2023-01-19  7:41   ` Zhang, Rui
2023-01-19  9:30     ` Daniel Lezcano
2023-01-19 12:11       ` Rafael J. Wysocki
2023-01-19 12:48         ` Daniel Lezcano
2023-01-19 13:24           ` Rafael J. Wysocki
2023-01-19 14:13             ` Daniel Lezcano
2023-01-19 15:05               ` Rafael J. Wysocki
2023-01-19 16:39                 ` Daniel Lezcano
2023-01-19 17:21                   ` Rafael J. Wysocki
2023-01-20 14:09                     ` Zhang, Rui
2023-01-20 14:13                       ` Rafael J. Wysocki
2023-01-18 21:11 ` [PATCH 4/5] thermal/core: Move the thermal trip code to a dedicated file Daniel Lezcano
2023-01-19  2:39   ` kernel test robot
2023-01-19  7:24   ` Zhang, Rui
2023-01-18 21:11 ` [PATCH 5/5] thermal/core: Sort the trip points when registering a thermal zone Daniel Lezcano
2023-01-19  7:22   ` Zhang, Rui [this message]
2023-01-19 10:25     ` Daniel Lezcano
2023-01-19 16:50       ` Zhang, Rui
2023-01-19 13:28 ` [PATCH 1/5] thermal/core: Fix unregistering netlink at thermal init time Rafael J. Wysocki
2023-01-19 13:40   ` Daniel Lezcano
2023-01-19 13:45     ` Rafael J. Wysocki
2023-01-19 14:07       ` Daniel Lezcano

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=f515876ea2e43e734b8d4ac7feda7f17ee04894f.camel@intel.com \
    --to=rui.zhang@intel.com \
    --cc=amitk@kernel.org \
    --cc=daniel.lezcano@linaro.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