Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 06d55c4

Browse files
committed
Merge branch 'thermal-core'
Merge thermal core changes for v6.11: - Fix and clean up several minor shortcomings in thermal debug (Rafael Wysocki). - Rename __thermal_zone_set_trips() to thermal_zone_set_trips() and make it use trip thresholds (Rafael Wysocki). - Use READ_ONCE() for lockless access to trip temperature and hysteresis (Rafael Wysocki). - Drop unnecessary cooling device target state checks from the Bang-Bang thermal governor (Rafael Wysocki). - Avoid invoking thermal governor .trip_crossed() callback for critical and hot trip points (Rafael Wysocki). * thermal-core: thermal: core: Avoid calling .trip_crossed() for critical and hot trips thermal: gov_bang_bang: Drop unnecessary cooling device target state checks thermal: trip: Use READ_ONCE() for lockless access to trip properties thermal: trip: Make thermal_zone_set_trips() use trip thresholds thermal: trip: Rename __thermal_zone_set_trips() to thermal_zone_set_trips() thermal: trip: Use common set of trip type names thermal/debugfs: Move some statements from under thermal_dbg->lock thermal/debugfs: Compute maximum temperature for mitigation episode as a whole thermal/debugfs: Adjust check for trips without statistics in tze_seq_show() thermal/debugfs: Fix up units in "mitigations" files thermal/debugfs: Print mitigation timestamp value in milliseconds thermal/debugfs: Do not extend mitigation episodes beyond system resume thermal/debugfs: Use helper to update trip point overstepping duration
2 parents 3995904 + 72196c2 commit 06d55c4

File tree

7 files changed

+112
-80
lines changed

7 files changed

+112
-80
lines changed

drivers/thermal/gov_bang_bang.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,16 @@ static void bang_bang_control(struct thermal_zone_device *tz,
5757
if (instance->trip != trip)
5858
continue;
5959

60-
if (instance->target == THERMAL_NO_TARGET)
61-
instance->target = 0;
62-
63-
if (instance->target != 0 && instance->target != 1) {
60+
if (instance->target != 0 && instance->target != 1 &&
61+
instance->target != THERMAL_NO_TARGET)
6462
pr_debug("Unexpected state %ld of thermal instance %s in bang-bang\n",
6563
instance->target, instance->name);
6664

67-
instance->target = 1;
68-
}
69-
7065
/*
7166
* Enable the fan when the trip is crossed on the way up and
7267
* disable it when the trip is crossed on the way down.
7368
*/
74-
if (instance->target == 0 && crossed_up)
75-
instance->target = 1;
76-
else if (instance->target == 1 && !crossed_up)
77-
instance->target = 0;
69+
instance->target = crossed_up;
7870

7971
dev_dbg(&instance->cdev->device, "target=%ld\n", instance->target);
8072

drivers/thermal/thermal_core.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ static void thermal_governor_trip_crossed(struct thermal_governor *governor,
463463
const struct thermal_trip *trip,
464464
bool crossed_up)
465465
{
466+
if (trip->type == THERMAL_TRIP_HOT || trip->type == THERMAL_TRIP_CRITICAL)
467+
return;
468+
466469
if (governor->trip_crossed)
467470
governor->trip_crossed(tz, trip, crossed_up);
468471
}
@@ -513,13 +516,13 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
513516
if (tz->temperature == THERMAL_TEMP_INVALID)
514517
return;
515518

516-
__thermal_zone_set_trips(tz);
517-
518519
tz->notify_event = event;
519520

520521
for_each_trip_desc(tz, td)
521522
handle_thermal_trip(tz, td, &way_up_list, &way_down_list);
522523

524+
thermal_zone_set_trips(tz);
525+
523526
list_sort(&way_up_list, &way_up_list, thermal_trip_notify_cmp);
524527
list_for_each_entry(td, &way_up_list, notify_list_node)
525528
thermal_trip_crossed(tz, &td->trip, governor, true);
@@ -1649,6 +1652,7 @@ static void thermal_zone_device_resume(struct work_struct *work)
16491652

16501653
tz->suspended = false;
16511654

1655+
thermal_debug_tz_resume(tz);
16521656
thermal_zone_device_init(tz);
16531657
__thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED);
16541658

drivers/thermal/thermal_core.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ void thermal_governor_update_tz(struct thermal_zone_device *tz,
244244
#define trip_to_trip_desc(__trip) \
245245
container_of(__trip, struct thermal_trip_desc, trip)
246246

247-
void __thermal_zone_set_trips(struct thermal_zone_device *tz);
247+
const char *thermal_trip_type_name(enum thermal_trip_type trip_type);
248+
249+
void thermal_zone_set_trips(struct thermal_zone_device *tz);
248250
int thermal_zone_trip_id(const struct thermal_zone_device *tz,
249251
const struct thermal_trip *trip);
250252
void thermal_zone_trip_updated(struct thermal_zone_device *tz,

drivers/thermal/thermal_debugfs.c

Lines changed: 72 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ struct cdev_record {
9494
* @trip_temp: trip temperature at mitigation start
9595
* @trip_hyst: trip hysteresis at mitigation start
9696
* @count: the number of times the zone temperature was above the trip point
97-
* @max: maximum recorded temperature above the trip point
9897
* @min: minimum recorded temperature above the trip point
9998
* @avg: average temperature above the trip point
10099
*/
@@ -104,7 +103,6 @@ struct trip_stats {
104103
int trip_temp;
105104
int trip_hyst;
106105
int count;
107-
int max;
108106
int min;
109107
int avg;
110108
};
@@ -122,12 +120,14 @@ struct trip_stats {
122120
* @timestamp: first trip point crossed the way up
123121
* @duration: total duration of the mitigation episode
124122
* @node: a list element to be added to the list of tz events
123+
* @max_temp: maximum zone temperature during this episode
125124
* @trip_stats: per trip point statistics, flexible array
126125
*/
127126
struct tz_episode {
128127
ktime_t timestamp;
129128
ktime_t duration;
130129
struct list_head node;
130+
int max_temp;
131131
struct trip_stats trip_stats[];
132132
};
133133

@@ -561,10 +561,11 @@ static struct tz_episode *thermal_debugfs_tz_event_alloc(struct thermal_zone_dev
561561
INIT_LIST_HEAD(&tze->node);
562562
tze->timestamp = now;
563563
tze->duration = KTIME_MIN;
564+
tze->max_temp = INT_MIN;
564565

565566
for (i = 0; i < tz->num_trips; i++) {
567+
tze->trip_stats[i].trip_temp = THERMAL_TEMP_INVALID;
566568
tze->trip_stats[i].min = INT_MAX;
567-
tze->trip_stats[i].max = INT_MIN;
568569
}
569570

570571
return tze;
@@ -573,20 +574,20 @@ static struct tz_episode *thermal_debugfs_tz_event_alloc(struct thermal_zone_dev
573574
void thermal_debug_tz_trip_up(struct thermal_zone_device *tz,
574575
const struct thermal_trip *trip)
575576
{
576-
struct tz_episode *tze;
577-
struct tz_debugfs *tz_dbg;
578577
struct thermal_debugfs *thermal_dbg = tz->debugfs;
579578
int trip_id = thermal_zone_trip_id(tz, trip);
580579
ktime_t now = ktime_get();
581580
struct trip_stats *trip_stats;
581+
struct tz_debugfs *tz_dbg;
582+
struct tz_episode *tze;
582583

583584
if (!thermal_dbg)
584585
return;
585586

586-
mutex_lock(&thermal_dbg->lock);
587-
588587
tz_dbg = &thermal_dbg->tz_dbg;
589588

589+
mutex_lock(&thermal_dbg->lock);
590+
590591
/*
591592
* The mitigation is starting. A mitigation can contain
592593
* several episodes where each of them is related to a
@@ -653,23 +654,33 @@ void thermal_debug_tz_trip_up(struct thermal_zone_device *tz,
653654
mutex_unlock(&thermal_dbg->lock);
654655
}
655656

657+
static void tz_episode_close_trip(struct tz_episode *tze, int trip_id, ktime_t now)
658+
{
659+
struct trip_stats *trip_stats = &tze->trip_stats[trip_id];
660+
ktime_t delta = ktime_sub(now, trip_stats->timestamp);
661+
662+
trip_stats->duration = ktime_add(delta, trip_stats->duration);
663+
/* Mark the end of mitigation for this trip point. */
664+
trip_stats->timestamp = KTIME_MAX;
665+
}
666+
656667
void thermal_debug_tz_trip_down(struct thermal_zone_device *tz,
657668
const struct thermal_trip *trip)
658669
{
659670
struct thermal_debugfs *thermal_dbg = tz->debugfs;
671+
int trip_id = thermal_zone_trip_id(tz, trip);
672+
ktime_t now = ktime_get();
660673
struct tz_episode *tze;
661674
struct tz_debugfs *tz_dbg;
662-
ktime_t delta, now = ktime_get();
663-
int trip_id = thermal_zone_trip_id(tz, trip);
664675
int i;
665676

666677
if (!thermal_dbg)
667678
return;
668679

669-
mutex_lock(&thermal_dbg->lock);
670-
671680
tz_dbg = &thermal_dbg->tz_dbg;
672681

682+
mutex_lock(&thermal_dbg->lock);
683+
673684
/*
674685
* The temperature crosses the way down but there was not
675686
* mitigation detected before. That may happen when the
@@ -695,13 +706,7 @@ void thermal_debug_tz_trip_down(struct thermal_zone_device *tz,
695706

696707
tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node);
697708

698-
delta = ktime_sub(now, tze->trip_stats[trip_id].timestamp);
699-
700-
tze->trip_stats[trip_id].duration =
701-
ktime_add(delta, tze->trip_stats[trip_id].duration);
702-
703-
/* Mark the end of mitigation for this trip point. */
704-
tze->trip_stats[trip_id].timestamp = KTIME_MAX;
709+
tz_episode_close_trip(tze, trip_id, now);
705710

706711
/*
707712
* This event closes the mitigation as we are crossing the
@@ -724,20 +729,22 @@ void thermal_debug_update_trip_stats(struct thermal_zone_device *tz)
724729
if (!thermal_dbg)
725730
return;
726731

727-
mutex_lock(&thermal_dbg->lock);
728-
729732
tz_dbg = &thermal_dbg->tz_dbg;
730733

734+
mutex_lock(&thermal_dbg->lock);
735+
731736
if (!tz_dbg->nr_trips)
732737
goto out;
733738

734739
tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node);
735740

741+
if (tz->temperature > tze->max_temp)
742+
tze->max_temp = tz->temperature;
743+
736744
for (i = 0; i < tz_dbg->nr_trips; i++) {
737745
int trip_id = tz_dbg->trips_crossed[i];
738746
struct trip_stats *trip_stats = &tze->trip_stats[trip_id];
739747

740-
trip_stats->max = max(trip_stats->max, tz->temperature);
741748
trip_stats->min = min(trip_stats->min, tz->temperature);
742749
trip_stats->avg += (tz->temperature - trip_stats->avg) /
743750
++trip_stats->count;
@@ -777,7 +784,6 @@ static int tze_seq_show(struct seq_file *s, void *v)
777784
struct thermal_zone_device *tz = thermal_dbg->tz_dbg.tz;
778785
struct thermal_trip_desc *td;
779786
struct tz_episode *tze;
780-
const char *type;
781787
u64 duration_ms;
782788
int trip_id;
783789
char c;
@@ -793,10 +799,10 @@ static int tze_seq_show(struct seq_file *s, void *v)
793799
c = '=';
794800
}
795801

796-
seq_printf(s, ",-Mitigation at %lluus, duration%c%llums\n",
797-
ktime_to_us(tze->timestamp), c, duration_ms);
802+
seq_printf(s, ",-Mitigation at %llums, duration%c%llums, max. temp=%dm°C\n",
803+
ktime_to_ms(tze->timestamp), c, duration_ms, tze->max_temp);
798804

799-
seq_printf(s, "| trip | type | temp(°mC) | hyst(°mC) | duration | avg(°mC) | min(°mC) | max(°mC) |\n");
805+
seq_printf(s, "| trip | type | temp(m°C) | hyst(m°C) | duration(ms) | avg(m°C) | min(m°C) |\n");
800806

801807
for_each_trip_desc(tz, td) {
802808
const struct thermal_trip *trip = &td->trip;
@@ -814,16 +820,9 @@ static int tze_seq_show(struct seq_file *s, void *v)
814820
trip_stats = &tze->trip_stats[trip_id];
815821

816822
/* Skip trips without any stats. */
817-
if (trip_stats->min > trip_stats->max)
823+
if (trip_stats->trip_temp == THERMAL_TEMP_INVALID)
818824
continue;
819825

820-
if (trip->type == THERMAL_TRIP_PASSIVE)
821-
type = "passive";
822-
else if (trip->type == THERMAL_TRIP_ACTIVE)
823-
type = "active";
824-
else
825-
type = "hot";
826-
827826
if (trip_stats->timestamp != KTIME_MAX) {
828827
/* Mitigation in progress. */
829828
ktime_t delta = ktime_sub(ktime_get(),
@@ -837,15 +836,14 @@ static int tze_seq_show(struct seq_file *s, void *v)
837836
c = ' ';
838837
}
839838

840-
seq_printf(s, "| %*d | %*s | %*d | %*d | %c%*lld | %*d | %*d | %*d |\n",
839+
seq_printf(s, "| %*d | %*s | %*d | %*d | %c%*lld | %*d | %*d |\n",
841840
4 , trip_id,
842-
8, type,
841+
8, thermal_trip_type_name(trip->type),
843842
9, trip_stats->trip_temp,
844843
9, trip_stats->trip_hyst,
845-
c, 10, duration_ms,
844+
c, 11, duration_ms,
846845
9, trip_stats->avg,
847-
9, trip_stats->min,
848-
9, trip_stats->max);
846+
9, trip_stats->min);
849847
}
850848

851849
return 0;
@@ -922,3 +920,39 @@ void thermal_debug_tz_remove(struct thermal_zone_device *tz)
922920
thermal_debugfs_remove_id(thermal_dbg);
923921
kfree(trips_crossed);
924922
}
923+
924+
void thermal_debug_tz_resume(struct thermal_zone_device *tz)
925+
{
926+
struct thermal_debugfs *thermal_dbg = tz->debugfs;
927+
ktime_t now = ktime_get();
928+
struct tz_debugfs *tz_dbg;
929+
struct tz_episode *tze;
930+
int i;
931+
932+
if (!thermal_dbg)
933+
return;
934+
935+
mutex_lock(&thermal_dbg->lock);
936+
937+
tz_dbg = &thermal_dbg->tz_dbg;
938+
939+
if (!tz_dbg->nr_trips)
940+
goto out;
941+
942+
/*
943+
* A mitigation episode was in progress before the preceding system
944+
* suspend transition, so close it because the zone handling is starting
945+
* over from scratch.
946+
*/
947+
tze = list_first_entry(&tz_dbg->tz_episodes, struct tz_episode, node);
948+
949+
for (i = 0; i < tz_dbg->nr_trips; i++)
950+
tz_episode_close_trip(tze, tz_dbg->trips_crossed[i], now);
951+
952+
tze->duration = ktime_sub(now, tze->timestamp);
953+
954+
tz_dbg->nr_trips = 0;
955+
956+
out:
957+
mutex_unlock(&thermal_dbg->lock);
958+
}

drivers/thermal/thermal_debugfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ void thermal_debug_cdev_remove(struct thermal_cooling_device *cdev);
77
void thermal_debug_cdev_state_update(const struct thermal_cooling_device *cdev, int state);
88
void thermal_debug_tz_add(struct thermal_zone_device *tz);
99
void thermal_debug_tz_remove(struct thermal_zone_device *tz);
10+
void thermal_debug_tz_resume(struct thermal_zone_device *tz);
1011
void thermal_debug_tz_trip_up(struct thermal_zone_device *tz,
1112
const struct thermal_trip *trip);
1213
void thermal_debug_tz_trip_down(struct thermal_zone_device *tz,
@@ -20,6 +21,7 @@ static inline void thermal_debug_cdev_state_update(const struct thermal_cooling_
2021
int state) {}
2122
static inline void thermal_debug_tz_add(struct thermal_zone_device *tz) {}
2223
static inline void thermal_debug_tz_remove(struct thermal_zone_device *tz) {}
24+
static inline void thermal_debug_tz_resume(struct thermal_zone_device *tz) {}
2325
static inline void thermal_debug_tz_trip_up(struct thermal_zone_device *tz,
2426
const struct thermal_trip *trip) {};
2527
static inline void thermal_debug_tz_trip_down(struct thermal_zone_device *tz,

drivers/thermal/thermal_sysfs.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,7 @@ trip_point_type_show(struct device *dev, struct device_attribute *attr,
8888
if (sscanf(attr->attr.name, "trip_point_%d_type", &trip_id) != 1)
8989
return -EINVAL;
9090

91-
switch (tz->trips[trip_id].trip.type) {
92-
case THERMAL_TRIP_CRITICAL:
93-
return sprintf(buf, "critical\n");
94-
case THERMAL_TRIP_HOT:
95-
return sprintf(buf, "hot\n");
96-
case THERMAL_TRIP_PASSIVE:
97-
return sprintf(buf, "passive\n");
98-
case THERMAL_TRIP_ACTIVE:
99-
return sprintf(buf, "active\n");
100-
default:
101-
return sprintf(buf, "unknown\n");
102-
}
91+
return sprintf(buf, "%s\n", thermal_trip_type_name(tz->trips[trip_id].trip.type));
10392
}
10493

10594
static ssize_t
@@ -150,7 +139,7 @@ trip_point_temp_show(struct device *dev, struct device_attribute *attr,
150139
if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip_id) != 1)
151140
return -EINVAL;
152141

153-
return sprintf(buf, "%d\n", tz->trips[trip_id].trip.temperature);
142+
return sprintf(buf, "%d\n", READ_ONCE(tz->trips[trip_id].trip.temperature));
154143
}
155144

156145
static ssize_t
@@ -174,7 +163,7 @@ trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
174163
trip = &tz->trips[trip_id].trip;
175164

176165
if (hyst != trip->hysteresis) {
177-
trip->hysteresis = hyst;
166+
WRITE_ONCE(trip->hysteresis, hyst);
178167

179168
thermal_zone_trip_updated(tz, trip);
180169
}
@@ -194,7 +183,7 @@ trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
194183
if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip_id) != 1)
195184
return -EINVAL;
196185

197-
return sprintf(buf, "%d\n", tz->trips[trip_id].trip.hysteresis);
186+
return sprintf(buf, "%d\n", READ_ONCE(tz->trips[trip_id].trip.hysteresis));
198187
}
199188

200189
static ssize_t

0 commit comments

Comments
 (0)