Skip to content

Commit bd700ba

Browse files
committed
thermal/debugfs: Avoid printing zero duration for mitigation events in progress
If a thermal mitigation event is in progress, its duration value has not been updated yet, so 0 will be printed as the event duration by tze_seq_show() which is confusing. Avoid doing that by marking the beginning of the event with the KTIME_MIN duration value and making tze_seq_show() compute the current event duration on the fly, in which case '>' will be printed instead of '=' in the event duration value field. Similarly, for trip points that have been crossed on the down, mark the end of mitigation with the KTIME_MAX timestamp value and make tze_seq_show() compute the current duration on the fly for the trip points still involved in the mitigation, in which cases the duration value printed by it will be prepended with a '>' character. Fixes: 7ef01f2 ("thermal/debugfs: Add thermal debugfs information for mitigation episodes") Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Lukasz Luba <[email protected]> Tested-by: Lukasz Luba <[email protected]>
1 parent 31a0fa0 commit bd700ba

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

drivers/thermal/thermal_debugfs.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ static struct tz_episode *thermal_debugfs_tz_event_alloc(struct thermal_zone_dev
556556

557557
INIT_LIST_HEAD(&tze->node);
558558
tze->timestamp = now;
559+
tze->duration = KTIME_MIN;
559560

560561
for (i = 0; i < tz->num_trips; i++) {
561562
tze->trip_stats[i].min = INT_MAX;
@@ -691,6 +692,9 @@ void thermal_debug_tz_trip_down(struct thermal_zone_device *tz,
691692
tze->trip_stats[trip_id].duration =
692693
ktime_add(delta, tze->trip_stats[trip_id].duration);
693694

695+
/* Mark the end of mitigation for this trip point. */
696+
tze->trip_stats[trip_id].timestamp = KTIME_MAX;
697+
694698
/*
695699
* This event closes the mitigation as we are crossing the
696700
* last trip point the way down.
@@ -766,15 +770,25 @@ static int tze_seq_show(struct seq_file *s, void *v)
766770
struct thermal_trip_desc *td;
767771
struct tz_episode *tze;
768772
const char *type;
773+
u64 duration_ms;
769774
int trip_id;
775+
char c;
770776

771777
tze = list_entry((struct list_head *)v, struct tz_episode, node);
772778

773-
seq_printf(s, ",-Mitigation at %lluus, duration=%llums\n",
774-
ktime_to_us(tze->timestamp),
775-
ktime_to_ms(tze->duration));
779+
if (tze->duration == KTIME_MIN) {
780+
/* Mitigation in progress. */
781+
duration_ms = ktime_to_ms(ktime_sub(ktime_get(), tze->timestamp));
782+
c = '>';
783+
} else {
784+
duration_ms = ktime_to_ms(tze->duration);
785+
c = '=';
786+
}
787+
788+
seq_printf(s, ",-Mitigation at %lluus, duration%c%llums\n",
789+
ktime_to_us(tze->timestamp), c, duration_ms);
776790

777-
seq_printf(s, "| trip | type | temp(°mC) | hyst(°mC) | duration | avg(°mC) | min(°mC) | max(°mC) |\n");
791+
seq_printf(s, "| trip | type | temp(°mC) | hyst(°mC) | duration | avg(°mC) | min(°mC) | max(°mC) |\n");
778792

779793
for_each_trip_desc(tz, td) {
780794
const struct thermal_trip *trip = &td->trip;
@@ -806,12 +820,25 @@ static int tze_seq_show(struct seq_file *s, void *v)
806820
else
807821
type = "hot";
808822

809-
seq_printf(s, "| %*d | %*s | %*d | %*d | %*lld | %*d | %*d | %*d |\n",
823+
if (trip_stats->timestamp != KTIME_MAX) {
824+
/* Mitigation in progress. */
825+
ktime_t delta = ktime_sub(ktime_get(),
826+
trip_stats->timestamp);
827+
828+
delta = ktime_add(delta, trip_stats->duration);
829+
duration_ms = ktime_to_ms(delta);
830+
c = '>';
831+
} else {
832+
duration_ms = ktime_to_ms(trip_stats->duration);
833+
c = ' ';
834+
}
835+
836+
seq_printf(s, "| %*d | %*s | %*d | %*d | %c%*lld | %*d | %*d | %*d |\n",
810837
4 , trip_id,
811838
8, type,
812839
9, trip->temperature,
813840
9, trip->hysteresis,
814-
10, ktime_to_ms(trip_stats->duration),
841+
c, 10, duration_ms,
815842
9, trip_stats->avg,
816843
9, trip_stats->min,
817844
9, trip_stats->max);

0 commit comments

Comments
 (0)