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