16
16
17
17
#include "thermal_core.h"
18
18
19
- #define INVALID_TRIP -1
20
-
21
19
#define FRAC_BITS 10
22
20
#define int_to_frac (x ) ((x) << FRAC_BITS)
23
21
#define frac_to_int (x ) ((x) >> FRAC_BITS)
@@ -55,23 +53,23 @@ static inline s64 div_frac(s64 x, s64 y)
55
53
* @err_integral: accumulated error in the PID controller.
56
54
* @prev_err: error in the previous iteration of the PID controller.
57
55
* Used to calculate the derivative term.
56
+ * @sustainable_power: Sustainable power (heat) that this thermal zone can
57
+ * dissipate
58
58
* @trip_switch_on: first passive trip point of the thermal zone. The
59
59
* governor switches on when this trip point is crossed.
60
60
* If the thermal zone only has one passive trip point,
61
- * @trip_switch_on should be INVALID_TRIP .
61
+ * @trip_switch_on should be NULL .
62
62
* @trip_max_desired_temperature: last passive trip point of the thermal
63
63
* zone. The temperature we are
64
64
* controlling for.
65
- * @sustainable_power: Sustainable power (heat) that this thermal zone can
66
- * dissipate
67
65
*/
68
66
struct power_allocator_params {
69
67
bool allocated_tzp ;
70
68
s64 err_integral ;
71
69
s32 prev_err ;
72
- int trip_switch_on ;
73
- int trip_max_desired_temperature ;
74
70
u32 sustainable_power ;
71
+ const struct thermal_trip * trip_switch_on ;
72
+ const struct thermal_trip * trip_max_desired_temperature ;
75
73
};
76
74
77
75
/**
@@ -90,14 +88,12 @@ static u32 estimate_sustainable_power(struct thermal_zone_device *tz)
90
88
u32 sustainable_power = 0 ;
91
89
struct thermal_instance * instance ;
92
90
struct power_allocator_params * params = tz -> governor_data ;
93
- const struct thermal_trip * trip_max_desired_temperature =
94
- & tz -> trips [params -> trip_max_desired_temperature ];
95
91
96
92
list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
97
93
struct thermal_cooling_device * cdev = instance -> cdev ;
98
94
u32 min_power ;
99
95
100
- if (instance -> trip != trip_max_desired_temperature )
96
+ if (instance -> trip != params -> trip_max_desired_temperature )
101
97
continue ;
102
98
103
99
if (!cdev_is_power_actor (cdev ))
@@ -116,24 +112,22 @@ static u32 estimate_sustainable_power(struct thermal_zone_device *tz)
116
112
* estimate_pid_constants() - Estimate the constants for the PID controller
117
113
* @tz: thermal zone for which to estimate the constants
118
114
* @sustainable_power: sustainable power for the thermal zone
119
- * @trip_switch_on: trip point number for the switch on temperature
115
+ * @trip_switch_on: trip point for the switch on temperature
120
116
* @control_temp: target temperature for the power allocator governor
121
117
*
122
118
* This function is used to update the estimation of the PID
123
119
* controller constants in struct thermal_zone_parameters.
124
120
*/
125
121
static void estimate_pid_constants (struct thermal_zone_device * tz ,
126
- u32 sustainable_power , int trip_switch_on ,
122
+ u32 sustainable_power ,
123
+ const struct thermal_trip * trip_switch_on ,
127
124
int control_temp )
128
125
{
129
- struct thermal_trip trip ;
130
126
u32 temperature_threshold = control_temp ;
131
- int ret ;
132
127
s32 k_i ;
133
128
134
- ret = __thermal_zone_get_trip (tz , trip_switch_on , & trip );
135
- if (!ret )
136
- temperature_threshold -= trip .temperature ;
129
+ if (trip_switch_on )
130
+ temperature_threshold -= trip_switch_on -> temperature ;
137
131
138
132
/*
139
133
* estimate_pid_constants() tries to find appropriate default
@@ -386,7 +380,7 @@ static int allocate_power(struct thermal_zone_device *tz,
386
380
struct thermal_instance * instance ;
387
381
struct power_allocator_params * params = tz -> governor_data ;
388
382
const struct thermal_trip * trip_max_desired_temperature =
389
- & tz -> trips [ params -> trip_max_desired_temperature ] ;
383
+ params -> trip_max_desired_temperature ;
390
384
u32 * req_power , * max_power , * granted_power , * extra_actor_power ;
391
385
u32 * weighted_req_power ;
392
386
u32 total_req_power , max_allocatable_power , total_weighted_req_power ;
@@ -496,7 +490,7 @@ static int allocate_power(struct thermal_zone_device *tz,
496
490
}
497
491
498
492
/**
499
- * get_governor_trips() - get the number of the two trip points that are key for this governor
493
+ * get_governor_trips() - get the two trip points that are key for this governor
500
494
* @tz: thermal zone to operate on
501
495
* @params: pointer to private data for this governor
502
496
*
@@ -513,46 +507,36 @@ static int allocate_power(struct thermal_zone_device *tz,
513
507
static void get_governor_trips (struct thermal_zone_device * tz ,
514
508
struct power_allocator_params * params )
515
509
{
516
- int i , last_active , last_passive ;
517
- bool found_first_passive ;
518
-
519
- found_first_passive = false;
520
- last_active = INVALID_TRIP ;
521
- last_passive = INVALID_TRIP ;
522
-
523
- for (i = 0 ; i < tz -> num_trips ; i ++ ) {
524
- struct thermal_trip trip ;
525
- int ret ;
526
-
527
- ret = __thermal_zone_get_trip (tz , i , & trip );
528
- if (ret ) {
529
- dev_warn (& tz -> device ,
530
- "Failed to get trip point %d type: %d\n" , i ,
531
- ret );
532
- continue ;
533
- }
534
-
535
- if (trip .type == THERMAL_TRIP_PASSIVE ) {
536
- if (!found_first_passive ) {
537
- params -> trip_switch_on = i ;
538
- found_first_passive = true;
539
- } else {
540
- last_passive = i ;
510
+ const struct thermal_trip * first_passive = NULL ;
511
+ const struct thermal_trip * last_passive = NULL ;
512
+ const struct thermal_trip * last_active = NULL ;
513
+ const struct thermal_trip * trip ;
514
+
515
+ for_each_trip (tz , trip ) {
516
+ switch (trip -> type ) {
517
+ case THERMAL_TRIP_PASSIVE :
518
+ if (!first_passive ) {
519
+ first_passive = trip ;
520
+ break ;
541
521
}
542
- } else if (trip .type == THERMAL_TRIP_ACTIVE ) {
543
- last_active = i ;
544
- } else {
522
+ last_passive = trip ;
523
+ break ;
524
+ case THERMAL_TRIP_ACTIVE :
525
+ last_active = trip ;
526
+ break ;
527
+ default :
545
528
break ;
546
529
}
547
530
}
548
531
549
- if (last_passive != INVALID_TRIP ) {
532
+ if (last_passive ) {
533
+ params -> trip_switch_on = first_passive ;
550
534
params -> trip_max_desired_temperature = last_passive ;
551
- } else if (found_first_passive ) {
552
- params -> trip_max_desired_temperature = params -> trip_switch_on ;
553
- params -> trip_switch_on = INVALID_TRIP ;
535
+ } else if (first_passive ) {
536
+ params -> trip_switch_on = NULL ;
537
+ params -> trip_max_desired_temperature = first_passive ;
554
538
} else {
555
- params -> trip_switch_on = INVALID_TRIP ;
539
+ params -> trip_switch_on = NULL ;
556
540
params -> trip_max_desired_temperature = last_active ;
557
541
}
558
542
}
@@ -567,14 +551,12 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update)
567
551
{
568
552
struct thermal_instance * instance ;
569
553
struct power_allocator_params * params = tz -> governor_data ;
570
- const struct thermal_trip * trip_max_desired_temperature =
571
- & tz -> trips [params -> trip_max_desired_temperature ];
572
554
u32 req_power ;
573
555
574
556
list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
575
557
struct thermal_cooling_device * cdev = instance -> cdev ;
576
558
577
- if (( instance -> trip != trip_max_desired_temperature ) ||
559
+ if (instance -> trip != params -> trip_max_desired_temperature ||
578
560
(!cdev_is_power_actor (instance -> cdev )))
579
561
continue ;
580
562
@@ -636,7 +618,6 @@ static int power_allocator_bind(struct thermal_zone_device *tz)
636
618
{
637
619
int ret ;
638
620
struct power_allocator_params * params ;
639
- struct thermal_trip trip ;
640
621
641
622
ret = check_power_actors (tz );
642
623
if (ret )
@@ -661,13 +642,11 @@ static int power_allocator_bind(struct thermal_zone_device *tz)
661
642
662
643
get_governor_trips (tz , params );
663
644
664
- if (tz -> num_trips > 0 ) {
665
- ret = __thermal_zone_get_trip (tz , params -> trip_max_desired_temperature ,
666
- & trip );
667
- if (!ret )
668
- estimate_pid_constants (tz , tz -> tzp -> sustainable_power ,
669
- params -> trip_switch_on ,
670
- trip .temperature );
645
+ if (params -> trip_max_desired_temperature ) {
646
+ int temp = params -> trip_max_desired_temperature -> temperature ;
647
+
648
+ estimate_pid_constants (tz , tz -> tzp -> sustainable_power ,
649
+ params -> trip_switch_on , temp );
671
650
}
672
651
673
652
reset_pid_controller (params );
@@ -697,11 +676,10 @@ static void power_allocator_unbind(struct thermal_zone_device *tz)
697
676
tz -> governor_data = NULL ;
698
677
}
699
678
700
- static int power_allocator_throttle (struct thermal_zone_device * tz , int trip_id )
679
+ static int power_allocator_throttle (struct thermal_zone_device * tz , int trip_index )
701
680
{
702
681
struct power_allocator_params * params = tz -> governor_data ;
703
- struct thermal_trip trip ;
704
- int ret ;
682
+ const struct thermal_trip * trip = & tz -> trips [trip_index ];
705
683
bool update ;
706
684
707
685
lockdep_assert_held (& tz -> lock );
@@ -710,12 +688,12 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_id)
710
688
* We get called for every trip point but we only need to do
711
689
* our calculations once
712
690
*/
713
- if (trip_id != params -> trip_max_desired_temperature )
691
+ if (trip != params -> trip_max_desired_temperature )
714
692
return 0 ;
715
693
716
- ret = __thermal_zone_get_trip ( tz , params -> trip_switch_on , & trip ) ;
717
- if (! ret && ( tz -> temperature < trip . temperature ) ) {
718
- update = ( tz -> last_temperature >= trip . temperature ) ;
694
+ trip = params -> trip_switch_on ;
695
+ if (trip && tz -> temperature < trip -> temperature ) {
696
+ update = tz -> last_temperature >= trip -> temperature ;
719
697
tz -> passive = 0 ;
720
698
reset_pid_controller (params );
721
699
allow_maximum_power (tz , update );
@@ -724,14 +702,7 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_id)
724
702
725
703
tz -> passive = 1 ;
726
704
727
- ret = __thermal_zone_get_trip (tz , params -> trip_max_desired_temperature , & trip );
728
- if (ret ) {
729
- dev_warn (& tz -> device , "Failed to get the maximum desired temperature: %d\n" ,
730
- ret );
731
- return ret ;
732
- }
733
-
734
- return allocate_power (tz , trip .temperature );
705
+ return allocate_power (tz , params -> trip_max_desired_temperature -> temperature );
735
706
}
736
707
737
708
static struct thermal_governor thermal_gov_power_allocator = {
0 commit comments