@@ -94,7 +94,6 @@ struct cdev_record {
94
94
* @trip_temp: trip temperature at mitigation start
95
95
* @trip_hyst: trip hysteresis at mitigation start
96
96
* @count: the number of times the zone temperature was above the trip point
97
- * @max: maximum recorded temperature above the trip point
98
97
* @min: minimum recorded temperature above the trip point
99
98
* @avg: average temperature above the trip point
100
99
*/
@@ -104,7 +103,6 @@ struct trip_stats {
104
103
int trip_temp ;
105
104
int trip_hyst ;
106
105
int count ;
107
- int max ;
108
106
int min ;
109
107
int avg ;
110
108
};
@@ -122,12 +120,14 @@ struct trip_stats {
122
120
* @timestamp: first trip point crossed the way up
123
121
* @duration: total duration of the mitigation episode
124
122
* @node: a list element to be added to the list of tz events
123
+ * @max_temp: maximum zone temperature during this episode
125
124
* @trip_stats: per trip point statistics, flexible array
126
125
*/
127
126
struct tz_episode {
128
127
ktime_t timestamp ;
129
128
ktime_t duration ;
130
129
struct list_head node ;
130
+ int max_temp ;
131
131
struct trip_stats trip_stats [];
132
132
};
133
133
@@ -561,10 +561,11 @@ static struct tz_episode *thermal_debugfs_tz_event_alloc(struct thermal_zone_dev
561
561
INIT_LIST_HEAD (& tze -> node );
562
562
tze -> timestamp = now ;
563
563
tze -> duration = KTIME_MIN ;
564
+ tze -> max_temp = INT_MIN ;
564
565
565
566
for (i = 0 ; i < tz -> num_trips ; i ++ ) {
567
+ tze -> trip_stats [i ].trip_temp = THERMAL_TEMP_INVALID ;
566
568
tze -> trip_stats [i ].min = INT_MAX ;
567
- tze -> trip_stats [i ].max = INT_MIN ;
568
569
}
569
570
570
571
return tze ;
@@ -573,20 +574,20 @@ static struct tz_episode *thermal_debugfs_tz_event_alloc(struct thermal_zone_dev
573
574
void thermal_debug_tz_trip_up (struct thermal_zone_device * tz ,
574
575
const struct thermal_trip * trip )
575
576
{
576
- struct tz_episode * tze ;
577
- struct tz_debugfs * tz_dbg ;
578
577
struct thermal_debugfs * thermal_dbg = tz -> debugfs ;
579
578
int trip_id = thermal_zone_trip_id (tz , trip );
580
579
ktime_t now = ktime_get ();
581
580
struct trip_stats * trip_stats ;
581
+ struct tz_debugfs * tz_dbg ;
582
+ struct tz_episode * tze ;
582
583
583
584
if (!thermal_dbg )
584
585
return ;
585
586
586
- mutex_lock (& thermal_dbg -> lock );
587
-
588
587
tz_dbg = & thermal_dbg -> tz_dbg ;
589
588
589
+ mutex_lock (& thermal_dbg -> lock );
590
+
590
591
/*
591
592
* The mitigation is starting. A mitigation can contain
592
593
* 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,
653
654
mutex_unlock (& thermal_dbg -> lock );
654
655
}
655
656
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
+
656
667
void thermal_debug_tz_trip_down (struct thermal_zone_device * tz ,
657
668
const struct thermal_trip * trip )
658
669
{
659
670
struct thermal_debugfs * thermal_dbg = tz -> debugfs ;
671
+ int trip_id = thermal_zone_trip_id (tz , trip );
672
+ ktime_t now = ktime_get ();
660
673
struct tz_episode * tze ;
661
674
struct tz_debugfs * tz_dbg ;
662
- ktime_t delta , now = ktime_get ();
663
- int trip_id = thermal_zone_trip_id (tz , trip );
664
675
int i ;
665
676
666
677
if (!thermal_dbg )
667
678
return ;
668
679
669
- mutex_lock (& thermal_dbg -> lock );
670
-
671
680
tz_dbg = & thermal_dbg -> tz_dbg ;
672
681
682
+ mutex_lock (& thermal_dbg -> lock );
683
+
673
684
/*
674
685
* The temperature crosses the way down but there was not
675
686
* mitigation detected before. That may happen when the
@@ -695,13 +706,7 @@ void thermal_debug_tz_trip_down(struct thermal_zone_device *tz,
695
706
696
707
tze = list_first_entry (& tz_dbg -> tz_episodes , struct tz_episode , node );
697
708
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 );
705
710
706
711
/*
707
712
* 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)
724
729
if (!thermal_dbg )
725
730
return ;
726
731
727
- mutex_lock (& thermal_dbg -> lock );
728
-
729
732
tz_dbg = & thermal_dbg -> tz_dbg ;
730
733
734
+ mutex_lock (& thermal_dbg -> lock );
735
+
731
736
if (!tz_dbg -> nr_trips )
732
737
goto out ;
733
738
734
739
tze = list_first_entry (& tz_dbg -> tz_episodes , struct tz_episode , node );
735
740
741
+ if (tz -> temperature > tze -> max_temp )
742
+ tze -> max_temp = tz -> temperature ;
743
+
736
744
for (i = 0 ; i < tz_dbg -> nr_trips ; i ++ ) {
737
745
int trip_id = tz_dbg -> trips_crossed [i ];
738
746
struct trip_stats * trip_stats = & tze -> trip_stats [trip_id ];
739
747
740
- trip_stats -> max = max (trip_stats -> max , tz -> temperature );
741
748
trip_stats -> min = min (trip_stats -> min , tz -> temperature );
742
749
trip_stats -> avg += (tz -> temperature - trip_stats -> avg ) /
743
750
++ trip_stats -> count ;
@@ -777,7 +784,6 @@ static int tze_seq_show(struct seq_file *s, void *v)
777
784
struct thermal_zone_device * tz = thermal_dbg -> tz_dbg .tz ;
778
785
struct thermal_trip_desc * td ;
779
786
struct tz_episode * tze ;
780
- const char * type ;
781
787
u64 duration_ms ;
782
788
int trip_id ;
783
789
char c ;
@@ -793,10 +799,10 @@ static int tze_seq_show(struct seq_file *s, void *v)
793
799
c = '=' ;
794
800
}
795
801
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 );
798
804
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" );
800
806
801
807
for_each_trip_desc (tz , td ) {
802
808
const struct thermal_trip * trip = & td -> trip ;
@@ -814,16 +820,9 @@ static int tze_seq_show(struct seq_file *s, void *v)
814
820
trip_stats = & tze -> trip_stats [trip_id ];
815
821
816
822
/* Skip trips without any stats. */
817
- if (trip_stats -> min > trip_stats -> max )
823
+ if (trip_stats -> trip_temp == THERMAL_TEMP_INVALID )
818
824
continue ;
819
825
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
-
827
826
if (trip_stats -> timestamp != KTIME_MAX ) {
828
827
/* Mitigation in progress. */
829
828
ktime_t delta = ktime_sub (ktime_get (),
@@ -837,15 +836,14 @@ static int tze_seq_show(struct seq_file *s, void *v)
837
836
c = ' ' ;
838
837
}
839
838
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" ,
841
840
4 , trip_id ,
842
- 8 , type ,
841
+ 8 , thermal_trip_type_name ( trip -> type ) ,
843
842
9 , trip_stats -> trip_temp ,
844
843
9 , trip_stats -> trip_hyst ,
845
- c , 10 , duration_ms ,
844
+ c , 11 , duration_ms ,
846
845
9 , trip_stats -> avg ,
847
- 9 , trip_stats -> min ,
848
- 9 , trip_stats -> max );
846
+ 9 , trip_stats -> min );
849
847
}
850
848
851
849
return 0 ;
@@ -922,3 +920,39 @@ void thermal_debug_tz_remove(struct thermal_zone_device *tz)
922
920
thermal_debugfs_remove_id (thermal_dbg );
923
921
kfree (trips_crossed );
924
922
}
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