Skip to content

Commit 3b4d4c9

Browse files
committed
Merge branches 'pm-runtime' and 'pm-powercap'
Merge runtime PM updates and power capping updates for 6.17-rc1: - Document return values of suspend-related API functions in the runtime PM framework (Sakari Ailus) - Mark last busy stamp in multiple autosuspend-related functions in the runtime PM framework and update its documentation (Sakari Ailus) - Take active children into account in pm_runtime_get_if_in_use() for consistency (Rafael Wysocki) - Fix NULL pointer dereference in get_pd_power_uw() in the dtpm_cpu power capping driver (Sivan Zohar-Kotzer) - Add support for the Bartlett Lake platform to the Intel RAPL power capping driver (Qiao Wei) - Add PL4 support for Panther Lake to the intel_rapl_msr power capping driver (Zhang Rui) * pm-runtime: PM: runtime: Take active children into account in pm_runtime_get_if_in_use() Documentation: PM: *_autosuspend() functions update last busy time PM: runtime: Mark last busy stamp in pm_request_autosuspend() PM: runtime: Mark last busy stamp in pm_runtime_autosuspend() PM: runtime: Mark last busy stamp in pm_runtime_put_sync_autosuspend() PM: runtime: Mark last busy stamp in pm_runtime_put_autosuspend() PM: runtime: Document return values of suspend-related API functions * pm-powercap: powercap: dtpm_cpu: Fix NULL pointer dereference in get_pd_power_uw() powercap: intel_rapl: Add support for Bartlett Lake platform powercap: intel_rapl_msr: Add PL4 support for Panther Lake
3 parents c4930d6 + 5188839 + 46dc574 commit 3b4d4c9

6 files changed

Lines changed: 208 additions & 60 deletions

File tree

Documentation/power/runtime_pm.rst

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,9 @@ 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
158-
device last busy mark, pm_runtime_mark_last_busy(), to control the delay under
159-
this circumstance). To prevent this (for example, if the callback routine has
160-
started a delayed suspend), the routine must return a non-zero value. Negative
161-
error return codes are ignored by the PM core.
157+
call to pm_runtime_autosuspend(). To prevent this (for example, if the callback
158+
routine has started a delayed suspend), the routine must return a non-zero
159+
value. Negative error return codes are ignored by the PM core.
162160

163161
The helper functions provided by the PM core, described in Section 4, guarantee
164162
that the following constraints are met with respect to runtime PM callbacks for
@@ -330,10 +328,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
330328
'power.disable_depth' is different from 0
331329

332330
`int pm_runtime_autosuspend(struct device *dev);`
333-
- same as pm_runtime_suspend() except that the autosuspend delay is taken
334-
`into account;` if pm_runtime_autosuspend_expiration() says the delay has
335-
not yet expired then an autosuspend is scheduled for the appropriate time
336-
and 0 is returned
331+
- same as pm_runtime_suspend() except that a call to
332+
pm_runtime_mark_last_busy() is made and an autosuspend is scheduled for
333+
the appropriate time and 0 is returned
337334

338335
`int pm_runtime_resume(struct device *dev);`
339336
- execute the subsystem-level resume callback for the device; returns 0 on
@@ -357,9 +354,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
357354
success or error code if the request has not been queued up
358355

359356
`int pm_request_autosuspend(struct device *dev);`
360-
- schedule the execution of the subsystem-level suspend callback for the
361-
device when the autosuspend delay has expired; if the delay has already
362-
expired then the work item is queued up immediately
357+
- Call pm_runtime_mark_last_busy() and schedule the execution of the
358+
subsystem-level suspend callback for the device when the autosuspend delay
359+
expires
363360

364361
`int pm_schedule_suspend(struct device *dev, unsigned int delay);`
365362
- schedule the execution of the subsystem-level suspend callback for the
@@ -411,8 +408,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
411408
pm_request_idle(dev) and return its result
412409

413410
`int pm_runtime_put_autosuspend(struct device *dev);`
414-
- does the same as __pm_runtime_put_autosuspend() for now, but in the
415-
future, will also call pm_runtime_mark_last_busy() as well, DO NOT USE!
411+
- set the power.last_busy field to the current time and decrement the
412+
device's usage counter; if the result is 0 then run
413+
pm_request_autosuspend(dev) and return its result
416414

417415
`int __pm_runtime_put_autosuspend(struct device *dev);`
418416
- decrement the device's usage counter; if the result is 0 then run
@@ -427,7 +425,8 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
427425
pm_runtime_suspend(dev) and return its result
428426

429427
`int pm_runtime_put_sync_autosuspend(struct device *dev);`
430-
- decrement the device's usage counter; if the result is 0 then run
428+
- set the power.last_busy field to the current time and decrement the
429+
device's usage counter; if the result is 0 then run
431430
pm_runtime_autosuspend(dev) and return its result
432431

433432
`void pm_runtime_enable(struct device *dev);`
@@ -870,11 +869,9 @@ device is automatically suspended (the subsystem or driver still has to call
870869
the appropriate PM routines); rather it means that runtime suspends will
871870
automatically be delayed until the desired period of inactivity has elapsed.
872871

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

@@ -885,12 +882,13 @@ instead of the non-autosuspend counterparts::
885882

886883
Instead of: pm_runtime_suspend use: pm_runtime_autosuspend;
887884
Instead of: pm_schedule_suspend use: pm_request_autosuspend;
888-
Instead of: pm_runtime_put use: __pm_runtime_put_autosuspend;
885+
Instead of: pm_runtime_put use: pm_runtime_put_autosuspend;
889886
Instead of: pm_runtime_put_sync use: pm_runtime_put_sync_autosuspend.
890887

891888
Drivers may also continue to use the non-autosuspend helper functions; they
892889
will behave normally, which means sometimes taking the autosuspend delay into
893-
account (see pm_runtime_idle).
890+
account (see pm_runtime_idle). The autosuspend variants of the functions also
891+
call pm_runtime_mark_last_busy().
894892

895893
Under some circumstances a driver or subsystem may want to prevent a device
896894
from autosuspending immediately, even though the usage counter is zero and the
@@ -922,12 +920,10 @@ Here is a schematic pseudo-code example::
922920
foo_io_completion(struct foo_priv *foo, void *req)
923921
{
924922
lock(&foo->private_lock);
925-
if (--foo->num_pending_requests == 0) {
926-
pm_runtime_mark_last_busy(&foo->dev);
927-
__pm_runtime_put_autosuspend(&foo->dev);
928-
} else {
923+
if (--foo->num_pending_requests == 0)
924+
pm_runtime_put_autosuspend(&foo->dev);
925+
else
929926
foo_process_next_request(foo);
930-
}
931927
unlock(&foo->private_lock);
932928
/* Send req result back to the user ... */
933929
}

drivers/base/power/runtime.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,10 +1203,12 @@ EXPORT_SYMBOL_GPL(__pm_runtime_resume);
12031203
*
12041204
* Return -EINVAL if runtime PM is disabled for @dev.
12051205
*
1206-
* Otherwise, if the runtime PM status of @dev is %RPM_ACTIVE and either
1207-
* @ign_usage_count is %true or the runtime PM usage counter of @dev is not
1208-
* zero, increment the usage counter of @dev and return 1. Otherwise, return 0
1209-
* without changing the usage counter.
1206+
* Otherwise, if its runtime PM status is %RPM_ACTIVE and (1) @ign_usage_count
1207+
* is set, or (2) @dev is not ignoring children and its active child count is
1208+
* nonero, or (3) the runtime PM usage counter of @dev is not zero, increment
1209+
* the usage counter of @dev and return 1.
1210+
*
1211+
* Otherwise, return 0 without changing the usage counter.
12101212
*
12111213
* If @ign_usage_count is %true, this function can be used to prevent suspending
12121214
* the device when its runtime PM status is %RPM_ACTIVE.
@@ -1228,7 +1230,8 @@ static int pm_runtime_get_conditional(struct device *dev, bool ign_usage_count)
12281230
retval = -EINVAL;
12291231
} else if (dev->power.runtime_status != RPM_ACTIVE) {
12301232
retval = 0;
1231-
} else if (ign_usage_count) {
1233+
} else if (ign_usage_count || (!dev->power.ignore_children &&
1234+
atomic_read(&dev->power.child_count) > 0)) {
12321235
retval = 1;
12331236
atomic_inc(&dev->power.usage_count);
12341237
} else {
@@ -1261,10 +1264,16 @@ EXPORT_SYMBOL_GPL(pm_runtime_get_if_active);
12611264
* @dev: Target device.
12621265
*
12631266
* Increment the runtime PM usage counter of @dev if its runtime PM status is
1264-
* %RPM_ACTIVE and its runtime PM usage counter is greater than 0, in which case
1265-
* it returns 1. If the device is in a different state or its usage_count is 0,
1266-
* 0 is returned. -EINVAL is returned if runtime PM is disabled for the device,
1267-
* in which case also the usage_count will remain unmodified.
1267+
* %RPM_ACTIVE and its runtime PM usage counter is greater than 0 or it is not
1268+
* ignoring children and its active child count is nonzero. 1 is returned in
1269+
* this case.
1270+
*
1271+
* If @dev is in a different state or it is not in use (that is, its usage
1272+
* counter is 0, or it is ignoring children, or its active child count is 0),
1273+
* 0 is returned.
1274+
*
1275+
* -EINVAL is returned if runtime PM is disabled for the device, in which case
1276+
* also the usage counter of @dev is not updated.
12681277
*/
12691278
int pm_runtime_get_if_in_use(struct device *dev)
12701279
{

drivers/powercap/dtpm_cpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ static u64 get_pd_power_uw(struct dtpm *dtpm)
9696
int i;
9797

9898
pd = em_cpu_get(dtpm_cpu->cpu);
99+
if (!pd)
100+
return 0;
99101

100102
pd_mask = em_span_cpus(pd);
101103

drivers/powercap/intel_rapl_common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,7 @@ static const struct x86_cpu_id rapl_ids[] __initconst = {
12771277
X86_MATCH_VFM(INTEL_RAPTORLAKE, &rapl_defaults_core),
12781278
X86_MATCH_VFM(INTEL_RAPTORLAKE_P, &rapl_defaults_core),
12791279
X86_MATCH_VFM(INTEL_RAPTORLAKE_S, &rapl_defaults_core),
1280+
X86_MATCH_VFM(INTEL_BARTLETTLAKE, &rapl_defaults_core),
12801281
X86_MATCH_VFM(INTEL_METEORLAKE, &rapl_defaults_core),
12811282
X86_MATCH_VFM(INTEL_METEORLAKE_L, &rapl_defaults_core),
12821283
X86_MATCH_VFM(INTEL_SAPPHIRERAPIDS_X, &rapl_defaults_spr_server),

drivers/powercap/intel_rapl_msr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ static const struct x86_cpu_id pl4_support_ids[] = {
150150
X86_MATCH_VFM(INTEL_METEORLAKE_L, NULL),
151151
X86_MATCH_VFM(INTEL_ARROWLAKE_U, NULL),
152152
X86_MATCH_VFM(INTEL_ARROWLAKE_H, NULL),
153+
X86_MATCH_VFM(INTEL_PANTHERLAKE_L, NULL),
153154
{}
154155
};
155156

0 commit comments

Comments
 (0)