From: Rafael J. Wysocki <[email protected]>
Add thermal_zone_device_lock() and thermal_zone_device_unlock() for
acquiring and releasing the thermal zone lock, respectively.
They will be used by the ACPI thermal driver to protect trip point
temperature updates against races with accesses from elsewhere.
Signed-off-by: Rafael J. Wysocki <[email protected]>
---
v2 -> v3: No changes.
v1 -> v2: New patch.
---
drivers/thermal/thermal_core.c | 13 +++++++++++++
include/linux/thermal.h | 2 ++
2 files changed, 15 insertions(+)
Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.c
+++ linux-pm/drivers/thermal/thermal_core.c
@@ -497,6 +498,18 @@ void thermal_zone_device_update(struct t
}
EXPORT_SYMBOL_GPL(thermal_zone_device_update);
+void thermal_zone_device_lock(struct thermal_zone_device *tz)
+{
+ mutex_lock(&tz->lock);
+}
+EXPORT_SYMBOL_GPL(thermal_zone_device_lock);
+
+void thermal_zone_device_unlock(struct thermal_zone_device *tz)
+{
+ mutex_unlock(&tz->lock);
+}
+EXPORT_SYMBOL_GPL(thermal_zone_device_unlock);
+
static void thermal_zone_device_check(struct work_struct *work)
{
struct thermal_zone_device *tz = container_of(work, struct
Index: linux-pm/include/linux/thermal.h
===================================================================
--- linux-pm.orig/include/linux/thermal.h
+++ linux-pm/include/linux/thermal.h
@@ -336,6 +336,8 @@ int thermal_zone_unbind_cooling_device(s
struct thermal_cooling_device *);
void thermal_zone_device_update(struct thermal_zone_device *,
enum thermal_notify_event);
+void thermal_zone_device_lock(struct thermal_zone_device *tz);
+void thermal_zone_device_unlock(struct thermal_zone_device *tz);
struct thermal_cooling_device *thermal_cooling_device_register(const char *,
void *, const struct thermal_cooling_device_ops *);
Hi Rafael,
On 25/07/2023 14:08, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <[email protected]>
>
> Add thermal_zone_device_lock() and thermal_zone_device_unlock() for
> acquiring and releasing the thermal zone lock, respectively.
>
> They will be used by the ACPI thermal driver to protect trip point
> temperature updates against races with accesses from elsewhere.
This change goes to the opposite direction of the previous thermal zone
cleanup and encapsulation we have done recently.
Here we give the possibility to a driver to act on the thermal core
internals.
Ideally, we should see tz->lock only in thermal_core.c
> Signed-off-by: Rafael J. Wysocki <[email protected]>
> ---
>
> v2 -> v3: No changes.
>
> v1 -> v2: New patch.
>
> ---
> drivers/thermal/thermal_core.c | 13 +++++++++++++
> include/linux/thermal.h | 2 ++
> 2 files changed, 15 insertions(+)
>
> Index: linux-pm/drivers/thermal/thermal_core.c
> ===================================================================
> --- linux-pm.orig/drivers/thermal/thermal_core.c
> +++ linux-pm/drivers/thermal/thermal_core.c
> @@ -497,6 +498,18 @@ void thermal_zone_device_update(struct t
> }
> EXPORT_SYMBOL_GPL(thermal_zone_device_update);
>
> +void thermal_zone_device_lock(struct thermal_zone_device *tz)
> +{
> + mutex_lock(&tz->lock);
> +}
> +EXPORT_SYMBOL_GPL(thermal_zone_device_lock);
> +
> +void thermal_zone_device_unlock(struct thermal_zone_device *tz)
> +{
> + mutex_unlock(&tz->lock);
> +}
> +EXPORT_SYMBOL_GPL(thermal_zone_device_unlock);
> +
> static void thermal_zone_device_check(struct work_struct *work)
> {
> struct thermal_zone_device *tz = container_of(work, struct
> Index: linux-pm/include/linux/thermal.h
> ===================================================================
> --- linux-pm.orig/include/linux/thermal.h
> +++ linux-pm/include/linux/thermal.h
> @@ -336,6 +336,8 @@ int thermal_zone_unbind_cooling_device(s
> struct thermal_cooling_device *);
> void thermal_zone_device_update(struct thermal_zone_device *,
> enum thermal_notify_event);
> +void thermal_zone_device_lock(struct thermal_zone_device *tz);
> +void thermal_zone_device_unlock(struct thermal_zone_device *tz);
>
> struct thermal_cooling_device *thermal_cooling_device_register(const char *,
> void *, const struct thermal_cooling_device_ops *);
>
>
>
--
<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
On Tue, Aug 1, 2023 at 8:30 PM Daniel Lezcano <[email protected]> wrote:
>
>
> Hi Rafael,
>
>
> On 25/07/2023 14:08, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <[email protected]>
> >
> > Add thermal_zone_device_lock() and thermal_zone_device_unlock() for
> > acquiring and releasing the thermal zone lock, respectively.
> >
> > They will be used by the ACPI thermal driver to protect trip point
> > temperature updates against races with accesses from elsewhere.
>
> This change goes to the opposite direction of the previous thermal zone
> cleanup and encapsulation we have done recently.
>
> Here we give the possibility to a driver to act on the thermal core
> internals.
>
> Ideally, we should see tz->lock only in thermal_core.c
There needs to be a way to lock the thing if it needs to be locked.
The thermal zone has been registered by the driver after all, and if
it needs to be updated, the driver needs to be able to do that safely.
I'm guessing that the suggested way is to disable the thermal zone for
the time of the update, but I'm kind of unsure if this is going to
work.
>
> > Signed-off-by: Rafael J. Wysocki <[email protected]>
> > ---
> >
> > v2 -> v3: No changes.
> >
> > v1 -> v2: New patch.
> >
> > ---
> > drivers/thermal/thermal_core.c | 13 +++++++++++++
> > include/linux/thermal.h | 2 ++
> > 2 files changed, 15 insertions(+)
> >
> > Index: linux-pm/drivers/thermal/thermal_core.c
> > ===================================================================
> > --- linux-pm.orig/drivers/thermal/thermal_core.c
> > +++ linux-pm/drivers/thermal/thermal_core.c
> > @@ -497,6 +498,18 @@ void thermal_zone_device_update(struct t
> > }
> > EXPORT_SYMBOL_GPL(thermal_zone_device_update);
> >
> > +void thermal_zone_device_lock(struct thermal_zone_device *tz)
> > +{
> > + mutex_lock(&tz->lock);
> > +}
> > +EXPORT_SYMBOL_GPL(thermal_zone_device_lock);
> > +
> > +void thermal_zone_device_unlock(struct thermal_zone_device *tz)
> > +{
> > + mutex_unlock(&tz->lock);
> > +}
> > +EXPORT_SYMBOL_GPL(thermal_zone_device_unlock);
> > +
> > static void thermal_zone_device_check(struct work_struct *work)
> > {
> > struct thermal_zone_device *tz = container_of(work, struct
> > Index: linux-pm/include/linux/thermal.h
> > ===================================================================
> > --- linux-pm.orig/include/linux/thermal.h
> > +++ linux-pm/include/linux/thermal.h
> > @@ -336,6 +336,8 @@ int thermal_zone_unbind_cooling_device(s
> > struct thermal_cooling_device *);
> > void thermal_zone_device_update(struct thermal_zone_device *,
> > enum thermal_notify_event);
> > +void thermal_zone_device_lock(struct thermal_zone_device *tz);
> > +void thermal_zone_device_unlock(struct thermal_zone_device *tz);
> >
> > struct thermal_cooling_device *thermal_cooling_device_register(const char *,
> > void *, const struct thermal_cooling_device_ops *);
> >
> >
> >