Skip to content

Commit c0ef3df

Browse files
Sakari Ailusrafaeljw
authored andcommitted
PM: runtime: Simplify pm_runtime_get_if_active() usage
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 <sakari.ailus@linux.intel.com> Reviewed-by: Alex Elder <elder@linaro.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Takashi Iwai <tiwai@suse.de> # sound/ Reviewed-by: Jacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com> # drivers/accel/ivpu/ Acked-by: Rodrigo Vivi <rodrigo.vivi@intel.com> # drivers/gpu/drm/i915/ Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Acked-by: Bjorn Helgaas <bhelgaas@google.com> # drivers/pci/ Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 841c351 commit c0ef3df

File tree

12 files changed

+50
-29
lines changed

12 files changed

+50
-29
lines changed

Documentation/power/runtime_pm.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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);`

drivers/accel/ivpu/ivpu_pm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ int ivpu_rpm_get_if_active(struct ivpu_device *vdev)
304304
{
305305
int ret;
306306

307-
ret = pm_runtime_get_if_active(vdev->drm.dev, false);
307+
ret = pm_runtime_get_if_in_use(vdev->drm.dev);
308308
drm_WARN_ON(&vdev->drm, ret < 0);
309309

310310
return ret;

drivers/base/power/runtime.c

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

11781178
/**
1179-
* pm_runtime_get_if_active - Conditionally bump up device usage counter.
1179+
* pm_runtime_get_conditional - Conditionally bump up device usage counter.
11801180
* @dev: Device to handle.
11811181
* @ign_usage_count: Whether or not to look at the current usage counter value.
11821182
*
@@ -1197,7 +1197,7 @@ EXPORT_SYMBOL_GPL(__pm_runtime_resume);
11971197
* The caller is responsible for decrementing the runtime PM usage counter of
11981198
* @dev after this function has returned a positive value for it.
11991199
*/
1200-
int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count)
1200+
static int pm_runtime_get_conditional(struct device *dev, bool ign_usage_count)
12011201
{
12021202
unsigned long flags;
12031203
int retval;
@@ -1218,8 +1218,39 @@ int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count)
12181218

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

1238+
/**
1239+
* pm_runtime_get_if_in_use - Conditionally bump up runtime PM usage counter.
1240+
* @dev: Target device.
1241+
*
1242+
* Increment the runtime PM usage counter of @dev if its runtime PM status is
1243+
* %RPM_ACTIVE and its runtime PM usage counter is greater than 0, in which case
1244+
* it returns 1. If the device is in a different state or its usage_count is 0,
1245+
* 0 is returned. -EINVAL is returned if runtime PM is disabled for the device,
1246+
* in which case also the usage_count will remain unmodified.
1247+
*/
1248+
int pm_runtime_get_if_in_use(struct device *dev)
1249+
{
1250+
return pm_runtime_get_conditional(dev, false);
1251+
}
1252+
EXPORT_SYMBOL_GPL(pm_runtime_get_if_in_use);
1253+
12231254
/**
12241255
* __pm_runtime_set_status - Set runtime PM status of a device.
12251256
* @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
@@ -2536,7 +2536,7 @@ static void pci_pme_list_scan(struct work_struct *work)
25362536
* If the device is in a low power state it
25372537
* should not be polled either.
25382538
*/
2539-
pm_status = pm_runtime_get_if_active(dev, true);
2539+
pm_status = pm_runtime_get_if_active(dev);
25402540
if (!pm_status)
25412541
continue;
25422542

0 commit comments

Comments
 (0)