Skip to content

Commit 6d47254

Browse files
committed
Merge tag 'pm-5.12-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull power management fixes from Rafael Wysocki: "These fix the usage of device links in the runtime PM core code and update the DTPM (Dynamic Thermal Power Management) feature added recently. Specifics: - Make the runtime PM core code avoid attempting to suspend supplier devices before updating the PM-runtime status of a consumer to 'suspended' (Rafael Wysocki). - Fix DTPM (Dynamic Thermal Power Management) root node initialization and label that feature as EXPERIMENTAL in Kconfig (Daniel Lezcano)" * tag 'pm-5.12-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: powercap/drivers/dtpm: Add the experimental label to the option description powercap/drivers/dtpm: Fix root node initialization PM: runtime: Update device status before letting suppliers suspend
2 parents ea6be46 + 7bff4c2 commit 6d47254

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

drivers/base/power/runtime.c

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -325,22 +325,22 @@ static void rpm_put_suppliers(struct device *dev)
325325
static int __rpm_callback(int (*cb)(struct device *), struct device *dev)
326326
__releases(&dev->power.lock) __acquires(&dev->power.lock)
327327
{
328-
int retval, idx;
329328
bool use_links = dev->power.links_count > 0;
329+
bool get = false;
330+
int retval, idx;
331+
bool put;
330332

331333
if (dev->power.irq_safe) {
332334
spin_unlock(&dev->power.lock);
335+
} else if (!use_links) {
336+
spin_unlock_irq(&dev->power.lock);
333337
} else {
338+
get = dev->power.runtime_status == RPM_RESUMING;
339+
334340
spin_unlock_irq(&dev->power.lock);
335341

336-
/*
337-
* Resume suppliers if necessary.
338-
*
339-
* The device's runtime PM status cannot change until this
340-
* routine returns, so it is safe to read the status outside of
341-
* the lock.
342-
*/
343-
if (use_links && dev->power.runtime_status == RPM_RESUMING) {
342+
/* Resume suppliers if necessary. */
343+
if (get) {
344344
idx = device_links_read_lock();
345345

346346
retval = rpm_get_suppliers(dev);
@@ -355,24 +355,36 @@ static int __rpm_callback(int (*cb)(struct device *), struct device *dev)
355355

356356
if (dev->power.irq_safe) {
357357
spin_lock(&dev->power.lock);
358-
} else {
359-
/*
360-
* If the device is suspending and the callback has returned
361-
* success, drop the usage counters of the suppliers that have
362-
* been reference counted on its resume.
363-
*
364-
* Do that if resume fails too.
365-
*/
366-
if (use_links
367-
&& ((dev->power.runtime_status == RPM_SUSPENDING && !retval)
368-
|| (dev->power.runtime_status == RPM_RESUMING && retval))) {
369-
idx = device_links_read_lock();
358+
return retval;
359+
}
370360

371-
fail:
372-
rpm_put_suppliers(dev);
361+
spin_lock_irq(&dev->power.lock);
373362

374-
device_links_read_unlock(idx);
375-
}
363+
if (!use_links)
364+
return retval;
365+
366+
/*
367+
* If the device is suspending and the callback has returned success,
368+
* drop the usage counters of the suppliers that have been reference
369+
* counted on its resume.
370+
*
371+
* Do that if the resume fails too.
372+
*/
373+
put = dev->power.runtime_status == RPM_SUSPENDING && !retval;
374+
if (put)
375+
__update_runtime_status(dev, RPM_SUSPENDED);
376+
else
377+
put = get && retval;
378+
379+
if (put) {
380+
spin_unlock_irq(&dev->power.lock);
381+
382+
idx = device_links_read_lock();
383+
384+
fail:
385+
rpm_put_suppliers(dev);
386+
387+
device_links_read_unlock(idx);
376388

377389
spin_lock_irq(&dev->power.lock);
378390
}

drivers/powercap/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ config IDLE_INJECT
4545
on a per CPU basis.
4646

4747
config DTPM
48-
bool "Power capping for Dynamic Thermal Power Management"
48+
bool "Power capping for Dynamic Thermal Power Management (EXPERIMENTAL)"
4949
help
5050
This enables support for the power capping for the dynamic
5151
thermal power management userspace engine.

drivers/powercap/dtpm.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ int dtpm_release_zone(struct powercap_zone *pcz)
207207
if (dtpm->ops)
208208
dtpm->ops->release(dtpm);
209209

210+
if (root == dtpm)
211+
root = NULL;
212+
210213
kfree(dtpm);
211214

212215
return 0;

0 commit comments

Comments
 (0)