Skip to content

Commit 03d3880

Browse files
committed
Merge tag 'thermal-6.14-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull thermal control fixes from Rafael Wysocki: "These fix the processing of DT thermal properties and the Power Allocator thermal governor: - Fix parsing cooling-maps in DT for trip points with more than one cooling device (Rafael Wysocki) - Fix granted_power computation in the Power Allocator thermal governor and make it update total_weight on configuration changes after the thermal zone has been registered (Yu-Che Cheng)" * tag 'thermal-6.14-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: thermal: gov_power_allocator: Update total_weight on bind and cdev updates thermal/of: Fix cdev lookup in thermal_of_should_bind() thermal: gov_power_allocator: Fix incorrect calculation in divvy_up_power()
2 parents 14ebe69 + 0cde378 commit 03d3880

File tree

2 files changed

+52
-30
lines changed

2 files changed

+52
-30
lines changed

drivers/thermal/gov_power_allocator.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ static void divvy_up_power(struct power_actor *power, int num_actors,
370370

371371
for (i = 0; i < num_actors; i++) {
372372
struct power_actor *pa = &power[i];
373-
u64 req_range = (u64)pa->req_power * power_range;
373+
u64 req_range = (u64)pa->weighted_req_power * power_range;
374374

375375
pa->granted_power = DIV_ROUND_CLOSEST_ULL(req_range,
376376
total_req_power);
@@ -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:

drivers/thermal/thermal_of.c

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,34 @@ static bool thermal_of_get_cooling_spec(struct device_node *map_np, int index,
274274
return true;
275275
}
276276

277+
static bool thermal_of_cm_lookup(struct device_node *cm_np,
278+
const struct thermal_trip *trip,
279+
struct thermal_cooling_device *cdev,
280+
struct cooling_spec *c)
281+
{
282+
for_each_child_of_node_scoped(cm_np, child) {
283+
struct device_node *tr_np;
284+
int count, i;
285+
286+
tr_np = of_parse_phandle(child, "trip", 0);
287+
if (tr_np != trip->priv)
288+
continue;
289+
290+
/* The trip has been found, look up the cdev. */
291+
count = of_count_phandle_with_args(child, "cooling-device",
292+
"#cooling-cells");
293+
if (count <= 0)
294+
pr_err("Add a cooling_device property with at least one device\n");
295+
296+
for (i = 0; i < count; i++) {
297+
if (thermal_of_get_cooling_spec(child, i, cdev, c))
298+
return true;
299+
}
300+
}
301+
302+
return false;
303+
}
304+
277305
static bool thermal_of_should_bind(struct thermal_zone_device *tz,
278306
const struct thermal_trip *trip,
279307
struct thermal_cooling_device *cdev,
@@ -293,27 +321,7 @@ static bool thermal_of_should_bind(struct thermal_zone_device *tz,
293321
goto out;
294322

295323
/* Look up the trip and the cdev in the cooling maps. */
296-
for_each_child_of_node_scoped(cm_np, child) {
297-
struct device_node *tr_np;
298-
int count, i;
299-
300-
tr_np = of_parse_phandle(child, "trip", 0);
301-
if (tr_np != trip->priv)
302-
continue;
303-
304-
/* The trip has been found, look up the cdev. */
305-
count = of_count_phandle_with_args(child, "cooling-device", "#cooling-cells");
306-
if (count <= 0)
307-
pr_err("Add a cooling_device property with at least one device\n");
308-
309-
for (i = 0; i < count; i++) {
310-
result = thermal_of_get_cooling_spec(child, i, cdev, c);
311-
if (result)
312-
break;
313-
}
314-
315-
break;
316-
}
324+
result = thermal_of_cm_lookup(cm_np, trip, cdev, c);
317325

318326
of_node_put(cm_np);
319327
out:

0 commit comments

Comments
 (0)