@@ -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 */
127126struct 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
573574void 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+
656667void 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+ }
0 commit comments