@@ -97,11 +97,9 @@ struct power_allocator_params {
9797 struct power_actor * power ;
9898};
9999
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 )
102101{
103- return (instance -> trip == params -> trip_max &&
104- cdev_is_power_actor (instance -> cdev ));
102+ return cdev_is_power_actor (instance -> cdev );
105103}
106104
107105/**
@@ -118,13 +116,14 @@ static bool power_actor_is_valid(struct power_allocator_params *params,
118116static u32 estimate_sustainable_power (struct thermal_zone_device * tz )
119117{
120118 struct power_allocator_params * params = tz -> governor_data ;
119+ const struct thermal_trip_desc * td = trip_to_trip_desc (params -> trip_max );
121120 struct thermal_cooling_device * cdev ;
122121 struct thermal_instance * instance ;
123122 u32 sustainable_power = 0 ;
124123 u32 min_power ;
125124
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 ))
128127 continue ;
129128
130129 cdev = instance -> cdev ;
@@ -323,9 +322,8 @@ power_actor_set_power(struct thermal_cooling_device *cdev,
323322 return ret ;
324323
325324 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 );
329327
330328 return 0 ;
331329}
@@ -356,11 +354,19 @@ static void divvy_up_power(struct power_actor *power, int num_actors,
356354 u32 extra_power = 0 ;
357355 int i ;
358356
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+ }
364370
365371 for (i = 0 ; i < num_actors ; i ++ ) {
366372 struct power_actor * pa = & power [i ];
@@ -400,6 +406,7 @@ static void divvy_up_power(struct power_actor *power, int num_actors,
400406static void allocate_power (struct thermal_zone_device * tz , int control_temp )
401407{
402408 struct power_allocator_params * params = tz -> governor_data ;
409+ const struct thermal_trip_desc * td = trip_to_trip_desc (params -> trip_max );
403410 unsigned int num_actors = params -> num_actors ;
404411 struct power_actor * power = params -> power ;
405412 struct thermal_cooling_device * cdev ;
@@ -417,10 +424,10 @@ static void allocate_power(struct thermal_zone_device *tz, int control_temp)
417424 /* Clean all buffers for new power estimations */
418425 memset (power , 0 , params -> buffer_size );
419426
420- list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
427+ list_for_each_entry (instance , & td -> thermal_instances , trip_node ) {
421428 struct power_actor * pa = & power [i ];
422429
423- if (!power_actor_is_valid (params , instance ))
430+ if (!power_actor_is_valid (instance ))
424431 continue ;
425432
426433 cdev = instance -> cdev ;
@@ -454,10 +461,10 @@ static void allocate_power(struct thermal_zone_device *tz, int control_temp)
454461 power_range );
455462
456463 i = 0 ;
457- list_for_each_entry (instance , & tz -> thermal_instances , tz_node ) {
464+ list_for_each_entry (instance , & td -> thermal_instances , trip_node ) {
458465 struct power_actor * pa = & power [i ];
459466
460- if (!power_actor_is_valid (params , instance ))
467+ if (!power_actor_is_valid (instance ))
461468 continue ;
462469
463470 power_actor_set_power (instance -> cdev , instance ,
@@ -538,29 +545,29 @@ static void reset_pid_controller(struct power_allocator_params *params)
538545static void allow_maximum_power (struct thermal_zone_device * tz )
539546{
540547 struct power_allocator_params * params = tz -> governor_data ;
548+ const struct thermal_trip_desc * td = trip_to_trip_desc (params -> trip_max );
541549 struct thermal_cooling_device * cdev ;
542550 struct thermal_instance * instance ;
543551 u32 req_power ;
544552
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 ))
547555 continue ;
548556
549557 cdev = instance -> cdev ;
550558
551559 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+ }
564571 }
565572}
566573
@@ -581,13 +588,11 @@ static void allow_maximum_power(struct thermal_zone_device *tz)
581588static int check_power_actors (struct thermal_zone_device * tz ,
582589 struct power_allocator_params * params )
583590{
591+ const struct thermal_trip_desc * td = trip_to_trip_desc (params -> trip_max );
584592 struct thermal_instance * instance ;
585593 int ret = 0 ;
586594
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 ) {
591596 if (!cdev_is_power_actor (instance -> cdev )) {
592597 dev_warn (& tz -> device , "power_allocator: %s is not a power actor\n" ,
593598 instance -> cdev -> type );
@@ -635,14 +640,15 @@ static void power_allocator_update_tz(struct thermal_zone_device *tz,
635640 enum thermal_notify_event reason )
636641{
637642 struct power_allocator_params * params = tz -> governor_data ;
643+ const struct thermal_trip_desc * td = trip_to_trip_desc (params -> trip_max );
638644 struct thermal_instance * instance ;
639645 int num_actors = 0 ;
640646
641647 switch (reason ) {
642648 case THERMAL_TZ_BIND_CDEV :
643649 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 ))
646652 num_actors ++ ;
647653
648654 if (num_actors == params -> num_actors )
@@ -652,8 +658,8 @@ static void power_allocator_update_tz(struct thermal_zone_device *tz,
652658 break ;
653659 case THERMAL_INSTANCE_WEIGHT_CHANGED :
654660 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 ))
657663 params -> total_weight += instance -> weight ;
658664 break ;
659665 default :
0 commit comments