Skip to content

Commit 670a5e3

Browse files
committed
thermal/core: Move the thermal zone lock out of the governors
All the governors throttling ops are taking/releasing the lock at the beginning and the end of the function. We can move the mutex to the throttling call site instead. Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 63561fe commit 670a5e3

File tree

5 files changed

+11
-19
lines changed

5 files changed

+11
-19
lines changed

drivers/thermal/gov_bang_bang.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,13 @@ static int bang_bang_control(struct thermal_zone_device *tz, int trip)
9696
{
9797
struct thermal_instance *instance;
9898

99-
mutex_lock(&tz->lock);
99+
lockdep_assert_held(&tz->lock);
100100

101101
thermal_zone_trip_update(tz, trip);
102102

103103
list_for_each_entry(instance, &tz->thermal_instances, tz_node)
104104
thermal_cdev_update(instance->cdev);
105105

106-
mutex_unlock(&tz->lock);
107-
108106
return 0;
109107
}
110108

drivers/thermal/gov_fair_share.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
8282
int total_instance = 0;
8383
int cur_trip_level = get_trip_level(tz);
8484

85-
mutex_lock(&tz->lock);
85+
lockdep_assert_held(&tz->lock);
8686

8787
list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
8888
if (instance->trip != trip)
@@ -112,8 +112,6 @@ static int fair_share_throttle(struct thermal_zone_device *tz, int trip)
112112
mutex_unlock(&cdev->lock);
113113
}
114114

115-
mutex_unlock(&tz->lock);
116-
117115
return 0;
118116
}
119117

drivers/thermal/gov_power_allocator.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -697,19 +697,19 @@ static void power_allocator_unbind(struct thermal_zone_device *tz)
697697

698698
static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
699699
{
700-
int ret = 0;
700+
int ret;
701701
int switch_on_temp, control_temp;
702702
struct power_allocator_params *params = tz->governor_data;
703703
bool update;
704704

705-
mutex_lock(&tz->lock);
705+
lockdep_assert_held(&tz->lock);
706706

707707
/*
708708
* We get called for every trip point but we only need to do
709709
* our calculations once
710710
*/
711711
if (trip != params->trip_max_desired_temperature)
712-
goto out;
712+
return 0;
713713

714714
ret = tz->ops->get_trip_temp(tz, params->trip_switch_on,
715715
&switch_on_temp);
@@ -718,7 +718,7 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
718718
tz->passive = 0;
719719
reset_pid_controller(params);
720720
allow_maximum_power(tz, update);
721-
goto out;
721+
return 0;
722722
}
723723

724724
tz->passive = 1;
@@ -729,14 +729,10 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip)
729729
dev_warn(&tz->device,
730730
"Failed to get the maximum desired temperature: %d\n",
731731
ret);
732-
goto out;
732+
return ret;
733733
}
734734

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

742738
static struct thermal_governor thermal_gov_power_allocator = {

drivers/thermal/gov_step_wise.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,13 @@ static int step_wise_throttle(struct thermal_zone_device *tz, int trip)
160160
{
161161
struct thermal_instance *instance;
162162

163-
mutex_lock(&tz->lock);
163+
lockdep_assert_held(&tz->lock);
164164

165165
thermal_zone_trip_update(tz, trip);
166166

167167
list_for_each_entry(instance, &tz->thermal_instances, tz_node)
168168
thermal_cdev_update(instance->cdev);
169169

170-
mutex_unlock(&tz->lock);
171-
172170
return 0;
173171
}
174172

drivers/thermal/thermal_core.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,10 @@ static void monitor_thermal_zone(struct thermal_zone_device *tz)
311311

312312
static void handle_non_critical_trips(struct thermal_zone_device *tz, int trip)
313313
{
314+
mutex_lock(&tz->lock);
314315
tz->governor ? tz->governor->throttle(tz, trip) :
315316
def_governor->throttle(tz, trip);
317+
mutex_unlock(&tz->lock);
316318
}
317319

318320
void thermal_zone_device_critical(struct thermal_zone_device *tz)

0 commit comments

Comments
 (0)