+/**
+ * struct tz_events - Store all events related to a mitigation episode
+ *
+ * The tz_events structure describes a mitigation episode.
So why not call it tz_mitigation?
+ if (dfs->tz.trip_index < 0) {
+ tze = thermal_debugfs_tz_event_alloc(tz, now);
+ if (!tze)
+ return;
+
+ list_add(&tze->node, &dfs->tz.tz_events);
+ }
+
+ dfs->tz.trip_index++;
+ dfs->tz.trips_crossed[dfs->tz.trip_index] = trip_id;
So trip_index is an index into trips_crossed[] and the value is the ID
of the trip passed by thermal_debug_tz_trip_up() IIUC, so the trip IDs
in trips_crossed[] are always sorted by the trip temperature, in the
ascending order.
It would be good to write this down somewhere in a comment.
And what if trip temperatures change during a mitigation episode such
that the order by the trip temperature changes?
+
+ tze = list_first_entry(&dfs->tz.tz_events, struct tz_events, node);
+ tze->trip_stats[trip_id].timestamp = now;
+ tze->trip_stats[trip_id].max = max(tze->trip_stats[trip_id].max, temperature);
+ tze->trip_stats[trip_id].min = min(tze->trip_stats[trip_id].min, temperature);
+ tze->trip_stats[trip_id].avg = tze->trip_stats[trip_id].avg +
+ (temperature - tze->trip_stats[trip_id].avg) /
+ tze->trip_stats[trip_id].count;
+
+ mutex_unlock(&dfs->lock);
+}