sysdev suspend/resume
Hi,
The return value of sysdev's suspend/resume methods is ignored, is this intended (it should not fail?) or just a bug? I'd like to abort the suspend process if one device fails.
Thanks,
Shaohua
Hi!
Quoted 3 lines
The return value of sysdev's suspend/resume methods is ignored, is this intended (it should not fail?) or just a bug? I'd like to abort the suspend process if one device fails.
I guess patch would be accepted... but please make sure you test those error paths, and printk name of failing driver.
Hmmm, I wonder how you are going to handle resume failure? AFAICS, there's no sane way to handle that.
Signature · 1 line
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms
Quoted 8 lines · Pavel Machek
Hi!
Quoted 3 lines
The return value of sysdev's suspend/resume methods is ignored, is this intended (it should not fail?) or just a bug? I'd like to abort the suspend process if one device fails.
I guess patch would be accepted... but please make sure you test those error paths, and printk name of failing driver.
It's a challenge to me, so many loops :). Below patch is a little ugly, but should cover all error paths.
Quoted 2 lines
Hmmm, I wonder how you are going to handle resume failure? AFAICS, there's no sane way to handle that.
We can't refuse to resume :).
Thanks,
Shaohua
---
linux-2.6.13-rc3-root/drivers/base/sys.c | 104 +++++++++++++++++++++++-------- 1 files changed, 80 insertions(+), 24 deletions(-)
drivers/base/sys.c renamed from drivers/base/sys.c~sysdev +80 -24
@@ -288,6 +288,22 @@ void sysdev_shutdown(void)up (&sysdev_drivers_lock); } +#define SYSDEV_RESUME (cls, dev, drv) \ +/* First, call the class-specific one */ \ + if (cls->resume) \ + cls->resume(dev); \ + \ +/* Call auxillary drivers next. */ \ + list_for_each_entry(drv, &cls->drivers, entry) {\ +if (drv->resume) \ + drv->resume (dev); \ + } \ + \ +/* Call global drivers. */ \ + list_for_each_entry(drv, &sysdev_drivers, entry) {\ +if (drv->resume) \ + drv->resume (dev); \ + }/** * sysdev_suspend - Suspend all system devices.
@@ -305,38 +321,93 @@ void sysdev_shutdown(void)int sysdev_suspend (pm_message_t state) {struct sysdev_class * cls; +struct sys_device *sysdev, *err_dev; +struct sysdev_driver *drv, *err_drv; +int ret;pr_debug ("Suspending System Devices\n" );list_for_each_entry_reverse (cls, &system_subsys.kset.list, kset.kobj.entry) { -struct sys_device * sysdev;pr_debug ("Suspending type '%s':\n" ,kobject_name (&cls->kset.kobj));list_for_each_entry (sysdev, &cls->kset.list, kobj.entry) { -struct sysdev_driver * drv;pr_debug (" %s\n" ,kobject_name (&sysdev->kobj));/* Call global drivers first. */ list_for_each_entry (drv, &sysdev_drivers, entry) { -if (drv->suspend) - drv->suspend (sysdev, state); +if (drv->suspend) { + ret = drv->suspend (sysdev, state); +if (ret) + goto gbl_driver; + } }/* Call auxillary drivers next. */ list_for_each_entry (drv, &cls->drivers, entry) { -if (drv->suspend) - drv->suspend (sysdev, state); +if (drv->suspend) { + ret = drv->suspend (sysdev, state); +if (ret) + goto aux_driver; + } }/* Now call the generic one */ -if (cls->suspend) - cls->suspend (sysdev, state); +if (cls->suspend) { + ret = cls->suspend (sysdev, state); +if (ret) + goto cls_driver; + } } }return 0 ; +/* resume current sysdev */ +cls_driver: + drv =NULL ; +printk (KERN_ERR "Clss suspend failed for %s\n" , +kobject_name (&sysdev->kobj)); + +aux_driver: +if (drv) +printk (KERN_ERR "Class driver suspend failed for %s\n" , +kobject_name (&sysdev->kobj)); +list_for_each_entry (err_drv, &cls->drivers, entry) { +if (err_drv == drv) +break ; +if (err_drv->resume) + err_drv->resume (sysdev); + } + drv =NULL ; + +gbl_driver: +if (drv) +printk (KERN_ERR "sysdev driver suspend failed for %s\n" , +kobject_name (&sysdev->kobj)); +list_for_each_entry (err_drv, &sysdev_drivers, entry) { +if (err_drv == drv) +break ; +if (err_drv->resume) + err_drv->resume (sysdev); + } +/* resume other sysdevs in current class */ +list_for_each_entry (err_dev, &cls->kset.list, kobj.entry) { +if (err_dev == sysdev) +break ; +pr_debug (" %s\n" ,kobject_name (&err_dev->kobj)); +SYSDEV_RESUME (cls, err_dev, err_drv); + } + +/* resume other classes */ +list_for_each_entry_continue (cls, &system_subsys.kset.list, + kset.kobj.entry) { +list_for_each_entry (err_dev, &cls->kset.list, kobj.entry) { +pr_debug (" %s\n" ,kobject_name (&err_dev->kobj)); +SYSDEV_RESUME (cls, err_dev, err_drv); + } + } +return ret; }
@@ -365,22 +436,7 @@ int sysdev_resume(void)struct sysdev_driver * drv;pr_debug (" %s\n" ,kobject_name (&sysdev->kobj)); -/* First, call the class-specific one */ -if (cls->resume) - cls->resume (sysdev); - -/* Call auxillary drivers next. */ -list_for_each_entry (drv, &cls->drivers, entry) { -if (drv->resume) - drv->resume (sysdev); - } - -/* Call global drivers. */ -list_for_each_entry (drv, &sysdev_drivers, entry) { -if (drv->resume) - drv->resume (sysdev); - } - +SYSDEV_RESUME (cls, sysdev, drv); } }return 0 ;
_
Hi!
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
The return value of sysdev's suspend/resume methods is ignored, is this intended (it should not fail?) or just a bug? I'd like to abort the suspend process if one device fails.
I guess patch would be accepted... but please make sure you test those error paths, and printk name of failing driver.
It's a challenge to me, so many loops :). Below patch is a little ugly, but should cover all error paths.
It is indeed quite ugly. Could we get SYSDEV_RESUME inline function instead of ugly macro?
Quoted 13 lines
diff -puN
drivers/base/sys.c~sysdevdrivers/base/sys.cdrivers/base/sys.c renamed from drivers/base/sys.c~sysdev +6
-0@@ -288,6 +288,22 @@ void sysdev_shutdown(void)up (&sysdev_drivers_lock); } +#define SYSDEV_RESUME (cls, dev, drv) \ +/* First, call the class-specific one */ \ + if (cls->resume) \ + cls->resume(dev); \ + \ +/* Call auxillary drivers next. */ \
drivers/base/sys.c void sysdev_shutdown(void) · line 306
Quoted 10 lines
drivers/base/sys.c renamed from drivers/base/sys.c~sysdev +10
-0+ list_for_each_entry(drv, &cls->drivers, entry) {\ +if (drv->resume) \ + drv->resume (dev); \ + } \ + \ +/* Call global drivers. */ \ + list_for_each_entry(drv, &sysdev_drivers, entry) {\ +if (drv->resume) \ + drv->resume (dev); \ + }
Are you sure you are resuming already-resumed devices?
drivers/base/sys.c void sysdev_shutdown(void) · line 326
Quoted 9 lines
drivers/base/sys.c renamed from drivers/base/sys.c~sysdev +3
-0/** * sysdev_suspend - Suspend all system devices. @@ -305,38 +321,93 @@ void sysdev_shutdown(void)int sysdev_suspend (pm_message_t state) {struct sysdev_class * cls; +struct sys_device *sysdev, *err_dev; +struct sysdev_driver *drv, *err_drv; +int ret;
~~~~~~~~~~~~ use space not tab here. I see you got that habit from ACPI,
but it is just wrong.
drivers/base/sys.c void sysdev_shutdown(void) · line 369
Quoted 3 lines
drivers/base/sys.c renamed from drivers/base/sys.c~sysdev +3
-0+cls_driver: + drv =NULL ; + printk(KERN_ERR "Clss suspend failed for %s\n",
~~~~
Mssng vwls.
Pavel
Signature · 1 line
teflon -- maybe it is a trademark, but it should not be.
Hi,
Quoted 11 lines · Pavel Machek
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
The return value of sysdev's suspend/resume methods is ignored, is this intended (it should not fail?) or just a bug? I'd like to abort the suspend process if one device fails.
I guess patch would be accepted... but please make sure you test those error paths, and printk name of failing driver.
It's a challenge to me, so many loops :). Below patch is a little ugly, but should cover all error paths.
It is indeed quite ugly. Could we get
SYSDEV_RESUMEinline function instead of ugly macro?
It make senses. Thanks for your comments.
Quoted 18 lines
Quoted 18 lines
diff -puN
drivers/base/sys.c~sysdevdrivers/base/sys.cdrivers/base/sys.c renamed from drivers/base/sys.c~sysdev +10
-0@@ -288,6 +288,22 @@ void sysdev_shutdown(void)up (&sysdev_drivers_lock); } +#define SYSDEV_RESUME (cls, dev, drv) \ +/* First, call the class-specific one */ \ + if (cls->resume) \ + cls->resume(dev); \ + \ +/* Call auxillary drivers next. */ \ + list_for_each_entry(drv, &cls->drivers, entry) {\ +if (drv->resume) \ + drv->resume (dev); \ + } \
Quoted 8 lines
drivers/base/sys.c void sysdev_shutdown(void) · line 306
Quoted 6 lines
drivers/base/sys.c renamed from drivers/base/sys.c~sysdev +6
-0+ \ +/* Call global drivers. */ \ + list_for_each_entry(drv, &sysdev_drivers, entry) {\ +if (drv->resume) \ + drv->resume (dev); \ + }Are you sure you are resuming already-resumed devices?
What's your point? if sysdev_suspend failed, sysdev_resume isn't called, so it will not be resumed twice.
Thanks,
Shaohua
---
linux-2.6.13-rc3-root/drivers/base/sys.c | 107 ++++++++++++++++++++++++------- 1 files changed, 83 insertions(+), 24 deletions(-)
drivers/base/sys.c renamed from drivers/base/sys.c~sysdev +83 -24
@@ -288,6 +288,25 @@ void sysdev_shutdown(void)up (&sysdev_drivers_lock); } +static void inline do_sysdev_resume (struct sysdev_class *cls, +struct sys_device *dev,struct sysdev_driver *drv) +{ +/* First, call the class-specific one */ +if (cls->resume) + cls->resume (dev); + +/* Call auxillary drivers next. */ +list_for_each_entry (drv, &cls->drivers, entry) { +if (drv->resume) + drv->resume (dev); + } + +/* Call global drivers. */ +list_for_each_entry (drv, &sysdev_drivers, entry) { +if (drv->resume) + drv->resume (dev); + } +}/** * sysdev_suspend - Suspend all system devices.
@@ -305,38 +324,93 @@ void sysdev_shutdown(void)int sysdev_suspend (pm_message_t state) {struct sysdev_class * cls; +struct sys_device *sysdev, *err_dev; +struct sysdev_driver *drv, *err_drv; +int ret;pr_debug ("Suspending System Devices\n" );list_for_each_entry_reverse (cls, &system_subsys.kset.list, kset.kobj.entry) { -struct sys_device * sysdev;pr_debug ("Suspending type '%s':\n" ,kobject_name (&cls->kset.kobj));list_for_each_entry (sysdev, &cls->kset.list, kobj.entry) { -struct sysdev_driver * drv;pr_debug (" %s\n" ,kobject_name (&sysdev->kobj));/* Call global drivers first. */ list_for_each_entry (drv, &sysdev_drivers, entry) { -if (drv->suspend) - drv->suspend (sysdev, state); +if (drv->suspend) { + ret = drv->suspend (sysdev, state); +if (ret) + goto gbl_driver; + } }/* Call auxillary drivers next. */ list_for_each_entry (drv, &cls->drivers, entry) { -if (drv->suspend) - drv->suspend (sysdev, state); +if (drv->suspend) { + ret = drv->suspend (sysdev, state); +if (ret) + goto aux_driver; + } }/* Now call the generic one */ -if (cls->suspend) - cls->suspend (sysdev, state); +if (cls->suspend) { + ret = cls->suspend (sysdev, state); +if (ret) + goto cls_driver; + } } }return 0 ; +/* resume current sysdev */ +cls_driver: + drv =NULL ; +printk (KERN_ERR "Class suspend failed for %s\n" , +kobject_name (&sysdev->kobj)); + +aux_driver: +if (drv) +printk (KERN_ERR "Class driver suspend failed for %s\n" , +kobject_name (&sysdev->kobj)); +list_for_each_entry (err_drv, &cls->drivers, entry) { +if (err_drv == drv) +break ; +if (err_drv->resume) + err_drv->resume (sysdev); + } + drv =NULL ; + +gbl_driver: +if (drv) +printk (KERN_ERR "sysdev driver suspend failed for %s\n" , +kobject_name (&sysdev->kobj)); +list_for_each_entry (err_drv, &sysdev_drivers, entry) { +if (err_drv == drv) +break ; +if (err_drv->resume) + err_drv->resume (sysdev); + } +/* resume other sysdevs in current class */ +list_for_each_entry (err_dev, &cls->kset.list, kobj.entry) { +if (err_dev == sysdev) +break ; +pr_debug (" %s\n" ,kobject_name (&err_dev->kobj)); +do_sysdev_resume (cls, err_dev, err_drv); + } + +/* resume other classes */ +list_for_each_entry_continue (cls, &system_subsys.kset.list, + kset.kobj.entry) { +list_for_each_entry (err_dev, &cls->kset.list, kobj.entry) { +pr_debug (" %s\n" ,kobject_name (&err_dev->kobj)); +do_sysdev_resume (cls, err_dev, err_drv); + } + } +return ret; }
@@ -365,22 +439,7 @@ int sysdev_resume(void)struct sysdev_driver * drv;pr_debug (" %s\n" ,kobject_name (&sysdev->kobj)); -/* First, call the class-specific one */ -if (cls->resume) - cls->resume (sysdev); - -/* Call auxillary drivers next. */ -list_for_each_entry (drv, &cls->drivers, entry) { -if (drv->resume) - drv->resume (sysdev); - } - -/* Call global drivers. */ -list_for_each_entry (drv, &sysdev_drivers, entry) { -if (drv->resume) - drv->resume (sysdev); - } - +do_sysdev_resume (cls, sysdev, drv); } }return 0 ;
_
Hi!
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
(quoted diff) +10
-0+#define SYSDEV_RESUME(cls, dev, drv) \ + /* First, call the class-specific one */ \ + if (cls->resume) \ + cls->resume(dev); \ + \ + /* Call auxillary drivers next. */ \ + list_for_each_entry(drv, &cls->drivers, entry) {\ + if (drv->resume) \ + drv->resume(dev); \ + } \Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ \ + /* Call global drivers. */ \ + list_for_each_entry(drv, &sysdev_drivers, entry) {\ + if (drv->resume) \ + drv->resume(dev); \ + }Are you sure you are resuming already-resumed devices?
Quoted 2 lines
What's your point? if
sysdev_suspendfailed,sysdev_resumeisn't called, so it will not be resumed twice.
Probably nothing then, sorry for noise.
Pavel
Signature · 1 line
teflon -- maybe it is a trademark, but it should not be.
On Wed, 27 Jul 2005, Shaohua Li wrote:
The patch looks Ok, except for this function.
drivers/base/sys.c void sysdev_shutdown(void) · line 293
Quoted 10 lines
diff -puN
drivers/base/sys.c~sysdevdrivers/base/sys.cdrivers/base/sys.c renamed from drivers/base/sys.c~sysdev +3
-0@@ -288,6 +288,25 @@ void sysdev_shutdown(void)up (&sysdev_drivers_lock); } +static void inline do_sysdev_resume (struct sysdev_class *cls, +struct sys_device *dev,struct sysdev_driver *drv) +{
* It does not need to be inlined.
* Internal helpers are prefix'd with "__" instead of "do_", so this would be '__sysdev_resume()'.
* drv is a temporary variable
* cls can be ascertained from the sys_device
So, the first few lines should be
static void __sysdev_resume(struct sys_device * dev)
{
struct sysdev_class * cls = dev->cls;
struct sysdev_driver * dev;
...Thanks,
Pat
One small correction that one eagle-eyed participant noticed:
Quoted 6 lines · Patrick Mochel
So, the first few lines should be
static void
__sysdev_resume(struct sys_device * dev){ struct sysdev_class * cls = dev->cls; struct sysdev_driver * dev;
That should be:
struct sysdev_driver * drv;
Thanks,
Pat
Hi,
Quoted 15 lines · Patrick Mochel
Review
Quoted 3 lines
(quoted diff) +3
-0+static void inline do_sysdev_resume(struct sysdev_class *cls, + struct sys_device *dev, struct sysdev_driver *drv) +{* It does not need to be inlined.
* Internal helpers are prefix'd with "__" instead of "
do_", so this would be '__sysdev_resume()'.* drv is a temporary variable
* cls can be ascertained from the
sys_device
Quoted 7 lines
So, the first few lines should be
static void
__sysdev_resume(struct sys_device * dev){ struct sysdev_class * cls = dev->cls; struct sysdev_driver * dev; ...
Thanks. A updated one.
---
linux-2.6.13-rc3-root/drivers/base/sys.c | 110 +++++++++++++++++++++++-------- 1 files changed, 85 insertions(+), 25 deletions(-)
drivers/base/sys.c renamed from drivers/base/sys.c~sysdev +85 -25
@@ -288,6 +288,27 @@ void sysdev_shutdown(void)up (&sysdev_drivers_lock); } +static void __sysdev_resume (struct sys_device *dev) +{ +struct sysdev_class *cls = dev->cls; +struct sysdev_driver *drv; + +/* First, call the class-specific one */ +if (cls->resume) + cls->resume (dev); + +/* Call auxillary drivers next. */ +list_for_each_entry (drv, &cls->drivers, entry) { +if (drv->resume) + drv->resume (dev); + } + +/* Call global drivers. */ +list_for_each_entry (drv, &sysdev_drivers, entry) { +if (drv->resume) + drv->resume (dev); + } +}/** * sysdev_suspend - Suspend all system devices.
@@ -305,38 +326,93 @@ void sysdev_shutdown(void)int sysdev_suspend (pm_message_t state) {struct sysdev_class * cls; +struct sys_device *sysdev, *err_dev; +struct sysdev_driver *drv, *err_drv; +int ret;pr_debug ("Suspending System Devices\n" );list_for_each_entry_reverse (cls, &system_subsys.kset.list, kset.kobj.entry) { -struct sys_device * sysdev;pr_debug ("Suspending type '%s':\n" ,kobject_name (&cls->kset.kobj));list_for_each_entry (sysdev, &cls->kset.list, kobj.entry) { -struct sysdev_driver * drv;pr_debug (" %s\n" ,kobject_name (&sysdev->kobj));/* Call global drivers first. */ list_for_each_entry (drv, &sysdev_drivers, entry) { -if (drv->suspend) - drv->suspend (sysdev, state); +if (drv->suspend) { + ret = drv->suspend (sysdev, state); +if (ret) + goto gbl_driver; + } }/* Call auxillary drivers next. */ list_for_each_entry (drv, &cls->drivers, entry) { -if (drv->suspend) - drv->suspend (sysdev, state); +if (drv->suspend) { + ret = drv->suspend (sysdev, state); +if (ret) + goto aux_driver; + } }/* Now call the generic one */ -if (cls->suspend) - cls->suspend (sysdev, state); +if (cls->suspend) { + ret = cls->suspend (sysdev, state); +if (ret) + goto cls_driver; + } } }return 0 ; +/* resume current sysdev */ +cls_driver: + drv =NULL ; +printk (KERN_ERR "Class suspend failed for %s\n" , +kobject_name (&sysdev->kobj)); + +aux_driver: +if (drv) +printk (KERN_ERR "Class driver suspend failed for %s\n" , +kobject_name (&sysdev->kobj)); +list_for_each_entry (err_drv, &cls->drivers, entry) { +if (err_drv == drv) +break ; +if (err_drv->resume) + err_drv->resume (sysdev); + } + drv =NULL ; + +gbl_driver: +if (drv) +printk (KERN_ERR "sysdev driver suspend failed for %s\n" , +kobject_name (&sysdev->kobj)); +list_for_each_entry (err_drv, &sysdev_drivers, entry) { +if (err_drv == drv) +break ; +if (err_drv->resume) + err_drv->resume (sysdev); + } +/* resume other sysdevs in current class */ +list_for_each_entry (err_dev, &cls->kset.list, kobj.entry) { +if (err_dev == sysdev) +break ; +pr_debug (" %s\n" ,kobject_name (&err_dev->kobj)); +__sysdev_resume (err_dev); + } + +/* resume other classes */ +list_for_each_entry_continue (cls, &system_subsys.kset.list, + kset.kobj.entry) { +list_for_each_entry (err_dev, &cls->kset.list, kobj.entry) { +pr_debug (" %s\n" ,kobject_name (&err_dev->kobj)); +__sysdev_resume (err_dev); + } + } +return ret; }
@@ -362,25 +438,9 @@ int sysdev_resume(void) kobject_name(&cls->kset.kobj));list_for_each_entry (sysdev, &cls->kset.list, kobj.entry) { -struct sysdev_driver * drv;pr_debug (" %s\n" ,kobject_name (&sysdev->kobj)); -/* First, call the class-specific one */ -if (cls->resume) - cls->resume (sysdev); - -/* Call auxillary drivers next. */ -list_for_each_entry (drv, &cls->drivers, entry) { -if (drv->resume) - drv->resume (sysdev); - } - -/* Call global drivers. */ -list_for_each_entry (drv, &sysdev_drivers, entry) { -if (drv->resume) - drv->resume (sysdev); - } - +__sysdev_resume (sysdev); } }return 0 ;
_