@@ -97,11 +97,9 @@ struct power_allocator_params {
97
97
struct power_actor * power ;
98
98
};
99
99
100
- static bool power_actor_is_valid (struct power_allocator_params * params ,
101
- struct thermal_instance * instance )
100
+ static bool power_actor_is_valid (struct thermal_instance * instance )
102
101
{
103
- return (instance -> trip == params -> trip_max &&
104
- cdev_is_power_actor (instance -> cdev ));
102
+ return cdev_is_power_actor (instance -> cdev );
105
103
}
106
104
107
105
/**
@@ -118,13 +116,14 @@ static bool power_actor_is_valid(struct power_allocator_params *params,
118
116
static u32 estimate_sustainable_power (struct thermal_zone_device * tz )
119
117
{
120
118
struct power_allocator_params * params = tz -> governor_data ;
119
+ const struct thermal_trip_desc * td = trip_to_trip_desc (params -> trip_max );
121
120
struct thermal_cooling_device * cdev ;
122
121
struct thermal_instance * instance ;
123
122
u32 sustainable_power = 0 ;
124
123
u32 min_power ;
125
124
126
- list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
127
- if (!power_actor_is_valid (params , instance ))
125
+ list_for_each_entry (instance , & td -> thermal_instances , trip_node ) {
126
+ if (!power_actor_is_valid (instance ))
128
127
continue ;
129
128
130
129
cdev = instance -> cdev ;
@@ -323,9 +322,8 @@ power_actor_set_power(struct thermal_cooling_device *cdev,
323
322
return ret ;
324
323
325
324
instance -> target = clamp_val (state , instance -> lower , instance -> upper );
326
- mutex_lock (& cdev -> lock );
327
- __thermal_cdev_update (cdev );
328
- mutex_unlock (& cdev -> lock );
325
+
326
+ thermal_cdev_update_nocheck (cdev );
329
327
330
328
return 0 ;
331
329
}
@@ -356,11 +354,19 @@ static void divvy_up_power(struct power_actor *power, int num_actors,
356
354
u32 extra_power = 0 ;
357
355
int i ;
358
356
359
- /*
360
- * Prevent division by 0 if none of the actors request power.
361
- */
362
- if (!total_req_power )
363
- total_req_power = 1 ;
357
+ if (!total_req_power ) {
358
+ /*
359
+ * Nobody requested anything, just give everybody
360
+ * the maximum power
361
+ */
362
+ for (i = 0 ; i < num_actors ; i ++ ) {
363
+ struct power_actor * pa = & power [i ];
364
+
365
+ pa -> granted_power = pa -> max_power ;
366
+ }
367
+
368
+ return ;
369
+ }
364
370
365
371
for (i = 0 ; i < num_actors ; i ++ ) {
366
372
struct power_actor * pa = & power [i ];
@@ -400,6 +406,7 @@ static void divvy_up_power(struct power_actor *power, int num_actors,
400
406
static void allocate_power (struct thermal_zone_device * tz , int control_temp )
401
407
{
402
408
struct power_allocator_params * params = tz -> governor_data ;
409
+ const struct thermal_trip_desc * td = trip_to_trip_desc (params -> trip_max );
403
410
unsigned int num_actors = params -> num_actors ;
404
411
struct power_actor * power = params -> power ;
405
412
struct thermal_cooling_device * cdev ;
@@ -417,10 +424,10 @@ static void allocate_power(struct thermal_zone_device *tz, int control_temp)
417
424
/* Clean all buffers for new power estimations */
418
425
memset (power , 0 , params -> buffer_size );
419
426
420
- list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
427
+ list_for_each_entry (instance , & td -> thermal_instances , trip_node ) {
421
428
struct power_actor * pa = & power [i ];
422
429
423
- if (!power_actor_is_valid (params , instance ))
430
+ if (!power_actor_is_valid (instance ))
424
431
continue ;
425
432
426
433
cdev = instance -> cdev ;
@@ -454,10 +461,10 @@ static void allocate_power(struct thermal_zone_device *tz, int control_temp)
454
461
power_range );
455
462
456
463
i = 0 ;
457
- list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
464
+ list_for_each_entry (instance , & td -> thermal_instances , trip_node ) {
458
465
struct power_actor * pa = & power [i ];
459
466
460
- if (!power_actor_is_valid (params , instance ))
467
+ if (!power_actor_is_valid (instance ))
461
468
continue ;
462
469
463
470
power_actor_set_power (instance -> cdev , instance ,
@@ -538,29 +545,29 @@ static void reset_pid_controller(struct power_allocator_params *params)
538
545
static void allow_maximum_power (struct thermal_zone_device * tz )
539
546
{
540
547
struct power_allocator_params * params = tz -> governor_data ;
548
+ const struct thermal_trip_desc * td = trip_to_trip_desc (params -> trip_max );
541
549
struct thermal_cooling_device * cdev ;
542
550
struct thermal_instance * instance ;
543
551
u32 req_power ;
544
552
545
- list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
546
- if (!power_actor_is_valid (params , instance ))
553
+ list_for_each_entry (instance , & td -> thermal_instances , trip_node ) {
554
+ if (!power_actor_is_valid (instance ))
547
555
continue ;
548
556
549
557
cdev = instance -> cdev ;
550
558
551
559
instance -> target = 0 ;
552
- mutex_lock (& cdev -> lock );
553
- /*
554
- * Call for updating the cooling devices local stats and avoid
555
- * periods of dozen of seconds when those have not been
556
- * maintained.
557
- */
558
- cdev -> ops -> get_requested_power (cdev , & req_power );
559
-
560
- if (params -> update_cdevs )
561
- __thermal_cdev_update (cdev );
562
-
563
- mutex_unlock (& cdev -> lock );
560
+ scoped_guard (cooling_dev , cdev ) {
561
+ /*
562
+ * Call for updating the cooling devices local stats and
563
+ * avoid periods of dozen of seconds when those have not
564
+ * been maintained.
565
+ */
566
+ cdev -> ops -> get_requested_power (cdev , & req_power );
567
+
568
+ if (params -> update_cdevs )
569
+ __thermal_cdev_update (cdev );
570
+ }
564
571
}
565
572
}
566
573
@@ -581,13 +588,11 @@ static void allow_maximum_power(struct thermal_zone_device *tz)
581
588
static int check_power_actors (struct thermal_zone_device * tz ,
582
589
struct power_allocator_params * params )
583
590
{
591
+ const struct thermal_trip_desc * td = trip_to_trip_desc (params -> trip_max );
584
592
struct thermal_instance * instance ;
585
593
int ret = 0 ;
586
594
587
- list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
588
- if (instance -> trip != params -> trip_max )
589
- continue ;
590
-
595
+ list_for_each_entry (instance , & td -> thermal_instances , trip_node ) {
591
596
if (!cdev_is_power_actor (instance -> cdev )) {
592
597
dev_warn (& tz -> device , "power_allocator: %s is not a power actor\n" ,
593
598
instance -> cdev -> type );
@@ -635,14 +640,15 @@ static void power_allocator_update_tz(struct thermal_zone_device *tz,
635
640
enum thermal_notify_event reason )
636
641
{
637
642
struct power_allocator_params * params = tz -> governor_data ;
643
+ const struct thermal_trip_desc * td = trip_to_trip_desc (params -> trip_max );
638
644
struct thermal_instance * instance ;
639
645
int num_actors = 0 ;
640
646
641
647
switch (reason ) {
642
648
case THERMAL_TZ_BIND_CDEV :
643
649
case THERMAL_TZ_UNBIND_CDEV :
644
- list_for_each_entry (instance , & tz -> thermal_instances , tz_node )
645
- if (power_actor_is_valid (params , instance ))
650
+ list_for_each_entry (instance , & td -> thermal_instances , trip_node )
651
+ if (power_actor_is_valid (instance ))
646
652
num_actors ++ ;
647
653
648
654
if (num_actors == params -> num_actors )
@@ -652,8 +658,8 @@ static void power_allocator_update_tz(struct thermal_zone_device *tz,
652
658
break ;
653
659
case THERMAL_INSTANCE_WEIGHT_CHANGED :
654
660
params -> total_weight = 0 ;
655
- list_for_each_entry (instance , & tz -> thermal_instances , tz_node )
656
- if (power_actor_is_valid (params , instance ))
661
+ list_for_each_entry (instance , & td -> thermal_instances , trip_node )
662
+ if (power_actor_is_valid (instance ))
657
663
params -> total_weight += instance -> weight ;
658
664
break ;
659
665
default :
0 commit comments