Skip to content

Commit 7ddca58

Browse files
committed
thermal: core: Rearrange PM notification code
Move the code run for each thermal zone by the thermal PM notify handler to separate functions. This will help to make some subsequent changes look somewhat more straightforward, among other things. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Lukasz Luba <[email protected]>
1 parent 662f920 commit 7ddca58

File tree

1 file changed

+46
-42
lines changed

1 file changed

+46
-42
lines changed

drivers/thermal/thermal_core.c

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,48 @@ static void thermal_zone_device_resume(struct work_struct *work)
16841684
mutex_unlock(&tz->lock);
16851685
}
16861686

1687+
static void thermal_zone_pm_prepare(struct thermal_zone_device *tz)
1688+
{
1689+
mutex_lock(&tz->lock);
1690+
1691+
if (tz->resuming) {
1692+
/*
1693+
* thermal_zone_device_resume() queued up for this zone has not
1694+
* acquired the lock yet, so release it to let the function run
1695+
* and wait util it has done the work.
1696+
*/
1697+
mutex_unlock(&tz->lock);
1698+
1699+
wait_for_completion(&tz->resume);
1700+
1701+
mutex_lock(&tz->lock);
1702+
}
1703+
1704+
tz->suspended = true;
1705+
1706+
mutex_unlock(&tz->lock);
1707+
}
1708+
1709+
static void thermal_zone_pm_complete(struct thermal_zone_device *tz)
1710+
{
1711+
mutex_lock(&tz->lock);
1712+
1713+
cancel_delayed_work(&tz->poll_queue);
1714+
1715+
reinit_completion(&tz->resume);
1716+
tz->resuming = true;
1717+
1718+
/*
1719+
* Replace the work function with the resume one, which will restore the
1720+
* original work function and schedule the polling work if needed.
1721+
*/
1722+
INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_resume);
1723+
/* Queue up the work without a delay. */
1724+
mod_delayed_work(system_freezable_power_efficient_wq, &tz->poll_queue, 0);
1725+
1726+
mutex_unlock(&tz->lock);
1727+
}
1728+
16871729
static int thermal_pm_notify(struct notifier_block *nb,
16881730
unsigned long mode, void *_unused)
16891731
{
@@ -1695,27 +1737,8 @@ static int thermal_pm_notify(struct notifier_block *nb,
16951737
case PM_SUSPEND_PREPARE:
16961738
mutex_lock(&thermal_list_lock);
16971739

1698-
list_for_each_entry(tz, &thermal_tz_list, node) {
1699-
mutex_lock(&tz->lock);
1700-
1701-
if (tz->resuming) {
1702-
/*
1703-
* thermal_zone_device_resume() queued up for
1704-
* this zone has not acquired the lock yet, so
1705-
* release it to let the function run and wait
1706-
* util it has done the work.
1707-
*/
1708-
mutex_unlock(&tz->lock);
1709-
1710-
wait_for_completion(&tz->resume);
1711-
1712-
mutex_lock(&tz->lock);
1713-
}
1714-
1715-
tz->suspended = true;
1716-
1717-
mutex_unlock(&tz->lock);
1718-
}
1740+
list_for_each_entry(tz, &thermal_tz_list, node)
1741+
thermal_zone_pm_prepare(tz);
17191742

17201743
mutex_unlock(&thermal_list_lock);
17211744
break;
@@ -1724,27 +1747,8 @@ static int thermal_pm_notify(struct notifier_block *nb,
17241747
case PM_POST_SUSPEND:
17251748
mutex_lock(&thermal_list_lock);
17261749

1727-
list_for_each_entry(tz, &thermal_tz_list, node) {
1728-
mutex_lock(&tz->lock);
1729-
1730-
cancel_delayed_work(&tz->poll_queue);
1731-
1732-
reinit_completion(&tz->resume);
1733-
tz->resuming = true;
1734-
1735-
/*
1736-
* Replace the work function with the resume one, which
1737-
* will restore the original work function and schedule
1738-
* the polling work if needed.
1739-
*/
1740-
INIT_DELAYED_WORK(&tz->poll_queue,
1741-
thermal_zone_device_resume);
1742-
/* Queue up the work without a delay. */
1743-
mod_delayed_work(system_freezable_power_efficient_wq,
1744-
&tz->poll_queue, 0);
1745-
1746-
mutex_unlock(&tz->lock);
1747-
}
1750+
list_for_each_entry(tz, &thermal_tz_list, node)
1751+
thermal_zone_pm_complete(tz);
17481752

17491753
mutex_unlock(&thermal_list_lock);
17501754
break;

0 commit comments

Comments
 (0)