Skip to content

Commit 63561fe

Browse files
committed
thermal/governors: Group the thermal zone lock inside the throttle function
The thermal zone lock is taken in the different places in the throttling path. At the first glance it does not hurt to move them at the beginning and the end of the 'throttle' function. That will allow a consolidation of the lock in the next following changes. Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 15a7383 commit 63561fe

File tree

4 files changed

+20
-31
lines changed

4 files changed

+20
-31
lines changed

drivers/thermal/gov_bang_bang.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
3131
trip, trip_temp, tz->temperature,
3232
trip_hyst);
3333

34-
mutex_lock(&tz->lock);
35-
3634
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
3735
if (instance->trip != trip)
3836
continue;
@@ -65,8 +63,6 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
6563
instance->cdev->updated = false; /* cdev needs update */
6664
mutex_unlock(&instance->cdev->lock);
6765
}
68-
69-
mutex_unlock(&tz->lock);
7066
}
7167

7268
/**
@@ -100,10 +96,10 @@ static int bang_bang_control(struct thermal_zone_device *tz, int trip)
10096
{
10197
struct thermal_instance *instance;
10298

103-
thermal_zone_trip_update(tz, trip);
104-
10599
mutex_lock(&tz->lock);
106100

101+
thermal_zone_trip_update(tz, trip);
102+
107103
list_for_each_entry(instance, &tz->thermal_instances, tz_node)
108104
thermal_cdev_update(instance->cdev);
109105

drivers/thermal/gov_fair_share.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
113113
}
114114

115115
mutex_unlock(&tz->lock);
116+
116117
return 0;
117118
}
118119

drivers/thermal/gov_power_allocator.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,6 @@ static int allocate_power(struct thermal_zone_device *tz,
392392
int i, num_actors, total_weight, ret = 0;
393393
int trip_max_desired_temperature = params->trip_max_desired_temperature;
394394

395-
mutex_lock(&tz->lock);
396-
397395
num_actors = 0;
398396
total_weight = 0;
399397
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
@@ -404,10 +402,8 @@ static int allocate_power(struct thermal_zone_device *tz,
404402
}
405403
}
406404

407-
if (!num_actors) {
408-
ret = -ENODEV;
409-
goto unlock;
410-
}
405+
if (!num_actors)
406+
return -ENODEV;
411407

412408
/*
413409
* We need to allocate five arrays of the same size:
@@ -421,10 +417,8 @@ static int allocate_power(struct thermal_zone_device *tz,
421417
BUILD_BUG_ON(sizeof(*req_power) != sizeof(*extra_actor_power));
422418
BUILD_BUG_ON(sizeof(*req_power) != sizeof(*weighted_req_power));
423419
req_power = kcalloc(num_actors * 5, sizeof(*req_power), GFP_KERNEL);
424-
if (!req_power) {
425-
ret = -ENOMEM;
426-
goto unlock;
427-
}
420+
if (!req_power)
421+
return -ENOMEM;
428422

429423
max_power = &req_power[num_actors];
430424
granted_power = &req_power[2 * num_actors];
@@ -496,8 +490,6 @@ static int allocate_power(struct thermal_zone_device *tz,
496490
control_temp - tz->temperature);
497491

498492
kfree(req_power);
499-
unlock:
500-
mutex_unlock(&tz->lock);
501493

502494
return ret;
503495
}
@@ -576,7 +568,6 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update)
576568
struct power_allocator_params *params = tz->governor_data;
577569
u32 req_power;
578570

579-
mutex_lock(&tz->lock);
580571
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
581572
struct thermal_cooling_device *cdev = instance->cdev;
582573

@@ -598,7 +589,6 @@ static void allow_maximum_power(struct thermal_zone_device *tz, bool update)
598589

599590
mutex_unlock(&instance->cdev->lock);
600591
}
601-
mutex_unlock(&tz->lock);
602592
}
603593

604594
/**
@@ -707,17 +697,19 @@ static void power_allocator_unbind(struct thermal_zone_device *tz)
707697

708698
static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
709699
{
710-
int ret;
700+
int ret = 0;
711701
int switch_on_temp, control_temp;
712702
struct power_allocator_params *params = tz->governor_data;
713703
bool update;
714704

705+
mutex_lock(&tz->lock);
706+
715707
/*
716708
* We get called for every trip point but we only need to do
717709
* our calculations once
718710
*/
719711
if (trip != params->trip_max_desired_temperature)
720-
return 0;
712+
goto out;
721713

722714
ret = tz->ops->get_trip_temp(tz, params->trip_switch_on,
723715
&switch_on_temp);
@@ -726,7 +718,7 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
726718
tz->passive = 0;
727719
reset_pid_controller(params);
728720
allow_maximum_power(tz, update);
729-
return 0;
721+
goto out;
730722
}
731723

732724
tz->passive = 1;
@@ -737,10 +729,14 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
737729
dev_warn(&tz->device,
738730
"Failed to get the maximum desired temperature: %d\n",
739731
ret);
740-
return ret;
732+
goto out;
741733
}
742734

743-
return allocate_power(tz, control_temp);
735+
ret = allocate_power(tz, control_temp);
736+
737+
mutex_unlock(&tz->lock);
738+
out:
739+
return ret;
744740
}
745741

746742
static struct thermal_governor thermal_gov_power_allocator = {

drivers/thermal/gov_step_wise.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
117117
dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n",
118118
trip, trip_type, trip_temp, trend, throttle);
119119

120-
mutex_lock(&tz->lock);
121-
122120
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
123121
if (instance->trip != trip)
124122
continue;
@@ -145,8 +143,6 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
145143
instance->cdev->updated = false; /* cdev needs update */
146144
mutex_unlock(&instance->cdev->lock);
147145
}
148-
149-
mutex_unlock(&tz->lock);
150146
}
151147

152148
/**
@@ -164,10 +160,10 @@ static int step_wise_throttle(struct thermal_zone_device *tz, int trip)
164160
{
165161
struct thermal_instance *instance;
166162

167-
thermal_zone_trip_update(tz, trip);
168-
169163
mutex_lock(&tz->lock);
170164

165+
thermal_zone_trip_update(tz, trip);
166+
171167
list_for_each_entry(instance, &tz->thermal_instances, tz_node)
172168
thermal_cdev_update(instance->cdev);
173169

0 commit comments

Comments
 (0)