PM: runtime: Wrapper macros for usage counter guards
Subsystems (3)
Rafael J. Wysocki
maintainerv2 cover PM: runtime: Wrapper macros for usage counter guards
Hi All,
This supersedes
https://lore.kernel.org/linux-pm/[email protected]/
as discussed here:
https://lore.kernel.org/linux-pm/[email protected]/
It adds runtime PM wrapper macros around ACQUIRE() and ACQUIRE_ERR() involving the guards added recently (patch [1/3]) and then updates the code already using those guards (patches [2/3] and [3/3]) to make it look more straightforward.
Thanks!
Rafael J. Wysocki
maintainerPATCH v2 1/3 PM: runtime: Wrapper macros for ACQUIRE()/ACQUIRE_ERR()
From: Rafael J. Wysocki <[email protected]>
Add wrapper macros for ACQUIRE()/ACQUIRE_ERR() and runtime PM usage counter guards introduced recently: pm_runtime_active_try, pm_runtime_active_auto_try, pm_runtime_active_try_enabled, and pm_runtime_active_auto_try_enabled.
The new macros should be more straightforward to use.
For example, they can be used for rewriting a piece of code like below:
ACQUIRE(pm_runtime_active_try, pm)(dev);
if ((ret = ACQUIRE_ERR(pm_runtime_active_try, &pm)))
return ret;in the following way:
PM_RUNTIME_ACQUIRE(dev, pm);
if ((ret = PM_RUNTIME_ACQUIRE_ERR(&pm)))
return ret;If the original code does not care about the specific error code returned when attepmting to resume the device:
ACQUIRE(pm_runtime_active_try, pm)(dev);
if (ACQUIRE_ERR(pm_runtime_active_try, &pm))
return -ENXIO;it may be changed like this:
PM_RUNTIME_ACQUIRE(dev, pm);
if (PM_RUNTIME_ACQUIRE_ERR(&pm))
return -ENXIO;---
v1 -> v2:
* The new macros take the guard variable name as a parameter.
* The new ERR macro takes a guard variable pointer as a parameter (Dan).
* Added underscore prefix to the macro parameter names.
--- include/linux/pm_runtime.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
include/linux/pm_runtime.h +24 -0
@@ -637,6 +637,30 @@ DEFINE_GUARD_COND(pm_runtime_active_autoDEFINE_GUARD_COND (pm_runtime_active_auto, _try_enabled,pm_runtime_resume_and_get (_T), _RET ==0 ) +/* ACQUIRE() wrapper macros for the guards defined above. */ + +#define PM_RUNTIME_ACQUIRE (_dev, _var) \ + ACQUIRE(pm_runtime_active_try, _var)(_dev) + +#define PM_RUNTIME_ACQUIRE_AUTOSUSPEND (_dev, _var) \ + ACQUIRE(pm_runtime_active_auto_try, _var)(_dev) + +#define PM_RUNTIME_ACQUIRE_IF_ENABLED (_dev, _var) \ + ACQUIRE(pm_runtime_active_try_enabled, _var)(_dev) + +#define PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND (_dev, _var) \ + ACQUIRE(pm_runtime_active_auto_try_enabled, _var)(_dev) + +/* +* ACQUIRE_ERR() wrapper macro for guard pm_runtime_active. +* +* Always check PM_RUNTIME_ACQUIRE_ERR() after using one of the +* PM_RUNTIME_ACQUIRE*() macros defined above (yes, it can be used with +* any of them) and if it is nonzero, avoid accessing the given device. +*/ +#define PM_RUNTIME_ACQUIRE_ERR (_var_ptr) \ + ACQUIRE_ERR(pm_runtime_active, _var_ptr) +/** * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0. * @dev: Target device.
Re: [PATCH v2 1/3] PM: runtime: Wrapper macros for ACQUIRE()/ACQUIRE_ERR()
Quoted 68 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Add wrapper macros for ACQUIRE()/ACQUIRE_ERR() and runtime PM usage counter guards introduced recently:
pm_runtime_active_try,pm_runtime_active_auto_try,pm_runtime_active_try_enabled, andpm_runtime_active_auto_try_enabled.The new macros should be more straightforward to use.
For example, they can be used for rewriting a piece of code like below:
ACQUIRE(pm_runtime_active_try, pm)(dev); if ((ret = ACQUIRE_ERR(pm_runtime_active_try, &pm))) return ret;in the following way:
PM_RUNTIME_ACQUIRE(dev, pm); if ((ret = PM_RUNTIME_ACQUIRE_ERR(&pm))) return ret;If the original code does not care about the specific error code returned when attepmting to resume the device:
ACQUIRE(pm_runtime_active_try, pm)(dev); if (ACQUIRE_ERR(pm_runtime_active_try, &pm)) return -ENXIO;it may be changed like this:
PM_RUNTIME_ACQUIRE(dev, pm); if (PM_RUNTIME_ACQUIRE_ERR(&pm)) return -ENXIO;Signed-off-by Rafael J. Wysocki <[email protected]>Reviewed-by Dan Williams <[email protected]>---
v1 -> v2:
* The new macros take the guard variable name as a parameter.
* The new ERR macro takes a guard variable pointer as a parameter (Dan).
* Added underscore prefix to the macro parameter names.--- include/linux/pm_runtime.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)include/linux/pm_runtime.h +14
-0@@ -637,6 +637,30 @@ DEFINE_GUARD_COND(pm_runtime_active_autoDEFINE_GUARD_COND (pm_runtime_active_auto, _try_enabled,pm_runtime_resume_and_get (_T), _RET ==0 ) +/* ACQUIRE() wrapper macros for the guards defined above. */ + +#define PM_RUNTIME_ACQUIRE (_dev, _var) \ + ACQUIRE(pm_runtime_active_try, _var)(_dev) + +#define PM_RUNTIME_ACQUIRE_AUTOSUSPEND (_dev, _var) \ + ACQUIRE(pm_runtime_active_auto_try, _var)(_dev) + +#define PM_RUNTIME_ACQUIRE_IF_ENABLED (_dev, _var) \ + ACQUIRE(pm_runtime_active_try_enabled, _var)(_dev) + +#define PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND (_dev, _var) \ + ACQUIRE(pm_runtime_active_auto_try_enabled, _var)(_dev) +
include/linux/pm_runtime.h DEFINE_GUARD_COND(pm_runtime_active_auto · line 663
Quoted 10 lines
include/linux/pm_runtime.h +10
-0+/* +* ACQUIRE_ERR() wrapper macro for guard pm_runtime_active. +* +* Always check PM_RUNTIME_ACQUIRE_ERR() after using one of the +* PM_RUNTIME_ACQUIRE*() macros defined above (yes, it can be used with +* any of them) and if it is nonzero, avoid accessing the given device. +*/ +#define PM_RUNTIME_ACQUIRE_ERR (_var_ptr) \ + ACQUIRE_ERR(pm_runtime_active, _var_ptr) +
Signature · 3 lines
Best regards, Dhruva Gole Texas Instruments Incorporated
Re: [PATCH v2 1/3] PM: runtime: Wrapper macros for ACQUIRE()/ACQUIRE_ERR()
In reply to Rafael J. WysockiQuoted 37 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Add wrapper macros for ACQUIRE()/ACQUIRE_ERR() and runtime PM usage counter guards introduced recently:
pm_runtime_active_try,pm_runtime_active_auto_try,pm_runtime_active_try_enabled, andpm_runtime_active_auto_try_enabled.The new macros should be more straightforward to use.
For example, they can be used for rewriting a piece of code like below:
ACQUIRE(pm_runtime_active_try, pm)(dev); if ((ret = ACQUIRE_ERR(pm_runtime_active_try, &pm))) return ret;in the following way:
PM_RUNTIME_ACQUIRE(dev, pm); if ((ret = PM_RUNTIME_ACQUIRE_ERR(&pm))) return ret;If the original code does not care about the specific error code returned when attepmting to resume the device:
ACQUIRE(pm_runtime_active_try, pm)(dev); if (ACQUIRE_ERR(pm_runtime_active_try, &pm)) return -ENXIO;it may be changed like this:
PM_RUNTIME_ACQUIRE(dev, pm); if (PM_RUNTIME_ACQUIRE_ERR(&pm)) return -ENXIO;
Quoted 6 lines
---
v1 -> v2:
* The new macros take the guard variable name as a parameter.
* The new ERR macro takes a guard variable pointer as a parameter (Dan).
* Added underscore prefix to the macro parameter names.
Quoted 41 lines
--- include/linux/pm_runtime.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)include/linux/pm_runtime.h +24
-0@@ -637,6 +637,30 @@ DEFINE_GUARD_COND(pm_runtime_active_autoDEFINE_GUARD_COND (pm_runtime_active_auto, _try_enabled,pm_runtime_resume_and_get (_T), _RET ==0 ) +/* ACQUIRE() wrapper macros for the guards defined above. */ + +#define PM_RUNTIME_ACQUIRE (_dev, _var) \ + ACQUIRE(pm_runtime_active_try, _var)(_dev) + +#define PM_RUNTIME_ACQUIRE_AUTOSUSPEND (_dev, _var) \ + ACQUIRE(pm_runtime_active_auto_try, _var)(_dev) + +#define PM_RUNTIME_ACQUIRE_IF_ENABLED (_dev, _var) \ + ACQUIRE(pm_runtime_active_try_enabled, _var)(_dev) + +#define PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND (_dev, _var) \ + ACQUIRE(pm_runtime_active_auto_try_enabled, _var)(_dev) + +/* +* ACQUIRE_ERR() wrapper macro for guard pm_runtime_active. +* +* Always check PM_RUNTIME_ACQUIRE_ERR() after using one of the +* PM_RUNTIME_ACQUIRE*() macros defined above (yes, it can be used with +* any of them) and if it is nonzero, avoid accessing the given device. +*/ +#define PM_RUNTIME_ACQUIRE_ERR (_var_ptr) \ + ACQUIRE_ERR(pm_runtime_active, _var_ptr) +/** * pm_runtime_put_sync - Drop device usage counter and run "idle check" if 0. * @dev: Target device.
Rafael J. Wysocki
maintainerPATCH v2 2/3 ACPI: TAD: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Use new PM_RUNTIME_ACQUIRE() and PM_RUNTIME_ACQUIRE_ERR() wrapper macros to make the code look more straightforward.
No intentional funtional impact.
---
v1 -> v2: Adjust to the changes in patch [1/3].
--- drivers/acpi/acpi_tad.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/acpi/acpi_tad.c +12 -12
@@ -90,8 +90,8 @@ static int acpi_tad_set_real_time(struct args[0 ].buffer.pointer = (u8 *)rt; args[0 ].buffer.length =sizeof (*rt); -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ; status =acpi_evaluate_integer (handle,"_SRT" , &arg_list, &retval);
@@ -137,8 +137,8 @@ static int acpi_tad_get_real_time(struct {int ret; -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ; ret =acpi_tad_evaluate_grt (dev, rt);
@@ -275,8 +275,8 @@ static int acpi_tad_wake_set(struct devi args[0 ].integer.value = timer_id; args[1 ].integer.value = value; -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ; status =acpi_evaluate_integer (handle, method, &arg_list, &retval);
@@ -322,8 +322,8 @@ static ssize_t acpi_tad_wake_read(struct args[0 ].integer.value = timer_id; -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ; status =acpi_evaluate_integer (handle, method, &arg_list, &retval);
@@ -377,8 +377,8 @@ static int acpi_tad_clear_status(struct args[0 ].integer.value = timer_id; -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ; status =acpi_evaluate_integer (handle,"_CWS" , &arg_list, &retval);
@@ -417,8 +417,8 @@ static ssize_t acpi_tad_status_read(stru args[0 ].integer.value = timer_id; -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ; status =acpi_evaluate_integer (handle,"_GWS" , &arg_list, &retval);
Re: [PATCH v2 2/3] ACPI: TAD: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR()
Quoted 6 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Use new
PM_RUNTIME_ACQUIRE()andPM_RUNTIME_ACQUIRE_ERR()wrapper macros to make the code look more straightforward.No intentional funtional impact.
Nit: 'functional'
Quoted 81 lines
Signed-off-by Rafael J. Wysocki <[email protected]>---
v1 -> v2: Adjust to the changes in patch [1/3].
--- drivers/acpi/acpi_tad.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)drivers/acpi/acpi_tad.c +12
-12@@ -90,8 +90,8 @@ static int acpi_tad_set_real_time(struct args[0 ].buffer.pointer = (u8 *)rt; args[0 ].buffer.length =sizeof (*rt); -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ; status =acpi_evaluate_integer (handle,"_SRT" , &arg_list, &retval);@@ -137,8 +137,8 @@ static int acpi_tad_get_real_time(struct {int ret; -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ; ret =acpi_tad_evaluate_grt (dev, rt);@@ -275,8 +275,8 @@ static int acpi_tad_wake_set(struct devi args[0 ].integer.value = timer_id; args[1 ].integer.value = value; -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ; status =acpi_evaluate_integer (handle, method, &arg_list, &retval);@@ -322,8 +322,8 @@ static ssize_t acpi_tad_wake_read(struct args[0 ].integer.value = timer_id; -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ; status =acpi_evaluate_integer (handle, method, &arg_list, &retval);@@ -377,8 +377,8 @@ static int acpi_tad_clear_status(struct args[0 ].integer.value = timer_id; -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ; status =acpi_evaluate_integer (handle,"_CWS" , &arg_list, &retval);@@ -417,8 +417,8 @@ static ssize_t acpi_tad_status_read(stru args[0 ].integer.value = timer_id; -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ; status =acpi_evaluate_integer (handle,"_GWS" , &arg_list, &retval);
Signature · 3 lines
Best regards, Dhruva Gole Texas Instruments Incorporated
Rafael J. Wysocki
maintainerPATCH v2 3/3 PCI/sysfs: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR()
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
Use new PM_RUNTIME_ACQUIRE() and PM_RUNTIME_ACQUIRE_ERR() wrapper macros to make the code look more straightforward.
No intentional funtional impact.
---
v1 -> v2: Adjust to the changes in patch [1/3].
--- drivers/pci/pci-sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pci-sysfs.c +2 -2
@@ -1517,8 +1517,8 @@ static ssize_t reset_method_store(structreturn count; } -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ;if (sysfs_streq (buf,"default" )) {
Re: [PATCH v2 3/3] PCI/sysfs: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR()
Quoted 6 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Use new
PM_RUNTIME_ACQUIRE()andPM_RUNTIME_ACQUIRE_ERR()wrapper macros to make the code look more straightforward.No intentional funtional impact.
Same here ...
Quoted 26 lines
Signed-off-by Rafael J. Wysocki <[email protected]>---
v1 -> v2: Adjust to the changes in patch [1/3].
--- drivers/pci/pci-sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/pci-sysfs.c +2
-2@@ -1517,8 +1517,8 @@ static ssize_t reset_method_store(structreturn count; } -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ;if (sysfs_streq (buf,"default" )) {
Signature · 3 lines
Best regards, Dhruva Gole Texas Instruments Incorporated
Rafael J. Wysocki
maintainerRe: [PATCH v2 3/3] PCI/sysfs: Use PM_RUNTIME_ACQUIRE()/PM_RUNTIME_ACQUIRE_ERR()
Quoted 10 lines · Dhruva Gole
Quoted 6 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Use new
PM_RUNTIME_ACQUIRE()andPM_RUNTIME_ACQUIRE_ERR()wrapper macros to make the code look more straightforward.No intentional funtional impact.
Same here ...
Yup, will fix.
Quoted 1 line
Reviewed-by Dhruva Gole <[email protected]>
Thanks!
Bjorn & PCI people, if there are any concerns regarding the change below, please let me know.
Quoted 28 lines
Quoted 16 lines
Signed-off-by Rafael J. Wysocki <[email protected]>---
v1 -> v2: Adjust to the changes in patch [1/3].
--- drivers/pci/pci-sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/pci-sysfs.c static ssize_t reset_method_store(struct · line 1524
Quoted 10 lines
drivers/pci/pci-sysfs.c +2
-2@@ -1517,8 +1517,8 @@ static ssize_t reset_method_store(structreturn count; } -ACQUIRE (pm_runtime_active_try, pm)(dev); -if (ACQUIRE_ERR (pm_runtime_active_try, &pm)) +PM_RUNTIME_ACQUIRE (dev, pm); +if (PM_RUNTIME_ACQUIRE_ERR (&pm))return -ENXIO ;if (sysfs_streq (buf,"default" )) {--
Quoted 6 lines · On Thu, 13 Nov 2025 20:24:57 +0100 "Rafael J. Wysocki" <[email protected]>…
Hi All,
This supersedes
Quoted 8 lines
as discussed here:
https://lore.kernel.org/linux-pm/[email protected]/
It adds runtime PM wrapper macros around
ACQUIRE()andACQUIRE_ERR()involving the guards added recently (patch [1/3]) and then updates the code already using those guards (patches [2/3] and [3/3]) to make it look more straightforward.
for whole series.
Rafael J. Wysocki
maintainerQuoted 12 lines · Jonathan Cameron
Quoted 8 lines · On Thu, 13 Nov 2025 20:24:57 +0100 "Rafael J. Wysocki" <[email protected]>…
Hi All,
This supersedes
https://lore.kernel.org/linux-pm/[email protected]/
as discussed here:
Quoted 8 lines
Quoted 6 lines
https://lore.kernel.org/linux-pm/[email protected]/
It adds runtime PM wrapper macros around
ACQUIRE()andACQUIRE_ERR()involving the guards added recently (patch [1/3]) and then updates the code already using those guards (patches [2/3] and [3/3]) to make it look more straightforward.Reviewed-by Jonathan Cameron <[email protected]>for whole series.
Thank you!