PM / Sleep: Remove pm_runtime_suspended() from __pm_generic_call()
Subsystems (4)
PATCH 1/1 PM / Sleep: Remove pm_runtime_suspended() from __pm_generic_call()
From: Rafael J. Wysocki <[email protected]>
The pm_runtime_suspended() check in __pm_generic_call() doesn't really help and may cause problems to happen, because in some cases the system suspend callbacks need to be called even if the given device has been suspended by runtime PM. For example, if the device generally supports remote wakeup and is not enabled to wake up the system from sleep, it should be prevented from generating wakeup signals during system suspend and that has to be done by the suspend callbacks that the pm_runtime_suspended() check prevents from being executed. For this reason, remove the pm_runtime_suspended() check from __pm_generic_call().
--- drivers/base/power/generic_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/power/generic_ops.c +1 -1
@@ -106,7 +106,7 @@ static int __pm_generic_call(struct deviconst struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ;int (*callback)(struct device *); -if (!pm ||pm_runtime_suspended (dev)) +if (!pm)return 0 ;switch (event) {
PATCH 1/1 PM / Sleep: Simplify generic system suspend callbacks
From: Rafael J. Wysocki <[email protected]>
The pm_runtime_suspended() check in __pm_generic_call() doesn't really help and may cause problems to happen, because in some cases the system suspend callbacks need to be called even if the given device has been suspended by runtime PM. For example, if the device generally supports remote wakeup and is not enabled to wake up the system from sleep, it should be prevented from generating wakeup signals during system suspend and that has to be done by the suspend callbacks that the pm_runtime_suspended() check prevents from being executed.
Similarly, it may not be a good idea to unconditionally change the runtime PM status of the device to 'active' in __pm_generic_resume(), because the driver may want to leave the device in the 'suspended' state, depending on what happened to it before the system suspend and whether or not it is enabled to wake up the system.
For the above reasons, remove the pm_runtime_suspended() check from __pm_generic_call() and remove the code changing the device's runtime PM status from __pm_generic_resume().
--- drivers/base/power/generic_ops.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/base/power/generic_ops.c +2 -13
@@ -106,7 +106,7 @@ static int __pm_generic_call(struct deviconst struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ;int (*callback)(struct device *); -if (!pm ||pm_runtime_suspended (dev)) +if (!pm)return 0 ;switch (event) {
@@ -224,7 +224,6 @@ static int __pm_generic_resume(struct de {const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ;int (*callback)(struct device *); -int ret;if (!pm)return 0 ;
@@ -241,17 +240,7 @@ static int __pm_generic_resume(struct debreak ; } -if (!callback) -return 0 ; - - ret =callback (dev); -if (!ret && !noirq &&pm_runtime_enabled (dev)) { -pm_runtime_disable (dev); -pm_runtime_set_active (dev); -pm_runtime_enable (dev); - } - -return ret; +return callback ?callback (dev) :0 ; }/**
Re: [PATCH] PM / Sleep: Simplify generic system suspend callbacks
Quoted 19 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The
pm_runtime_suspended()check in__pm_generic_call()doesn't really help and may cause problems to happen, because in some cases the system suspend callbacks need to be called even if the given device has been suspended by runtime PM. For example, if the device generally supports remote wakeup and is not enabled to wake up the system from sleep, it should be prevented from generating wakeup signals during system suspend and that has to be done by the suspend callbacks that thepm_runtime_suspended()check prevents from being executed.Similarly, it may not be a good idea to unconditionally change the runtime PM status of the device to 'active' in
__pm_generic_resume(), because the driver may want to leave the device in the 'suspended' state, depending on what happened to it before the system suspend and whether or not it is enabled to wake up the system.
Quoted 5 lines
For the above reasons, remove the
pm_runtime_suspended()check from__pm_generic_call()and remove the code changing the device's runtime PM status from__pm_generic_resume().Signed-off-by Rafael J. Wysocki <[email protected]>
Well, I'm not seeing any objections, so I gather so this change is fine by everyone. I'm going to put it into linux-pm/linux-next, then.
Thanks,
Rafael
Quoted 51 lines
--- drivers/base/power/generic_ops.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)Index:
linux/drivers/base/power/generic_ops.c
===================================================================drivers/base/power/generic_ops.c +2
-14@@ -106,7 +106,7 @@ static int __pm_generic_call(struct deviconst struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ;int (*callback)(struct device *); -if (!pm ||pm_runtime_suspended (dev)) +if (!pm)return 0 ;switch (event) {@@ -224,7 +224,6 @@ static int __pm_generic_resume(struct de {const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ;int (*callback)(struct device *); -int ret;if (!pm)return 0 ;@@ -241,17 +240,7 @@ static int __pm_generic_resume(struct debreak ; } -if (!callback) -return 0 ; - - ret =callback (dev); -if (!ret && !noirq &&pm_runtime_enabled (dev)) { -pm_runtime_disable (dev); -pm_runtime_set_active (dev); -pm_runtime_enable (dev); - } - -return ret; +return callback ?callback (dev) :0 ; }/** -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
v2 cover PM / Sleep: Simplify generic system suspend callbacks
Hi Everyone,
One more udate here.
I forgot about the comments in this patch:
Quoted 20 lines · Rafael J. Wysocki
Quoted 19 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
The
pm_runtime_suspended()check in__pm_generic_call()doesn't really help and may cause problems to happen, because in some cases the system suspend callbacks need to be called even if the given device has been suspended by runtime PM. For example, if the device generally supports remote wakeup and is not enabled to wake up the system from sleep, it should be prevented from generating wakeup signals during system suspend and that has to be done by the suspend callbacks that thepm_runtime_suspended()check prevents from being executed.Similarly, it may not be a good idea to unconditionally change the runtime PM status of the device to 'active' in
__pm_generic_resume(), because the driver may want to leave the device in the 'suspended' state, depending on what happened to it before the system suspend and whether or not it is enabled to wake up the system.
Quoted 5 lines
Quoted 5 lines
For the above reasons, remove the
pm_runtime_suspended()check from__pm_generic_call()and remove the code changing the device's runtime PM status from__pm_generic_resume().Signed-off-by Rafael J. Wysocki <[email protected]>
so the updated one becomes [1/2] in the new series.
In addition to that I noticed that __pm_generic_call() and __pm_generic_resume() may be merged after [1/2], which is done by [2/2].
I regard these patches as 3.3 material, if there are no objections.
Thanks,
Rafael
PATCH v2 1/2 PM / Sleep: Simplify generic system suspend callbacks
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Simplify generic system suspend callbacks
The pm_runtime_suspended() check in __pm_generic_call() doesn't really help and may cause problems to happen, because in some cases the system suspend callbacks need to be called even if the given device has been suspended by runtime PM. For example, if the device generally supports remote wakeup and is not enabled to wake up the system from sleep, it should be prevented from generating wakeup signals during system suspend and that has to be done by the suspend callbacks that the pm_runtime_suspended() check prevents from being executed.
Similarly, it may not be a good idea to unconditionally change the runtime PM status of the device to 'active' in __pm_generic_resume(), because the driver may want to leave the device in the 'suspended' state, depending on what happened to it before the system suspend and whether or not it is enabled to wake up the system.
For the above reasons, remove the pm_runtime_suspended() check from __pm_generic_call() and remove the code changing the device's runtime PM status from __pm_generic_resume().
--- drivers/base/power/generic_ops.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-)
drivers/base/power/generic_ops.c +6 -18
@@ -97,16 +97,16 @@ int pm_generic_prepare(struct device *de* @event: PM transition of the system under way. * @bool: Whether or not this is the "noirq" stage. * -* If the device has not been suspended at run time, execute the -* suspend/freeze/poweroff/thaw callback provided by its driver, if defined, and -* return its error code. Otherwise, return zero. +* Execute the suspend/freeze/poweroff/thaw callback provided by the driver of +* @dev, if defined, and return its error code. Return 0 if the callback is +* not present. */ static int __pm_generic_call (struct device *dev,int event,bool noirq) {const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ;int (*callback)(struct device *); -if (!pm ||pm_runtime_suspended (dev)) +if (!pm)return 0 ;switch (event) {
@@ -217,14 +217,12 @@ EXPORT_SYMBOL_GPL(pm_generic_thaw);* @bool: Whether or not this is the "noirq" stage. * * Execute the resume/resotre callback provided by the @dev's driver, if -* defined. If it returns 0, change the device's runtime PM status to 'active'. -* Return the callback's error code. +* defined, and return its error code. Return 0 if the callback is not present. */ static int __pm_generic_resume (struct device *dev,int event,bool noirq) {const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ;int (*callback)(struct device *); -int ret;if (!pm)return 0 ;
@@ -241,17 +239,7 @@ static int __pm_generic_resume(struct debreak ; } -if (!callback) -return 0 ; - - ret =callback (dev); -if (!ret && !noirq &&pm_runtime_enabled (dev)) { -pm_runtime_disable (dev); -pm_runtime_set_active (dev); -pm_runtime_enable (dev); - } - -return ret; +return callback ?callback (dev) :0 ; }/**
PATCH v2 2/2 PM / Sleep: Merge internal functions in generic_ops.c
In reply to Rafael J. WysockiFrom: Rafael J. Wysocki <[email protected]>
After the change that removed the code related to runtime PM from __pm_generic_call() and __pm_generic_resume() these two functions need not be separate any more, so merge them.
--- drivers/base/power/generic_ops.c | 48 ++++++++------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-)
drivers/base/power/generic_ops.c +11 -37
@@ -97,7 +97,7 @@ int pm_generic_prepare(struct device *de* @event: PM transition of the system under way. * @bool: Whether or not this is the "noirq" stage. * -* Execute the suspend/freeze/poweroff/thaw callback provided by the driver of +* Execute the PM callback corresponding to @event provided by the driver of * @dev, if defined, and return its error code. Return 0 if the callback is * not present. */
@@ -119,9 +119,15 @@ static int __pm_generic_call(struct devicase PM_EVENT_HIBERNATE : callback = noirq ? pm->poweroff_noirq : pm->poweroff;break ; +case PM_EVENT_RESUME : + callback = noirq ? pm->resume_noirq : pm->resume; +break ;case PM_EVENT_THAW : callback = noirq ? pm->thaw_noirq : pm->thaw;break ; +case PM_EVENT_RESTORE : + callback = noirq ? pm->restore_noirq : pm->restore; +break ;default : callback =NULL ;break ;
@@ -211,44 +217,12 @@ int pm_generic_thaw(struct device *dev)EXPORT_SYMBOL_GPL (pm_generic_thaw);/** -* __pm_generic_resume - Generic resume/restore callback for subsystems. -* @dev: Device to handle. -* @event: PM transition of the system under way. -* @bool: Whether or not this is the "noirq" stage. -* -* Execute the resume/resotre callback provided by the @dev's driver, if -* defined, and return its error code. Return 0 if the callback is not present. -*/ -static int __pm_generic_resume (struct device *dev,int event,bool noirq) -{ -const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; -int (*callback)(struct device *); - -if (!pm) -return 0 ; - -switch (event) { -case PM_EVENT_RESUME : - callback = noirq ? pm->resume_noirq : pm->resume; -break ; -case PM_EVENT_RESTORE : - callback = noirq ? pm->restore_noirq : pm->restore; -break ; -default : - callback =NULL ; -break ; - } - -return callback ?callback (dev) :0 ; -} - -/** * pm_generic_resume_noirq - Generic resume_noirq callback for subsystems. * @dev: Device to resume. */ int pm_generic_resume_noirq (struct device *dev) { -return __pm_generic_resume (dev,PM_EVENT_RESUME , true); +return __pm_generic_call (dev,PM_EVENT_RESUME , true); }EXPORT_SYMBOL_GPL (pm_generic_resume_noirq);
@@ -258,7 +232,7 @@ EXPORT_SYMBOL_GPL(pm_generic_resume_noir*/ int pm_generic_resume (struct device *dev) { -return __pm_generic_resume (dev,PM_EVENT_RESUME , false); +return __pm_generic_call (dev,PM_EVENT_RESUME , false); }EXPORT_SYMBOL_GPL (pm_generic_resume);
@@ -268,7 +242,7 @@ EXPORT_SYMBOL_GPL(pm_generic_resume);*/ int pm_generic_restore_noirq (struct device *dev) { -return __pm_generic_resume (dev,PM_EVENT_RESTORE , true); +return __pm_generic_call (dev,PM_EVENT_RESTORE , true); }EXPORT_SYMBOL_GPL (pm_generic_restore_noirq);
@@ -278,7 +252,7 @@ EXPORT_SYMBOL_GPL(pm_generic_restore_noi*/ int pm_generic_restore (struct device *dev) { -return __pm_generic_resume (dev,PM_EVENT_RESTORE , false); +return __pm_generic_call (dev,PM_EVENT_RESTORE , false); }EXPORT_SYMBOL_GPL (pm_generic_restore);