Skip to content

Commit 0cde378

Browse files
ggiverrafaeljw
authored andcommitted
thermal: gov_power_allocator: Update total_weight on bind and cdev updates
params->total_weight is not initialized during bind and not updated when the bound cdev changes. The cooling device weight will not be used due to the uninitialized total_weight, until an update via sysfs is triggered. The bound cdevs are updated during thermal zone registration, where each cooling device will be bound to the thermal zone one by one, but power_allocator_bind() can be called without an additional cdev update when manually changing the policy of a thermal zone via sysfs. Add a new function to handle weight update logic, including updating total_weight, and call it when bind, weight changes, and cdev updates to ensure total_weight is always correct. Fixes: a3cd6db ("thermal: gov_power_allocator: Support new update callback of weights") Signed-off-by: Yu-Che Cheng <giver@chromium.org> Link: https://patch.msgid.link/20250222-fix-power-allocator-weight-v2-1-a94de86b685a@chromium.org [ rjw: Changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 423de5b commit 0cde378

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

drivers/thermal/gov_power_allocator.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,22 @@ static int allocate_actors_buffer(struct power_allocator_params *params,
641641
return ret;
642642
}
643643

644+
static void power_allocator_update_weight(struct power_allocator_params *params)
645+
{
646+
const struct thermal_trip_desc *td;
647+
struct thermal_instance *instance;
648+
649+
if (!params->trip_max)
650+
return;
651+
652+
td = trip_to_trip_desc(params->trip_max);
653+
654+
params->total_weight = 0;
655+
list_for_each_entry(instance, &td->thermal_instances, trip_node)
656+
if (power_actor_is_valid(instance))
657+
params->total_weight += instance->weight;
658+
}
659+
644660
static void power_allocator_update_tz(struct thermal_zone_device *tz,
645661
enum thermal_notify_event reason)
646662
{
@@ -656,16 +672,12 @@ static void power_allocator_update_tz(struct thermal_zone_device *tz,
656672
if (power_actor_is_valid(instance))
657673
num_actors++;
658674

659-
if (num_actors == params->num_actors)
660-
return;
675+
if (num_actors != params->num_actors)
676+
allocate_actors_buffer(params, num_actors);
661677

662-
allocate_actors_buffer(params, num_actors);
663-
break;
678+
fallthrough;
664679
case THERMAL_INSTANCE_WEIGHT_CHANGED:
665-
params->total_weight = 0;
666-
list_for_each_entry(instance, &td->thermal_instances, trip_node)
667-
if (power_actor_is_valid(instance))
668-
params->total_weight += instance->weight;
680+
power_allocator_update_weight(params);
669681
break;
670682
default:
671683
break;
@@ -731,6 +743,8 @@ static int power_allocator_bind(struct thermal_zone_device *tz)
731743

732744
tz->governor_data = params;
733745

746+
power_allocator_update_weight(params);
747+
734748
return 0;
735749

736750
free_params:

0 commit comments

Comments
 (0)