patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / Documentation / power / swsusp.txt
1 From kernel/suspend.c:
2
3  * BIG FAT WARNING *********************************************************
4  *
5  * If you have unsupported (*) devices using DMA...
6  *                              ...say goodbye to your data.
7  *
8  * If you touch anything on disk between suspend and resume...
9  *                              ...kiss your data goodbye.
10  *
11  * If your disk driver does not support suspend... (IDE does)
12  *                              ...you'd better find out how to get along
13  *                                 without your data.
14  *
15  * (*) pm interface support is needed to make it safe.
16
17 You need to append resume=/dev/your_swap_partition to kernel command
18 line. Then you suspend by echo 4 > /proc/acpi/sleep.
19
20 Pavel's unreliable guide to swsusp mess
21 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22
23 There are currently two versions of swap suspend in the kernel, the old
24 "Pavel's" version in kernel/power/swsusp.c and the new "Patrick's"
25 version in kernel/power/pmdisk.c. They provide the same functionality;
26 the old version looks ugly but was tested, while the new version looks
27 nicer but did not receive so much testing. echo 4 > /proc/acpi/sleep
28 calls the old version, echo disk > /sys/power/state calls the new one.
29
30 [In the future, when the new version is stable enough, two things can
31 happen:
32
33 * the new version is moved into swsusp.c, and swsusp is renamed to swap
34   suspend (Pavel prefers this)
35
36 * pmdisk is kept as is and swsusp.c is removed from the kernel]
37
38
39
40 Article about goals and implementation of Software Suspend for Linux
41 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42 Author: G\82ábor Kuti
43 Last revised: 2003-10-20 by Pavel Machek
44
45 Idea and goals to achieve
46
47 Nowadays it is common in several laptops that they have a suspend button. It
48 saves the state of the machine to a filesystem or to a partition and switches
49 to standby mode. Later resuming the machine the saved state is loaded back to
50 ram and the machine can continue its work. It has two real benefits. First we
51 save ourselves the time machine goes down and later boots up, energy costs
52 real high when running from batteries. The other gain is that we don't have to
53 interrupt our programs so processes that are calculating something for a long
54 time shouldn't need to be written interruptible.
55
56 Using the code
57
58 You have two ways to use this code. The first one is is with a patched
59 SysVinit (my patch is against 2.76 and available at my home page). You
60 might call 'swsusp' or 'shutdown -z <time>'. Next way is to echo 4 >
61 /proc/acpi/sleep.
62
63 Either way it saves the state of the machine into active swaps and then
64 reboots.  You must explicitly specify the swap partition to resume from with
65 ``resume='' kernel option. If signature is found it loads and restores saved
66 state. If the option ``noresume'' is specified as a boot parameter, it skips
67 the resuming.
68
69 In the meantime while the system is suspended you should not touch any of the
70 hardware!
71
72 About the code
73
74 Things to implement
75 - SMP support. I've done an SMP support but since I don't have access to a kind
76   of this one I cannot test it. Please SMP people test it.  .. Tested it,
77   doesn't work. Had no time to figure out why. There is some mess with
78   interrupts AFAIK..
79 - We should only make a copy of data related to kernel segment, since any
80   process data won't be changed.
81 - Should make more sanity checks. Or are these enough?
82
83 Not so important ideas for implementing
84
85 - If a real time process is running then don't suspend the machine.
86 - Support for adding/removing hardware while suspended?
87 - We should not free pages at the beginning so aggressively, most of them
88   go there anyway..
89
90 Drivers that need support
91 - pc_keyb -- perhaps we can wait for vojtech's input patches
92 - do IDE cdroms need some kind of support?
93 - IDE CD-RW -- how to deal with that?
94
95 Sleep states summary (thanx, Ducrot)
96 ====================================
97
98 In a really perfect world:
99 echo 1 > /proc/acpi/sleep       # for standby
100 echo 2 > /proc/acpi/sleep       # for suspend to ram
101 echo 3 > /proc/acpi/sleep       # for suspend to ram, but with more power conservative
102 echo 4 > /proc/acpi/sleep       # for suspend to disk
103 echo 5 > /proc/acpi/sleep       # for shutdown unfriendly the system
104
105 and perhaps
106 echo 4b > /proc/acpi/sleep      # for suspend to disk via s4bios
107
108
109 FAQ:
110
111 Q: well, suspending a server is IMHO a really stupid thing,
112 but... (Diego Zuccato):
113
114 A: You bought new UPS for your server. How do you install it without
115 bringing machine down? Suspend to disk, rearrange power cables,
116 resume.
117
118 You have your server on UPS. Power died, and UPS is indicating 30
119 seconds to failure. What do you do? Suspend to disk.
120
121 Ethernet card in your server died. You want to replace it. Your
122 server is not hotplug capable. What do you do? Suspend to disk,
123 replace ethernet card, resume. If you are fast your users will not
124 even see broken connections.
125
126
127 Q: Maybe I'm missing something, but why don't the regular I/O paths work?
128
129 A: We do use the regular I/O paths. However we cannot restore the data
130 to its original location as we load it. That would create an
131 inconsistent kernel state which would certainly result in an oops.
132 Instead, we load the image into unused memory and then atomically copy
133 it back to it original location. This implies, of course, a maximum
134 image size of half the amount of memory.
135
136 There are two solutions to this:
137
138 * require half of memory to be free during suspend. That way you can
139 read "new" data onto free spots, then cli and copy
140
141 * assume we had special "polling" ide driver that only uses memory
142 between 0-640KB. That way, I'd have to make sure that 0-640KB is free
143 during suspending, but otherwise it would work...
144
145 suspend2 shares this fundamental limitation, but does not include user
146 data and disk caches into "used memory" by saving them in
147 advance. That means that the limitation goes away in practice.
148
149 Q: Does linux support ACPI S4?
150
151 A: No.
152
153 When swsusp was created, ACPI was not too widespread, so we tried to
154 avoid using ACPI-specific stuff. ACPI also is/was notoriously
155 buggy. These days swsusp works on APM-only i386 machines and even
156 without any power managment at all. Some versions also work on PPC.
157
158 That means that machine does not enter S4 on suspend-to-disk, but
159 simply enters S5. That has few advantages, you can for example boot
160 windows on next boot, and return to your Linux session later. You
161 could even have few different Linuxes on your box (not sharing any
162 partitions), and switch between them.
163
164 It also has disadvantages. On HP nx5000, if you unplug power cord
165 while machine is suspended-to-disk, Linux will fail to notice that.
166
167 Q: My machine doesn't work with ACPI. How can I use swsusp than ?
168
169 A: Do a reboot() syscall with right parameters. Warning: glibc gets in
170 its way, so check with strace:
171
172 reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, 0xd000fce2)
173
174 (Thanks to Peter Osterlund:)
175
176 #include <unistd.h>
177 #include <syscall.h>
178
179 #define LINUX_REBOOT_MAGIC1     0xfee1dead
180 #define LINUX_REBOOT_MAGIC2     672274793
181 #define LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
182
183 int main()
184 {
185     syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
186             LINUX_REBOOT_CMD_SW_SUSPEND, 0);
187     return 0;
188 }
189
190 Q: What is 'suspend2'?
191
192 A: suspend2 is 'Software Suspend 2', a forked implementation of
193 suspend-to-disk which is available as separate patches for 2.4 and 2.6
194 kernels from swsusp.sourceforge.net. It includes support for SMP, 4GB
195 highmem and preemption. It also has a extensible architecture that
196 allows for arbitrary transformations on the image (compression,
197 encryption) and arbitrary backends for writing the image (eg to swap
198 or an NFS share[Work In Progress]). Questions regarding suspend2
199 should be sent to the mailing list available through the suspend2
200 website, and not to the Linux Kernel Mailing List. We are working
201 toward merging suspend2 into the mainline kernel.