aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/power/swsusp.txt
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /Documentation/power/swsusp.txt
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'Documentation/power/swsusp.txt')
-rw-r--r--Documentation/power/swsusp.txt235
1 files changed, 235 insertions, 0 deletions
diff --git a/Documentation/power/swsusp.txt b/Documentation/power/swsusp.txt
new file mode 100644
index 000000000000..c7c3459fde43
--- /dev/null
+++ b/Documentation/power/swsusp.txt
@@ -0,0 +1,235 @@
1From 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 * If you change your hardware while system is suspended...
19 * ...well, it was not good idea.
20 *
21 * (*) suspend/resume support is needed to make it safe.
22
23You need to append resume=/dev/your_swap_partition to kernel command
24line. Then you suspend by
25
26echo shutdown > /sys/power/disk; echo disk > /sys/power/state
27
28. If you feel ACPI works pretty well on your system, you might try
29
30echo platform > /sys/power/disk; echo disk > /sys/power/state
31
32
33
34Article about goals and implementation of Software Suspend for Linux
35~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36Author: G‚ábor Kuti
37Last revised: 2003-10-20 by Pavel Machek
38
39Idea and goals to achieve
40
41Nowadays it is common in several laptops that they have a suspend button. It
42saves the state of the machine to a filesystem or to a partition and switches
43to standby mode. Later resuming the machine the saved state is loaded back to
44ram and the machine can continue its work. It has two real benefits. First we
45save ourselves the time machine goes down and later boots up, energy costs
46are real high when running from batteries. The other gain is that we don't have to
47interrupt our programs so processes that are calculating something for a long
48time shouldn't need to be written interruptible.
49
50swsusp saves the state of the machine into active swaps and then reboots or
51powerdowns. You must explicitly specify the swap partition to resume from with
52``resume='' kernel option. If signature is found it loads and restores saved
53state. If the option ``noresume'' is specified as a boot parameter, it skips
54the resuming.
55
56In the meantime while the system is suspended you should not add/remove any
57of the hardware, write to the filesystems, etc.
58
59Sleep states summary
60====================
61
62There are three different interfaces you can use, /proc/acpi should
63work like this:
64
65In a really perfect world:
66echo 1 > /proc/acpi/sleep # for standby
67echo 2 > /proc/acpi/sleep # for suspend to ram
68echo 3 > /proc/acpi/sleep # for suspend to ram, but with more power conservative
69echo 4 > /proc/acpi/sleep # for suspend to disk
70echo 5 > /proc/acpi/sleep # for shutdown unfriendly the system
71
72and perhaps
73echo 4b > /proc/acpi/sleep # for suspend to disk via s4bios
74
75Frequently Asked Questions
76==========================
77
78Q: well, suspending a server is IMHO a really stupid thing,
79but... (Diego Zuccato):
80
81A: You bought new UPS for your server. How do you install it without
82bringing machine down? Suspend to disk, rearrange power cables,
83resume.
84
85You have your server on UPS. Power died, and UPS is indicating 30
86seconds to failure. What do you do? Suspend to disk.
87
88Ethernet card in your server died. You want to replace it. Your
89server is not hotplug capable. What do you do? Suspend to disk,
90replace ethernet card, resume. If you are fast your users will not
91even see broken connections.
92
93
94Q: Maybe I'm missing something, but why don't the regular I/O paths work?
95
96A: We do use the regular I/O paths. However we cannot restore the data
97to its original location as we load it. That would create an
98inconsistent kernel state which would certainly result in an oops.
99Instead, we load the image into unused memory and then atomically copy
100it back to it original location. This implies, of course, a maximum
101image size of half the amount of memory.
102
103There are two solutions to this:
104
105* require half of memory to be free during suspend. That way you can
106read "new" data onto free spots, then cli and copy
107
108* assume we had special "polling" ide driver that only uses memory
109between 0-640KB. That way, I'd have to make sure that 0-640KB is free
110during suspending, but otherwise it would work...
111
112suspend2 shares this fundamental limitation, but does not include user
113data and disk caches into "used memory" by saving them in
114advance. That means that the limitation goes away in practice.
115
116Q: Does linux support ACPI S4?
117
118A: Yes. That's what echo platform > /sys/power/disk does.
119
120Q: My machine doesn't work with ACPI. How can I use swsusp than ?
121
122A: Do a reboot() syscall with right parameters. Warning: glibc gets in
123its way, so check with strace:
124
125reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, 0xd000fce2)
126
127(Thanks to Peter Osterlund:)
128
129#include <unistd.h>
130#include <syscall.h>
131
132#define LINUX_REBOOT_MAGIC1 0xfee1dead
133#define LINUX_REBOOT_MAGIC2 672274793
134#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
135
136int main()
137{
138 syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
139 LINUX_REBOOT_CMD_SW_SUSPEND, 0);
140 return 0;
141}
142
143Also /sys/ interface should be still present.
144
145Q: What is 'suspend2'?
146
147A: suspend2 is 'Software Suspend 2', a forked implementation of
148suspend-to-disk which is available as separate patches for 2.4 and 2.6
149kernels from swsusp.sourceforge.net. It includes support for SMP, 4GB
150highmem and preemption. It also has a extensible architecture that
151allows for arbitrary transformations on the image (compression,
152encryption) and arbitrary backends for writing the image (eg to swap
153or an NFS share[Work In Progress]). Questions regarding suspend2
154should be sent to the mailing list available through the suspend2
155website, and not to the Linux Kernel Mailing List. We are working
156toward merging suspend2 into the mainline kernel.
157
158Q: A kernel thread must voluntarily freeze itself (call 'refrigerator').
159I found some kernel threads that don't do it, and they don't freeze
160so the system can't sleep. Is this a known behavior?
161
162A: All such kernel threads need to be fixed, one by one. Select the
163place where the thread is safe to be frozen (no kernel semaphores
164should be held at that point and it must be safe to sleep there), and
165add:
166
167 if (current->flags & PF_FREEZE)
168 refrigerator(PF_FREEZE);
169
170If the thread is needed for writing the image to storage, you should
171instead set the PF_NOFREEZE process flag when creating the thread.
172
173
174Q: What is the difference between between "platform", "shutdown" and
175"firmware" in /sys/power/disk?
176
177A:
178
179shutdown: save state in linux, then tell bios to powerdown
180
181platform: save state in linux, then tell bios to powerdown and blink
182 "suspended led"
183
184firmware: tell bios to save state itself [needs BIOS-specific suspend
185 partition, and has very little to do with swsusp]
186
187"platform" is actually right thing to do, but "shutdown" is most
188reliable.
189
190Q: I do not understand why you have such strong objections to idea of
191selective suspend.
192
193A: Do selective suspend during runtime power managment, that's okay. But
194its useless for suspend-to-disk. (And I do not see how you could use
195it for suspend-to-ram, I hope you do not want that).
196
197Lets see, so you suggest to
198
199* SUSPEND all but swap device and parents
200* Snapshot
201* Write image to disk
202* SUSPEND swap device and parents
203* Powerdown
204
205Oh no, that does not work, if swap device or its parents uses DMA,
206you've corrupted data. You'd have to do
207
208* SUSPEND all but swap device and parents
209* FREEZE swap device and parents
210* Snapshot
211* UNFREEZE swap device and parents
212* Write
213* SUSPEND swap device and parents
214
215Which means that you still need that FREEZE state, and you get more
216complicated code. (And I have not yet introduce details like system
217devices).
218
219Q: There don't seem to be any generally useful behavioral
220distinctions between SUSPEND and FREEZE.
221
222A: Doing SUSPEND when you are asked to do FREEZE is always correct,
223but it may be unneccessarily slow. If you want USB to stay simple,
224slowness may not matter to you. It can always be fixed later.
225
226For devices like disk it does matter, you do not want to spindown for
227FREEZE.
228
229Q: After resuming, system is paging heavilly, leading to very bad interactivity.
230
231A: Try running
232
233cat `cat /proc/[0-9]*/maps | grep / | sed 's:.* /:/:' | sort -u` > /dev/null
234
235after resume. swapoff -a; swapon -a may also be usefull.