* [PATCH v1 0/4] thermal: core: Fixes related to trip points that get changed
@ 2024-05-23 15:55 Rafael J. Wysocki
2024-05-23 15:57 ` [PATCH v1 1/4] thermal/debugfs: Print initial trip temperature and hysteresis in tze_seq_show() Rafael J. Wysocki
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-05-23 15:55 UTC (permalink / raw)
To: Linux PM
Cc: LKML, Rafael J. Wysocki, Lukasz Luba, Daniel Lezcano,
Srinivas Pandruvada, Zhang Rui
Hi Everyone,
These are fixes (for 6.10-rc) related to the handling of trip points that
change during mitigation episodes involving them.
The first two address the handling of such trips by the thermal debug code, the
third one is a cleanup prerequisite for the next one, and the last one amends
a recent fix.
Please refer to the individual patch changelogs for details.
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 1/4] thermal/debugfs: Print initial trip temperature and hysteresis in tze_seq_show()
2024-05-23 15:55 [PATCH v1 0/4] thermal: core: Fixes related to trip points that get changed Rafael J. Wysocki
@ 2024-05-23 15:57 ` Rafael J. Wysocki
2024-05-23 15:58 ` [PATCH v1 2/4] thermal/debugfs: Allow tze_seq_show() to print statistics for invalid trips Rafael J. Wysocki
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-05-23 15:57 UTC (permalink / raw)
To: Linux PM
Cc: LKML, Rafael J. Wysocki, Lukasz Luba, Daniel Lezcano,
Srinivas Pandruvada, Zhang Rui
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
The temperature and hysteresis of a trip point may change during a
mitigation episode it is involved in (it may even become invalid
altogether), so in order to avoid possible confusion related to that,
store the temperature and hysteresis of trip points at the time they
are crossed on the way up and print those values instead of their
current temperature and hysteresis.
Fixes: 7ef01f228c9f ("thermal/debugfs: Add thermal debugfs information for mitigation episodes")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/thermal/thermal_debugfs.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
Index: linux-pm/drivers/thermal/thermal_debugfs.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_debugfs.c
+++ linux-pm/drivers/thermal/thermal_debugfs.c
@@ -91,6 +91,8 @@ struct cdev_record {
*
* @timestamp: the trip crossing timestamp
* @duration: total time when the zone temperature was above the trip point
+ * @trip_temp: trip temperature at mitigation start
+ * @trip_hyst: trip hysteresis at mitigation start
* @count: the number of times the zone temperature was above the trip point
* @max: maximum recorded temperature above the trip point
* @min: minimum recorded temperature above the trip point
@@ -99,6 +101,8 @@ struct cdev_record {
struct trip_stats {
ktime_t timestamp;
ktime_t duration;
+ int trip_temp;
+ int trip_hyst;
int count;
int max;
int min;
@@ -574,6 +581,7 @@ void thermal_debug_tz_trip_up(struct the
struct thermal_debugfs *thermal_dbg = tz->debugfs;
int trip_id = thermal_zone_trip_id(tz, trip);
ktime_t now = ktime_get();
+ struct trip_stats *trip_stats;
if (!thermal_dbg)
return;
@@ -639,7 +647,10 @@ void thermal_debug_tz_trip_up(struct the
tz_dbg->trips_crossed[tz_dbg->nr_trips++] = trip_id;
tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node);
- tze->trip_stats[trip_id].timestamp = now;
+ trip_stats = &tze->trip_stats[trip_id];
+ trip_stats->trip_temp = trip->temperature;
+ trip_stats->trip_hyst = trip->hysteresis;
+ trip_stats->timestamp = now;
unlock:
mutex_unlock(&thermal_dbg->lock);
@@ -836,8 +847,8 @@ static int tze_seq_show(struct seq_file
seq_printf(s, "| %*d | %*s | %*d | %*d | %c%*lld | %*d | %*d | %*d |\n",
4 , trip_id,
8, type,
- 9, trip->temperature,
- 9, trip->hysteresis,
+ 9, trip_stats->trip_temp,
+ 9, trip_stats->trip_hyst,
c, 10, duration_ms,
9, trip_stats->avg,
9, trip_stats->min,
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 2/4] thermal/debugfs: Allow tze_seq_show() to print statistics for invalid trips
2024-05-23 15:55 [PATCH v1 0/4] thermal: core: Fixes related to trip points that get changed Rafael J. Wysocki
2024-05-23 15:57 ` [PATCH v1 1/4] thermal/debugfs: Print initial trip temperature and hysteresis in tze_seq_show() Rafael J. Wysocki
@ 2024-05-23 15:58 ` Rafael J. Wysocki
2024-05-23 16:00 ` [PATCH v1 3/4] thermal: core: Introduce thermal_trip_crossed() Rafael J. Wysocki
2024-05-23 16:05 ` [PATCH v1 4/4] thermal: trip: Trigger trip down notifications when trips involved in mitigation become invalid Rafael J. Wysocki
3 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-05-23 15:58 UTC (permalink / raw)
To: Linux PM
Cc: LKML, Rafael J. Wysocki, Lukasz Luba, Daniel Lezcano,
Srinivas Pandruvada, Zhang Rui
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Commit a6258fde8de3 ("thermal/debugfs: Make tze_seq_show() skip invalid
trips and trips with no stats") modified tze_seq_show() to skip invalid
trips, but it overlooked the fact that a trip may become invalid during
a mitigation eposide involving it, in which case its statistics should
still be reported.
For this reason, remove the invalid trip temperature check from the
main loop in tze_seq_show().
The trips that have never been valid will still be skipped after this
change because there are no statistics to report for them.
Fixes: a6258fde8de3 ("thermal/debugfs: Make tze_seq_show() skip invalid trips and trips with no stats")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/thermal/thermal_debugfs.c | 4 ----
1 file changed, 4 deletions(-)
Index: linux-pm/drivers/thermal/thermal_debugfs.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_debugfs.c
+++ linux-pm/drivers/thermal/thermal_debugfs.c
@@ -802,10 +802,6 @@ static int tze_seq_show(struct seq_file
const struct thermal_trip *trip = &td->trip;
struct trip_stats *trip_stats;
- /* Skip invalid trips. */
- if (trip->temperature == THERMAL_TEMP_INVALID)
- continue;
-
/*
* There is no possible mitigation happening at the
* critical trip point, so the stats will be always
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 3/4] thermal: core: Introduce thermal_trip_crossed()
2024-05-23 15:55 [PATCH v1 0/4] thermal: core: Fixes related to trip points that get changed Rafael J. Wysocki
2024-05-23 15:57 ` [PATCH v1 1/4] thermal/debugfs: Print initial trip temperature and hysteresis in tze_seq_show() Rafael J. Wysocki
2024-05-23 15:58 ` [PATCH v1 2/4] thermal/debugfs: Allow tze_seq_show() to print statistics for invalid trips Rafael J. Wysocki
@ 2024-05-23 16:00 ` Rafael J. Wysocki
2024-05-23 16:05 ` [PATCH v1 4/4] thermal: trip: Trigger trip down notifications when trips involved in mitigation become invalid Rafael J. Wysocki
3 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-05-23 16:00 UTC (permalink / raw)
To: Linux PM
Cc: LKML, Rafael J. Wysocki, Lukasz Luba, Daniel Lezcano,
Srinivas Pandruvada, Zhang Rui
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Add a helper function called thermal_trip_crossed() to be invoked by
__thermal_zone_device_update() in order to notify user space, the
thermal debug code and the zone governor about trip crossing.
Subsequently, this will also be used in the case when a trip point
becomes invalid after being crossed on the way up.
No intentional functional impact.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/thermal/thermal_core.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.c
+++ linux-pm/drivers/thermal/thermal_core.c
@@ -467,6 +467,21 @@ static void thermal_governor_trip_crosse
governor->trip_crossed(tz, trip, crossed_up);
}
+static void thermal_trip_crossed(struct thermal_zone_device *tz,
+ const struct thermal_trip *trip,
+ struct thermal_governor *governor,
+ bool crossed_up)
+{
+ if (crossed_up) {
+ thermal_notify_tz_trip_up(tz, trip);
+ thermal_debug_tz_trip_up(tz, trip);
+ } else {
+ thermal_notify_tz_trip_down(tz, trip);
+ thermal_debug_tz_trip_down(tz, trip);
+ }
+ thermal_governor_trip_crossed(governor, tz, trip, crossed_up);
+}
+
static int thermal_trip_notify_cmp(void *ascending, const struct list_head *a,
const struct list_head *b)
{
@@ -506,18 +521,12 @@ void __thermal_zone_device_update(struct
handle_thermal_trip(tz, td, &way_up_list, &way_down_list);
list_sort(&way_up_list, &way_up_list, thermal_trip_notify_cmp);
- list_for_each_entry(td, &way_up_list, notify_list_node) {
- thermal_notify_tz_trip_up(tz, &td->trip);
- thermal_debug_tz_trip_up(tz, &td->trip);
- thermal_governor_trip_crossed(governor, tz, &td->trip, true);
- }
+ list_for_each_entry(td, &way_up_list, notify_list_node)
+ thermal_trip_crossed(tz, &td->trip, governor, true);
list_sort(NULL, &way_down_list, thermal_trip_notify_cmp);
- list_for_each_entry(td, &way_down_list, notify_list_node) {
- thermal_notify_tz_trip_down(tz, &td->trip);
- thermal_debug_tz_trip_down(tz, &td->trip);
- thermal_governor_trip_crossed(governor, tz, &td->trip, false);
- }
+ list_for_each_entry(td, &way_down_list, notify_list_node)
+ thermal_trip_crossed(tz, &td->trip, governor, false);
if (governor->manage)
governor->manage(tz);
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 4/4] thermal: trip: Trigger trip down notifications when trips involved in mitigation become invalid
2024-05-23 15:55 [PATCH v1 0/4] thermal: core: Fixes related to trip points that get changed Rafael J. Wysocki
` (2 preceding siblings ...)
2024-05-23 16:00 ` [PATCH v1 3/4] thermal: core: Introduce thermal_trip_crossed() Rafael J. Wysocki
@ 2024-05-23 16:05 ` Rafael J. Wysocki
3 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2024-05-23 16:05 UTC (permalink / raw)
To: Linux PM
Cc: LKML, Rafael J. Wysocki, Lukasz Luba, Daniel Lezcano,
Srinivas Pandruvada, Zhang Rui
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
When a trip point becomes invalid after being crossed on the way up,
it is involved in a mitigation episode that needs to be adjusted to
compensate for the trip going away.
For this reason, introduce thermal_zone_trip_down() as a wrapper
around thermal_trip_crossed() and make thermal_zone_set_trip_temp()
call it if the new temperature of the trip at hand is equal to
THERMAL_TEMP_INVALID and it has been crossed on the way up to trigger
all of the necessary adjustments in user space, the thermal debug
code and the zone governor.
Fixes: 8c69a777e480 ("thermal: core: Fix the handling of invalid trip points")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
Initially, I had thought that this would be a cleanup rather than a fix, but
then I realized that there was the Bang-bang governor that needed to undo
mitigation when the trip that triggered it became invalid before getting
crossed on the way down.
---
drivers/thermal/thermal_core.c | 6 ++++++
drivers/thermal/thermal_core.h | 2 ++
drivers/thermal/thermal_trip.c | 20 ++++++++++++--------
3 files changed, 20 insertions(+), 8 deletions(-)
Index: linux-pm/drivers/thermal/thermal_core.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.c
+++ linux-pm/drivers/thermal/thermal_core.c
@@ -602,6 +602,12 @@ void thermal_zone_device_update(struct t
}
EXPORT_SYMBOL_GPL(thermal_zone_device_update);
+void thermal_zone_trip_down(struct thermal_zone_device *tz,
+ const struct thermal_trip *trip)
+{
+ thermal_trip_crossed(tz, trip, thermal_get_tz_governor(tz), false);
+}
+
int for_each_thermal_governor(int (*cb)(struct thermal_governor *, void *),
void *data)
{
Index: linux-pm/drivers/thermal/thermal_core.h
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.h
+++ linux-pm/drivers/thermal/thermal_core.h
@@ -246,6 +246,8 @@ int thermal_zone_trip_id(const struct th
void thermal_zone_trip_updated(struct thermal_zone_device *tz,
const struct thermal_trip *trip);
int __thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
+void thermal_zone_trip_down(struct thermal_zone_device *tz,
+ const struct thermal_trip *trip);
/* sysfs I/F */
int thermal_zone_create_device_groups(struct thermal_zone_device *tz);
Index: linux-pm/drivers/thermal/thermal_trip.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_trip.c
+++ linux-pm/drivers/thermal/thermal_trip.c
@@ -152,17 +152,23 @@ void thermal_zone_set_trip_temp(struct t
if (trip->temperature == temp)
return;
+ trip->temperature = temp;
+ thermal_notify_tz_trip_change(tz, trip);
+
if (temp == THERMAL_TEMP_INVALID) {
struct thermal_trip_desc *td = trip_to_trip_desc(trip);
- if (trip->type == THERMAL_TRIP_PASSIVE &&
- tz->temperature >= td->threshold) {
+ if (tz->temperature >= td->threshold) {
/*
- * The trip has been crossed, so the thermal zone's
- * passive count needs to be adjusted.
+ * The trip has been crossed on the way up, so some
+ * adjustments are needed to compensate for the lack
+ * of it going forward.
*/
- tz->passive--;
- WARN_ON_ONCE(tz->passive < 0);
+ if (trip->type == THERMAL_TRIP_PASSIVE) {
+ tz->passive--;
+ WARN_ON_ONCE(tz->passive < 0);
+ }
+ thermal_zone_trip_down(tz, trip);
}
/*
* Invalidate the threshold to avoid triggering a spurious
@@ -170,7 +176,5 @@ void thermal_zone_set_trip_temp(struct t
*/
td->threshold = INT_MAX;
}
- trip->temperature = temp;
- thermal_notify_tz_trip_change(tz, trip);
}
EXPORT_SYMBOL_GPL(thermal_zone_set_trip_temp);
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-05-23 16:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-23 15:55 [PATCH v1 0/4] thermal: core: Fixes related to trip points that get changed Rafael J. Wysocki
2024-05-23 15:57 ` [PATCH v1 1/4] thermal/debugfs: Print initial trip temperature and hysteresis in tze_seq_show() Rafael J. Wysocki
2024-05-23 15:58 ` [PATCH v1 2/4] thermal/debugfs: Allow tze_seq_show() to print statistics for invalid trips Rafael J. Wysocki
2024-05-23 16:00 ` [PATCH v1 3/4] thermal: core: Introduce thermal_trip_crossed() Rafael J. Wysocki
2024-05-23 16:05 ` [PATCH v1 4/4] thermal: trip: Trigger trip down notifications when trips involved in mitigation become invalid Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox