* [PATCH v1 1/4] thermal: core: Add function to walk trips under zone lock
2023-10-02 17:58 [PATCH v1 0/4] thermal: Improve iteration over trip points Rafael J. Wysocki
@ 2023-10-02 17:59 ` Rafael J. Wysocki
2023-10-02 18:00 ` [PATCH v1 2/4] ACPI: thermal: Use thermal_zone_for_each_trip() Rafael J. Wysocki
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2023-10-02 17:59 UTC (permalink / raw)
To: Linux PM
Cc: LKML, Linux ACPI, Daniel Lezcano, Zhang Rui, Srinivas Pandruvada,
Rafael J. Wysocki
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Add a wrapper around for_each_thermal_trip(), called
thermal_zone_for_each_trip(), that will invoke the former under the
thermal zone lock and pass its return value to the caller.
Two drivers will be modified subsequently to use this new function.
No functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/thermal/thermal_trip.c | 14 ++++++++++++++
include/linux/thermal.h | 3 +++
2 files changed, 17 insertions(+)
Index: linux-pm/drivers/thermal/thermal_trip.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_trip.c
+++ linux-pm/drivers/thermal/thermal_trip.c
@@ -27,6 +27,20 @@ int for_each_thermal_trip(struct thermal
}
EXPORT_SYMBOL_GPL(for_each_thermal_trip);
+int thermal_zone_for_each_trip(struct thermal_zone_device *tz,
+ int (*cb)(struct thermal_trip *, void *),
+ void *data)
+{
+ int ret;
+
+ mutex_lock(&tz->lock);
+ ret = for_each_thermal_trip(tz, cb, data);
+ mutex_unlock(&tz->lock);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(thermal_zone_for_each_trip);
+
int thermal_zone_get_num_trips(struct thermal_zone_device *tz)
{
return tz->num_trips;
Index: linux-pm/include/linux/thermal.h
===================================================================
--- linux-pm.orig/include/linux/thermal.h
+++ linux-pm/include/linux/thermal.h
@@ -287,6 +287,9 @@ int thermal_zone_set_trip(struct thermal
int for_each_thermal_trip(struct thermal_zone_device *tz,
int (*cb)(struct thermal_trip *, void *),
void *data);
+int thermal_zone_for_each_trip(struct thermal_zone_device *tz,
+ int (*cb)(struct thermal_trip *, void *),
+ void *data);
int thermal_zone_get_num_trips(struct thermal_zone_device *tz);
int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp);
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v1 2/4] ACPI: thermal: Use thermal_zone_for_each_trip()
2023-10-02 17:58 [PATCH v1 0/4] thermal: Improve iteration over trip points Rafael J. Wysocki
2023-10-02 17:59 ` [PATCH v1 1/4] thermal: core: Add function to walk trips under zone lock Rafael J. Wysocki
@ 2023-10-02 18:00 ` Rafael J. Wysocki
2023-10-02 18:02 ` [PATCH v1 3/4] thermal: core: Drop thermal_zone_device_exec() Rafael J. Wysocki
2023-10-02 18:03 ` [PATCH v1 4/4] thermal: int340x: Use thermal_zone_for_each_trip() Rafael J. Wysocki
3 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2023-10-02 18:00 UTC (permalink / raw)
To: Linux PM
Cc: LKML, Linux ACPI, Daniel Lezcano, Zhang Rui, Srinivas Pandruvada,
Rafael J. Wysocki
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Rearrange the code handling notifications from the platform firmware
to carry out one loop over trip points instead of two and use
thermal_zone_for_each_trip() for that, which is more straightforward
that using a combination of thermal_zone_device_exec() and
for_each_thermal_trip(), each with its own callback function.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/thermal.c | 58 +++++++++++++++++++++++++++----------------------
1 file changed, 32 insertions(+), 26 deletions(-)
Index: linux-pm/drivers/acpi/thermal.c
===================================================================
--- linux-pm.orig/drivers/acpi/thermal.c
+++ linux-pm/drivers/acpi/thermal.c
@@ -95,6 +95,7 @@ struct acpi_thermal_passive {
struct acpi_thermal_active {
struct acpi_thermal_trip trip;
+ int index;
};
struct acpi_thermal_trips {
@@ -285,14 +286,36 @@ static void acpi_thermal_update_active_t
ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state");
}
+struct adjust_trip_data {
+ struct acpi_thermal *tz;
+ u32 event;
+};
+
static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data)
{
struct acpi_thermal_trip *acpi_trip = trip->priv;
- struct acpi_thermal *tz = data;
+ struct adjust_trip_data *atd = data;
+ struct acpi_thermal *tz = atd->tz;
if (!acpi_trip)
return 0;
+ if (trip->type == THERMAL_TRIP_PASSIVE) {
+ if (atd->event == ACPI_THERMAL_NOTIFY_THRESHOLDS)
+ acpi_thermal_update_passive_trip(tz);
+ else
+ acpi_thermal_update_trip_devices(tz, ACPI_THERMAL_TRIP_PASSIVE);
+ } else {
+ /* Since acpi_trip is present, this must be an active trip. */
+ struct acpi_thermal_active *active;
+
+ active = container_of(acpi_trip, struct acpi_thermal_active, trip);
+ if (atd->event == ACPI_THERMAL_NOTIFY_THRESHOLDS)
+ acpi_thermal_update_active_trip(tz, active->index);
+ else
+ acpi_thermal_update_trip_devices(tz, active->index);
+ }
+
if (acpi_thermal_trip_valid(acpi_trip))
trip->temperature = acpi_thermal_temp(tz, acpi_trip->temp_dk);
else
@@ -301,25 +324,6 @@ static int acpi_thermal_adjust_trip(stru
return 0;
}
-static void acpi_thermal_adjust_thermal_zone(struct thermal_zone_device *thermal,
- unsigned long data)
-{
- struct acpi_thermal *tz = thermal_zone_device_priv(thermal);
- int i;
-
- if (data == ACPI_THERMAL_NOTIFY_THRESHOLDS) {
- acpi_thermal_update_passive_trip(tz);
- for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
- acpi_thermal_update_active_trip(tz, i);
- } else {
- acpi_thermal_update_trip_devices(tz, ACPI_THERMAL_TRIP_PASSIVE);
- for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
- acpi_thermal_update_trip_devices(tz, i);
- }
-
- for_each_thermal_trip(tz->thermal_zone, acpi_thermal_adjust_trip, tz);
-}
-
static void acpi_queue_thermal_check(struct acpi_thermal *tz)
{
if (!work_pending(&tz->thermal_check_work))
@@ -328,17 +332,18 @@ static void acpi_queue_thermal_check(str
static void acpi_thermal_trips_update(struct acpi_thermal *tz, u32 event)
{
+ struct adjust_trip_data atd = { .tz = tz, .event = event };
struct acpi_device *adev = tz->device;
/*
- * Use thermal_zone_device_exec() to carry out the trip points
+ * Use thermal_zone_for_each_trip() to carry out the trip points
* update, so as to protect thermal_get_trend() from getting stale
* trip point temperatures and to prevent thermal_zone_device_update()
* invoked from acpi_thermal_check_fn() from producing inconsistent
* results.
*/
- thermal_zone_device_exec(tz->thermal_zone,
- acpi_thermal_adjust_thermal_zone, event);
+ thermal_zone_for_each_trip(tz->thermal_zone,
+ acpi_thermal_adjust_trip, &atd);
acpi_queue_thermal_check(tz);
acpi_bus_generate_netlink_event(adev->pnp.device_class,
dev_name(&adev->dev), event, 0);
@@ -466,11 +471,12 @@ static int acpi_thermal_get_trip_points(
count++;
for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
- if (acpi_thermal_init_trip(tz, i))
+ if (acpi_thermal_init_trip(tz, i)) {
+ tz->trips.active[i].index = i;
count++;
- else
+ } else {
break;
-
+ }
}
while (++i < ACPI_THERMAL_MAX_ACTIVE)
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v1 3/4] thermal: core: Drop thermal_zone_device_exec()
2023-10-02 17:58 [PATCH v1 0/4] thermal: Improve iteration over trip points Rafael J. Wysocki
2023-10-02 17:59 ` [PATCH v1 1/4] thermal: core: Add function to walk trips under zone lock Rafael J. Wysocki
2023-10-02 18:00 ` [PATCH v1 2/4] ACPI: thermal: Use thermal_zone_for_each_trip() Rafael J. Wysocki
@ 2023-10-02 18:02 ` Rafael J. Wysocki
2023-10-02 18:03 ` [PATCH v1 4/4] thermal: int340x: Use thermal_zone_for_each_trip() Rafael J. Wysocki
3 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2023-10-02 18:02 UTC (permalink / raw)
To: Linux PM
Cc: LKML, Linux ACPI, Daniel Lezcano, Zhang Rui, Srinivas Pandruvada,
Rafael J. Wysocki
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Because thermal_zone_device_exec() has no users any more and there are
no plans to use it anywhere, revert commit 9a99a996d1ec ("thermal: core:
Introduce thermal_zone_device_exec()") that introduced it.
No functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/thermal/thermal_core.c | 19 -------------------
include/linux/thermal.h | 4 ----
2 files changed, 23 deletions(-)
Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.c
+++ linux-pm/drivers/thermal/thermal_core.c
@@ -493,25 +493,6 @@ void thermal_zone_device_update(struct t
}
EXPORT_SYMBOL_GPL(thermal_zone_device_update);
-/**
- * thermal_zone_device_exec - Run a callback under the zone lock.
- * @tz: Thermal zone.
- * @cb: Callback to run.
- * @data: Data to pass to the callback.
- */
-void thermal_zone_device_exec(struct thermal_zone_device *tz,
- void (*cb)(struct thermal_zone_device *,
- unsigned long),
- unsigned long data)
-{
- mutex_lock(&tz->lock);
-
- cb(tz, data);
-
- mutex_unlock(&tz->lock);
-}
-EXPORT_SYMBOL_GPL(thermal_zone_device_exec);
-
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
@@ -340,10 +340,6 @@ 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_exec(struct thermal_zone_device *tz,
- void (*cb)(struct thermal_zone_device *,
- unsigned long),
- unsigned long data);
struct thermal_cooling_device *thermal_cooling_device_register(const char *,
void *, const struct thermal_cooling_device_ops *);
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v1 4/4] thermal: int340x: Use thermal_zone_for_each_trip()
2023-10-02 17:58 [PATCH v1 0/4] thermal: Improve iteration over trip points Rafael J. Wysocki
` (2 preceding siblings ...)
2023-10-02 18:02 ` [PATCH v1 3/4] thermal: core: Drop thermal_zone_device_exec() Rafael J. Wysocki
@ 2023-10-02 18:03 ` Rafael J. Wysocki
3 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2023-10-02 18:03 UTC (permalink / raw)
To: Linux PM
Cc: LKML, Linux ACPI, Daniel Lezcano, Zhang Rui, Srinivas Pandruvada,
Rafael J. Wysocki
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Modify int340x_thermal_update_trips() to use thermal_zone_for_each_trip()
for walking trips instead of using the trips[] table passed to the
thermal zone registration function.
For this purpose, store active trip point indices in the priv fieids of
the corresponding thermal_trip structures.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c | 76 +++++------
1 file changed, 41 insertions(+), 35 deletions(-)
Index: linux-pm/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
===================================================================
--- linux-pm.orig/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
+++ linux-pm/drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
@@ -67,6 +67,16 @@ static struct thermal_zone_device_ops in
.critical = int340x_thermal_critical,
};
+static inline void *int_to_trip_priv(int i)
+{
+ return (void *)(long)i;
+}
+
+static inline int trip_priv_to_int(const struct thermal_trip *trip)
+{
+ return (long)trip->priv;
+}
+
static int int340x_thermal_read_trips(struct acpi_device *zone_adev,
struct thermal_trip *zone_trips,
int trip_cnt)
@@ -101,6 +111,7 @@ static int int340x_thermal_read_trips(st
break;
zone_trips[trip_cnt].type = THERMAL_TRIP_ACTIVE;
+ zone_trips[trip_cnt].priv = int_to_trip_priv(i);
trip_cnt++;
}
@@ -212,45 +223,40 @@ void int340x_thermal_zone_remove(struct
}
EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove);
-void int340x_thermal_update_trips(struct int34x_thermal_zone *int34x_zone)
+static int int340x_update_one_trip(struct thermal_trip *trip, void *arg)
{
- struct acpi_device *zone_adev = int34x_zone->adev;
- struct thermal_trip *zone_trips = int34x_zone->trips;
- int trip_cnt = int34x_zone->zone->num_trips;
- int act_trip_nr = 0;
- int i;
-
- mutex_lock(&int34x_zone->zone->lock);
-
- for (i = int34x_zone->aux_trip_nr; i < trip_cnt; i++) {
- int temp, err;
-
- switch (zone_trips[i].type) {
- case THERMAL_TRIP_CRITICAL:
- err = thermal_acpi_critical_trip_temp(zone_adev, &temp);
- break;
- case THERMAL_TRIP_HOT:
- err = thermal_acpi_hot_trip_temp(zone_adev, &temp);
- break;
- case THERMAL_TRIP_PASSIVE:
- err = thermal_acpi_passive_trip_temp(zone_adev, &temp);
- break;
- case THERMAL_TRIP_ACTIVE:
- err = thermal_acpi_active_trip_temp(zone_adev, act_trip_nr++,
- &temp);
- break;
- default:
- err = -ENODEV;
- }
- if (err) {
- zone_trips[i].temperature = THERMAL_TEMP_INVALID;
- continue;
- }
+ struct acpi_device *zone_adev = arg;
+ int temp, err;
- zone_trips[i].temperature = temp;
+ switch (trip->type) {
+ case THERMAL_TRIP_CRITICAL:
+ err = thermal_acpi_critical_trip_temp(zone_adev, &temp);
+ break;
+ case THERMAL_TRIP_HOT:
+ err = thermal_acpi_hot_trip_temp(zone_adev, &temp);
+ break;
+ case THERMAL_TRIP_PASSIVE:
+ err = thermal_acpi_passive_trip_temp(zone_adev, &temp);
+ break;
+ case THERMAL_TRIP_ACTIVE:
+ err = thermal_acpi_active_trip_temp(zone_adev,
+ trip_priv_to_int(trip),
+ &temp);
+ break;
+ default:
+ err = -ENODEV;
}
+ if (err)
+ temp = THERMAL_TEMP_INVALID;
- mutex_unlock(&int34x_zone->zone->lock);
+ trip->temperature = temp;
+ return 0;
+}
+
+void int340x_thermal_update_trips(struct int34x_thermal_zone *int34x_zone)
+{
+ thermal_zone_for_each_trip(int34x_zone->zone, int340x_update_one_trip,
+ int34x_zone->adev);
}
EXPORT_SYMBOL_GPL(int340x_thermal_update_trips);
^ permalink raw reply [flat|nested] 5+ messages in thread