linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Lezcano <daniel.lezcano@linaro.org>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Linux ACPI <linux-acpi@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linux PM <linux-pm@vger.kernel.org>,
	Michal Wilczynski <michal.wilczynski@intel.com>,
	Zhang Rui <rui.zhang@intel.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Subject: Re: [PATCH v3 1/8] thermal: core: Add mechanism for connecting trips with driver data
Date: Tue, 1 Aug 2023 20:29:12 +0200	[thread overview]
Message-ID: <2d0315d4-35b4-84db-4dcb-c9528abad825@linaro.org> (raw)
In-Reply-To: <4501957.LvFx2qVVIh@kreacher>

On 25/07/2023 14:04, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Some drivers need to update trip point data (temperature and/or
> hysteresis) upon notifications from the platform firmware or they
> may need to reprogram hardware when trip point parameters are changed
> via sysfs.  For those purposes, they need to connect struct thermal_trip
> to a private data set associated with the trip or the other way around
> and using a trip point index for that may not always work, because the
> core may need to reorder the trips during thermal zone registration (in
> particular, they may need to be sorted).
> 
> To allow that to be done without using a trip point index, introduce
> a new field in struct thermal_trip that can be pointed by the driver
> to its own data structure containing a trip pointer to be initialized
> by the core during thermal zone registration.  That pointer will then
> have to be updated by the core every time the location of the given
> trip point object in memory changes.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> 
> v2 -> v3: No changes.
> 
> v1 -> v2: No changes.
> 
> ---
>   drivers/thermal/thermal_core.c |   20 +++++++++++++++++---
>   include/linux/thermal.h        |   13 +++++++++++++
>   2 files changed, 30 insertions(+), 3 deletions(-)
> 
> Index: linux-pm/include/linux/thermal.h
> ===================================================================
> --- linux-pm.orig/include/linux/thermal.h
> +++ linux-pm/include/linux/thermal.h
> @@ -76,16 +76,29 @@ struct thermal_zone_device_ops {
>   	void (*critical)(struct thermal_zone_device *);
>   };
>   
> +struct thermal_trip_ref {
> +	struct thermal_trip *trip;
> +};

That introduces a circular dependency. That should be avoided.

>   /**
>    * struct thermal_trip - representation of a point in temperature domain
>    * @temperature: temperature value in miliCelsius
>    * @hysteresis: relative hysteresis in miliCelsius
>    * @type: trip point type
> + * @driver_ref: driver's reference to this trip point
> + *
> + * If @driver_ref is not NULL, the trip pointer in the object pointed to by it
> + * will be initialized by the core during thermal zone registration and updated
> + * whenever the location of the given trip object changes.  This allows the
> + * driver to access the trip point data without knowing the relative ordering
> + * of trips within the trip table used by the core and, given a trip pointer,
> + * to get back to its private data associated with the given trip.
>    */
>   struct thermal_trip {
>   	int temperature;
>   	int hysteresis;
>   	enum thermal_trip_type type;
> +	struct thermal_trip_ref *driver_ref;
>   };

Why not use void *priv ?

AFAICT, the ACPI driver is the only one where when we reorder the trip 
points, the trip id is no longer matching the definition provided by the 
ACPI description.

It is possible to have the driver *specific* code to define its own 
structure with the id and use it instead of the trip_id.

So we end up with the ACPI driver registering the trip points with a 
data structure containing a private trip id.

The thermal framework is not supposed to have to deal with this kind of 
driver issues and from a higher perspective, any driver specific thing 
must stay in the driver.

eg.

struct acpi_thermal_trip_data {
	int id;
	... other info
};

struct acpi_thermal_trip_data attd[NRTRIPS] = { .id = 0 }, { .id = 1 }, ...

struct thermal_trip trips[NRTRIPS];

trips[i].priv = &attd[i];


The drivers with another kind of specific trip data can use this field.


>   struct thermal_cooling_device_ops {
> Index: linux-pm/drivers/thermal/thermal_core.c
> ===================================================================
> --- linux-pm.orig/drivers/thermal/thermal_core.c
> +++ linux-pm/drivers/thermal/thermal_core.c
> @@ -1306,14 +1306,28 @@ thermal_zone_device_register_with_trips(
>   	if (result)
>   		goto release_device;
>   
> +	mutex_lock(&tz->lock);
> +
>   	for (count = 0; count < num_trips; count++) {
> -		struct thermal_trip trip;
> +		int temperature = 0;
> +
> +		if (trips) {
> +			temperature = trips[count].temperature;
> +			if (trips[count].driver_ref)
> +				trips[count].driver_ref->trip = &trips[count];
> +		} else {
> +			struct thermal_trip trip;

As mentioned above, that should not appear in the thermal core code.


> -		result = thermal_zone_get_trip(tz, count, &trip);
> -		if (result || !trip.temperature)
> +			result = __thermal_zone_get_trip(tz, count, &trip);
> +			if (!result)
> +				temperature = trip.temperature;
> +		}
> +		if (!temperature)
>   			set_bit(count, &tz->trips_disabled);
>   	}
>   
> +	mutex_unlock(&tz->lock);
> +
>   	/* Update 'this' zone's governor information */
>   	mutex_lock(&thermal_governor_lock);
>   
> 
> 
> 

-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


  reply	other threads:[~2023-08-01 18:29 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-18 18:01 [PATCH v1 0/7] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-07-18 18:02 ` [PATCH v1 1/7] thermal: core: Add mechanism for connecting trips with driver data Rafael J. Wysocki
2023-07-18 18:04 ` [PATCH v1 2/7] thermal: core: Do not handle trip points with invalid temperature Rafael J. Wysocki
2023-07-18 18:05 ` [PATCH v1 3/7] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Rafael J. Wysocki
2023-07-18 18:06 ` [PATCH v1 4/7] ACPI: thermal: Hold thermal_check_lock around trip updates Rafael J. Wysocki
2023-07-18 18:06 ` [PATCH v1 5/7] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-07-19 18:46   ` Rafael J. Wysocki
2023-07-18 18:07 ` [PATCH v1 6/7] ACPI: thermal: Rework thermal_get_trend() Rafael J. Wysocki
2023-07-19 18:50   ` Rafael J. Wysocki
2023-07-18 18:19 ` [PATCH v1 7/7] ACPI: thermal: Drop unnecessary thermal zone callbacks Rafael J. Wysocki
2023-07-18 22:45 ` [PATCH v1 0/7] ACPI: thermal: Use trip point table to register thermal zones Daniel Lezcano
2023-07-19 13:33   ` Rafael J. Wysocki
2023-07-21 12:44 ` [PATCH v2 0/8] " Rafael J. Wysocki
2023-07-21 12:46   ` [PATCH v2 1/8] thermal: core: Add mechanism for connecting trips with driver data Rafael J. Wysocki
2023-07-21 12:47   ` [PATCH v2 2/8] thermal: core: Do not handle trip points with invalid temperature Rafael J. Wysocki
2023-07-21 12:50   ` [PATCH v2 3/8] thermal: core: Add routines for locking and unlocking thermal zones Rafael J. Wysocki
2023-07-21 14:12   ` [PATCH v2 4/8] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Rafael J. Wysocki
2023-07-21 14:51   ` [PATCH v2 5/8] ACPI: thermal: Hold thermal zone lock around trip updates Rafael J. Wysocki
2023-07-21 15:00   ` [PATCH v2 6/8] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-07-21 15:08   ` [PATCH v2 7/8] ACPI: thermal: Rework thermal_get_trend() Rafael J. Wysocki
2023-07-21 15:10   ` [PATCH v2 8/8] ACPI: thermal: Drop unnecessary thermal zone callbacks Rafael J. Wysocki
2023-07-23 10:19   ` [PATCH v2 0/8] ACPI: thermal: Use trip point table to register thermal zones Daniel Lezcano
2023-07-24  7:59     ` Rafael J. Wysocki
2023-07-25 12:02 ` [PATCH v3 " Rafael J. Wysocki
2023-07-25 12:04   ` [PATCH v3 1/8] thermal: core: Add mechanism for connecting trips with driver data Rafael J. Wysocki
2023-08-01 18:29     ` Daniel Lezcano [this message]
2023-08-01 19:02       ` Rafael J. Wysocki
2023-08-02 12:34         ` Daniel Lezcano
2023-08-02 13:03           ` Rafael J. Wysocki
2023-08-02 15:50             ` Daniel Lezcano
2023-08-02 16:48               ` Rafael J. Wysocki
2023-08-03 13:06                 ` Daniel Lezcano
2023-08-03 14:15                   ` Rafael J. Wysocki
2023-08-03 16:20                     ` Daniel Lezcano
2023-08-03 19:58                       ` Rafael J. Wysocki
2023-08-04  8:17                         ` Daniel Lezcano
2023-08-04 11:14                           ` Rafael J. Wysocki
2023-07-25 12:06   ` [PATCH v3 2/8] thermal: core: Do not handle trip points with invalid temperature Rafael J. Wysocki
2023-08-01 18:29     ` Daniel Lezcano
2023-08-01 19:05       ` Rafael J. Wysocki
2023-08-01 19:31         ` Daniel Lezcano
2023-07-25 12:08   ` [PATCH v3 3/8] thermal: core: Add routines for locking and unlocking thermal zones Rafael J. Wysocki
2023-08-01 18:30     ` Daniel Lezcano
2023-08-01 19:11       ` Rafael J. Wysocki
2023-07-25 12:09   ` [PATCH v3 4/8] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Rafael J. Wysocki
2023-07-25 12:16   ` [PATCH v3 5/8] ACPI: thermal: Hold thermal zone lock around trip updates Rafael J. Wysocki
2023-08-01 18:39     ` Daniel Lezcano
2023-08-01 18:51       ` Rafael J. Wysocki
2023-07-25 12:20   ` [PATCH v3 6/8] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-07-25 18:08     ` Rafael J. Wysocki
2023-07-25 18:12     ` [PATCH v3.1 " Rafael J. Wysocki
2023-07-25 12:22   ` [PATCH v3 7/8] ACPI: thermal: Rework thermal_get_trend() Rafael J. Wysocki
2023-07-25 12:24   ` [PATCH v3 8/8] ACPI: thermal: Drop unnecessary thermal zone callbacks Rafael J. Wysocki
2023-08-01 18:26   ` [PATCH v3 0/8] ACPI: thermal: Use trip point table to register thermal zones Daniel Lezcano
2023-08-01 18:39     ` Rafael J. Wysocki
2023-08-04 20:58 ` [PATCH v4 00/10] " Rafael J. Wysocki
2023-08-04 21:00   ` [PATCH v4 01/10] thermal: core: Do not handle trip points with invalid temperature Rafael J. Wysocki
2023-08-07 11:25     ` Daniel Lezcano
2023-08-04 21:03   ` [PATCH v4 02/10] thermal: core: Introduce thermal_zone_device_adjust() Rafael J. Wysocki
2023-08-04 21:04   ` [PATCH v4 03/10] thermal: core: Add priv pointer to struct thermal_trip Rafael J. Wysocki
2023-08-07 11:25     ` Daniel Lezcano
2023-08-04 21:05   ` [PATCH v4 04/10] thermal: core: Add thermal_zone_update_trip_temp() helper routine Rafael J. Wysocki
2023-08-07 11:29     ` Daniel Lezcano
2023-08-07 15:40       ` Rafael J. Wysocki
2023-08-07 16:17         ` Daniel Lezcano
2023-08-07 16:23           ` Rafael J. Wysocki
2023-08-04 21:07   ` [PATCH v4 05/10] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Rafael J. Wysocki
2023-08-04 21:13   ` [PATCH v4 06/10] ACPI: thermal: Carry out trip point updates under zone lock Rafael J. Wysocki
2023-08-04 21:18   ` [PATCH v4 07/10] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-08-04 21:22   ` [PATCH v4 08/10] ACPI: thermal: Rework thermal_get_trend() Rafael J. Wysocki
2023-08-04 21:24   ` [PATCH v4 09/10] ACPI: thermal: Drop unnecessary thermal zone callbacks Rafael J. Wysocki
2023-08-04 21:25   ` [PATCH v4 10/10] thermal: core: Eliminate code duplication from acpi_thermal_notify() Rafael J. Wysocki
2023-08-07 17:59 ` [PATCH v5 00/11] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-08-07 18:01   ` [PATCH v5 01/11] thermal: core: Do not handle trip points with invalid temperature Rafael J. Wysocki
2023-08-07 18:02   ` [PATCH v5 02/11] thermal: core: Introduce thermal_zone_device_adjust() Rafael J. Wysocki
2023-08-07 18:04   ` [PATCH v5 03/11] thermal: core: Add priv pointer to struct thermal_trip Rafael J. Wysocki
2023-08-07 18:06   ` [PATCH v5 04/11] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Rafael J. Wysocki
2023-08-07 18:08   ` [PATCH v5 05/11] ACPI: thermal: Carry out trip point updates under zone lock Rafael J. Wysocki
2023-08-16 16:25     ` Daniel Lezcano
2023-08-17 13:09       ` Rafael J. Wysocki
2023-08-07 18:10   ` [PATCH v5 06/11] ACPI: thermal: Introduce struct acpi_thermal_trip Rafael J. Wysocki
2023-08-07 18:11   ` [PATCH v5 07/11] thermal: core: Rework and rename __for_each_thermal_trip() Rafael J. Wysocki
2023-08-07 18:14   ` [PATCH v5 08/11] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-08-09 11:07     ` [PATCH v5.1 " Rafael J. Wysocki
2023-08-07 18:17   ` [PATCH v5 09/11] ACPI: thermal: Rework thermal_get_trend() Rafael J. Wysocki
2023-08-07 18:18   ` [PATCH v5 10/11] ACPI: thermal: Drop unnecessary thermal zone callbacks Rafael J. Wysocki
2023-08-07 18:20   ` [PATCH v5 11/11] thermal: core: Eliminate code duplication from acpi_thermal_notify() Rafael J. Wysocki

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=2d0315d4-35b4-84db-4dcb-c9528abad825@linaro.org \
    --to=daniel.lezcano@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=michal.wilczynski@intel.com \
    --cc=rjw@rjwysocki.net \
    --cc=rui.zhang@intel.com \
    --cc=srinivas.pandruvada@linux.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).