Merge runtime PM framework updates and a core power management code fix for 6.18-rc1: - Make pm_runtime_put*() family of functions return 1 when the given device is already suspended which is consistent with the documentation (Brian Norris) - Add basic kunit tests for runtime PM API contracts and update return values in kerneldoc coments for the runtime PM API (Brian Norris, Dan Carpenter) - Add auto-cleanup macros for runtime PM "resume and get" and "get without resume" operations, use one of them in the PCI core and drop the existing "free" macro introduced for similar purpose, but somewhat cumbersome to use (Rafael Wysocki) - Make the core power management code avoid waiting on device links marked as SYNC_STATE_ONLY which is consistent with the handling of those device links elsewhere (Pin-yen Lin) * pm-core: PM: sleep: Do not wait on SYNC_STATE_ONLY device links * pm-runtime: PM: runtime: Fix error checking for kunit_device_register() PM: runtime: Introduce one more usage counter guard PM: runtime: Drop DEFINE_FREE() for pm_runtime_put() PCI/sysfs: Use runtime PM guard macro for auto-cleanup PM: runtime: Add auto-cleanup macros for "resume and get" operations PM: runtime: Update kerneldoc return codes PM: runtime: Make put{,_sync}() return 1 when already suspended PM: runtime: Add basic kunit tests for API contracts
Showing the changes to include/linux (1 of 9 files). Show all
Unified · Split
| @@ -21,6 +21,7 @@ · 20 unmodified lines | ||
| 21 | 21 | #define RPM_GET_PUT 0x04 /* Increment/decrement the |
| 22 | 22 | usage_count */ |
| 23 | 23 | #define RPM_AUTO 0x08 /* Use autosuspend_delay */ |
| 24 | +#define RPM_TRANSPARENT 0x10 /* Succeed if runtime PM is disabled */ | |
| 24 | 25 | |
| 25 | 26 | /* |
| 26 | 27 | * Use this for defining a set of PM operations to be used in all situations |
| @@ -350,13 +351,12 @@ static inline int pm_runtime_force_resume(struct device *dev) { return -ENXIO; } · 323 unmodified lines | ||
| 350 | 351 | * * 0: Success. |
| 351 | 352 | * * -EINVAL: Runtime PM error. |
| 352 | 353 | * * -EACCES: Runtime PM disabled. |
| 353 | − * * -EAGAIN: Runtime PM usage_count non-zero, Runtime PM status change ongoing | |
| 354 | − * or device not in %RPM_ACTIVE state. | |
| 354 | + * * -EAGAIN: Runtime PM usage counter non-zero, Runtime PM status change | |
| 355 | + * ongoing or device not in %RPM_ACTIVE state. | |
| 355 | 356 | * * -EBUSY: Runtime PM child_count non-zero. |
| 356 | 357 | * * -EPERM: Device PM QoS resume latency 0. |
| 357 | 358 | * * -EINPROGRESS: Suspend already in progress. |
| 358 | 359 | * * -ENOSYS: CONFIG_PM not enabled. |
| 359 | − * * 1: Device already suspended. | |
| 360 | 360 | * Other values and conditions for the above values are possible as returned by |
| 361 | 361 | * Runtime PM idle and suspend callbacks. |
| 362 | 362 | */ |
| @@ -370,14 +370,15 @@ static inline int pm_runtime_idle(struct device *dev) · 7 unmodified lines | ||
| 370 | 370 | * @dev: Target device. |
| 371 | 371 | * |
| 372 | 372 | * Return: |
| 373 | + * * 1: Success; device was already suspended. | |
| 373 | 374 | * * 0: Success. |
| 374 | 375 | * * -EINVAL: Runtime PM error. |
| 375 | 376 | * * -EACCES: Runtime PM disabled. |
| 376 | − * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing. | |
| 377 | + * * -EAGAIN: Runtime PM usage counter non-zero or Runtime PM status change | |
| 378 | + * ongoing. | |
| 377 | 379 | * * -EBUSY: Runtime PM child_count non-zero. |
| 378 | 380 | * * -EPERM: Device PM QoS resume latency 0. |
| 379 | 381 | * * -ENOSYS: CONFIG_PM not enabled. |
| 380 | − * * 1: Device already suspended. | |
| 381 | 382 | * Other values and conditions for the above values are possible as returned by |
| 382 | 383 | * Runtime PM suspend callbacks. |
| 383 | 384 | */ |
| @@ -396,14 +397,15 @@ static inline int pm_runtime_suspend(struct device *dev) · 12 unmodified lines | ||
| 396 | 397 | * engaging its "idle check" callback. |
| 397 | 398 | * |
| 398 | 399 | * Return: |
| 400 | + * * 1: Success; device was already suspended. | |
| 399 | 401 | * * 0: Success. |
| 400 | 402 | * * -EINVAL: Runtime PM error. |
| 401 | 403 | * * -EACCES: Runtime PM disabled. |
| 402 | − * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing. | |
| 404 | + * * -EAGAIN: Runtime PM usage counter non-zero or Runtime PM status change | |
| 405 | + * ongoing. | |
| 403 | 406 | * * -EBUSY: Runtime PM child_count non-zero. |
| 404 | 407 | * * -EPERM: Device PM QoS resume latency 0. |
| 405 | 408 | * * -ENOSYS: CONFIG_PM not enabled. |
| 406 | − * * 1: Device already suspended. | |
| 407 | 409 | * Other values and conditions for the above values are possible as returned by |
| 408 | 410 | * Runtime PM suspend callbacks. |
| 409 | 411 | */ |
| @@ -433,13 +435,12 @@ static inline int pm_runtime_resume(struct device *dev) · 23 unmodified lines | ||
| 433 | 435 | * * 0: Success. |
| 434 | 436 | * * -EINVAL: Runtime PM error. |
| 435 | 437 | * * -EACCES: Runtime PM disabled. |
| 436 | − * * -EAGAIN: Runtime PM usage_count non-zero, Runtime PM status change ongoing | |
| 437 | − * or device not in %RPM_ACTIVE state. | |
| 438 | + * * -EAGAIN: Runtime PM usage counter non-zero, Runtime PM status change | |
| 439 | + * ongoing or device not in %RPM_ACTIVE state. | |
| 438 | 440 | * * -EBUSY: Runtime PM child_count non-zero. |
| 439 | 441 | * * -EPERM: Device PM QoS resume latency 0. |
| 440 | 442 | * * -EINPROGRESS: Suspend already in progress. |
| 441 | 443 | * * -ENOSYS: CONFIG_PM not enabled. |
| 442 | − * * 1: Device already suspended. | |
| 443 | 444 | */ |
| 444 | 445 | static inline int pm_request_idle(struct device *dev) |
| 445 | 446 | { |
| @@ -464,15 +465,16 @@ static inline int pm_request_resume(struct device *dev) · 18 unmodified lines | ||
| 464 | 465 | * equivalent pm_runtime_autosuspend() for @dev asynchronously. |
| 465 | 466 | * |
| 466 | 467 | * Return: |
| 468 | + * * 1: Success; device was already suspended. | |
| 467 | 469 | * * 0: Success. |
| 468 | 470 | * * -EINVAL: Runtime PM error. |
| 469 | 471 | * * -EACCES: Runtime PM disabled. |
| 470 | − * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing. | |
| 472 | + * * -EAGAIN: Runtime PM usage counter non-zero or Runtime PM status change | |
| 473 | + * ongoing. | |
| 471 | 474 | * * -EBUSY: Runtime PM child_count non-zero. |
| 472 | 475 | * * -EPERM: Device PM QoS resume latency 0. |
| 473 | 476 | * * -EINPROGRESS: Suspend already in progress. |
| 474 | 477 | * * -ENOSYS: CONFIG_PM not enabled. |
| 475 | − * * 1: Device already suspended. | |
| 476 | 478 | */ |
| 477 | 479 | static inline int pm_request_autosuspend(struct device *dev) |
| 478 | 480 | { |
| @@ -511,6 +513,19 @@ static inline int pm_runtime_get_sync(struct device *dev) · 32 unmodified lines | ||
| 511 | 513 | return __pm_runtime_resume(dev, RPM_GET_PUT); |
| 512 | 514 | } |
| 513 | 515 | |
| 516 | +static inline int pm_runtime_get_active(struct device *dev, int rpmflags) | |
| 517 | +{ | |
| 518 | + int ret; | |
| 519 | + | |
| 520 | + ret = __pm_runtime_resume(dev, RPM_GET_PUT | rpmflags); | |
| 521 | + if (ret < 0) { | |
| 522 | + pm_runtime_put_noidle(dev); | |
| 523 | + return ret; | |
| 524 | + } | |
| 525 | + | |
| 526 | + return 0; | |
| 527 | +} | |
| 528 | + | |
| 514 | 529 | /** |
| 515 | 530 | * pm_runtime_resume_and_get - Bump up usage counter of a device and resume it. |
| 516 | 531 | * @dev: Target device. |
| @@ -521,15 +536,7 @@ static inline int pm_runtime_get_sync(struct device *dev) · 4 unmodified lines | ||
| 521 | 536 | */ |
| 522 | 537 | static inline int pm_runtime_resume_and_get(struct device *dev) |
| 523 | 538 | { |
| 524 | − int ret; | |
| 525 | − | |
| 526 | − ret = __pm_runtime_resume(dev, RPM_GET_PUT); | |
| 527 | − if (ret < 0) { | |
| 528 | − pm_runtime_put_noidle(dev); | |
| 529 | − return ret; | |
| 530 | − } | |
| 531 | − | |
| 532 | − return 0; | |
| 539 | + return pm_runtime_get_active(dev, 0); | |
| 533 | 540 | } |
| 534 | 541 | |
| 535 | 542 | /** |
| @@ -540,23 +547,22 @@ static inline int pm_runtime_resume_and_get(struct device *dev) · 4 unmodified lines | ||
| 540 | 547 | * equal to 0, queue up a work item for @dev like in pm_request_idle(). |
| 541 | 548 | * |
| 542 | 549 | * Return: |
| 550 | + * * 1: Success. Usage counter dropped to zero, but device was already suspended. | |
| 543 | 551 | * * 0: Success. |
| 544 | 552 | * * -EINVAL: Runtime PM error. |
| 545 | 553 | * * -EACCES: Runtime PM disabled. |
| 546 | − * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing. | |
| 554 | + * * -EAGAIN: Runtime PM usage counter became non-zero or Runtime PM status | |
| 555 | + * change ongoing. | |
| 547 | 556 | * * -EBUSY: Runtime PM child_count non-zero. |
| 548 | 557 | * * -EPERM: Device PM QoS resume latency 0. |
| 549 | 558 | * * -EINPROGRESS: Suspend already in progress. |
| 550 | 559 | * * -ENOSYS: CONFIG_PM not enabled. |
| 551 | − * * 1: Device already suspended. | |
| 552 | 560 | */ |
| 553 | 561 | static inline int pm_runtime_put(struct device *dev) |
| 554 | 562 | { |
| 555 | 563 | return __pm_runtime_idle(dev, RPM_GET_PUT | RPM_ASYNC); |
| 556 | 564 | } |
| 557 | 565 | |
| 558 | −DEFINE_FREE(pm_runtime_put, struct device *, if (_T) pm_runtime_put(_T)) | |
| 559 | − | |
| 560 | 566 | /** |
| 561 | 567 | * __pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0. |
| 562 | 568 | * @dev: Target device. |
| @@ -565,15 +571,16 @@ DEFINE_FREE(pm_runtime_put, struct device *, if (_T) pm_runtime_put(_T)) · 2 unmodified lines | ||
| 565 | 571 | * equal to 0, queue up a work item for @dev like in pm_request_autosuspend(). |
| 566 | 572 | * |
| 567 | 573 | * Return: |
| 574 | + * * 1: Success. Usage counter dropped to zero, but device was already suspended. | |
| 568 | 575 | * * 0: Success. |
| 569 | 576 | * * -EINVAL: Runtime PM error. |
| 570 | 577 | * * -EACCES: Runtime PM disabled. |
| 571 | − * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing. | |
| 578 | + * * -EAGAIN: Runtime PM usage counter became non-zero or Runtime PM status | |
| 579 | + * change ongoing. | |
| 572 | 580 | * * -EBUSY: Runtime PM child_count non-zero. |
| 573 | 581 | * * -EPERM: Device PM QoS resume latency 0. |
| 574 | 582 | * * -EINPROGRESS: Suspend already in progress. |
| 575 | 583 | * * -ENOSYS: CONFIG_PM not enabled. |
| 576 | − * * 1: Device already suspended. | |
| 577 | 584 | */ |
| 578 | 585 | static inline int __pm_runtime_put_autosuspend(struct device *dev) |
| 579 | 586 | { |
| @@ -590,15 +597,16 @@ static inline int __pm_runtime_put_autosuspend(struct device *dev) · 10 unmodified lines | ||
| 590 | 597 | * in pm_request_autosuspend(). |
| 591 | 598 | * |
| 592 | 599 | * Return: |
| 600 | + * * 1: Success. Usage counter dropped to zero, but device was already suspended. | |
| 593 | 601 | * * 0: Success. |
| 594 | 602 | * * -EINVAL: Runtime PM error. |
| 595 | 603 | * * -EACCES: Runtime PM disabled. |
| 596 | − * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing. | |
| 604 | + * * -EAGAIN: Runtime PM usage counter became non-zero or Runtime PM status | |
| 605 | + * change ongoing. | |
| 597 | 606 | * * -EBUSY: Runtime PM child_count non-zero. |
| 598 | 607 | * * -EPERM: Device PM QoS resume latency 0. |
| 599 | 608 | * * -EINPROGRESS: Suspend already in progress. |
| 600 | 609 | * * -ENOSYS: CONFIG_PM not enabled. |
| 601 | − * * 1: Device already suspended. | |
| 602 | 610 | */ |
| 603 | 611 | static inline int pm_runtime_put_autosuspend(struct device *dev) |
| 604 | 612 | { |
| @@ -606,6 +614,29 @@ static inline int pm_runtime_put_autosuspend(struct device *dev) · 1 unmodified line | ||
| 606 | 614 | return __pm_runtime_put_autosuspend(dev); |
| 607 | 615 | } |
| 608 | 616 | |
| 617 | +DEFINE_GUARD(pm_runtime_noresume, struct device *, | |
| 618 | + pm_runtime_get_noresume(_T), pm_runtime_put_noidle(_T)); | |
| 619 | + | |
| 620 | +DEFINE_GUARD(pm_runtime_active, struct device *, | |
| 621 | + pm_runtime_get_sync(_T), pm_runtime_put(_T)); | |
| 622 | +DEFINE_GUARD(pm_runtime_active_auto, struct device *, | |
| 623 | + pm_runtime_get_sync(_T), pm_runtime_put_autosuspend(_T)); | |
| 624 | +/* | |
| 625 | + * Use the following guards with ACQUIRE()/ACQUIRE_ERR(). | |
| 626 | + * | |
| 627 | + * The difference between the "_try" and "_try_enabled" variants is that the | |
| 628 | + * former do not produce an error when runtime PM is disabled for the given | |
| 629 | + * device. | |
| 630 | + */ | |
| 631 | +DEFINE_GUARD_COND(pm_runtime_active, _try, | |
| 632 | + pm_runtime_get_active(_T, RPM_TRANSPARENT)) | |
| 633 | +DEFINE_GUARD_COND(pm_runtime_active, _try_enabled, | |
| 634 | + pm_runtime_resume_and_get(_T)) | |
| 635 | +DEFINE_GUARD_COND(pm_runtime_active_auto, _try, | |
| 636 | + pm_runtime_get_active(_T, RPM_TRANSPARENT)) | |
| 637 | +DEFINE_GUARD_COND(pm_runtime_active_auto, _try_enabled, | |
| 638 | + pm_runtime_resume_and_get(_T)) | |
| 639 | + | |
| 609 | 640 | /** |
| 610 | 641 | * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0. |
| 611 | 642 | * @dev: Target device. |
| @@ -619,14 +650,15 @@ static inline int pm_runtime_put_autosuspend(struct device *dev) · 7 unmodified lines | ||
| 619 | 650 | * if it returns an error code. |
| 620 | 651 | * |
| 621 | 652 | * Return: |
| 653 | + * * 1: Success. Usage counter dropped to zero, but device was already suspended. | |
| 622 | 654 | * * 0: Success. |
| 623 | 655 | * * -EINVAL: Runtime PM error. |
| 624 | 656 | * * -EACCES: Runtime PM disabled. |
| 625 | − * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing. | |
| 657 | + * * -EAGAIN: Runtime PM usage counter became non-zero or Runtime PM status | |
| 658 | + * change ongoing. | |
| 626 | 659 | * * -EBUSY: Runtime PM child_count non-zero. |
| 627 | 660 | * * -EPERM: Device PM QoS resume latency 0. |
| 628 | 661 | * * -ENOSYS: CONFIG_PM not enabled. |
| 629 | − * * 1: Device already suspended. | |
| 630 | 662 | * Other values and conditions for the above values are possible as returned by |
| 631 | 663 | * Runtime PM suspend callbacks. |
| 632 | 664 | */ |
| @@ -646,15 +678,15 @@ static inline int pm_runtime_put_sync(struct device *dev) · 13 unmodified lines | ||
| 646 | 678 | * if it returns an error code. |
| 647 | 679 | * |
| 648 | 680 | * Return: |
| 681 | + * * 1: Success. Usage counter dropped to zero, but device was already suspended. | |
| 649 | 682 | * * 0: Success. |
| 650 | 683 | * * -EINVAL: Runtime PM error. |
| 651 | 684 | * * -EACCES: Runtime PM disabled. |
| 652 | − * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing. | |
| 653 | − * * -EAGAIN: usage_count non-zero or Runtime PM status change ongoing. | |
| 685 | + * * -EAGAIN: Runtime PM usage counter became non-zero or Runtime PM status | |
| 686 | + * change ongoing. | |
| 654 | 687 | * * -EBUSY: Runtime PM child_count non-zero. |
| 655 | 688 | * * -EPERM: Device PM QoS resume latency 0. |
| 656 | 689 | * * -ENOSYS: CONFIG_PM not enabled. |
| 657 | − * * 1: Device already suspended. | |
| 658 | 690 | * Other values and conditions for the above values are possible as returned by |
| 659 | 691 | * Runtime PM suspend callbacks. |
| 660 | 692 | */ |
| @@ -677,15 +709,16 @@ static inline int pm_runtime_put_sync_suspend(struct device *dev) · 16 unmodified lines | ||
| 677 | 709 | * if it returns an error code. |
| 678 | 710 | * |
| 679 | 711 | * Return: |
| 712 | + * * 1: Success. Usage counter dropped to zero, but device was already suspended. | |
| 680 | 713 | * * 0: Success. |
| 681 | 714 | * * -EINVAL: Runtime PM error. |
| 682 | 715 | * * -EACCES: Runtime PM disabled. |
| 683 | − * * -EAGAIN: Runtime PM usage_count non-zero or Runtime PM status change ongoing. | |
| 716 | + * * -EAGAIN: Runtime PM usage counter became non-zero or Runtime PM status | |
| 717 | + * change ongoing. | |
| 684 | 718 | * * -EBUSY: Runtime PM child_count non-zero. |
| 685 | 719 | * * -EPERM: Device PM QoS resume latency 0. |
| 686 | 720 | * * -EINPROGRESS: Suspend already in progress. |
| 687 | 721 | * * -ENOSYS: CONFIG_PM not enabled. |
| 688 | − * * 1: Device already suspended. | |
| 689 | 722 | * Other values and conditions for the above values are possible as returned by |
| 690 | 723 | * Runtime PM suspend callbacks. |
| 691 | 724 | */ |