Skip to content

Commit b70dbf4

Browse files
lukaszluba-armdlezcano
authored andcommitted
thermal/core: Create a helper __thermal_cdev_update() without a lock
There is a need to have a helper function which updates cooling device state from the governors code. With this change governor can use lock and unlock while calling helper function. This avoid unnecessary second time lock/unlock which was in previous solution present in governor implementation. This new helper function must be called with mutex 'cdev->lock' hold. The changed been discussed and part of code presented in thread: https://lore.kernel.org/linux-pm/20210419084536.25000-1-lukasz.luba@arm.com/ Co-developed-by: Daniel Lezcano <daniel.lezcano@linaro.org> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Signed-off-by: Lukasz Luba <lukasz.luba@arm.com> Link: https://lore.kernel.org/r/20210422114308.29684-2-lukasz.luba@arm.com
1 parent 26b2f03 commit b70dbf4

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

drivers/thermal/thermal_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
6666
}
6767

6868
void thermal_cdev_update(struct thermal_cooling_device *);
69+
void __thermal_cdev_update(struct thermal_cooling_device *cdev);
6970

7071
/**
7172
* struct thermal_trip - representation of a point in temperature domain

drivers/thermal/thermal_helpers.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,11 @@ static void thermal_cdev_set_cur_state(struct thermal_cooling_device *cdev,
192192
thermal_cooling_device_stats_update(cdev, target);
193193
}
194194

195-
void thermal_cdev_update(struct thermal_cooling_device *cdev)
195+
void __thermal_cdev_update(struct thermal_cooling_device *cdev)
196196
{
197197
struct thermal_instance *instance;
198198
unsigned long target = 0;
199199

200-
mutex_lock(&cdev->lock);
201-
/* cooling device is updated*/
202-
if (cdev->updated) {
203-
mutex_unlock(&cdev->lock);
204-
return;
205-
}
206-
207200
/* Make sure cdev enters the deepest cooling state */
208201
list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
209202
dev_dbg(&cdev->device, "zone%d->target=%lu\n",
@@ -216,11 +209,25 @@ void thermal_cdev_update(struct thermal_cooling_device *cdev)
216209

217210
thermal_cdev_set_cur_state(cdev, target);
218211

219-
cdev->updated = true;
220-
mutex_unlock(&cdev->lock);
221212
trace_cdev_update(cdev, target);
222213
dev_dbg(&cdev->device, "set to state %lu\n", target);
223214
}
215+
216+
/**
217+
* thermal_cdev_update - update cooling device state if needed
218+
* @cdev: pointer to struct thermal_cooling_device
219+
*
220+
* Update the cooling device state if there is a need.
221+
*/
222+
void thermal_cdev_update(struct thermal_cooling_device *cdev)
223+
{
224+
mutex_lock(&cdev->lock);
225+
if (!cdev->updated) {
226+
__thermal_cdev_update(cdev);
227+
cdev->updated = true;
228+
}
229+
mutex_unlock(&cdev->lock);
230+
}
224231
EXPORT_SYMBOL(thermal_cdev_update);
225232

226233
/**

0 commit comments

Comments
 (0)