Skip to content

Commit 7874b58

Browse files
committed
Merge branch 'pm-runtime'
Merge changes related to the runtime power management of devices for 6.9-rc1: - Simplify pm_runtime_get_if_active() usage and add a replacement for pm_runtime_put_autosuspend() (Sakari Ailus). - Add a tracepoint for runtime_status changes tracking (Vilas Bhat). - Fix section title markdown in the runtime PM documentation (Yiwei Lin). * pm-runtime: Documentation: PM: Fix runtime_pm.rst markdown syntax PM: runtime: add tracepoint for runtime_status changes PM: runtime: Add pm_runtime_put_autosuspend() replacement PM: runtime: Simplify pm_runtime_get_if_active() usage
2 parents 86b84bd + e650956 commit 7874b58

File tree

13 files changed

+117
-35
lines changed

13 files changed

+117
-35
lines changed

Documentation/power/runtime_pm.rst

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ suspending the device are satisfied) and to queue up a suspend request for the
154154
device in that case. If there is no idle callback, or if the callback returns
155155
0, then the PM core will attempt to carry out a runtime suspend of the device,
156156
also respecting devices configured for autosuspend. In essence this means a
157-
call to pm_runtime_autosuspend() (do note that drivers needs to update the
157+
call to __pm_runtime_autosuspend() (do note that drivers needs to update the
158158
device last busy mark, pm_runtime_mark_last_busy(), to control the delay under
159159
this circumstance). To prevent this (for example, if the callback routine has
160160
started a delayed suspend), the routine must return a non-zero value. Negative
@@ -396,10 +396,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
396396
nonzero, increment the counter and return 1; otherwise return 0 without
397397
changing the counter
398398

399-
`int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count);`
399+
`int pm_runtime_get_if_active(struct device *dev);`
400400
- return -EINVAL if 'power.disable_depth' is nonzero; otherwise, if the
401-
runtime PM status is RPM_ACTIVE, and either ign_usage_count is true
402-
or the device's usage_count is non-zero, increment the counter and
401+
runtime PM status is RPM_ACTIVE, increment the counter and
403402
return 1; otherwise return 0 without changing the counter
404403

405404
`void pm_runtime_put_noidle(struct device *dev);`
@@ -410,6 +409,10 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
410409
pm_request_idle(dev) and return its result
411410

412411
`int pm_runtime_put_autosuspend(struct device *dev);`
412+
- does the same as __pm_runtime_put_autosuspend() for now, but in the
413+
future, will also call pm_runtime_mark_last_busy() as well, DO NOT USE!
414+
415+
`int __pm_runtime_put_autosuspend(struct device *dev);`
413416
- decrement the device's usage counter; if the result is 0 then run
414417
pm_request_autosuspend(dev) and return its result
415418

@@ -540,6 +543,7 @@ It is safe to execute the following helper functions from interrupt context:
540543
- pm_runtime_put_noidle()
541544
- pm_runtime_put()
542545
- pm_runtime_put_autosuspend()
546+
- __pm_runtime_put_autosuspend()
543547
- pm_runtime_enable()
544548
- pm_suspend_ignore_children()
545549
- pm_runtime_set_active()
@@ -730,6 +734,7 @@ out the following operations:
730734
for it, respectively.
731735

732736
7. Generic subsystem callbacks
737+
==============================
733738

734739
Subsystems may wish to conserve code space by using the set of generic power
735740
management callbacks provided by the PM core, defined in
@@ -865,9 +870,9 @@ automatically be delayed until the desired period of inactivity has elapsed.
865870

866871
Inactivity is determined based on the power.last_busy field. Drivers should
867872
call pm_runtime_mark_last_busy() to update this field after carrying out I/O,
868-
typically just before calling pm_runtime_put_autosuspend(). The desired length
869-
of the inactivity period is a matter of policy. Subsystems can set this length
870-
initially by calling pm_runtime_set_autosuspend_delay(), but after device
873+
typically just before calling __pm_runtime_put_autosuspend(). The desired
874+
length of the inactivity period is a matter of policy. Subsystems can set this
875+
length initially by calling pm_runtime_set_autosuspend_delay(), but after device
871876
registration the length should be controlled by user space, using the
872877
/sys/devices/.../power/autosuspend_delay_ms attribute.
873878

@@ -878,7 +883,7 @@ instead of the non-autosuspend counterparts::
878883

879884
Instead of: pm_runtime_suspend use: pm_runtime_autosuspend;
880885
Instead of: pm_schedule_suspend use: pm_request_autosuspend;
881-
Instead of: pm_runtime_put use: pm_runtime_put_autosuspend;
886+
Instead of: pm_runtime_put use: __pm_runtime_put_autosuspend;
882887
Instead of: pm_runtime_put_sync use: pm_runtime_put_sync_autosuspend.
883888

884889
Drivers may also continue to use the non-autosuspend helper functions; they
@@ -917,7 +922,7 @@ Here is a schematic pseudo-code example::
917922
lock(&foo->private_lock);
918923
if (--foo->num_pending_requests == 0) {
919924
pm_runtime_mark_last_busy(&foo->dev);
920-
pm_runtime_put_autosuspend(&foo->dev);
925+
__pm_runtime_put_autosuspend(&foo->dev);
921926
} else {
922927
foo_process_next_request(foo);
923928
}

drivers/accel/ivpu/ivpu_pm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ int ivpu_rpm_get_if_active(struct ivpu_device *vdev)
309309
{
310310
int ret;
311311

312-
ret = pm_runtime_get_if_active(vdev->drm.dev, false);
312+
ret = pm_runtime_get_if_in_use(vdev->drm.dev);
313313
drm_WARN_ON(&vdev->drm, ret < 0);
314314

315315
return ret;

drivers/base/power/runtime.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static void update_pm_runtime_accounting(struct device *dev)
9494
static void __update_runtime_status(struct device *dev, enum rpm_status status)
9595
{
9696
update_pm_runtime_accounting(dev);
97+
trace_rpm_status(dev, status);
9798
dev->power.runtime_status = status;
9899
}
99100

@@ -1176,7 +1177,7 @@ int __pm_runtime_resume(struct device *dev, int rpmflags)
11761177
EXPORT_SYMBOL_GPL(__pm_runtime_resume);
11771178

11781179
/**
1179-
* pm_runtime_get_if_active - Conditionally bump up device usage counter.
1180+
* pm_runtime_get_conditional - Conditionally bump up device usage counter.
11801181
* @dev: Device to handle.
11811182
* @ign_usage_count: Whether or not to look at the current usage counter value.
11821183
*
@@ -1197,7 +1198,7 @@ EXPORT_SYMBOL_GPL(__pm_runtime_resume);
11971198
* The caller is responsible for decrementing the runtime PM usage counter of
11981199
* @dev after this function has returned a positive value for it.
11991200
*/
1200-
int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count)
1201+
static int pm_runtime_get_conditional(struct device *dev, bool ign_usage_count)
12011202
{
12021203
unsigned long flags;
12031204
int retval;
@@ -1218,8 +1219,39 @@ int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count)
12181219

12191220
return retval;
12201221
}
1222+
1223+
/**
1224+
* pm_runtime_get_if_active - Bump up runtime PM usage counter if the device is
1225+
* in active state
1226+
* @dev: Target device.
1227+
*
1228+
* Increment the runtime PM usage counter of @dev if its runtime PM status is
1229+
* %RPM_ACTIVE, in which case it returns 1. If the device is in a different
1230+
* state, 0 is returned. -EINVAL is returned if runtime PM is disabled for the
1231+
* device, in which case also the usage_count will remain unmodified.
1232+
*/
1233+
int pm_runtime_get_if_active(struct device *dev)
1234+
{
1235+
return pm_runtime_get_conditional(dev, true);
1236+
}
12211237
EXPORT_SYMBOL_GPL(pm_runtime_get_if_active);
12221238

1239+
/**
1240+
* pm_runtime_get_if_in_use - Conditionally bump up runtime PM usage counter.
1241+
* @dev: Target device.
1242+
*
1243+
* Increment the runtime PM usage counter of @dev if its runtime PM status is
1244+
* %RPM_ACTIVE and its runtime PM usage counter is greater than 0, in which case
1245+
* it returns 1. If the device is in a different state or its usage_count is 0,
1246+
* 0 is returned. -EINVAL is returned if runtime PM is disabled for the device,
1247+
* in which case also the usage_count will remain unmodified.
1248+
*/
1249+
int pm_runtime_get_if_in_use(struct device *dev)
1250+
{
1251+
return pm_runtime_get_conditional(dev, false);
1252+
}
1253+
EXPORT_SYMBOL_GPL(pm_runtime_get_if_in_use);
1254+
12231255
/**
12241256
* __pm_runtime_set_status - Set runtime PM status of a device.
12251257
* @dev: Device to handle.

drivers/gpu/drm/i915/intel_runtime_pm.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,10 @@ static intel_wakeref_t __intel_runtime_pm_get_if_active(struct intel_runtime_pm
246246
* function, since the power state is undefined. This applies
247247
* atm to the late/early system suspend/resume handlers.
248248
*/
249-
if (pm_runtime_get_if_active(rpm->kdev, ignore_usecount) <= 0)
249+
if ((ignore_usecount &&
250+
pm_runtime_get_if_active(rpm->kdev) <= 0) ||
251+
(!ignore_usecount &&
252+
pm_runtime_get_if_in_use(rpm->kdev) <= 0))
250253
return 0;
251254
}
252255

drivers/gpu/drm/xe/xe_pm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ int xe_pm_runtime_put(struct xe_device *xe)
330330

331331
int xe_pm_runtime_get_if_active(struct xe_device *xe)
332332
{
333-
return pm_runtime_get_if_active(xe->drm.dev, true);
333+
return pm_runtime_get_if_active(xe->drm.dev);
334334
}
335335

336336
void xe_pm_assert_unbounded_bridge(struct xe_device *xe)

drivers/media/i2c/ccs/ccs-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ static int ccs_set_ctrl(struct v4l2_ctrl *ctrl)
674674
break;
675675
}
676676

677-
pm_status = pm_runtime_get_if_active(&client->dev, true);
677+
pm_status = pm_runtime_get_if_active(&client->dev);
678678
if (!pm_status)
679679
return 0;
680680

drivers/media/i2c/ov64a40.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3287,7 +3287,7 @@ static int ov64a40_set_ctrl(struct v4l2_ctrl *ctrl)
32873287
exp_max, 1, exp_val);
32883288
}
32893289

3290-
pm_status = pm_runtime_get_if_active(ov64a40->dev, true);
3290+
pm_status = pm_runtime_get_if_active(ov64a40->dev);
32913291
if (!pm_status)
32923292
return 0;
32933293

drivers/media/i2c/thp7312.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ static int thp7312_s_ctrl(struct v4l2_ctrl *ctrl)
10521052
if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE)
10531053
return -EINVAL;
10541054

1055-
if (!pm_runtime_get_if_active(thp7312->dev, true))
1055+
if (!pm_runtime_get_if_active(thp7312->dev))
10561056
return 0;
10571057

10581058
switch (ctrl->id) {

drivers/net/ipa/ipa_smp2p.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static void ipa_smp2p_notify(struct ipa_smp2p *smp2p)
9292
return;
9393

9494
dev = &smp2p->ipa->pdev->dev;
95-
smp2p->power_on = pm_runtime_get_if_active(dev, true) > 0;
95+
smp2p->power_on = pm_runtime_get_if_active(dev) > 0;
9696

9797
/* Signal whether the IPA power is enabled */
9898
mask = BIT(smp2p->enabled_bit);

drivers/pci/pci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2532,7 +2532,7 @@ static void pci_pme_list_scan(struct work_struct *work)
25322532
* course of the call.
25332533
*/
25342534
if (bdev) {
2535-
bref = pm_runtime_get_if_active(bdev, true);
2535+
bref = pm_runtime_get_if_active(bdev);
25362536
if (!bref)
25372537
continue;
25382538

0 commit comments

Comments
 (0)