Skip to content

Commit 8d4d26d

Browse files
Sakari Ailusopsiff
authored andcommitted
PM: runtime: Simplify pm_runtime_get_if_active() usage
[ Upstream commit c0ef3df ] There are two ways to opportunistically increment a device's runtime PM usage count, calling either pm_runtime_get_if_active() or pm_runtime_get_if_in_use(). The former has an argument to tell whether to ignore the usage count or not, and the latter simply calls the former with ign_usage_count set to false. The other users that want to ignore the usage_count will have to explicitly set that argument to true which is a bit cumbersome. To make this function more practical to use, remove the ign_usage_count argument from the function. The main implementation is in a static function called pm_runtime_get_conditional() and implementations of pm_runtime_get_if_active() and pm_runtime_get_if_in_use() are moved to runtime.c. Signed-off-by: Sakari Ailus <[email protected]> Reviewed-by: Alex Elder <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Acked-by: Takashi Iwai <[email protected]> # sound/ Reviewed-by: Jacek Lawrynowicz <[email protected]> # drivers/accel/ivpu/ Acked-by: Rodrigo Vivi <[email protected]> # drivers/gpu/drm/i915/ Reviewed-by: Rodrigo Vivi <[email protected]> Acked-by: Bjorn Helgaas <[email protected]> # drivers/pci/ Signed-off-by: Rafael J. Wysocki <[email protected]> [ Removed changes to code that didn't exist in older trees ] Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit ac2e62cab0977960420a0f4b3197932591a104f8)
1 parent d81432c commit 8d4d26d

File tree

9 files changed

+47
-26
lines changed

9 files changed

+47
-26
lines changed

Documentation/power/runtime_pm.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
398398
nonzero, increment the counter and return 1; otherwise return 0 without
399399
changing the counter
400400

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

407406
`void pm_runtime_put_noidle(struct device *dev);`

drivers/base/power/runtime.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ int __pm_runtime_resume(struct device *dev, int rpmflags)
11751175
EXPORT_SYMBOL_GPL(__pm_runtime_resume);
11761176

11771177
/**
1178-
* pm_runtime_get_if_active - Conditionally bump up device usage counter.
1178+
* pm_runtime_get_conditional - Conditionally bump up device usage counter.
11791179
* @dev: Device to handle.
11801180
* @ign_usage_count: Whether or not to look at the current usage counter value.
11811181
*
@@ -1196,7 +1196,7 @@ EXPORT_SYMBOL_GPL(__pm_runtime_resume);
11961196
* The caller is responsible for decrementing the runtime PM usage counter of
11971197
* @dev after this function has returned a positive value for it.
11981198
*/
1199-
int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count)
1199+
static int pm_runtime_get_conditional(struct device *dev, bool ign_usage_count)
12001200
{
12011201
unsigned long flags;
12021202
int retval;
@@ -1217,8 +1217,39 @@ int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count)
12171217

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

1237+
/**
1238+
* pm_runtime_get_if_in_use - Conditionally bump up runtime PM usage counter.
1239+
* @dev: Target device.
1240+
*
1241+
* Increment the runtime PM usage counter of @dev if its runtime PM status is
1242+
* %RPM_ACTIVE and its runtime PM usage counter is greater than 0, in which case
1243+
* it returns 1. If the device is in a different state or its usage_count is 0,
1244+
* 0 is returned. -EINVAL is returned if runtime PM is disabled for the device,
1245+
* in which case also the usage_count will remain unmodified.
1246+
*/
1247+
int pm_runtime_get_if_in_use(struct device *dev)
1248+
{
1249+
return pm_runtime_get_conditional(dev, false);
1250+
}
1251+
EXPORT_SYMBOL_GPL(pm_runtime_get_if_in_use);
1252+
12221253
/**
12231254
* __pm_runtime_set_status - Set runtime PM status of a device.
12241255
* @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
@@ -434,7 +434,10 @@ static intel_wakeref_t __intel_runtime_pm_get_if_active(struct intel_runtime_pm
434434
* function, since the power state is undefined. This applies
435435
* atm to the late/early system suspend/resume handlers.
436436
*/
437-
if (pm_runtime_get_if_active(rpm->kdev, ignore_usecount) <= 0)
437+
if ((ignore_usecount &&
438+
pm_runtime_get_if_active(rpm->kdev) <= 0) ||
439+
(!ignore_usecount &&
440+
pm_runtime_get_if_in_use(rpm->kdev) <= 0))
438441
return 0;
439442
}
440443

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ static int ccs_set_ctrl(struct v4l2_ctrl *ctrl)
665665
break;
666666
}
667667

668-
pm_status = pm_runtime_get_if_active(&client->dev, true);
668+
pm_status = pm_runtime_get_if_active(&client->dev);
669669
if (!pm_status)
670670
return 0;
671671

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
@@ -2493,7 +2493,7 @@ static void pci_pme_list_scan(struct work_struct *work)
24932493
* course of the call.
24942494
*/
24952495
if (bdev) {
2496-
bref = pm_runtime_get_if_active(bdev, true);
2496+
bref = pm_runtime_get_if_active(bdev);
24972497
if (!bref)
24982498
continue;
24992499

drivers/ufs/core/ufshcd-priv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ static inline int ufshcd_rpm_get_sync(struct ufs_hba *hba)
326326

327327
static inline int ufshcd_rpm_get_if_active(struct ufs_hba *hba)
328328
{
329-
return pm_runtime_get_if_active(&hba->ufs_device_wlun->sdev_gendev, true);
329+
return pm_runtime_get_if_active(&hba->ufs_device_wlun->sdev_gendev);
330330
}
331331

332332
static inline int ufshcd_rpm_put_sync(struct ufs_hba *hba)

include/linux/pm_runtime.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ extern int pm_runtime_force_resume(struct device *dev);
7373
extern int __pm_runtime_idle(struct device *dev, int rpmflags);
7474
extern int __pm_runtime_suspend(struct device *dev, int rpmflags);
7575
extern int __pm_runtime_resume(struct device *dev, int rpmflags);
76-
extern int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count);
76+
extern int pm_runtime_get_if_active(struct device *dev);
77+
extern int pm_runtime_get_if_in_use(struct device *dev);
7778
extern int pm_schedule_suspend(struct device *dev, unsigned int delay);
7879
extern int __pm_runtime_set_status(struct device *dev, unsigned int status);
7980
extern int pm_runtime_barrier(struct device *dev);
@@ -95,18 +96,6 @@ extern void pm_runtime_release_supplier(struct device_link *link);
9596

9697
extern int devm_pm_runtime_enable(struct device *dev);
9798

98-
/**
99-
* pm_runtime_get_if_in_use - Conditionally bump up runtime PM usage counter.
100-
* @dev: Target device.
101-
*
102-
* Increment the runtime PM usage counter of @dev if its runtime PM status is
103-
* %RPM_ACTIVE and its runtime PM usage counter is greater than 0.
104-
*/
105-
static inline int pm_runtime_get_if_in_use(struct device *dev)
106-
{
107-
return pm_runtime_get_if_active(dev, false);
108-
}
109-
11099
/**
111100
* pm_suspend_ignore_children - Set runtime PM behavior regarding children.
112101
* @dev: Target device.
@@ -277,8 +266,7 @@ static inline int pm_runtime_get_if_in_use(struct device *dev)
277266
{
278267
return -EINVAL;
279268
}
280-
static inline int pm_runtime_get_if_active(struct device *dev,
281-
bool ign_usage_count)
269+
static inline int pm_runtime_get_if_active(struct device *dev)
282270
{
283271
return -EINVAL;
284272
}

sound/hda/hdac_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ EXPORT_SYMBOL_GPL(snd_hdac_power_up_pm);
611611
int snd_hdac_keep_power_up(struct hdac_device *codec)
612612
{
613613
if (!atomic_inc_not_zero(&codec->in_pm)) {
614-
int ret = pm_runtime_get_if_active(&codec->dev, true);
614+
int ret = pm_runtime_get_if_active(&codec->dev);
615615
if (!ret)
616616
return -1;
617617
if (ret < 0)

0 commit comments

Comments
 (0)