diff options
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/power/devices.txt | 847 | ||||
-rw-r--r-- | Documentation/power/pm_qos_interface.txt | 48 | ||||
-rw-r--r-- | Documentation/power/userland-swsusp.txt | 4 |
3 files changed, 512 insertions, 387 deletions
diff --git a/Documentation/power/devices.txt b/Documentation/power/devices.txt index c9abbd86bc18..57080cd74575 100644 --- a/Documentation/power/devices.txt +++ b/Documentation/power/devices.txt | |||
@@ -1,7 +1,13 @@ | |||
1 | Device Power Management | ||
2 | |||
3 | Copyright (c) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. | ||
4 | Copyright (c) 2010 Alan Stern <stern@rowland.harvard.edu> | ||
5 | |||
6 | |||
1 | Most of the code in Linux is device drivers, so most of the Linux power | 7 | Most of the code in Linux is device drivers, so most of the Linux power |
2 | management code is also driver-specific. Most drivers will do very little; | 8 | management (PM) code is also driver-specific. Most drivers will do very |
3 | others, especially for platforms with small batteries (like cell phones), | 9 | little; others, especially for platforms with small batteries (like cell |
4 | will do a lot. | 10 | phones), will do a lot. |
5 | 11 | ||
6 | This writeup gives an overview of how drivers interact with system-wide | 12 | This writeup gives an overview of how drivers interact with system-wide |
7 | power management goals, emphasizing the models and interfaces that are | 13 | power management goals, emphasizing the models and interfaces that are |
@@ -15,9 +21,10 @@ Drivers will use one or both of these models to put devices into low-power | |||
15 | states: | 21 | states: |
16 | 22 | ||
17 | System Sleep model: | 23 | System Sleep model: |
18 | Drivers can enter low power states as part of entering system-wide | 24 | Drivers can enter low-power states as part of entering system-wide |
19 | low-power states like "suspend-to-ram", or (mostly for systems with | 25 | low-power states like "suspend" (also known as "suspend-to-RAM"), or |
20 | disks) "hibernate" (suspend-to-disk). | 26 | (mostly for systems with disks) "hibernation" (also known as |
27 | "suspend-to-disk"). | ||
21 | 28 | ||
22 | This is something that device, bus, and class drivers collaborate on | 29 | This is something that device, bus, and class drivers collaborate on |
23 | by implementing various role-specific suspend and resume methods to | 30 | by implementing various role-specific suspend and resume methods to |
@@ -25,33 +32,41 @@ states: | |||
25 | them without loss of data. | 32 | them without loss of data. |
26 | 33 | ||
27 | Some drivers can manage hardware wakeup events, which make the system | 34 | Some drivers can manage hardware wakeup events, which make the system |
28 | leave that low-power state. This feature may be disabled using the | 35 | leave the low-power state. This feature may be enabled or disabled |
29 | relevant /sys/devices/.../power/wakeup file; enabling it may cost some | 36 | using the relevant /sys/devices/.../power/wakeup file (for Ethernet |
30 | power usage, but let the whole system enter low power states more often. | 37 | drivers the ioctl interface used by ethtool may also be used for this |
38 | purpose); enabling it may cost some power usage, but let the whole | ||
39 | system enter low-power states more often. | ||
31 | 40 | ||
32 | Runtime Power Management model: | 41 | Runtime Power Management model: |
33 | Drivers may also enter low power states while the system is running, | 42 | Devices may also be put into low-power states while the system is |
34 | independently of other power management activity. Upstream drivers | 43 | running, independently of other power management activity in principle. |
35 | will normally not know (or care) if the device is in some low power | 44 | However, devices are not generally independent of each other (for |
36 | state when issuing requests; the driver will auto-resume anything | 45 | example, a parent device cannot be suspended unless all of its child |
37 | that's needed when it gets a request. | 46 | devices have been suspended). Moreover, depending on the bus type the |
38 | 47 | device is on, it may be necessary to carry out some bus-specific | |
39 | This doesn't have, or need much infrastructure; it's just something you | 48 | operations on the device for this purpose. Devices put into low power |
40 | should do when writing your drivers. For example, clk_disable() unused | 49 | states at run time may require special handling during system-wide power |
41 | clocks as part of minimizing power drain for currently-unused hardware. | 50 | transitions (suspend or hibernation). |
42 | Of course, sometimes clusters of drivers will collaborate with each | 51 | |
43 | other, which could involve task-specific power management. | 52 | For these reasons not only the device driver itself, but also the |
44 | 53 | appropriate subsystem (bus type, device type or device class) driver and | |
45 | There's not a lot to be said about those low power states except that they | 54 | the PM core are involved in runtime power management. As in the system |
46 | are very system-specific, and often device-specific. Also, that if enough | 55 | sleep power management case, they need to collaborate by implementing |
47 | drivers put themselves into low power states (at "runtime"), the effect may be | 56 | various role-specific suspend and resume methods, so that the hardware |
48 | the same as entering some system-wide low-power state (system sleep) ... and | 57 | is cleanly powered down and reactivated without data or service loss. |
49 | that synergies exist, so that several drivers using runtime pm might put the | 58 | |
50 | system into a state where even deeper power saving options are available. | 59 | There's not a lot to be said about those low-power states except that they are |
51 | 60 | very system-specific, and often device-specific. Also, that if enough devices | |
52 | Most suspended devices will have quiesced all I/O: no more DMA or irqs, no | 61 | have been put into low-power states (at runtime), the effect may be very similar |
53 | more data read or written, and requests from upstream drivers are no longer | 62 | to entering some system-wide low-power state (system sleep) ... and that |
54 | accepted. A given bus or platform may have different requirements though. | 63 | synergies exist, so that several drivers using runtime PM might put the system |
64 | into a state where even deeper power saving options are available. | ||
65 | |||
66 | Most suspended devices will have quiesced all I/O: no more DMA or IRQs (except | ||
67 | for wakeup events), no more data read or written, and requests from upstream | ||
68 | drivers are no longer accepted. A given bus or platform may have different | ||
69 | requirements though. | ||
55 | 70 | ||
56 | Examples of hardware wakeup events include an alarm from a real time clock, | 71 | Examples of hardware wakeup events include an alarm from a real time clock, |
57 | network wake-on-LAN packets, keyboard or mouse activity, and media insertion | 72 | network wake-on-LAN packets, keyboard or mouse activity, and media insertion |
@@ -60,129 +75,152 @@ or removal (for PCMCIA, MMC/SD, USB, and so on). | |||
60 | 75 | ||
61 | Interfaces for Entering System Sleep States | 76 | Interfaces for Entering System Sleep States |
62 | =========================================== | 77 | =========================================== |
63 | Most of the programming interfaces a device driver needs to know about | 78 | There are programming interfaces provided for subsystems (bus type, device type, |
64 | relate to that first model: entering a system-wide low power state, | 79 | device class) and device drivers to allow them to participate in the power |
65 | rather than just minimizing power consumption by one device. | 80 | management of devices they are concerned with. These interfaces cover both |
66 | 81 | system sleep and runtime power management. | |
67 | 82 | ||
68 | Bus Driver Methods | 83 | |
69 | ------------------ | 84 | Device Power Management Operations |
70 | The core methods to suspend and resume devices reside in struct bus_type. | 85 | ---------------------------------- |
71 | These are mostly of interest to people writing infrastructure for busses | 86 | Device power management operations, at the subsystem level as well as at the |
72 | like PCI or USB, or because they define the primitives that device drivers | 87 | device driver level, are implemented by defining and populating objects of type |
73 | may need to apply in domain-specific ways to their devices: | 88 | struct dev_pm_ops: |
74 | 89 | ||
75 | struct bus_type { | 90 | struct dev_pm_ops { |
76 | ... | 91 | int (*prepare)(struct device *dev); |
77 | int (*suspend)(struct device *dev, pm_message_t state); | 92 | void (*complete)(struct device *dev); |
78 | int (*resume)(struct device *dev); | 93 | int (*suspend)(struct device *dev); |
94 | int (*resume)(struct device *dev); | ||
95 | int (*freeze)(struct device *dev); | ||
96 | int (*thaw)(struct device *dev); | ||
97 | int (*poweroff)(struct device *dev); | ||
98 | int (*restore)(struct device *dev); | ||
99 | int (*suspend_noirq)(struct device *dev); | ||
100 | int (*resume_noirq)(struct device *dev); | ||
101 | int (*freeze_noirq)(struct device *dev); | ||
102 | int (*thaw_noirq)(struct device *dev); | ||
103 | int (*poweroff_noirq)(struct device *dev); | ||
104 | int (*restore_noirq)(struct device *dev); | ||
105 | int (*runtime_suspend)(struct device *dev); | ||
106 | int (*runtime_resume)(struct device *dev); | ||
107 | int (*runtime_idle)(struct device *dev); | ||
79 | }; | 108 | }; |
80 | 109 | ||
81 | Bus drivers implement those methods as appropriate for the hardware and | 110 | This structure is defined in include/linux/pm.h and the methods included in it |
82 | the drivers using it; PCI works differently from USB, and so on. Not many | 111 | are also described in that file. Their roles will be explained in what follows. |
83 | people write bus drivers; most driver code is a "device driver" that | 112 | For now, it should be sufficient to remember that the last three methods are |
84 | builds on top of bus-specific framework code. | 113 | specific to runtime power management while the remaining ones are used during |
114 | system-wide power transitions. | ||
85 | 115 | ||
86 | For more information on these driver calls, see the description later; | 116 | There also is a deprecated "old" or "legacy" interface for power management |
87 | they are called in phases for every device, respecting the parent-child | 117 | operations available at least for some subsystems. This approach does not use |
88 | sequencing in the driver model tree. Note that as this is being written, | 118 | struct dev_pm_ops objects and it is suitable only for implementing system sleep |
89 | only the suspend() and resume() are widely available; not many bus drivers | 119 | power management methods. Therefore it is not described in this document, so |
90 | leverage all of those phases, or pass them down to lower driver levels. | 120 | please refer directly to the source code for more information about it. |
91 | 121 | ||
92 | 122 | ||
93 | /sys/devices/.../power/wakeup files | 123 | Subsystem-Level Methods |
94 | ----------------------------------- | 124 | ----------------------- |
95 | All devices in the driver model have two flags to control handling of | 125 | The core methods to suspend and resume devices reside in struct dev_pm_ops |
96 | wakeup events, which are hardware signals that can force the device and/or | 126 | pointed to by the pm member of struct bus_type, struct device_type and |
97 | system out of a low power state. These are initialized by bus or device | 127 | struct class. They are mostly of interest to the people writing infrastructure |
98 | driver code using device_init_wakeup(dev,can_wakeup). | 128 | for buses, like PCI or USB, or device type and device class drivers. |
99 | 129 | ||
100 | The "can_wakeup" flag just records whether the device (and its driver) can | 130 | Bus drivers implement these methods as appropriate for the hardware and the |
101 | physically support wakeup events. When that flag is clear, the sysfs | 131 | drivers using it; PCI works differently from USB, and so on. Not many people |
102 | "wakeup" file is empty, and device_may_wakeup() returns false. | 132 | write subsystem-level drivers; most driver code is a "device driver" that builds |
133 | on top of bus-specific framework code. | ||
103 | 134 | ||
104 | For devices that can issue wakeup events, a separate flag controls whether | 135 | For more information on these driver calls, see the description later; |
105 | that device should try to use its wakeup mechanism. The initial value of | 136 | they are called in phases for every device, respecting the parent-child |
106 | device_may_wakeup() will be true, so that the device's "wakeup" file holds | 137 | sequencing in the driver model tree. |
107 | the value "enabled". Userspace can change that to "disabled" so that | ||
108 | device_may_wakeup() returns false; or change it back to "enabled" (so that | ||
109 | it returns true again). | ||
110 | 138 | ||
111 | 139 | ||
112 | EXAMPLE: PCI Device Driver Methods | 140 | /sys/devices/.../power/wakeup files |
113 | ----------------------------------- | 141 | ----------------------------------- |
114 | PCI framework software calls these methods when the PCI device driver bound | 142 | All devices in the driver model have two flags to control handling of wakeup |
115 | to a device device has provided them: | 143 | events (hardware signals that can force the device and/or system out of a low |
116 | 144 | power state). These flags are initialized by bus or device driver code using | |
117 | struct pci_driver { | 145 | device_set_wakeup_capable() and device_set_wakeup_enable(), defined in |
118 | ... | 146 | include/linux/pm_wakeup.h. |
119 | int (*suspend)(struct pci_device *pdev, pm_message_t state); | ||
120 | int (*suspend_late)(struct pci_device *pdev, pm_message_t state); | ||
121 | 147 | ||
122 | int (*resume_early)(struct pci_device *pdev); | 148 | The "can_wakeup" flag just records whether the device (and its driver) can |
123 | int (*resume)(struct pci_device *pdev); | 149 | physically support wakeup events. The device_set_wakeup_capable() routine |
124 | }; | 150 | affects this flag. The "should_wakeup" flag controls whether the device should |
125 | 151 | try to use its wakeup mechanism. device_set_wakeup_enable() affects this flag; | |
126 | Drivers will implement those methods, and call PCI-specific procedures | 152 | for the most part drivers should not change its value. The initial value of |
127 | like pci_set_power_state(), pci_enable_wake(), pci_save_state(), and | 153 | should_wakeup is supposed to be false for the majority of devices; the major |
128 | pci_restore_state() to manage PCI-specific mechanisms. (PCI config space | 154 | exceptions are power buttons, keyboards, and Ethernet adapters whose WoL |
129 | could be saved during driver probe, if it weren't for the fact that some | 155 | (wake-on-LAN) feature has been set up with ethtool. |
130 | systems rely on userspace tweaking using setpci.) Devices are suspended | 156 | |
131 | before their bridges enter low power states, and likewise bridges resume | 157 | Whether or not a device is capable of issuing wakeup events is a hardware |
132 | before their devices. | 158 | matter, and the kernel is responsible for keeping track of it. By contrast, |
133 | 159 | whether or not a wakeup-capable device should issue wakeup events is a policy | |
134 | 160 | decision, and it is managed by user space through a sysfs attribute: the | |
135 | Upper Layers of Driver Stacks | 161 | power/wakeup file. User space can write the strings "enabled" or "disabled" to |
136 | ----------------------------- | 162 | set or clear the should_wakeup flag, respectively. Reads from the file will |
137 | Device drivers generally have at least two interfaces, and the methods | 163 | return the corresponding string if can_wakeup is true, but if can_wakeup is |
138 | sketched above are the ones which apply to the lower level (nearer PCI, USB, | 164 | false then reads will return an empty string, to indicate that the device |
139 | or other bus hardware). The network and block layers are examples of upper | 165 | doesn't support wakeup events. (But even though the file appears empty, writes |
140 | level interfaces, as is a character device talking to userspace. | 166 | will still affect the should_wakeup flag.) |
141 | 167 | ||
142 | Power management requests normally need to flow through those upper levels, | 168 | The device_may_wakeup() routine returns true only if both flags are set. |
143 | which often use domain-oriented requests like "blank that screen". In | 169 | Drivers should check this routine when putting devices in a low-power state |
144 | some cases those upper levels will have power management intelligence that | 170 | during a system sleep transition, to see whether or not to enable the devices' |
145 | relates to end-user activity, or other devices that work in cooperation. | 171 | wakeup mechanisms. However for runtime power management, wakeup events should |
146 | 172 | be enabled whenever the device and driver both support them, regardless of the | |
147 | When those interfaces are structured using class interfaces, there is a | 173 | should_wakeup flag. |
148 | standard way to have the upper layer stop issuing requests to a given | 174 | |
149 | class device (and restart later): | 175 | |
150 | 176 | /sys/devices/.../power/control files | |
151 | struct class { | 177 | ------------------------------------ |
152 | ... | 178 | Each device in the driver model has a flag to control whether it is subject to |
153 | int (*suspend)(struct device *dev, pm_message_t state); | 179 | runtime power management. This flag, called runtime_auto, is initialized by the |
154 | int (*resume)(struct device *dev); | 180 | bus type (or generally subsystem) code using pm_runtime_allow() or |
155 | }; | 181 | pm_runtime_forbid(); the default is to allow runtime power management. |
156 | 182 | ||
157 | Those calls are issued in specific phases of the process by which the | 183 | The setting can be adjusted by user space by writing either "on" or "auto" to |
158 | system enters a low power "suspend" state, or resumes from it. | 184 | the device's power/control sysfs file. Writing "auto" calls pm_runtime_allow(), |
159 | 185 | setting the flag and allowing the device to be runtime power-managed by its | |
160 | 186 | driver. Writing "on" calls pm_runtime_forbid(), clearing the flag, returning | |
161 | Calling Drivers to Enter System Sleep States | 187 | the device to full power if it was in a low-power state, and preventing the |
162 | ============================================ | 188 | device from being runtime power-managed. User space can check the current value |
163 | When the system enters a low power state, each device's driver is asked | 189 | of the runtime_auto flag by reading the file. |
164 | to suspend the device by putting it into state compatible with the target | 190 | |
191 | The device's runtime_auto flag has no effect on the handling of system-wide | ||
192 | power transitions. In particular, the device can (and in the majority of cases | ||
193 | should and will) be put into a low-power state during a system-wide transition | ||
194 | to a sleep state even though its runtime_auto flag is clear. | ||
195 | |||
196 | For more information about the runtime power management framework, refer to | ||
197 | Documentation/power/runtime_pm.txt. | ||
198 | |||
199 | |||
200 | Calling Drivers to Enter and Leave System Sleep States | ||
201 | ====================================================== | ||
202 | When the system goes into a sleep state, each device's driver is asked to | ||
203 | suspend the device by putting it into a state compatible with the target | ||
165 | system state. That's usually some version of "off", but the details are | 204 | system state. That's usually some version of "off", but the details are |
166 | system-specific. Also, wakeup-enabled devices will usually stay partly | 205 | system-specific. Also, wakeup-enabled devices will usually stay partly |
167 | functional in order to wake the system. | 206 | functional in order to wake the system. |
168 | 207 | ||
169 | When the system leaves that low power state, the device's driver is asked | 208 | When the system leaves that low-power state, the device's driver is asked to |
170 | to resume it. The suspend and resume operations always go together, and | 209 | resume it by returning it to full power. The suspend and resume operations |
171 | both are multi-phase operations. | 210 | always go together, and both are multi-phase operations. |
172 | 211 | ||
173 | For simple drivers, suspend might quiesce the device using the class code | 212 | For simple drivers, suspend might quiesce the device using class code |
174 | and then turn its hardware as "off" as possible with late_suspend. The | 213 | and then turn its hardware as "off" as possible during suspend_noirq. The |
175 | matching resume calls would then completely reinitialize the hardware | 214 | matching resume calls would then completely reinitialize the hardware |
176 | before reactivating its class I/O queues. | 215 | before reactivating its class I/O queues. |
177 | 216 | ||
178 | More power-aware drivers drivers will use more than one device low power | 217 | More power-aware drivers might prepare the devices for triggering system wakeup |
179 | state, either at runtime or during system sleep states, and might trigger | 218 | events. |
180 | system wakeup events. | ||
181 | 219 | ||
182 | 220 | ||
183 | Call Sequence Guarantees | 221 | Call Sequence Guarantees |
184 | ------------------------ | 222 | ------------------------ |
185 | To ensure that bridges and similar links needed to talk to a device are | 223 | To ensure that bridges and similar links needing to talk to a device are |
186 | available when the device is suspended or resumed, the device tree is | 224 | available when the device is suspended or resumed, the device tree is |
187 | walked in a bottom-up order to suspend devices. A top-down order is | 225 | walked in a bottom-up order to suspend devices. A top-down order is |
188 | used to resume those devices. | 226 | used to resume those devices. |
@@ -194,67 +232,310 @@ its parent; and can't be removed or suspended after that parent. | |||
194 | The policy is that the device tree should match hardware bus topology. | 232 | The policy is that the device tree should match hardware bus topology. |
195 | (Or at least the control bus, for devices which use multiple busses.) | 233 | (Or at least the control bus, for devices which use multiple busses.) |
196 | In particular, this means that a device registration may fail if the parent of | 234 | In particular, this means that a device registration may fail if the parent of |
197 | the device is suspending (ie. has been chosen by the PM core as the next | 235 | the device is suspending (i.e. has been chosen by the PM core as the next |
198 | device to suspend) or has already suspended, as well as after all of the other | 236 | device to suspend) or has already suspended, as well as after all of the other |
199 | devices have been suspended. Device drivers must be prepared to cope with such | 237 | devices have been suspended. Device drivers must be prepared to cope with such |
200 | situations. | 238 | situations. |
201 | 239 | ||
202 | 240 | ||
203 | Suspending Devices | 241 | System Power Management Phases |
204 | ------------------ | 242 | ------------------------------ |
205 | Suspending a given device is done in several phases. Suspending the | 243 | Suspending or resuming the system is done in several phases. Different phases |
206 | system always includes every phase, executing calls for every device | 244 | are used for standby or memory sleep states ("suspend-to-RAM") and the |
207 | before the next phase begins. Not all busses or classes support all | 245 | hibernation state ("suspend-to-disk"). Each phase involves executing callbacks |
208 | these callbacks; and not all drivers use all the callbacks. | 246 | for every device before the next phase begins. Not all busses or classes |
247 | support all these callbacks and not all drivers use all the callbacks. The | ||
248 | various phases always run after tasks have been frozen and before they are | ||
249 | unfrozen. Furthermore, the *_noirq phases run at a time when IRQ handlers have | ||
250 | been disabled (except for those marked with the IRQ_WAKEUP flag). | ||
209 | 251 | ||
210 | The phases are seen by driver notifications issued in this order: | 252 | Most phases use bus, type, and class callbacks (that is, methods defined in |
253 | dev->bus->pm, dev->type->pm, and dev->class->pm). The prepare and complete | ||
254 | phases are exceptions; they use only bus callbacks. When multiple callbacks | ||
255 | are used in a phase, they are invoked in the order: <class, type, bus> during | ||
256 | power-down transitions and in the opposite order during power-up transitions. | ||
257 | For example, during the suspend phase the PM core invokes | ||
211 | 258 | ||
212 | 1 class.suspend(dev, message) is called after tasks are frozen, for | 259 | dev->class->pm.suspend(dev); |
213 | devices associated with a class that has such a method. This | 260 | dev->type->pm.suspend(dev); |
214 | method may sleep. | 261 | dev->bus->pm.suspend(dev); |
215 | 262 | ||
216 | Since I/O activity usually comes from such higher layers, this is | 263 | before moving on to the next device, whereas during the resume phase the core |
217 | a good place to quiesce all drivers of a given type (and keep such | 264 | invokes |
218 | code out of those drivers). | ||
219 | 265 | ||
220 | 2 bus.suspend(dev, message) is called next. This method may sleep, | 266 | dev->bus->pm.resume(dev); |
221 | and is often morphed into a device driver call with bus-specific | 267 | dev->type->pm.resume(dev); |
222 | parameters and/or rules. | 268 | dev->class->pm.resume(dev); |
223 | 269 | ||
224 | This call should handle parts of device suspend logic that require | 270 | These callbacks may in turn invoke device- or driver-specific methods stored in |
225 | sleeping. It probably does work to quiesce the device which hasn't | 271 | dev->driver->pm, but they don't have to. |
226 | been abstracted into class.suspend(). | ||
227 | 272 | ||
228 | The pm_message_t parameter is currently used to refine those semantics | ||
229 | (described later). | ||
230 | 273 | ||
231 | At the end of those phases, drivers should normally have stopped all I/O | 274 | Entering System Suspend |
232 | transactions (DMA, IRQs), saved enough state that they can re-initialize | 275 | ----------------------- |
233 | or restore previous state (as needed by the hardware), and placed the | 276 | When the system goes into the standby or memory sleep state, the phases are: |
234 | device into a low-power state. On many platforms they will also use | 277 | |
235 | clk_disable() to gate off one or more clock sources; sometimes they will | 278 | prepare, suspend, suspend_noirq. |
236 | also switch off power supplies, or reduce voltages. Drivers which have | 279 | |
237 | runtime PM support may already have performed some or all of the steps | 280 | 1. The prepare phase is meant to prevent races by preventing new devices |
238 | needed to prepare for the upcoming system sleep state. | 281 | from being registered; the PM core would never know that all the |
282 | children of a device had been suspended if new children could be | ||
283 | registered at will. (By contrast, devices may be unregistered at any | ||
284 | time.) Unlike the other suspend-related phases, during the prepare | ||
285 | phase the device tree is traversed top-down. | ||
286 | |||
287 | The prepare phase uses only a bus callback. After the callback method | ||
288 | returns, no new children may be registered below the device. The method | ||
289 | may also prepare the device or driver in some way for the upcoming | ||
290 | system power transition, but it should not put the device into a | ||
291 | low-power state. | ||
292 | |||
293 | 2. The suspend methods should quiesce the device to stop it from performing | ||
294 | I/O. They also may save the device registers and put it into the | ||
295 | appropriate low-power state, depending on the bus type the device is on, | ||
296 | and they may enable wakeup events. | ||
297 | |||
298 | 3. The suspend_noirq phase occurs after IRQ handlers have been disabled, | ||
299 | which means that the driver's interrupt handler will not be called while | ||
300 | the callback method is running. The methods should save the values of | ||
301 | the device's registers that weren't saved previously and finally put the | ||
302 | device into the appropriate low-power state. | ||
303 | |||
304 | The majority of subsystems and device drivers need not implement this | ||
305 | callback. However, bus types allowing devices to share interrupt | ||
306 | vectors, like PCI, generally need it; otherwise a driver might encounter | ||
307 | an error during the suspend phase by fielding a shared interrupt | ||
308 | generated by some other device after its own device had been set to low | ||
309 | power. | ||
310 | |||
311 | At the end of these phases, drivers should have stopped all I/O transactions | ||
312 | (DMA, IRQs), saved enough state that they can re-initialize or restore previous | ||
313 | state (as needed by the hardware), and placed the device into a low-power state. | ||
314 | On many platforms they will gate off one or more clock sources; sometimes they | ||
315 | will also switch off power supplies or reduce voltages. (Drivers supporting | ||
316 | runtime PM may already have performed some or all of these steps.) | ||
317 | |||
318 | If device_may_wakeup(dev) returns true, the device should be prepared for | ||
319 | generating hardware wakeup signals to trigger a system wakeup event when the | ||
320 | system is in the sleep state. For example, enable_irq_wake() might identify | ||
321 | GPIO signals hooked up to a switch or other external hardware, and | ||
322 | pci_enable_wake() does something similar for the PCI PME signal. | ||
323 | |||
324 | If any of these callbacks returns an error, the system won't enter the desired | ||
325 | low-power state. Instead the PM core will unwind its actions by resuming all | ||
326 | the devices that were suspended. | ||
327 | |||
328 | |||
329 | Leaving System Suspend | ||
330 | ---------------------- | ||
331 | When resuming from standby or memory sleep, the phases are: | ||
332 | |||
333 | resume_noirq, resume, complete. | ||
334 | |||
335 | 1. The resume_noirq callback methods should perform any actions needed | ||
336 | before the driver's interrupt handlers are invoked. This generally | ||
337 | means undoing the actions of the suspend_noirq phase. If the bus type | ||
338 | permits devices to share interrupt vectors, like PCI, the method should | ||
339 | bring the device and its driver into a state in which the driver can | ||
340 | recognize if the device is the source of incoming interrupts, if any, | ||
341 | and handle them correctly. | ||
342 | |||
343 | For example, the PCI bus type's ->pm.resume_noirq() puts the device into | ||
344 | the full-power state (D0 in the PCI terminology) and restores the | ||
345 | standard configuration registers of the device. Then it calls the | ||
346 | device driver's ->pm.resume_noirq() method to perform device-specific | ||
347 | actions. | ||
348 | |||
349 | 2. The resume methods should bring the the device back to its operating | ||
350 | state, so that it can perform normal I/O. This generally involves | ||
351 | undoing the actions of the suspend phase. | ||
352 | |||
353 | 3. The complete phase uses only a bus callback. The method should undo the | ||
354 | actions of the prepare phase. Note, however, that new children may be | ||
355 | registered below the device as soon as the resume callbacks occur; it's | ||
356 | not necessary to wait until the complete phase. | ||
357 | |||
358 | At the end of these phases, drivers should be as functional as they were before | ||
359 | suspending: I/O can be performed using DMA and IRQs, and the relevant clocks are | ||
360 | gated on. Even if the device was in a low-power state before the system sleep | ||
361 | because of runtime power management, afterwards it should be back in its | ||
362 | full-power state. There are multiple reasons why it's best to do this; they are | ||
363 | discussed in more detail in Documentation/power/runtime_pm.txt. | ||
239 | 364 | ||
240 | When any driver sees that its device_can_wakeup(dev), it should make sure | 365 | However, the details here may again be platform-specific. For example, |
241 | to use the relevant hardware signals to trigger a system wakeup event. | 366 | some systems support multiple "run" states, and the mode in effect at |
242 | For example, enable_irq_wake() might identify GPIO signals hooked up to | 367 | the end of resume might not be the one which preceded suspension. |
243 | a switch or other external hardware, and pci_enable_wake() does something | 368 | That means availability of certain clocks or power supplies changed, |
244 | similar for PCI's PME# signal. | 369 | which could easily affect how a driver works. |
370 | |||
371 | Drivers need to be able to handle hardware which has been reset since the | ||
372 | suspend methods were called, for example by complete reinitialization. | ||
373 | This may be the hardest part, and the one most protected by NDA'd documents | ||
374 | and chip errata. It's simplest if the hardware state hasn't changed since | ||
375 | the suspend was carried out, but that can't be guaranteed (in fact, it ususally | ||
376 | is not the case). | ||
377 | |||
378 | Drivers must also be prepared to notice that the device has been removed | ||
379 | while the system was powered down, whenever that's physically possible. | ||
380 | PCMCIA, MMC, USB, Firewire, SCSI, and even IDE are common examples of busses | ||
381 | where common Linux platforms will see such removal. Details of how drivers | ||
382 | will notice and handle such removals are currently bus-specific, and often | ||
383 | involve a separate thread. | ||
384 | |||
385 | These callbacks may return an error value, but the PM core will ignore such | ||
386 | errors since there's nothing it can do about them other than printing them in | ||
387 | the system log. | ||
388 | |||
389 | |||
390 | Entering Hibernation | ||
391 | -------------------- | ||
392 | Hibernating the system is more complicated than putting it into the standby or | ||
393 | memory sleep state, because it involves creating and saving a system image. | ||
394 | Therefore there are more phases for hibernation, with a different set of | ||
395 | callbacks. These phases always run after tasks have been frozen and memory has | ||
396 | been freed. | ||
397 | |||
398 | The general procedure for hibernation is to quiesce all devices (freeze), create | ||
399 | an image of the system memory while everything is stable, reactivate all | ||
400 | devices (thaw), write the image to permanent storage, and finally shut down the | ||
401 | system (poweroff). The phases used to accomplish this are: | ||
402 | |||
403 | prepare, freeze, freeze_noirq, thaw_noirq, thaw, complete, | ||
404 | prepare, poweroff, poweroff_noirq | ||
405 | |||
406 | 1. The prepare phase is discussed in the "Entering System Suspend" section | ||
407 | above. | ||
408 | |||
409 | 2. The freeze methods should quiesce the device so that it doesn't generate | ||
410 | IRQs or DMA, and they may need to save the values of device registers. | ||
411 | However the device does not have to be put in a low-power state, and to | ||
412 | save time it's best not to do so. Also, the device should not be | ||
413 | prepared to generate wakeup events. | ||
414 | |||
415 | 3. The freeze_noirq phase is analogous to the suspend_noirq phase discussed | ||
416 | above, except again that the device should not be put in a low-power | ||
417 | state and should not be allowed to generate wakeup events. | ||
418 | |||
419 | At this point the system image is created. All devices should be inactive and | ||
420 | the contents of memory should remain undisturbed while this happens, so that the | ||
421 | image forms an atomic snapshot of the system state. | ||
422 | |||
423 | 4. The thaw_noirq phase is analogous to the resume_noirq phase discussed | ||
424 | above. The main difference is that its methods can assume the device is | ||
425 | in the same state as at the end of the freeze_noirq phase. | ||
426 | |||
427 | 5. The thaw phase is analogous to the resume phase discussed above. Its | ||
428 | methods should bring the device back to an operating state, so that it | ||
429 | can be used for saving the image if necessary. | ||
430 | |||
431 | 6. The complete phase is discussed in the "Leaving System Suspend" section | ||
432 | above. | ||
433 | |||
434 | At this point the system image is saved, and the devices then need to be | ||
435 | prepared for the upcoming system shutdown. This is much like suspending them | ||
436 | before putting the system into the standby or memory sleep state, and the phases | ||
437 | are similar. | ||
438 | |||
439 | 7. The prepare phase is discussed above. | ||
440 | |||
441 | 8. The poweroff phase is analogous to the suspend phase. | ||
442 | |||
443 | 9. The poweroff_noirq phase is analogous to the suspend_noirq phase. | ||
444 | |||
445 | The poweroff and poweroff_noirq callbacks should do essentially the same things | ||
446 | as the suspend and suspend_noirq callbacks. The only notable difference is that | ||
447 | they need not store the device register values, because the registers should | ||
448 | already have been stored during the freeze or freeze_noirq phases. | ||
449 | |||
450 | |||
451 | Leaving Hibernation | ||
452 | ------------------- | ||
453 | Resuming from hibernation is, again, more complicated than resuming from a sleep | ||
454 | state in which the contents of main memory are preserved, because it requires | ||
455 | a system image to be loaded into memory and the pre-hibernation memory contents | ||
456 | to be restored before control can be passed back to the image kernel. | ||
457 | |||
458 | Although in principle, the image might be loaded into memory and the | ||
459 | pre-hibernation memory contents restored by the boot loader, in practice this | ||
460 | can't be done because boot loaders aren't smart enough and there is no | ||
461 | established protocol for passing the necessary information. So instead, the | ||
462 | boot loader loads a fresh instance of the kernel, called the boot kernel, into | ||
463 | memory and passes control to it in the usual way. Then the boot kernel reads | ||
464 | the system image, restores the pre-hibernation memory contents, and passes | ||
465 | control to the image kernel. Thus two different kernels are involved in | ||
466 | resuming from hibernation. In fact, the boot kernel may be completely different | ||
467 | from the image kernel: a different configuration and even a different version. | ||
468 | This has important consequences for device drivers and their subsystems. | ||
469 | |||
470 | To be able to load the system image into memory, the boot kernel needs to | ||
471 | include at least a subset of device drivers allowing it to access the storage | ||
472 | medium containing the image, although it doesn't need to include all of the | ||
473 | drivers present in the image kernel. After the image has been loaded, the | ||
474 | devices managed by the boot kernel need to be prepared for passing control back | ||
475 | to the image kernel. This is very similar to the initial steps involved in | ||
476 | creating a system image, and it is accomplished in the same way, using prepare, | ||
477 | freeze, and freeze_noirq phases. However the devices affected by these phases | ||
478 | are only those having drivers in the boot kernel; other devices will still be in | ||
479 | whatever state the boot loader left them. | ||
480 | |||
481 | Should the restoration of the pre-hibernation memory contents fail, the boot | ||
482 | kernel would go through the "thawing" procedure described above, using the | ||
483 | thaw_noirq, thaw, and complete phases, and then continue running normally. This | ||
484 | happens only rarely. Most often the pre-hibernation memory contents are | ||
485 | restored successfully and control is passed to the image kernel, which then | ||
486 | becomes responsible for bringing the system back to the working state. | ||
487 | |||
488 | To achieve this, the image kernel must restore the devices' pre-hibernation | ||
489 | functionality. The operation is much like waking up from the memory sleep | ||
490 | state, although it involves different phases: | ||
491 | |||
492 | restore_noirq, restore, complete | ||
493 | |||
494 | 1. The restore_noirq phase is analogous to the resume_noirq phase. | ||
495 | |||
496 | 2. The restore phase is analogous to the resume phase. | ||
497 | |||
498 | 3. The complete phase is discussed above. | ||
499 | |||
500 | The main difference from resume[_noirq] is that restore[_noirq] must assume the | ||
501 | device has been accessed and reconfigured by the boot loader or the boot kernel. | ||
502 | Consequently the state of the device may be different from the state remembered | ||
503 | from the freeze and freeze_noirq phases. The device may even need to be reset | ||
504 | and completely re-initialized. In many cases this difference doesn't matter, so | ||
505 | the resume[_noirq] and restore[_norq] method pointers can be set to the same | ||
506 | routines. Nevertheless, different callback pointers are used in case there is a | ||
507 | situation where it actually matters. | ||
245 | 508 | ||
246 | If a driver (or bus, or class) fails it suspend method, the system won't | ||
247 | enter the desired low power state; it will resume all the devices it's | ||
248 | suspended so far. | ||
249 | 509 | ||
250 | Note that drivers may need to perform different actions based on the target | 510 | System Devices |
251 | system lowpower/sleep state. At this writing, there are only platform | 511 | -------------- |
252 | specific APIs through which drivers could determine those target states. | 512 | System devices (sysdevs) follow a slightly different API, which can be found in |
513 | |||
514 | include/linux/sysdev.h | ||
515 | drivers/base/sys.c | ||
516 | |||
517 | System devices will be suspended with interrupts disabled, and after all other | ||
518 | devices have been suspended. On resume, they will be resumed before any other | ||
519 | devices, and also with interrupts disabled. These things occur in special | ||
520 | "sysdev_driver" phases, which affect only system devices. | ||
521 | |||
522 | Thus, after the suspend_noirq (or freeze_noirq or poweroff_noirq) phase, when | ||
523 | the non-boot CPUs are all offline and IRQs are disabled on the remaining online | ||
524 | CPU, then a sysdev_driver.suspend phase is carried out, and the system enters a | ||
525 | sleep state (or a system image is created). During resume (or after the image | ||
526 | has been created or loaded) a sysdev_driver.resume phase is carried out, IRQs | ||
527 | are enabled on the only online CPU, the non-boot CPUs are enabled, and the | ||
528 | resume_noirq (or thaw_noirq or restore_noirq) phase begins. | ||
529 | |||
530 | Code to actually enter and exit the system-wide low power state sometimes | ||
531 | involves hardware details that are only known to the boot firmware, and | ||
532 | may leave a CPU running software (from SRAM or flash memory) that monitors | ||
533 | the system and manages its wakeup sequence. | ||
253 | 534 | ||
254 | 535 | ||
255 | Device Low Power (suspend) States | 536 | Device Low Power (suspend) States |
256 | --------------------------------- | 537 | --------------------------------- |
257 | Device low-power states aren't very standard. One device might only handle | 538 | Device low-power states aren't standard. One device might only handle |
258 | "on" and "off, while another might support a dozen different versions of | 539 | "on" and "off, while another might support a dozen different versions of |
259 | "on" (how many engines are active?), plus a state that gets back to "on" | 540 | "on" (how many engines are active?), plus a state that gets back to "on" |
260 | faster than from a full "off". | 541 | faster than from a full "off". |
@@ -265,7 +546,7 @@ PCI device may not perform DMA or issue IRQs, and any wakeup events it | |||
265 | issues would be issued through the PME# bus signal. Plus, there are | 546 | issues would be issued through the PME# bus signal. Plus, there are |
266 | several PCI-standard device states, some of which are optional. | 547 | several PCI-standard device states, some of which are optional. |
267 | 548 | ||
268 | In contrast, integrated system-on-chip processors often use irqs as the | 549 | In contrast, integrated system-on-chip processors often use IRQs as the |
269 | wakeup event sources (so drivers would call enable_irq_wake) and might | 550 | wakeup event sources (so drivers would call enable_irq_wake) and might |
270 | be able to treat DMA completion as a wakeup event (sometimes DMA can stay | 551 | be able to treat DMA completion as a wakeup event (sometimes DMA can stay |
271 | active too, it'd only be the CPU and some peripherals that sleep). | 552 | active too, it'd only be the CPU and some peripherals that sleep). |
@@ -284,120 +565,17 @@ ways; the aforementioned LCD might be active in one product's "standby", | |||
284 | but a different product using the same SOC might work differently. | 565 | but a different product using the same SOC might work differently. |
285 | 566 | ||
286 | 567 | ||
287 | Meaning of pm_message_t.event | 568 | Power Management Notifiers |
288 | ----------------------------- | 569 | -------------------------- |
289 | Parameters to suspend calls include the device affected and a message of | 570 | There are some operations that cannot be carried out by the power management |
290 | type pm_message_t, which has one field: the event. If driver does not | 571 | callbacks discussed above, because the callbacks occur too late or too early. |
291 | recognize the event code, suspend calls may abort the request and return | 572 | To handle these cases, subsystems and device drivers may register power |
292 | a negative errno. However, most drivers will be fine if they implement | 573 | management notifiers that are called before tasks are frozen and after they have |
293 | PM_EVENT_SUSPEND semantics for all messages. | 574 | been thawed. Generally speaking, the PM notifiers are suitable for performing |
575 | actions that either require user space to be available, or at least won't | ||
576 | interfere with user space. | ||
294 | 577 | ||
295 | The event codes are used to refine the goal of suspending the device, and | 578 | For details refer to Documentation/power/notifiers.txt. |
296 | mostly matter when creating or resuming system memory image snapshots, as | ||
297 | used with suspend-to-disk: | ||
298 | |||
299 | PM_EVENT_SUSPEND -- quiesce the driver and put hardware into a low-power | ||
300 | state. When used with system sleep states like "suspend-to-RAM" or | ||
301 | "standby", the upcoming resume() call will often be able to rely on | ||
302 | state kept in hardware, or issue system wakeup events. | ||
303 | |||
304 | PM_EVENT_HIBERNATE -- Put hardware into a low-power state and enable wakeup | ||
305 | events as appropriate. It is only used with hibernation | ||
306 | (suspend-to-disk) and few devices are able to wake up the system from | ||
307 | this state; most are completely powered off. | ||
308 | |||
309 | PM_EVENT_FREEZE -- quiesce the driver, but don't necessarily change into | ||
310 | any low power mode. A system snapshot is about to be taken, often | ||
311 | followed by a call to the driver's resume() method. Neither wakeup | ||
312 | events nor DMA are allowed. | ||
313 | |||
314 | PM_EVENT_PRETHAW -- quiesce the driver, knowing that the upcoming resume() | ||
315 | will restore a suspend-to-disk snapshot from a different kernel image. | ||
316 | Drivers that are smart enough to look at their hardware state during | ||
317 | resume() processing need that state to be correct ... a PRETHAW could | ||
318 | be used to invalidate that state (by resetting the device), like a | ||
319 | shutdown() invocation would before a kexec() or system halt. Other | ||
320 | drivers might handle this the same way as PM_EVENT_FREEZE. Neither | ||
321 | wakeup events nor DMA are allowed. | ||
322 | |||
323 | To enter "standby" (ACPI S1) or "Suspend to RAM" (STR, ACPI S3) states, or | ||
324 | the similarly named APM states, only PM_EVENT_SUSPEND is used; the other event | ||
325 | codes are used for hibernation ("Suspend to Disk", STD, ACPI S4). | ||
326 | |||
327 | There's also PM_EVENT_ON, a value which never appears as a suspend event | ||
328 | but is sometimes used to record the "not suspended" device state. | ||
329 | |||
330 | |||
331 | Resuming Devices | ||
332 | ---------------- | ||
333 | Resuming is done in multiple phases, much like suspending, with all | ||
334 | devices processing each phase's calls before the next phase begins. | ||
335 | |||
336 | The phases are seen by driver notifications issued in this order: | ||
337 | |||
338 | 1 bus.resume(dev) reverses the effects of bus.suspend(). This may | ||
339 | be morphed into a device driver call with bus-specific parameters; | ||
340 | implementations may sleep. | ||
341 | |||
342 | 2 class.resume(dev) is called for devices associated with a class | ||
343 | that has such a method. Implementations may sleep. | ||
344 | |||
345 | This reverses the effects of class.suspend(), and would usually | ||
346 | reactivate the device's I/O queue. | ||
347 | |||
348 | At the end of those phases, drivers should normally be as functional as | ||
349 | they were before suspending: I/O can be performed using DMA and IRQs, and | ||
350 | the relevant clocks are gated on. The device need not be "fully on"; it | ||
351 | might be in a runtime lowpower/suspend state that acts as if it were. | ||
352 | |||
353 | However, the details here may again be platform-specific. For example, | ||
354 | some systems support multiple "run" states, and the mode in effect at | ||
355 | the end of resume() might not be the one which preceded suspension. | ||
356 | That means availability of certain clocks or power supplies changed, | ||
357 | which could easily affect how a driver works. | ||
358 | |||
359 | |||
360 | Drivers need to be able to handle hardware which has been reset since the | ||
361 | suspend methods were called, for example by complete reinitialization. | ||
362 | This may be the hardest part, and the one most protected by NDA'd documents | ||
363 | and chip errata. It's simplest if the hardware state hasn't changed since | ||
364 | the suspend() was called, but that can't always be guaranteed. | ||
365 | |||
366 | Drivers must also be prepared to notice that the device has been removed | ||
367 | while the system was powered off, whenever that's physically possible. | ||
368 | PCMCIA, MMC, USB, Firewire, SCSI, and even IDE are common examples of busses | ||
369 | where common Linux platforms will see such removal. Details of how drivers | ||
370 | will notice and handle such removals are currently bus-specific, and often | ||
371 | involve a separate thread. | ||
372 | |||
373 | |||
374 | Note that the bus-specific runtime PM wakeup mechanism can exist, and might | ||
375 | be defined to share some of the same driver code as for system wakeup. For | ||
376 | example, a bus-specific device driver's resume() method might be used there, | ||
377 | so it wouldn't only be called from bus.resume() during system-wide wakeup. | ||
378 | See bus-specific information about how runtime wakeup events are handled. | ||
379 | |||
380 | |||
381 | System Devices | ||
382 | -------------- | ||
383 | System devices follow a slightly different API, which can be found in | ||
384 | |||
385 | include/linux/sysdev.h | ||
386 | drivers/base/sys.c | ||
387 | |||
388 | System devices will only be suspended with interrupts disabled, and after | ||
389 | all other devices have been suspended. On resume, they will be resumed | ||
390 | before any other devices, and also with interrupts disabled. | ||
391 | |||
392 | That is, IRQs are disabled, the suspend_late() phase begins, then the | ||
393 | sysdev_driver.suspend() phase, and the system enters a sleep state. Then | ||
394 | the sysdev_driver.resume() phase begins, followed by the resume_early() | ||
395 | phase, after which IRQs are enabled. | ||
396 | |||
397 | Code to actually enter and exit the system-wide low power state sometimes | ||
398 | involves hardware details that are only known to the boot firmware, and | ||
399 | may leave a CPU running software (from SRAM or flash memory) that monitors | ||
400 | the system and manages its wakeup sequence. | ||
401 | 579 | ||
402 | 580 | ||
403 | Runtime Power Management | 581 | Runtime Power Management |
@@ -407,82 +585,23 @@ running. This feature is useful for devices that are not being used, and | |||
407 | can offer significant power savings on a running system. These devices | 585 | can offer significant power savings on a running system. These devices |
408 | often support a range of runtime power states, which might use names such | 586 | often support a range of runtime power states, which might use names such |
409 | as "off", "sleep", "idle", "active", and so on. Those states will in some | 587 | as "off", "sleep", "idle", "active", and so on. Those states will in some |
410 | cases (like PCI) be partially constrained by a bus the device uses, and will | 588 | cases (like PCI) be partially constrained by the bus the device uses, and will |
411 | usually include hardware states that are also used in system sleep states. | 589 | usually include hardware states that are also used in system sleep states. |
412 | 590 | ||
413 | However, note that if a driver puts a device into a runtime low power state | 591 | A system-wide power transition can be started while some devices are in low |
414 | and the system then goes into a system-wide sleep state, it normally ought | 592 | power states due to runtime power management. The system sleep PM callbacks |
415 | to resume into that runtime low power state rather than "full on". Such | 593 | should recognize such situations and react to them appropriately, but the |
416 | distinctions would be part of the driver-internal state machine for that | 594 | necessary actions are subsystem-specific. |
417 | hardware; the whole point of runtime power management is to be sure that | 595 | |
418 | drivers are decoupled in that way from the state machine governing phases | 596 | In some cases the decision may be made at the subsystem level while in other |
419 | of the system-wide power/sleep state transitions. | 597 | cases the device driver may be left to decide. In some cases it may be |
420 | 598 | desirable to leave a suspended device in that state during a system-wide power | |
421 | 599 | transition, but in other cases the device must be put back into the full-power | |
422 | Power Saving Techniques | 600 | state temporarily, for example so that its system wakeup capability can be |
423 | ----------------------- | 601 | disabled. This all depends on the hardware and the design of the subsystem and |
424 | Normally runtime power management is handled by the drivers without specific | 602 | device driver in question. |
425 | userspace or kernel intervention, by device-aware use of techniques like: | 603 | |
426 | 604 | During system-wide resume from a sleep state it's best to put devices into the | |
427 | Using information provided by other system layers | 605 | full-power state, as explained in Documentation/power/runtime_pm.txt. Refer to |
428 | - stay deeply "off" except between open() and close() | 606 | that document for more information regarding this particular issue as well as |
429 | - if transceiver/PHY indicates "nobody connected", stay "off" | 607 | for information on the device runtime power management framework in general. |
430 | - application protocols may include power commands or hints | ||
431 | |||
432 | Using fewer CPU cycles | ||
433 | - using DMA instead of PIO | ||
434 | - removing timers, or making them lower frequency | ||
435 | - shortening "hot" code paths | ||
436 | - eliminating cache misses | ||
437 | - (sometimes) offloading work to device firmware | ||
438 | |||
439 | Reducing other resource costs | ||
440 | - gating off unused clocks in software (or hardware) | ||
441 | - switching off unused power supplies | ||
442 | - eliminating (or delaying/merging) IRQs | ||
443 | - tuning DMA to use word and/or burst modes | ||
444 | |||
445 | Using device-specific low power states | ||
446 | - using lower voltages | ||
447 | - avoiding needless DMA transfers | ||
448 | |||
449 | Read your hardware documentation carefully to see the opportunities that | ||
450 | may be available. If you can, measure the actual power usage and check | ||
451 | it against the budget established for your project. | ||
452 | |||
453 | |||
454 | Examples: USB hosts, system timer, system CPU | ||
455 | ---------------------------------------------- | ||
456 | USB host controllers make interesting, if complex, examples. In many cases | ||
457 | these have no work to do: no USB devices are connected, or all of them are | ||
458 | in the USB "suspend" state. Linux host controller drivers can then disable | ||
459 | periodic DMA transfers that would otherwise be a constant power drain on the | ||
460 | memory subsystem, and enter a suspend state. In power-aware controllers, | ||
461 | entering that suspend state may disable the clock used with USB signaling, | ||
462 | saving a certain amount of power. | ||
463 | |||
464 | The controller will be woken from that state (with an IRQ) by changes to the | ||
465 | signal state on the data lines of a given port, for example by an existing | ||
466 | peripheral requesting "remote wakeup" or by plugging a new peripheral. The | ||
467 | same wakeup mechanism usually works from "standby" sleep states, and on some | ||
468 | systems also from "suspend to RAM" (or even "suspend to disk") states. | ||
469 | (Except that ACPI may be involved instead of normal IRQs, on some hardware.) | ||
470 | |||
471 | System devices like timers and CPUs may have special roles in the platform | ||
472 | power management scheme. For example, system timers using a "dynamic tick" | ||
473 | approach don't just save CPU cycles (by eliminating needless timer IRQs), | ||
474 | but they may also open the door to using lower power CPU "idle" states that | ||
475 | cost more than a jiffie to enter and exit. On x86 systems these are states | ||
476 | like "C3"; note that periodic DMA transfers from a USB host controller will | ||
477 | also prevent entry to a C3 state, much like a periodic timer IRQ. | ||
478 | |||
479 | That kind of runtime mechanism interaction is common. "System On Chip" (SOC) | ||
480 | processors often have low power idle modes that can't be entered unless | ||
481 | certain medium-speed clocks (often 12 or 48 MHz) are gated off. When the | ||
482 | drivers gate those clocks effectively, then the system idle task may be able | ||
483 | to use the lower power idle modes and thereby increase battery life. | ||
484 | |||
485 | If the CPU can have a "cpufreq" driver, there also may be opportunities | ||
486 | to shift to lower voltage settings and reduce the power cost of executing | ||
487 | a given number of instructions. (Without voltage adjustment, it's rare | ||
488 | for cpufreq to save much power; the cost-per-instruction must go down.) | ||
diff --git a/Documentation/power/pm_qos_interface.txt b/Documentation/power/pm_qos_interface.txt index c40866e8b957..bfed898a03fc 100644 --- a/Documentation/power/pm_qos_interface.txt +++ b/Documentation/power/pm_qos_interface.txt | |||
@@ -18,44 +18,46 @@ and pm_qos_params.h. This is done because having the available parameters | |||
18 | being runtime configurable or changeable from a driver was seen as too easy to | 18 | being runtime configurable or changeable from a driver was seen as too easy to |
19 | abuse. | 19 | abuse. |
20 | 20 | ||
21 | For each parameter a list of performance requirements is maintained along with | 21 | For each parameter a list of performance requests is maintained along with |
22 | an aggregated target value. The aggregated target value is updated with | 22 | an aggregated target value. The aggregated target value is updated with |
23 | changes to the requirement list or elements of the list. Typically the | 23 | changes to the request list or elements of the list. Typically the |
24 | aggregated target value is simply the max or min of the requirement values held | 24 | aggregated target value is simply the max or min of the request values held |
25 | in the parameter list elements. | 25 | in the parameter list elements. |
26 | 26 | ||
27 | From kernel mode the use of this interface is simple: | 27 | From kernel mode the use of this interface is simple: |
28 | pm_qos_add_requirement(param_id, name, target_value): | ||
29 | Will insert a named element in the list for that identified PM_QOS parameter | ||
30 | with the target value. Upon change to this list the new target is recomputed | ||
31 | and any registered notifiers are called only if the target value is now | ||
32 | different. | ||
33 | 28 | ||
34 | pm_qos_update_requirement(param_id, name, new_target_value): | 29 | handle = pm_qos_add_request(param_class, target_value): |
35 | Will search the list identified by the param_id for the named list element and | 30 | Will insert an element into the list for that identified PM_QOS class with the |
36 | then update its target value, calling the notification tree if the aggregated | 31 | target value. Upon change to this list the new target is recomputed and any |
37 | target is changed. with that name is already registered. | 32 | registered notifiers are called only if the target value is now different. |
33 | Clients of pm_qos need to save the returned handle. | ||
38 | 34 | ||
39 | pm_qos_remove_requirement(param_id, name): | 35 | void pm_qos_update_request(handle, new_target_value): |
40 | Will search the identified list for the named element and remove it, after | 36 | Will update the list element pointed to by the handle with the new target value |
41 | removal it will update the aggregate target and call the notification tree if | 37 | and recompute the new aggregated target, calling the notification tree if the |
42 | the target was changed as a result of removing the named requirement. | 38 | target is changed. |
39 | |||
40 | void pm_qos_remove_request(handle): | ||
41 | Will remove the element. After removal it will update the aggregate target and | ||
42 | call the notification tree if the target was changed as a result of removing | ||
43 | the request. | ||
43 | 44 | ||
44 | 45 | ||
45 | From user mode: | 46 | From user mode: |
46 | Only processes can register a pm_qos requirement. To provide for automatic | 47 | Only processes can register a pm_qos request. To provide for automatic |
47 | cleanup for process the interface requires the process to register its | 48 | cleanup of a process, the interface requires the process to register its |
48 | parameter requirements in the following way: | 49 | parameter requests in the following way: |
49 | 50 | ||
50 | To register the default pm_qos target for the specific parameter, the process | 51 | To register the default pm_qos target for the specific parameter, the process |
51 | must open one of /dev/[cpu_dma_latency, network_latency, network_throughput] | 52 | must open one of /dev/[cpu_dma_latency, network_latency, network_throughput] |
52 | 53 | ||
53 | As long as the device node is held open that process has a registered | 54 | As long as the device node is held open that process has a registered |
54 | requirement on the parameter. The name of the requirement is "process_<PID>" | 55 | request on the parameter. |
55 | derived from the current->pid from within the open system call. | ||
56 | 56 | ||
57 | To change the requested target value the process needs to write a s32 value to | 57 | To change the requested target value the process needs to write an s32 value to |
58 | the open device node. This translates to a pm_qos_update_requirement call. | 58 | the open device node. Alternatively the user mode program could write a hex |
59 | string for the value using 10 char long format e.g. "0x12345678". This | ||
60 | translates to a pm_qos_update_request call. | ||
59 | 61 | ||
60 | To remove the user mode request for a target value simply close the device | 62 | To remove the user mode request for a target value simply close the device |
61 | node. | 63 | node. |
diff --git a/Documentation/power/userland-swsusp.txt b/Documentation/power/userland-swsusp.txt index b967cd9137d6..81680f9f5909 100644 --- a/Documentation/power/userland-swsusp.txt +++ b/Documentation/power/userland-swsusp.txt | |||
@@ -24,6 +24,10 @@ assumed to be in the resume mode. The device cannot be open for simultaneous | |||
24 | reading and writing. It is also impossible to have the device open more than | 24 | reading and writing. It is also impossible to have the device open more than |
25 | once at a time. | 25 | once at a time. |
26 | 26 | ||
27 | Even opening the device has side effects. Data structures are | ||
28 | allocated, and PM_HIBERNATION_PREPARE / PM_RESTORE_PREPARE chains are | ||
29 | called. | ||
30 | |||
27 | The ioctl() commands recognized by the device are: | 31 | The ioctl() commands recognized by the device are: |
28 | 32 | ||
29 | SNAPSHOT_FREEZE - freeze user space processes (the current process is | 33 | SNAPSHOT_FREEZE - freeze user space processes (the current process is |