Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Sakari Ailus and committed by
Rafael J. Wysocki
c0ef3df8 841c3516

+50 -29
+2 -3
Documentation/power/runtime_pm.rst
··· 396 396 nonzero, increment the counter and return 1; otherwise return 0 without 397 397 changing the counter 398 398 399 - `int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count);` 399 + `int pm_runtime_get_if_active(struct device *dev);` 400 400 - 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 403 402 return 1; otherwise return 0 without changing the counter 404 403 405 404 `void pm_runtime_put_noidle(struct device *dev);`
+1 -1
drivers/accel/ivpu/ivpu_pm.c
··· 304 304 { 305 305 int ret; 306 306 307 - ret = pm_runtime_get_if_active(vdev->drm.dev, false); 307 + ret = pm_runtime_get_if_in_use(vdev->drm.dev); 308 308 drm_WARN_ON(&vdev->drm, ret < 0); 309 309 310 310 return ret;
+33 -2
drivers/base/power/runtime.c
··· 1176 1176 EXPORT_SYMBOL_GPL(__pm_runtime_resume); 1177 1177 1178 1178 /** 1179 - * pm_runtime_get_if_active - Conditionally bump up device usage counter. 1179 + * pm_runtime_get_conditional - Conditionally bump up device usage counter. 1180 1180 * @dev: Device to handle. 1181 1181 * @ign_usage_count: Whether or not to look at the current usage counter value. 1182 1182 * ··· 1197 1197 * The caller is responsible for decrementing the runtime PM usage counter of 1198 1198 * @dev after this function has returned a positive value for it. 1199 1199 */ 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) 1201 1201 { 1202 1202 unsigned long flags; 1203 1203 int retval; ··· 1218 1218 1219 1219 return retval; 1220 1220 } 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 + } 1221 1236 EXPORT_SYMBOL_GPL(pm_runtime_get_if_active); 1237 + 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); 1222 1253 1223 1254 /** 1224 1255 * __pm_runtime_set_status - Set runtime PM status of a device.
+4 -1
drivers/gpu/drm/i915/intel_runtime_pm.c
··· 246 246 * function, since the power state is undefined. This applies 247 247 * atm to the late/early system suspend/resume handlers. 248 248 */ 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)) 250 253 return 0; 251 254 } 252 255
+1 -1
drivers/gpu/drm/xe/xe_pm.c
··· 330 330 331 331 int xe_pm_runtime_get_if_active(struct xe_device *xe) 332 332 { 333 - return pm_runtime_get_if_active(xe->drm.dev, true); 333 + return pm_runtime_get_if_active(xe->drm.dev); 334 334 } 335 335 336 336 void xe_pm_assert_unbounded_bridge(struct xe_device *xe)
+1 -1
drivers/media/i2c/ccs/ccs-core.c
··· 674 674 break; 675 675 } 676 676 677 - pm_status = pm_runtime_get_if_active(&client->dev, true); 677 + pm_status = pm_runtime_get_if_active(&client->dev); 678 678 if (!pm_status) 679 679 return 0; 680 680
+1 -1
drivers/media/i2c/ov64a40.c
··· 3287 3287 exp_max, 1, exp_val); 3288 3288 } 3289 3289 3290 - pm_status = pm_runtime_get_if_active(ov64a40->dev, true); 3290 + pm_status = pm_runtime_get_if_active(ov64a40->dev); 3291 3291 if (!pm_status) 3292 3292 return 0; 3293 3293
+1 -1
drivers/media/i2c/thp7312.c
··· 1052 1052 if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) 1053 1053 return -EINVAL; 1054 1054 1055 - if (!pm_runtime_get_if_active(thp7312->dev, true)) 1055 + if (!pm_runtime_get_if_active(thp7312->dev)) 1056 1056 return 0; 1057 1057 1058 1058 switch (ctrl->id) {
+1 -1
drivers/net/ipa/ipa_smp2p.c
··· 92 92 return; 93 93 94 94 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; 96 96 97 97 /* Signal whether the IPA power is enabled */ 98 98 mask = BIT(smp2p->enabled_bit);
+1 -1
drivers/pci/pci.c
··· 2536 2536 * If the device is in a low power state it 2537 2537 * should not be polled either. 2538 2538 */ 2539 - pm_status = pm_runtime_get_if_active(dev, true); 2539 + pm_status = pm_runtime_get_if_active(dev); 2540 2540 if (!pm_status) 2541 2541 continue; 2542 2542
+3 -15
include/linux/pm_runtime.h
··· 72 72 extern int __pm_runtime_idle(struct device *dev, int rpmflags); 73 73 extern int __pm_runtime_suspend(struct device *dev, int rpmflags); 74 74 extern int __pm_runtime_resume(struct device *dev, int rpmflags); 75 - extern int pm_runtime_get_if_active(struct device *dev, bool ign_usage_count); 75 + extern int pm_runtime_get_if_active(struct device *dev); 76 + extern int pm_runtime_get_if_in_use(struct device *dev); 76 77 extern int pm_schedule_suspend(struct device *dev, unsigned int delay); 77 78 extern int __pm_runtime_set_status(struct device *dev, unsigned int status); 78 79 extern int pm_runtime_barrier(struct device *dev); ··· 94 93 extern void pm_runtime_release_supplier(struct device_link *link); 95 94 96 95 extern int devm_pm_runtime_enable(struct device *dev); 97 - 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 96 110 97 /** 111 98 * pm_suspend_ignore_children - Set runtime PM behavior regarding children. ··· 264 275 { 265 276 return -EINVAL; 266 277 } 267 - static inline int pm_runtime_get_if_active(struct device *dev, 268 - bool ign_usage_count) 278 + static inline int pm_runtime_get_if_active(struct device *dev) 269 279 { 270 280 return -EINVAL; 271 281 }
+1 -1
sound/hda/hdac_device.c
··· 612 612 int snd_hdac_keep_power_up(struct hdac_device *codec) 613 613 { 614 614 if (!atomic_inc_not_zero(&codec->in_pm)) { 615 - int ret = pm_runtime_get_if_active(&codec->dev, true); 615 + int ret = pm_runtime_get_if_active(&codec->dev); 616 616 if (!ret) 617 617 return -1; 618 618 if (ret < 0)