Android PM fixes
Subsystems (2)
cover Android PM fixes
These patches fixes some bugs where we occasionally got stuck entering or leaving suspend.
--
Arve Hjønnevåg
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 1/2 PM: Wait for console in resume.
Avoids later waking up to a blinking cursor if the device woke up and returned to sleep before the console switch happened.
--- kernel/power/console.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
kernel/power/console.c +6 -0
@@ -78,6 +78,12 @@ void pm_restore_console(void) }set_console (orig_fgconsole);release_console_sem (); + +if (vt_waitactive (orig_fgconsole)) { +pr_debug ("Resume: Can't switch VCs." ); +return ; + } + kmsg_redirect = orig_kmsg; }#endif
Signature · 6 lines
1.6.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 2/2 PM: Fix suspend_console/resume_console to use only one semaphore.
This fixes a race if another thread acquired the console while it was suspended and released it after it was resumed the secondary console semaphre would be left locked, and the primary semaphore would be released twice. This in turn caused the console switch on suspend or resume to hang forever.
Note that suspend_console does not actually lock the console for clients that use acquire_console_sem, it only locks it for clients that use try_acquire_console_sem. If we change suspend_console to fully lock the console, then the kernel may deadlock on suspend.
--- kernel/printk.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
kernel/printk.c +9 -6
@@ -73,7 +73,6 @@ EXPORT_SYMBOL(oops_in_progress);* driver system. */ static DECLARE_MUTEX (console_sem); -static DECLARE_MUTEX (secondary_console_sem);struct console *console_drivers;EXPORT_SYMBOL_GPL (console_drivers);
@@ -896,12 +895,14 @@ void suspend_console(void)printk ("Suspending console(s) (use no_console_suspend to debug)\n" );acquire_console_sem (); console_suspended =1 ; +up (&console_sem); }void resume_console (void ) {if (!console_suspend_enabled)return ; +down (&console_sem); console_suspended =0 ;release_console_sem (); }
@@ -917,11 +918,9 @@ void resume_console(void)void acquire_console_sem (void ) {BUG_ON (in_interrupt ()); -if (console_suspended) { -down (&secondary_console_sem); -return ; - }down (&console_sem); +if (console_suspended) +return ; console_locked =1 ; console_may_schedule =1 ; }
@@ -931,6 +930,10 @@ int try_acquire_console_sem(void) {if (down_trylock (&console_sem))return -1 ; +if (console_suspended) { +up (&console_sem); +return -1 ; + } console_locked =1 ; console_may_schedule =0 ;return 0 ;
@@ -984,7 +987,7 @@ void release_console_sem(void)unsigned wake_klogd =0 ;if (console_suspended) { -up (&secondary_console_sem); +up (&console_sem);return ; }
Signature · 6 lines
1.6.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [PATCH 2/2] PM: Fix suspend_console/resume_console to use only one semaphore.
Quoted 6 lines · Arve Hj??nnev??g
This fixes a race if another thread acquired the console while it was suspended and released it after it was resumed the secondary console semaphre would be left locked, and the primary semaphore would be released twice. This in turn caused the console switch on suspend or resume to hang forever.
Quoted 7 lines
Note that
suspend_consoledoes not actually lock the console for clients that useacquire_console_sem, it only locks it for clients that usetry_acquire_console_sem. If we changesuspend_consoleto fully lock the console, then the kernel may deadlock on suspend.Signed-off-by Arve Hj??nnev??g <[email protected]>
This probably needs to go to lkml for proper review. Getting rid of secondary_console_sem would be nice cleanup in itself...
Quoted 65 lines
--- kernel/printk.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)kernel/printk.c +9
-6@@ -73,7 +73,6 @@ EXPORT_SYMBOL(oops_in_progress);* driver system. */ static DECLARE_MUTEX (console_sem); -static DECLARE_MUTEX (secondary_console_sem);struct console *console_drivers;EXPORT_SYMBOL_GPL (console_drivers);@@ -896,12 +895,14 @@ void suspend_console(void)printk ("Suspending console(s) (use no_console_suspend to debug)\n" );acquire_console_sem (); console_suspended =1 ; +up (&console_sem); }void resume_console (void ) {if (!console_suspend_enabled)return ; +down (&console_sem); console_suspended =0 ;release_console_sem (); }@@ -917,11 +918,9 @@ void resume_console(void)void acquire_console_sem (void ) {BUG_ON (in_interrupt ()); -if (console_suspended) { -down (&secondary_console_sem); -return ; - }down (&console_sem); +if (console_suspended) +return ; console_locked =1 ; console_may_schedule =1 ; }@@ -931,6 +930,10 @@ int try_acquire_console_sem(void) {if (down_trylock (&console_sem))return -1 ; +if (console_suspended) { +up (&console_sem); +return -1 ; + } console_locked =1 ; console_may_schedule =0 ;return 0 ;@@ -984,7 +987,7 @@ void release_console_sem(void)unsigned wake_klogd =0 ;if (console_suspended) { -up (&secondary_console_sem); +up (&console_sem);return ; }
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
PATCH 1/2 PM: Wait for console in resume.
Avoids later waking up to a blinking cursor if the device woke up and returned to sleep before the console switch happened.
--- kernel/power/console.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
kernel/power/console.c +6 -0
@@ -78,6 +78,12 @@ void pm_restore_console(void) }set_console (orig_fgconsole);release_console_sem (); + +if (vt_waitactive (orig_fgconsole)) { +pr_debug ("Resume: Can't switch VCs." ); +return ; + } + kmsg_redirect = orig_kmsg; }#endif
Signature · 6 lines
1.6.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 1/2 PM: Wait for console in resume.
In reply to Pavel MachekAvoids later waking up to a blinking cursor if the device woke up and returned to sleep before the console switch happened.
--- kernel/power/console.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
kernel/power/console.c +6 -0
@@ -78,6 +78,12 @@ void pm_restore_console(void) }set_console (orig_fgconsole);release_console_sem (); + +if (vt_waitactive (orig_fgconsole)) { +pr_debug ("Resume: Can't switch VCs." ); +return ; + } + kmsg_redirect = orig_kmsg; }#endif
Signature · 1 line
1.6.1
PATCH 2/2 PM: Fix suspend_console/resume_console to use only one semaphore.
This fixes a race if another thread acquired the console while it was suspended and released it after it was resumed the secondary console semaphre would be left locked, and the primary semaphore would be released twice. This in turn caused the console switch on suspend or resume to hang forever.
Note that suspend_console does not actually lock the console for clients that use acquire_console_sem, it only locks it for clients that use try_acquire_console_sem. If we change suspend_console to fully lock the console, then the kernel may deadlock on suspend.
--- kernel/printk.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
kernel/printk.c +9 -6
@@ -73,7 +73,6 @@ EXPORT_SYMBOL(oops_in_progress);* driver system. */ static DECLARE_MUTEX (console_sem); -static DECLARE_MUTEX (secondary_console_sem);struct console *console_drivers;EXPORT_SYMBOL_GPL (console_drivers);
@@ -896,12 +895,14 @@ void suspend_console(void)printk ("Suspending console(s) (use no_console_suspend to debug)\n" );acquire_console_sem (); console_suspended =1 ; +up (&console_sem); }void resume_console (void ) {if (!console_suspend_enabled)return ; +down (&console_sem); console_suspended =0 ;release_console_sem (); }
@@ -917,11 +918,9 @@ void resume_console(void)void acquire_console_sem (void ) {BUG_ON (in_interrupt ()); -if (console_suspended) { -down (&secondary_console_sem); -return ; - }down (&console_sem); +if (console_suspended) +return ; console_locked =1 ; console_may_schedule =1 ; }
@@ -931,6 +930,10 @@ int try_acquire_console_sem(void) {if (down_trylock (&console_sem))return -1 ; +if (console_suspended) { +up (&console_sem); +return -1 ; + } console_locked =1 ; console_may_schedule =0 ;return 0 ;
@@ -984,7 +987,7 @@ void release_console_sem(void)unsigned wake_klogd =0 ;if (console_suspended) { -up (&secondary_console_sem); +up (&console_sem);return ; }
Signature · 6 lines
1.6.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 2/2 PM: Fix suspend_console/resume_console to use only one semaphore.
In reply to Arve HjønnevågThis fixes a race if another thread acquired the console while it was suspended and released it after it was resumed the secondary console semaphre would be left locked, and the primary semaphore would be released twice. This in turn caused the console switch on suspend or resume to hang forever.
Note that suspend_console does not actually lock the console for clients that use acquire_console_sem, it only locks it for clients that use try_acquire_console_sem. If we change suspend_console to fully lock the console, then the kernel may deadlock on suspend.
--- kernel/printk.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
kernel/printk.c +9 -6
@@ -73,7 +73,6 @@ EXPORT_SYMBOL(oops_in_progress);* driver system. */ static DECLARE_MUTEX (console_sem); -static DECLARE_MUTEX (secondary_console_sem);struct console *console_drivers;EXPORT_SYMBOL_GPL (console_drivers);
@@ -896,12 +895,14 @@ void suspend_console(void)printk ("Suspending console(s) (use no_console_suspend to debug)\n" );acquire_console_sem (); console_suspended =1 ; +up (&console_sem); }void resume_console (void ) {if (!console_suspend_enabled)return ; +down (&console_sem); console_suspended =0 ;release_console_sem (); }
@@ -917,11 +918,9 @@ void resume_console(void)void acquire_console_sem (void ) {BUG_ON (in_interrupt ()); -if (console_suspended) { -down (&secondary_console_sem); -return ; - }down (&console_sem); +if (console_suspended) +return ; console_locked =1 ; console_may_schedule =1 ; }
@@ -931,6 +930,10 @@ int try_acquire_console_sem(void) {if (down_trylock (&console_sem))return -1 ; +if (console_suspended) { +up (&console_sem); +return -1 ; + } console_locked =1 ; console_may_schedule =0 ;return 0 ;
@@ -984,7 +987,7 @@ void release_console_sem(void)unsigned wake_klogd =0 ;if (console_suspended) { -up (&secondary_console_sem); +up (&console_sem);return ; }
Signature · 1 line
1.6.1
PATCH 1/1 PM: Fix suspend_console/resume_console to use only one semaphore.
This fixes a race where a thread acquires the console while the console is suspended, and the console is resumed before this thread releases it. In this case, the secondary console semaphore would be left locked, and the primary semaphore would be released twice. This in turn would cause the console switch on suspend or resume to hang forever.
Note that suspend_console does not actually lock the console for clients that use acquire_console_sem, it only locks it for clients that use try_acquire_console_sem. If we change suspend_console to fully lock the console, then the kernel may deadlock on suspend. One client of try_acquire_console_sem is acquire_console_semaphore_for_printk, which uses it to prevent printk from using the console while it is suspended.
--- kernel/printk.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
kernel/printk.c +9 -6
@@ -73,7 +73,6 @@ EXPORT_SYMBOL(oops_in_progress);* driver system. */ static DECLARE_MUTEX (console_sem); -static DECLARE_MUTEX (secondary_console_sem);struct console *console_drivers;EXPORT_SYMBOL_GPL (console_drivers);
@@ -891,12 +890,14 @@ void suspend_console(void)printk ("Suspending console(s) (use no_console_suspend to debug)\n" );acquire_console_sem (); console_suspended =1 ; +up (&console_sem); }void resume_console (void ) {if (!console_suspend_enabled)return ; +down (&console_sem); console_suspended =0 ;release_console_sem (); }
@@ -912,11 +913,9 @@ void resume_console(void)void acquire_console_sem (void ) {BUG_ON (in_interrupt ()); -if (console_suspended) { -down (&secondary_console_sem); -return ; - }down (&console_sem); +if (console_suspended) +return ; console_locked =1 ; console_may_schedule =1 ; }
@@ -926,6 +925,10 @@ int try_acquire_console_sem(void) {if (down_trylock (&console_sem))return -1 ; +if (console_suspended) { +up (&console_sem); +return -1 ; + } console_locked =1 ; console_may_schedule =0 ;return 0 ;
@@ -979,7 +982,7 @@ void release_console_sem(void)unsigned wake_klogd =0 ;if (console_suspended) { -up (&secondary_console_sem); +up (&console_sem);return ; }
Signature · 6 lines
1.6.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
PATCH 1/1 PM: Fix suspend_console/resume_console to use only one semaphore.
In reply to Arve HjønnevågThis fixes a race where a thread acquires the console while the console is suspended, and the console is resumed before this thread releases it. In this case, the secondary console semaphore would be left locked, and the primary semaphore would be released twice. This in turn would cause the console switch on suspend or resume to hang forever.
Note that suspend_console does not actually lock the console for clients that use acquire_console_sem, it only locks it for clients that use try_acquire_console_sem. If we change suspend_console to fully lock the console, then the kernel may deadlock on suspend. One client of try_acquire_console_sem is acquire_console_semaphore_for_printk, which uses it to prevent printk from using the console while it is suspended.
--- kernel/printk.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
kernel/printk.c +9 -6
@@ -73,7 +73,6 @@ EXPORT_SYMBOL(oops_in_progress);* driver system. */ static DECLARE_MUTEX (console_sem); -static DECLARE_MUTEX (secondary_console_sem);struct console *console_drivers;EXPORT_SYMBOL_GPL (console_drivers);
@@ -891,12 +890,14 @@ void suspend_console(void)printk ("Suspending console(s) (use no_console_suspend to debug)\n" );acquire_console_sem (); console_suspended =1 ; +up (&console_sem); }void resume_console (void ) {if (!console_suspend_enabled)return ; +down (&console_sem); console_suspended =0 ;release_console_sem (); }
@@ -912,11 +913,9 @@ void resume_console(void)void acquire_console_sem (void ) {BUG_ON (in_interrupt ()); -if (console_suspended) { -down (&secondary_console_sem); -return ; - }down (&console_sem); +if (console_suspended) +return ; console_locked =1 ; console_may_schedule =1 ; }
@@ -926,6 +925,10 @@ int try_acquire_console_sem(void) {if (down_trylock (&console_sem))return -1 ; +if (console_suspended) { +up (&console_sem); +return -1 ; + } console_locked =1 ; console_may_schedule =0 ;return 0 ;
@@ -979,7 +982,7 @@ void release_console_sem(void)unsigned wake_klogd =0 ;if (console_suspended) { -up (&secondary_console_sem); +up (&console_sem);return ; }
Signature · 1 line
1.6.1
Re: [PATCH] PM: Fix suspend_console/resume_console to use only one semaphore.
Quoted 7 lines · Arve Hjønnevåg
This fixes a race where a thread acquires the console while the console is suspended, and the console is resumed before this thread releases it. In this case, the secondary console semaphore would be left locked, and the primary semaphore would be released twice. This in turn would cause the console switch on suspend or resume to hang forever.
Quoted 7 lines
Note that
suspend_consoledoes not actually lock the console for clients that useacquire_console_sem, it only locks it for clients that usetry_acquire_console_sem. If we changesuspend_consoleto fully lock the console, then the kernel may deadlock on suspend. One client oftry_acquire_console_semisacquire_console_semaphore_for_printk, which uses it to prevent printk from using the console while it is suspended.
Right, we shouldn't hold the semaphore over the whole time. In fact, I even have some doubts about the need for suspending the console at all...
The way I did it back then for powerbooks was to implement a "suspended" state in the fbdev/fbcon core which the drivers call effectively causing the core to stop touching the framebuffer. Works fine for kernel consoles though of course userspace or X needs something different, but that's orthogonal.
Of course that doesn't help with serial, vgacon etc... so each drivers needs to suspend itself and be made to ignore incoming requests but that's something that has to be done anyway at some stage...
I suspect the suspend console trick is mostly helpful with vgacon..
Ben.
Quoted 73 lines
Signed-off-by Arve Hjønnevåg <[email protected]>--- kernel/printk.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)kernel/printk.c +9
-6@@ -73,7 +73,6 @@ EXPORT_SYMBOL(oops_in_progress);* driver system. */ static DECLARE_MUTEX (console_sem); -static DECLARE_MUTEX (secondary_console_sem);struct console *console_drivers;EXPORT_SYMBOL_GPL (console_drivers);@@ -891,12 +890,14 @@ void suspend_console(void)printk ("Suspending console(s) (use no_console_suspend to debug)\n" );acquire_console_sem (); console_suspended =1 ; +up (&console_sem); }void resume_console (void ) {if (!console_suspend_enabled)return ; +down (&console_sem); console_suspended =0 ;release_console_sem (); }@@ -912,11 +913,9 @@ void resume_console(void)void acquire_console_sem (void ) {BUG_ON (in_interrupt ()); -if (console_suspended) { -down (&secondary_console_sem); -return ; - }down (&console_sem); +if (console_suspended) +return ; console_locked =1 ; console_may_schedule =1 ; }@@ -926,6 +925,10 @@ int try_acquire_console_sem(void) {if (down_trylock (&console_sem))return -1 ; +if (console_suspended) { +up (&console_sem); +return -1 ; + } console_locked =1 ; console_may_schedule =0 ;return 0 ;@@ -979,7 +982,7 @@ void release_console_sem(void)unsigned wake_klogd =0 ;if (console_suspended) { -up (&secondary_console_sem); +up (&console_sem);return ; }Signature · 6 lines
1.6.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm
_______________________________________________
linux-pm mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/linux-pm
Re: [linux-pm] [PATCH] PM: Fix suspend_console/resume_console to use only one semaphore.
In reply to Arve HjønnevågQuoted 7 lines · Arve Hjønnevåg
This fixes a race where a thread acquires the console while the console is suspended, and the console is resumed before this thread releases it. In this case, the secondary console semaphore would be left locked, and the primary semaphore would be released twice. This in turn would cause the console switch on suspend or resume to hang forever.
Quoted 7 lines
Note that
suspend_consoledoes not actually lock the console for clients that useacquire_console_sem, it only locks it for clients that usetry_acquire_console_sem. If we changesuspend_consoleto fully lock the console, then the kernel may deadlock on suspend. One client oftry_acquire_console_semisacquire_console_semaphore_for_printk, which uses it to prevent printk from using the console while it is suspended.
Right, we shouldn't hold the semaphore over the whole time. In fact, I even have some doubts about the need for suspending the console at all...
The way I did it back then for powerbooks was to implement a "suspended" state in the fbdev/fbcon core which the drivers call effectively causing the core to stop touching the framebuffer. Works fine for kernel consoles though of course userspace or X needs something different, but that's orthogonal.
Of course that doesn't help with serial, vgacon etc... so each drivers needs to suspend itself and be made to ignore incoming requests but that's something that has to be done anyway at some stage...
I suspect the suspend console trick is mostly helpful with vgacon..
Ben.
Quoted 73 lines
Signed-off-by Arve Hjønnevåg <[email protected]>--- kernel/printk.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)kernel/printk.c +9
-6@@ -73,7 +73,6 @@ EXPORT_SYMBOL(oops_in_progress);* driver system. */ static DECLARE_MUTEX (console_sem); -static DECLARE_MUTEX (secondary_console_sem);struct console *console_drivers;EXPORT_SYMBOL_GPL (console_drivers);@@ -891,12 +890,14 @@ void suspend_console(void)printk ("Suspending console(s) (use no_console_suspend to debug)\n" );acquire_console_sem (); console_suspended =1 ; +up (&console_sem); }void resume_console (void ) {if (!console_suspend_enabled)return ; +down (&console_sem); console_suspended =0 ;release_console_sem (); }@@ -912,11 +913,9 @@ void resume_console(void)void acquire_console_sem (void ) {BUG_ON (in_interrupt ()); -if (console_suspended) { -down (&secondary_console_sem); -return ; - }down (&console_sem); +if (console_suspended) +return ; console_locked =1 ; console_may_schedule =1 ; }@@ -926,6 +925,10 @@ int try_acquire_console_sem(void) {if (down_trylock (&console_sem))return -1 ; +if (console_suspended) { +up (&console_sem); +return -1 ; + } console_locked =1 ; console_may_schedule =0 ;return 0 ;@@ -979,7 +982,7 @@ void release_console_sem(void)unsigned wake_klogd =0 ;if (console_suspended) { -up (&secondary_console_sem); +up (&console_sem);return ; }Signature · 6 lines
1.6.1 _______________________________________________ linux-pm mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/linux-pm