2003-09-10 00:32:43

by Patrick Mochel

[permalink] [raw]
Subject: Power Management Update


Here is the next round of power management updates. BK users can get the
changesets listed below from

bk://kernel.bkbits.net:/home/mochel/linux-2.5-power

A patch against 2.6.0-test5 can be found at

http://developer.osdl.org/~mochel/patches/test5-pm1/test5-pm1.diff.bz2

The patches for each individual changeset can be found in that directory.

The changesets there, and listed below, are cumulative, meaning they
include all of the patches I posted last week. The highlights from this
release are the following:

- Fixed suspend-to-disk support with preempt and SMP enabled.

Suspend-to-disk will work on a UP system with SMP enabled, though it will
definitely not on an SMP system. This is on the TODO list, albeit at low
priority.

- Several small bug fixes.

- swsusp has been forked into two workable trees.

The code base of swsusp itself has been reverted to its state around
2.6.0-test3. A suspend-to-disk implementation called 'pmdisk' has been
created in kernel/power/pmdisk.c that offers (for now) identical
functionality, and an almost identical code base. That will change in the
near future, as I submit more cleanups to it.

The pmdisk implementation is accessible via the sysfs interface:

echo -n disk > /sys/power/state

While swsusp is accessible via the /proc/acpi/sleep interface. It is
possible to tie swsusp into the sysfs interface, and will entertain
patches to do such a thing.

Note the new config menu options for pmdisk when building the kernel.


There is still a lot to do, including fixing the random crashes that some
people are experiencing. I appreciate the testing people have done, and
will appreciate any feedback concerning the patches or the functionality
the patches implement.

Enjoy.

Thanks,


Pat



This will update the following files:

arch/i386/kernel/suspend.c | 141 ----
arch/i386/kernel/suspend_asm.S | 94 ---
arch/i386/Kconfig | 44 -
arch/i386/Makefile | 1
arch/i386/kernel/Makefile | 2
arch/i386/power/Makefile | 3
arch/i386/power/cpu.c | 141 ++++
arch/i386/power/pmdisk.S | 94 +++
arch/i386/power/swsusp.S | 126 +++-
drivers/acpi/sleep/main.c | 53 +
drivers/acpi/sleep/proc.c | 73 ++
drivers/acpi/sleep/sleep.h | 3
drivers/base/core.c | 33 -
drivers/base/power/main.c | 13
drivers/base/power/power.h | 3
drivers/base/power/resume.c | 21
drivers/base/power/suspend.c | 10
include/asm-i386/suspend.h | 7
include/linux/suspend.h | 15
kernel/power/Kconfig | 92 +++
kernel/power/Makefile | 5
kernel/power/console.c | 2
kernel/power/disk.c | 427 +++++++++++++--
kernel/power/main.c | 459 +++-------------
kernel/power/pmdisk.c | 1162 +++++++++++++++++++++++++++++++++++++----
kernel/power/power.h | 41 -
kernel/power/swsusp.c | 1095 ++++++++++++++++++++++----------------
kernel/sched.c | 4
kernel/sys.c | 9
29 files changed, 2804 insertions(+), 1369 deletions(-)

through these ChangeSets:

<[email protected]> (03/09/09 1.1217.3.32)
[swsusp] Fix software_suspend() inline return value when SOFTWARE_SUSPEND=n.

<[email protected]> (03/09/09 1.1217.3.31)
[power] Revert swsusp to 2.6.0-test3 state.

- From Pavel (mostly, though with some fixups).
- Note that I would never publically admit to putting such code into the
kernel.
- Someone ought to really review this patch some day.

<[email protected]> (03/09/09 1.1217.3.30)
[power] Make pmdisk compile when CONFIG_SOFTWARE_SUSPEND=n.

<[email protected]> (03/09/09 1.1217.3.29)
[power] Make pmdisk compilable and usable.

- Fork arch/i386/power/swsusp.S into arch/i386/power/pmdisk.S
- Change name of all externally visible swsusp_* functions to pmdisk_*
- Make pm_suspend_disk() call pmdisk_ functions.
- Make sure pmdisk.o is compiled if the config option is set.
- Add CONFIG_PM_DISK_PARTITION option, which allows user to compile in
default resume partition.
- Add pmdisk= setup option, which allows user to override or disable default
resume partition.
- Change name of global names in pmdisk that conflict with those in swsusp.

<[email protected]> (03/09/09 1.1217.3.27)
[power] Move PM options into kernel/power/Kconfig.

- Add option for CONFIG_PM_DISK (suspend-to-disk functionality).

- Other arch's should include this, instead of defining their own options.
Will fixup any problems with that..

<[email protected]> (03/09/09 1.1217.3.26)
[power] Fork swsusp.

The cloned implementation is in kernel/power/pmdisk.c.

<[email protected]> (03/09/08 1.1217.3.24)
[power] Fix swsusp with preempt and clean up.

In order to snapshot memory, interrupts must be disabled. However, in order
to write the saved image to disk, interrupts must be re-enabled and devices
resumed. Previously, both actions were called from swsusp_arch_suspend().

This patch separates those two actions has only the snapshotting routine
called from swsusp_arch_suspend(). swsusp now handles it's own disabling of
interrupts only for the time required. This is now handled from swsusp_save()
and swsusp_write() now handles writing the image only (called with interrupts
enabled).

swsusp_save_image() was renamed to swsusp_suspend() (and the old incarnation
deleted since it was simply a wrapper).

<[email protected]> (03/09/08 1.1217.3.23)
[swsusp] Make sure we call restore_processor_state() when suspending.

- Added unconditionally to exit path of swsusp_arch_suspend(). This is done
to call kernel_fpu_end() to reset the preempt count on suspend.

- Note that we must preserve %eax across that call.

<[email protected]> (03/09/08 1.1217.3.22)
[power] Add support for refrigerator to the migration_thread.

- The PM code currently must signal each kernel thread when suspending, and
each thread must call refrigerator() to stop itself. This patch adds
support for this to migration_thread, which allows suspend states to work
on an SMP-enabled kernel (though not necessarily an SMP machine).

- Note I do not know why the process freezing code was designed in such a
way. One would think we could do it without having to call each thread
individually, and fix up the threads that need special work individually..

<[email protected]> (03/09/08 1.1217.3.21)
[power] Make sure we restore interrupts if device_power_down() fails.

<[email protected]> (03/09/08 1.1217.3.20)
[power] Simplify error handling in pm_suspend_prepare().

<[email protected]> (03/09/04 1.1153.114.3)
[power] Whitespace fixes.

From the -test4-mm5 tree.

<[email protected]> (03/08/30 1.1153.76.10)
[acpi] Replace /proc/acpi/sleep

- Bad to remove proc file now, even though it's nearly useless. Reinstated
in the name of compatibility.

- Restored original semantics - if software_suspend() is enabled, then just
call that (and never go into low-power state). Otherwise, call acpi_suspend().

- acpi_suspend() is simply a wrapper for pm_suspend(), passing down the right
argument. This is so we don't have to do everything manually anymore.

- Fixed long-standing bug by checking for "4b" in string written in to
determine if we want to enter S4bios.

<[email protected]> (03/08/30 1.1153.76.9)
[swsusp] Restore software_suspend() call.

- Allows 'backdoor' interface to swsusp, as requested by Pavel.

- Simply a wrapper to pm_suspend(), though guaranteeing that swsusp is used,
and system is shutdown (and put into low-power state).

- Call in sys_reboot() changed back to call to software_suspend().

<[email protected]> (03/08/30 1.1153.76.8)
[swsusp] Use BIO interface when reading from swap.

- bios are the preferred method for doing this type of stuff in 2.6. The
__bread() uses bio's in the end anyway.

- bios make it really easy to implement write functionality, so we are able
to reset the swap signature immediately after checking it during resume.
So, if something happens while resuming, we will still have valid swap to
use.

- Thanks to Jens for some help in getting it working several months ago.

<[email protected]> (03/08/29 1.1153.76.7)
[swsusp] Minor cleanups in read_suspend_image()

- Make resume_bdev global to file, so we don't have to pass it around (we
always use the same one, so it shouldn't make a difference).

- Allocate cur in read_suspend_image(), since it's the only function that
uses it.

- Check all errors and make sure we free cur if any happen.

- Make sure to return errors from the functions called, not our own.

- Free the pagedir if we hit an error after we allocate it.

<[email protected]> (03/08/27 1.1153.76.6)
[acpi] Move register save closer to call to enter sleep state.

- By moving acpi_{save,restore}_state_mem() into acpi_pm_enter(), implying
after interrupts have been disabled and nothing else is running on the
system, S3 is able to resume properly.

<[email protected]> (03/08/27 1.1153.76.5)
[power] Make sure devices get added to the PM lists before bus_add_device().

- Prevents ordering issues when drivers add more devices ->probe().

<[email protected]> (03/08/26 1.1153.76.4)
[power] Separate suspend-to-disk from other suspend sequences.

- Put in kernel/power/disk.c
- Make compilation depend on CONFIG_SOFTWARE_SUSPEND (should probably be
renamed to CONFIG_PM_STD or some such).

<[email protected]> (03/08/25 1.1153.76.3)
[power] Fix handling of pm_users.

- Actually decrement on device_pm_release()
- Call from device_pm_remove().

<[email protected]> (03/08/25 1.1153.76.1)
[power] Fix device suspend handling

- Handle -EAGAIN in device_suspend() properly: keep going, with error reset
to 0.

- Call dpm_resume() if we got a real error, instead of device_resume(), which
would deadlock.

<[email protected]> (03/08/22 1.1153.60.8)
[power] swsusp Cleanups

- do_magic()
- Rename to swsusp_arch_suspend().
- Move declaration to swsusp.c

- arch_prepare_suspend()
- Return an int
- Fix x86 version to return -EFAULT if cpu does not have pse, instead of
calling panic().
- Call from swsusp_save().

- do_magic_suspend_1()
- Move body to pm_suspend_disk()
- Remove.

- do_magic_suspend_2()
- Rename to swsusp_suspend()
- Move IRQ fiddling to suspend_save_image(), since that's the only call
that needs it.
- Return an int.

- do_magic_resume_1()
- Move body to pm_resume().
- Remove

- do_magic_resume_2()
- Rename to swsusp_resume().
- Return an int.

- swsusp general
- Remove unnecessary includes.
- Remove suspend_pagedir_lock, since it was only used to disable IRQs.
- Change swsusp_{suspend,resume} return an int, so pm_suspend_disk() knows
if anything failed.



<[email protected]> (03/08/22 1.1153.60.7)
[power] Move i386-specific swsusp code to arch/i386/power/

<[email protected]> (03/08/22 1.1153.60.6)
[power] Fix up sysfs state handling.

<[email protected]> (03/08/22 1.1153.60.5)
[power] Make sure console level is high when suspending.

<[email protected]> (03/08/22 1.1153.62.1)
[power] Fix sysfs state reporting.




2003-09-10 13:04:46

by Daniele Venzano

[permalink] [raw]
Subject: Re: Power Management Update

On Tue, Sep 09, 2003 at 05:38:53PM -0700, Patrick Mochel wrote:
>
> A patch against 2.6.0-test5 can be found at
>
> http://developer.osdl.org/~mochel/patches/test5-pm1/test5-pm1.diff.bz2
>

I tried your patch on a Asus L3D, and here are the results:

echo -n standby > /sys/power/state
----------------------------------
Works fine, but on resume I get this message:
APIC error on CPU0: 00(00)
The resume continues and completes, but then it switches to init 0 and
halts.
So this is what happens:
- standby
- resume (with the above message)
- init 0 (this I have still to understand...)
If not for the init 0 part, that's ok.

echo -n mem > /sys/power/state
------------------------------
Suspend seems to go well, but on resume the screen stays black, I hear
the fan turning up, then nothing else. The machine doesn't respond
to pings or sysrq, hard reset required.
Removing the ehci module, I get something more strange, the resume seems
to go well, but the screen remains turned off (I'm not using framebuffer
or X). After some disk activity, the power led goes off. I think it is
againg going in init 0 just after resume.
Reading logs confirms this idea, it is going in init 0 just after
resuming completes.

Couldn't try disk suspend for time constraints, perhaps next days...

Someone has a clue on why it is switching to init 0 ?

Attached you find dmesg and tipical suspend->resume messages

--
----------------------------------------
Daniele Venzano
Web: http://digilander.iol.it/webvenza/


Attachments:
(No filename) (1.47 kB)
dmesg (11.52 kB)
susp.log (2.76 kB)
Download all attachments

2003-09-10 18:10:58

by Pavel Machek

[permalink] [raw]
Subject: Re: Power Management Update

Hi!

> <[email protected]> (03/09/09 1.1217.3.31)
> [power] Revert swsusp to 2.6.0-test3 state.
>
> - From Pavel (mostly, though with some fixups).
> - Note that I would never publically admit to putting such code into the
> kernel.
> - Someone ought to really review this patch some day.

@@ -6,11 +6,12 @@
#include <asm/desc.h>
#include <asm/i387.h>

-static inline void
+static inline int
arch_prepare_suspend(void)
{
if (!cpu_has_pse)
- panic("pse required");
+ return -EPERM;
+ return 0;
}

/* image of the saved processor state */

You still want to do some printk(), otherwise we'll get very ugly bug
reports ("it does not suspend and I don't know why"). Also without
check in swsusp.c, this could corrupt data (page table accessed bits
might flip something during copy).

--- /usr/src/tmp/linux/kernel/power/swsusp.c 2003-09-10 19:58:08.000000000 +0200
+++ /usr/src/linux/kernel/power/swsusp.c 2003-09-10 19:57:16.000000000 +0200
@@ -697,7 +697,8 @@
static void do_software_suspend(void)
{
printk("Doing software_suspend()\n");
- arch_prepare_suspend();
+ if (arch_prepare_suspend())
+ return;
if (pm_prepare_console())
printk( "%sCan't allocate a console... proceeding\n", name_suspend);
if (!prepare_suspend_processes()) {


Minor nits:

--- linux-2.5-virgin/kernel/power/pmdisk.c Wed Dec 31 16:00:00 1969
+++ linux-2.5-power/kernel/power/pmdisk.c Tue Sep 9 13:54:33 2003
@@ -0,0 +1,942 @@
+/*
+ * kernel/power/pmdisk.c - Suspend-to-disk implmentation
~ missing 'e'


+ /* we ignore all swap devices that are
not the resume_file */
+ if (1) {
+// FIXME if(resume_device ==
swap_info[i].swap_device) {
+ swapfile_used[i] =
SWAPFILE_SUSPEND;

If you want this FIXME fixed, I got patch from Aristeu Sergio Rozanski
Filho <[email protected]>. Not yet tested, that's why I was
holding it. (attached).

Pavel
--
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]


Attachments:
(No filename) (2.13 kB)
delme_swsusp-swap_name.diff (1.37 kB)
Download all attachments

2003-09-10 21:02:45

by Patrick Mochel

[permalink] [raw]
Subject: Re: Power Management Update


> Any chance of this patch to be released against mm series? BTW i have
> tried suspend to disk (2.6.0-test4-mm6) with reiserfs filesystem
> it worked fine and no fs corruption.

Good to hear. Thanks for testing.

Andrew picked up the last bunch of patches for the -mm series, so most of
it already resides in that tree. With some luck, he'll do the same with
the remaining patches. Otherwise, I can post an incremental patch on top
of the latest -mm kernel.


Pat

2003-09-10 20:55:28

by Subodh Shrivastava

[permalink] [raw]
Subject: Re: Power Management Update

Any chance of this patch to be released against mm series? BTW i have
tried suspend to disk (2.6.0-test4-mm6) with reiserfs filesystem
it worked fine and no fs corruption.

Thanks
Subodh

PS: please CC me in the reply i am not subscribed to the list.

2003-09-10 21:46:19

by Subodh Shrivastava

[permalink] [raw]
Subject: Re: Power Management Update



Patrick Mochel wrote:

>>Any chance of this patch to be released against mm series? BTW i have
>>tried suspend to disk (2.6.0-test4-mm6) with reiserfs filesystem
>>it worked fine and no fs corruption.
>>
>>
>
>Good to hear. Thanks for testing.
>
>
Tried it with 2.6.0-test5-mm1.

When i tried suspend to disk with my usb modem (Alcatel Speedtouch)
attached, system generated oops, couldn't get a dump on disk, will send
the handwritten oops later. When i tried from X suspend to disk was
successful but resume failed and system rebooted itself, did not get a
chance to figure out what went wrong.

>Andrew picked up the last bunch of patches for the -mm series, so most of
>it already resides in that tree. With some luck, he'll do the same with
>
>the remaining patches. Otherwise, I can post an incremental patch on top
>of the latest -mm kernel.
>
Please if you can

>
>
> Pat
>
>
>
>
Subodh

2003-09-10 22:49:40

by Patrick Mochel

[permalink] [raw]
Subject: Re: Power Management Update


> Attached here are the digital picture of the oops generated, for suspend
> to disk with usb modem connected (Alcatel Sppedtouch).

Thanks.

Note that if sending digital photos, please just send them to me
privately. I don't think many people appreciate getting 1.2M emails. :)

Thanks,


Pat

2003-09-11 00:23:53

by Greg KH

[permalink] [raw]
Subject: Re: Power Management Update

On Wed, Sep 10, 2003 at 09:44:36PM +0100, Subodh Shrivastava wrote:
>
>
> Patrick Mochel wrote:
>
> >>Any chance of this patch to be released against mm series? BTW i have
> >>tried suspend to disk (2.6.0-test4-mm6) with reiserfs filesystem
> >>it worked fine and no fs corruption.
> >>
> >>
> >
> >Good to hear. Thanks for testing.
> >
> >
> Tried it with 2.6.0-test5-mm1.
>
> When i tried suspend to disk with my usb modem (Alcatel Speedtouch)
> attached, system generated oops, couldn't get a dump on disk, will send
> the handwritten oops later. When i tried from X suspend to disk was
> successful but resume failed and system rebooted itself, did not get a
> chance to figure out what went wrong.

There was a patch by Pavel to fix the USB core bug. To rule this out,
unload the usbcore module before suspending.

Sorry about that.

greg k-h

2003-09-11 04:49:34

by Michael Frank

[permalink] [raw]
Subject: Re: Power Management Update

Applied test5-pm1.diff to 2.6.0-test5

patch creates drivers/cpufreq/cpufreq_powersave.c, which _is_ already in -test5

S3/mem PCI LNK's do not resume.

/proc/acpi/alarm hang on wakeup

echo multiple times > /proc/acpi/alarm

Sep 11 12:41:29 mhfl2 kernel: irq 9: nobody cared!
Sep 11 12:41:29 mhfl2 kernel: Call Trace:
Sep 11 12:41:29 mhfl2 kernel: [<c010c35b>] __report_bad_irq+0x2b/0x90
Sep 11 12:41:29 mhfl2 kernel: [<c010c363>] __report_bad_irq+0x33/0x90
Sep 11 12:41:29 mhfl2 kernel: [<c010c438>] note_interrupt+0x50/0x78
Sep 11 12:41:29 mhfl2 kernel: [<c010c5b2>] do_IRQ+0x96/0xf4
Sep 11 12:41:29 mhfl2 kernel: [<c010afe8>] common_interrupt+0x18/0x20
Sep 11 12:41:29 mhfl2 kernel: [<c011de78>] do_softirq+0x48/0xb0
Sep 11 12:41:29 mhfl2 kernel: [<c010c600>] do_IRQ+0xe4/0xf4
Sep 11 12:41:29 mhfl2 kernel: [<c010afe8>] common_interrupt+0x18/0x20
Sep 11 12:41:29 mhfl2 kernel: [<c01e305d>] acpi_os_write_port+0x35/0x50
Sep 11 12:41:29 mhfl2 kernel: [<c01f852e>] acpi_hw_low_level_write+0x7e/0x11e
Sep 11 12:41:29 mhfl2 kernel: [<c01f827d>] acpi_hw_register_write+0xb9/0x1c0
Sep 11 12:41:29 mhfl2 kernel: [<c01f7f96>] acpi_set_register+0x262/0x2d0
Sep 11 12:41:29 mhfl2 kernel: [<c020cbac>] acpi_system_write_alarm+0x4f0/0x53c
Sep 11 12:41:30 mhfl2 kernel: [<c0150000>] put_dirty_page+0x68/0xec
Sep 11 12:41:30 mhfl2 kernel: [<c0147dae>] vfs_write+0x9e/0xd0
Sep 11 12:41:30 mhfl2 kernel: [<c0147e60>] sys_write+0x30/0x50
Sep 11 12:41:30 mhfl2 kernel: [<c010adc7>] syscall_call+0x7/0xb
Sep 11 12:41:30 mhfl2 kernel:
Sep 11 12:41:30 mhfl2 kernel: handlers:
Sep 11 12:41:30 mhfl2 kernel: [<c01e2ebc>] (acpi_irq+0x0/0x1c)
Sep 11 12:41:30 mhfl2 kernel: Disabling IRQ #9

Regards
Michael


2003-09-11 06:06:24

by CaT

[permalink] [raw]
Subject: Re: Power Management Update

On Tue, Sep 09, 2003 at 05:38:53PM -0700, Patrick Mochel wrote:
> A patch against 2.6.0-test5 can be found at
>
> http://developer.osdl.org/~mochel/patches/test5-pm1/test5-pm1.diff.bz2
>
> The patches for each individual changeset can be found in that directory.

Here's my experience with the patch for the various suspend levels (all
activated through /sys/power/state). It looks like there are problems
activating the resume code.

standby:

never turns off screen. just seems to hang after hwsleep-0257. power light
flashes. hitting power button causes power light to stop flashing but no
resume happens. system is hung and powercycle req.

serial console output:

Stopping tasks: ===================================|
hda: start_power_step(step: 0)
hda: start_power_step(step: 1)
hda: complete_power_step(step: 1, stat: 50, err: 0)
hda: completing PM request, suspend
PM: Entering state.
hwsleep-0257 [15] acpi_enter_sleep_state: Entering sleep state [S1]

mem:

does stopping tasks and laptop powers down. power light flashes as if in
suspend.

serial console output:

Stopping tasks: =================================|

hand typed continued console out:

hda: start_power_step(step: 0)
hda: start_power_step(step: 1)
hda: complete_power_step(step: 1, stat: 50, err: 0)
hda: completing PM request, suspend
PM: Entering state.
hwsleep-0257 [15] acpi_enter_sleep_state: Entering sleep state [S3]

On resume it is as for standby.

disk (firmware):
activates h/w suspend just fine. bios appears to resume properly (all progress
meters hit 100%) but it never seems to pass control back to the OS (or, at
least, the OS never completes the resume as per above situations)

serial console output:

Stopping tasks: =================================|
Freeing memory: ....................|
hda: start_power_step(step: 0)
hda: start_power_step(step: 1)
hda: complete_power_step(step: 1, stat: 50, err: 0)
hda: completing PM request, suspend
PM: Attempting to suspend to disk.

--
"How can I not love the Americans? They helped me with a flat tire the
other day," he said.
- http://tinyurl.com/h6fo