upgrade to linux 2.6.10-1.12_FC2
[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  * (*) suspend/resume 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
22
23 echo shutdown > /sys/power/disk; echo disk > /sys/power/state
24
25 . If you feel ACPI works pretty well on your system, you might try
26
27 echo platform > /sys/power/disk; echo disk > /sys/power/state
28
29
30
31 Article about goals and implementation of Software Suspend for Linux
32 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33 Author: G\82ábor Kuti
34 Last revised: 2003-10-20 by Pavel Machek
35
36 Idea and goals to achieve
37
38 Nowadays it is common in several laptops that they have a suspend button. It
39 saves the state of the machine to a filesystem or to a partition and switches
40 to standby mode. Later resuming the machine the saved state is loaded back to
41 ram and the machine can continue its work. It has two real benefits. First we
42 save ourselves the time machine goes down and later boots up, energy costs
43 are real high when running from batteries. The other gain is that we don't have to
44 interrupt our programs so processes that are calculating something for a long
45 time shouldn't need to be written interruptible.
46
47 swsusp saves the state of the machine into active swaps and then reboots or
48 powerdowns.  You must explicitly specify the swap partition to resume from with
49 ``resume='' kernel option. If signature is found it loads and restores saved
50 state. If the option ``noresume'' is specified as a boot parameter, it skips
51 the resuming.
52
53 In the meantime while the system is suspended you should not add/remove any
54 of the hardware, write to the filesystems, etc.
55
56 Sleep states summary
57 ====================
58
59 There are three different interfaces you can use, /proc/acpi should
60 work like this:
61
62 In a really perfect world:
63 echo 1 > /proc/acpi/sleep       # for standby
64 echo 2 > /proc/acpi/sleep       # for suspend to ram
65 echo 3 > /proc/acpi/sleep       # for suspend to ram, but with more power conservative
66 echo 4 > /proc/acpi/sleep       # for suspend to disk
67 echo 5 > /proc/acpi/sleep       # for shutdown unfriendly the system
68
69 and perhaps
70 echo 4b > /proc/acpi/sleep      # for suspend to disk via s4bios
71
72 Frequently Asked Questions
73 ==========================
74
75 Q: well, suspending a server is IMHO a really stupid thing,
76 but... (Diego Zuccato):
77
78 A: You bought new UPS for your server. How do you install it without
79 bringing machine down? Suspend to disk, rearrange power cables,
80 resume.
81
82 You have your server on UPS. Power died, and UPS is indicating 30
83 seconds to failure. What do you do? Suspend to disk.
84
85 Ethernet card in your server died. You want to replace it. Your
86 server is not hotplug capable. What do you do? Suspend to disk,
87 replace ethernet card, resume. If you are fast your users will not
88 even see broken connections.
89
90
91 Q: Maybe I'm missing something, but why don't the regular I/O paths work?
92
93 A: We do use the regular I/O paths. However we cannot restore the data
94 to its original location as we load it. That would create an
95 inconsistent kernel state which would certainly result in an oops.
96 Instead, we load the image into unused memory and then atomically copy
97 it back to it original location. This implies, of course, a maximum
98 image size of half the amount of memory.
99
100 There are two solutions to this:
101
102 * require half of memory to be free during suspend. That way you can
103 read "new" data onto free spots, then cli and copy
104
105 * assume we had special "polling" ide driver that only uses memory
106 between 0-640KB. That way, I'd have to make sure that 0-640KB is free
107 during suspending, but otherwise it would work...
108
109 suspend2 shares this fundamental limitation, but does not include user
110 data and disk caches into "used memory" by saving them in
111 advance. That means that the limitation goes away in practice.
112
113 Q: Does linux support ACPI S4?
114
115 A: Yes. That's what echo platform > /sys/power/disk does.
116
117 Q: My machine doesn't work with ACPI. How can I use swsusp than ?
118
119 A: Do a reboot() syscall with right parameters. Warning: glibc gets in
120 its way, so check with strace:
121
122 reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, 0xd000fce2)
123
124 (Thanks to Peter Osterlund:)
125
126 #include <unistd.h>
127 #include <syscall.h>
128
129 #define LINUX_REBOOT_MAGIC1     0xfee1dead
130 #define LINUX_REBOOT_MAGIC2     672274793
131 #define LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
132
133 int main()
134 {
135     syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
136             LINUX_REBOOT_CMD_SW_SUSPEND, 0);
137     return 0;
138 }
139
140 Also /sys/ interface should be still present.
141
142 Q: What is 'suspend2'?
143
144 A: suspend2 is 'Software Suspend 2', a forked implementation of
145 suspend-to-disk which is available as separate patches for 2.4 and 2.6
146 kernels from swsusp.sourceforge.net. It includes support for SMP, 4GB
147 highmem and preemption. It also has a extensible architecture that
148 allows for arbitrary transformations on the image (compression,
149 encryption) and arbitrary backends for writing the image (eg to swap
150 or an NFS share[Work In Progress]). Questions regarding suspend2
151 should be sent to the mailing list available through the suspend2
152 website, and not to the Linux Kernel Mailing List. We are working
153 toward merging suspend2 into the mainline kernel.
154
155 Q: A kernel thread must voluntarily freeze itself (call 'refrigerator').
156 I found some kernel threads that don't do it, and they don't freeze
157 so the system can't sleep. Is this a known behavior?
158
159 A: All such kernel threads need to be fixed, one by one. Select the
160 place where the thread is safe to be frozen (no kernel semaphores
161 should be held at that point and it must be safe to sleep there), and
162 add:
163
164             if (current->flags & PF_FREEZE)
165                     refrigerator(PF_FREEZE);
166
167 If the thread is needed for writing the image to storage, you should
168 instead set the PF_NOFREEZE process flag when creating the thread.
169
170
171 Q: What is the difference between between "platform", "shutdown" and
172 "firmware" in /sys/power/disk?
173
174 A:
175
176 shutdown: save state in linux, then tell bios to powerdown
177
178 platform: save state in linux, then tell bios to powerdown and blink
179           "suspended led"
180
181 firmware: tell bios to save state itself [needs BIOS-specific suspend
182           partition, and has very little to do with swsusp]
183
184 "platform" is actually right thing to do, but "shutdown" is most
185 reliable.