/[gentoo]/xml/htdocs/doc/en/power-management-guide.xml
Gentoo

Diff of /xml/htdocs/doc/en/power-management-guide.xml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.9 Revision 1.21
1<?xml version='1.0' encoding="UTF-8"?> 1<?xml version='1.0' encoding="UTF-8"?>
2<!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> 2<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
3<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/power-management-guide.xml,v 1.9 2005/03/12 16:52:22 so Exp $ --> 3<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/power-management-guide.xml,v 1.21 2006/08/17 00:45:29 rane Exp $ -->
4<guide link="power-management-guide.xml"> 4<guide link="/doc/en/power-management-guide.xml">
5<title>Power Management Guide</title> 5<title>Power Management Guide</title>
6 6
7<author title="Author"> 7<author title="Author">
8 <mail link="fragfred@gmx.de">Dennis Nienhüser</mail> 8 <mail link="earthwings@gentoo.org">Dennis Nienhüser</mail>
9</author>
10<author title="Editor">
11 <mail link="chriswhite@gentoo.org">Chris White</mail>
9</author> 12</author>
10 13
11<abstract> 14<abstract>
12Power Management is the key to extend battery run time on mobile systems like 15Power Management is the key to extend battery run time on mobile systems like
13laptops. This guide assists you setting it up on your laptop. 16laptops. This guide assists you setting it up on your laptop.
14</abstract> 17</abstract>
15 18
16<!-- The content of this document is licensed under the CC-BY-SA license --> 19<!-- The content of this document is licensed under the CC-BY-SA license -->
17<!-- See http://creativecommons.org/licenses/by-sa/2.0 --> 20<!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
18<license/> 21<license/>
19 22
20<version>1.19</version> 23<version>1.28</version>
21<date>2005-03-12</date> 24<date>2006-07-26</date>
22 25
23<chapter> 26<chapter>
24<title>Introduction</title> 27<title>Introduction</title>
25
26<section> 28<section>
27<title>Why Power Management?</title>
28
29<body> 29<body>
30 30
31<p> 31<p>
32Capacity and lifetime of laptop batteries has improved much in the last years. 32Capacity and lifetime of laptop batteries have improved much in the last years.
33Nevertheless modern processors consume much more energy than older ones and 33Nevertheless modern processors consume much more energy than older ones and
34each laptop generation introduces more devices hungry for energy. That's why 34each laptop generation introduces more devices hungry for energy. That's why
35Power Management is more important than ever. Increasing battery run time 35Power Management is more important than ever. Increasing battery run time
36doesn't necessarily mean buying another battery. Much can be achieved applying 36doesn't necessarily mean buying another battery. Much can be achieved applying
37intelligent Power Management policies. 37intelligent Power Management policies.
38</p> 38</p>
39 39
40</body> 40</body>
41</section> 41</section>
42
43<section> 42<section>
44<title>A quick overview</title> 43<title>A Quick Overview</title>
45<body> 44<body>
46 45
47<p> 46<p>
48Please notice that this guide describes Power Management for <e>laptops</e>. 47Please notice that this guide describes Power Management for <e>laptops</e>.
49While some sections might also suite for <e>servers</e>, others do not and may 48While some sections might also suite for <e>servers</e>, others do not and may
55As this guide has become rather long, here's a short overview helping you to 54As this guide has become rather long, here's a short overview helping you to
56find your way through it. 55find your way through it.
57</p> 56</p>
58 57
59<p> 58<p>
60The <e>Prerequisites</e> chapter talks about some requirements that should be 59The <uri link="#doc_chap2">Prerequisites</uri> chapter talks about some
61met before any of the following device individual sections will work. This 60requirements that should be met before any of the following device individual
62includes BIOS settings, kernel configuration and some simplifications in user 61sections will work. This includes BIOS settings, kernel configuration and some
63land. The following three chapters focus on devices that typically consume most 62simplifications in user land. The following three chapters focus on devices
64energy - processor, display and hard drive. Each can be configured seperately. 63that typically consume most energy - processor, display and hard drive. Each
65<e>CPU Power Management</e> shows how to adjust the processor's frequency to 64can be configured seperately. <uri link="#doc_chap3">CPU Power Management</uri>
66save a maximum of energy whithout losing too much performance. A few different 65shows how to adjust the processor's frequency to save a maximum of energy
67tricks prevent your hard drive from working unnecessarily often in <e>Disk Power 66without losing too much performance. A few different tricks prevent your hard
67drive from working unnecessarily often in <uri link="#doc_chap5">Disk Power
68Management</e> (decreasing noise level as a nice side effect). Some notes on 68Management</uri> (decreasing noise level as a nice side effect). Some notes on
69Wireless LAN and USB finish the device section in <e>Power Management for other 69graphics cards, Wireless LAN and USB finish the device section in <uri
70devices</e> while another chapter is dedicated to the (rather experimental) 70link="#doc_chap6">Power Management For Other Devices</uri> while another
71<e>sleep states</e>. Last not least <e>Troubleshooting</e> lists common 71chapter is dedicated to the (rather experimental) <uri link="#doc_chap7">sleep
72pitfalls. 72states</uri>. Last not least <uri link="#doc_chap8">Troubleshooting</uri> lists
73common pitfalls.
73</p> 74</p>
74 75
75</body> 76</body>
76</section>
77
78<section> 77</section>
78<section>
79<title>Power Budget for each component</title> 79<title>Power Budget For Each Component</title>
80<body> 80<body>
81 81
82<figure link="/images/energy-budget.png" short="Which component consumes how 82<figure link="/images/energy-budget.png" short="Which component consumes how
83much energy?" caption="Power budget for each component"/> 83much energy?" caption="Power budget for each component"/>
84 84
95</chapter> 95</chapter>
96 96
97<chapter> 97<chapter>
98<title>Prerequisites</title> 98<title>Prerequisites</title>
99<section> 99<section>
100<title>What has to be done first</title>
101<body>
102
103<p>
104Before going into the details on making individual devices Power Management
105aware, make sure certain requirements are met. After controlling the BIOS
106settings, some kernel options want to be enabled - these are in short ACPI,
107sleep states and CPU frequency scaling. As power saving most of the time comes
108along with performance loss or increased latency, it should only be enabled
109when running on batteries. That's where a new runlevel <e>battery</e> comes in
110handy.
111</p>
112
113</body> 100<body>
114</section> 101
102<p>
103Before discussing the details of making individual devices Power Management
104aware, make sure certain requirements are met. After controlling BIOS settings,
105some kernel options want to be enabled - these are in short ACPI, sleep states
106and CPU frequency scaling. As power saving most of the time comes along with
107performance loss or increased latency, it should only be enabled when running
108on batteries. That's where a new runlevel <e>battery</e> comes in handy.
109</p>
110
111</body>
115<section> 112</section>
113<section>
116<title>The BIOS part</title> 114<title>The BIOS Part</title>
117<body> 115<body>
118 116
119<p> 117<p>
120First have a look into your BIOS Power Management settings. The best way is to 118First have a look into your BIOS Power Management settings. The best way is to
121combine BIOS and operating system policies, but for the moment it's better to 119combine BIOS and operating system policies, but for the moment it's better to
125</p> 123</p>
126 124
127</body> 125</body>
128</section> 126</section>
129<section> 127<section>
128<title>Setting USE Flags</title>
129<body>
130
131<p>
132Please check that the <c>acpi</c> USE flag is set in
133<path>/etc/make.conf</path>. Other USE flags that might be interesting for your
134system are <c>apm</c>, <c>lm_sensors</c>, <c>nforce2</c>, <c>nvidia</c>,
135<c>pmu</c>. See <path>/usr/portage/profiles/use*.desc</path> for details. If
136you forgot to set one of these flags, you can recompile affected packages using
137the <c>--newuse</c> flag in <c>emerge</c>, see <c>man emerge</c>.
138</p>
139
140</body>
141</section>
142<section>
130<title>Configuring the kernel</title> 143<title>Configuring The Kernel</title>
131<body> 144<body>
132 145
133<p> 146<p>
134ACPI (Advanced Configuration and Power Interface) support in the kernel is 147ACPI (Advanced Configuration and Power Interface) support in the kernel is
135still work in progress. Using a recent kernel will make sure you'll get the 148still work in progress. Using a recent kernel will make sure you'll get the
136most out of it. 149most out of it.
137</p> 150</p>
138 151
139<p> 152<p>
140In kernel config, activate at least these options: 153There are different kernel sources in Portage. I'd recommend using
154<c>gentoo-sources</c> or <c>suspend2-sources</c>. The latter contains patches
155for Software Suspend 2, see the chapter about <uri link="#doc_chap7">sleep
156states</uri> for more details. When configuring the kernel, activate at least
157these options:
141</p> 158</p>
142 159
143<pre caption="Minimum kernel setup for Power Management (Kernel 2.6)"> 160<pre caption="Minimum kernel setup for Power Management (Kernel 2.6)">
144Power Management Options ---&gt; 161Power Management Options ---&gt;
145 [*] Power Management Support 162 [*] Power Management Support
146 [ ] Software Suspend 163 [ ] Software Suspend
147 [ ] Suspend-to-Disk Support
148 164
149 ACPI( Advanced Configuration and Power Interface ) Support ---&gt; 165 ACPI( Advanced Configuration and Power Interface ) Support ---&gt;
150 [*] ACPI Support 166 [*] ACPI Support
151 [ ] Sleep States 167 [ ] Sleep States
152 &lt;M&gt; AC Adapter 168 [ ] /proc/acpi/sleep (deprecated)
153 &lt;M&gt; Battery 169 [*] AC Adapter
170 [*] Battery
154 &lt;M&gt; Button 171 &lt;M&gt; Button
172 &lt;M&gt; Video
173 [ ] Generic Hotkey
155 &lt;M&gt; Fan 174 &lt;M&gt; Fan
156 &lt;M&gt; Processor 175 &lt;M&gt; Processor
157 &lt;M&gt; Thermal Zone 176 &lt;M&gt; Thermal Zone
158 &lt; &gt; ASUS/Medion Laptop Extras 177 &lt; &gt; ASUS/Medion Laptop Extras
178 &lt; &gt; IBM ThinkPad Laptop Extras
159 &lt; &gt; Toshiba Laptop Extras 179 &lt; &gt; Toshiba Laptop Extras
180 (0) Disable ACPI for systems before Jan 1st this year
160 [ ] Debug Statements 181 [ ] Debug Statements
161 182 [*] Power Management Timer Support
183 &lt; &gt; ACPI0004,PNP0A05 and PNP0A06 Container Driver (EXPERIMENTAL)
184
162 CPU Frequency Scaling ---&gt; 185 CPU Frequency Scaling ---&gt;
163 [*] CPU Frequency scaling 186 [*] CPU Frequency scaling
187 [ ] Enable CPUfreq debugging
188 &lt; &gt; CPU frequency translation statistics
189 [ ] CPU frequency translation statistics details
164 Default CPUFreq governor (userspace) 190 Default CPUFreq governor (userspace)
165 &lt;*&gt; 'performance' governor 191 &lt;*&gt; 'performance' governor
166 &lt;*&gt; 'powersave' governor 192 &lt;*&gt; 'powersave' governor
167 &lt;*&gt; 'ondemand' cpufreq policy governor 193 &lt;*&gt; 'ondemand' cpufreq policy governor
194 &lt;*&gt; 'conservative' cpufreq governor
168 &lt;*&gt; CPU frequency table helpers 195 &lt;*&gt; CPU frequency table helpers
169 &lt;M&gt; ACPI Processor P-States driver 196 &lt;M&gt; ACPI Processor P-States driver
170 &lt;*&gt; <i>CPUFreq driver for your processor</i> 197 &lt;*&gt; <i>CPUFreq driver for your processor</i>
171</pre> 198</pre>
172 199
173<p> 200<p>
174Decide yourself whether you want to enable Software Suspend, Suspend-to-Disk and 201Decide yourself whether you want to enable Software Suspend, and Sleep States
175Sleep States (see below). If you own an ASUS, Medion or Toshiba laptop, enable 202(see below). If you own an ASUS, Medion, IBM Thinkpad or Toshiba laptop, enable
176the appropriate section. Recent kernel versions (2.6.9 and later) include an 203the appropriate section.
177<e>'ondemand' governor</e> for CPU Frequency Scaling, activate it as well when
178using such a kernel.
179</p>
180
181<p> 204</p>
205
206<p>
182The kernel has to know how to enable CPU frequency scaling on your processor. As 207The kernel has to know how to enable CPU frequency scaling on your processor.
183each type of CPU has a different interface, you've got to choose the right 208As each type of CPU has a different interface, you've got to choose the right
184driver for your processor. Be careful here - enabling <e>Intel Pentium 4 clock 209driver for your processor. Be careful here - enabling <c>Intel Pentium 4 clock
185modulation</e> on a Pentium M system will lead to strange results for example. 210modulation</c> on a Pentium M system will lead to strange results for example.
186Consult the kernel documentation if you're unsure which one to take. 211Consult the kernel documentation if you're unsure which one to take.
187</p> 212</p>
188 213
189<p> 214<p>
190Compile your kernel, make sure the right modules get loaded at startup and boot 215Compile your kernel, make sure the right modules get loaded at startup and boot
191into your new ACPI-enabled kernel. Next run <c>emerge sys-apps/acpid</c> to get 216into your new ACPI-enabled kernel. Next run <c>emerge sys-power/acpid</c> to
192the acpi daemon. This one informs you about events like switching from AC to 217get the acpi daemon. This one informs you about events like switching from AC
193battery or closing the lid. Make sure the module <e>button</e> is loaded if you 218to battery or closing the lid. Make sure the modules are loaded if you didn't
194didn't compile it into the kernel and start acpid with <c>/etc/init.d/acpid 219compile them into the kernel and start acpid by executing <c>/etc/init.d/acpid
195start</c>. Run <c>rc-update add acpid default</c> to load it on startup. You'll 220start</c>. Run <c>rc-update add acpid default</c> to load it on startup. You'll
196soon see how to use it. 221soon see how to use it.
197</p> 222</p>
198 223
199<pre caption="Installing acpid"> 224<pre caption="Installing acpid">
200# <i>emerge sys-apps/acpid</i> 225# <i>emerge sys-power/acpid</i>
201# <i>modprobe button</i>
202# <i>/etc/init.d/acpid start</i> 226# <i>/etc/init.d/acpid start</i>
203# <i>rc-update add acpid default</i> 227# <i>rc-update add acpid default</i>
204</pre> 228</pre>
205 229
206</body> 230</body>
207</section> 231</section>
208<section> 232<section>
209<title>Creating a "battery" runlevel</title> 233<title>Creating A "battery" Runlevel</title>
210<body> 234<body>
211 235
212<p> 236<p>
213The default policy will be to enable Power Management only when needed - 237The default policy will be to enable Power Management only when needed -
214running on batteries. To make the switch between AC and battery convenient, 238running on batteries. To make the switch between AC and battery convenient,
215create a runlevel <e>battery</e> that holds all the scripts starting and 239create a runlevel <c>battery</c> that holds all the scripts starting and
216stopping Power Management. 240stopping Power Management.
217</p> 241</p>
218 242
219<note> 243<note>
220You can safely skip this section if you don't like the idea of having another 244You can safely skip this section if you don't like the idea of having another
221runlevel. However, skipping this step will make the rest a bit trickier to set 245runlevel. However, skipping this step will make the rest a bit trickier to set
222up. The next sections assume a runlevel <e>battery</e> exists. 246up. The next sections assume a runlevel <c>battery</c> exists.
223</note> 247</note>
224 248
225<pre caption="Creating a battery runlevel"> 249<pre caption="Creating a battery runlevel">
226# <i>cd /etc/runlevels</i> 250# <i>cd /etc/runlevels</i>
227# <i>cp -a default battery</i> 251# <i>cp -a default battery</i>
228</pre> 252</pre>
229 253
230<p> 254<p>
231Finished. Your new runlevel <e>battery</e> contains everything like 255Finished. Your new runlevel <c>battery</c> contains everything like
232<e>default</e>, but there is no automatic switch between both yet. Time to 256<c>default</c>, but there is no automatic switch between both yet. Time to
233change it. 257change it.
234</p> 258</p>
235 259
236</body> 260</body>
237</section> 261</section>
238<section> 262<section>
239<title>Reacting on ACPI events</title> 263<title>Reacting On ACPI Events</title>
240<body> 264<body>
241 265
242<p> 266<p>
243Typical ACPI events are closing the lid, changing the power source or pressing 267Typical ACPI events are closing the lid, changing the power source or pressing
244the sleep button. An important event is changing the power source, which should 268the sleep button. An important event is changing the power source, which should
245cause a runlevel switch. Create the following files to switch between 269cause a runlevel switch. A small script will take care of it.
246<e>default</e> and <e>battery</e> runlevel depending on the power source: 270</p>
271
247</p> 272<p>
273First you need a script which changes the runlevel to <c>default</c>
274respectively <c>battery</c> depending on the power source. The script uses the
275<c>on_ac_power</c> command from <c>sys-power/powermgmt-base</c> - make sure the
276package is installed on your system.
277</p>
248 278
279<pre caption="Installing powermgt-base">
280# <i>emerge powermgmt-base</i>
281</pre>
282
283<p>
284You are now able to determine the power source by executing <c>on_ac_power
285&amp;&amp; echo AC available || echo Running on batteries</c> in a shell. The
286script below is responsible for changing runlevels. Save it as
287<path>/etc/acpi/actions/pmg_switch_runlevel.sh</path>.
288</p>
289
249<pre caption="/etc/acpi/switch_runlevel.sh"> 290<pre caption="/etc/acpi/actions/pmg_switch_runlevel.sh">
250#!/bin/bash 291#!/bin/bash
251 292
293<comment># BEGIN configuration</comment>
252RUNLEVEL_AC="default" 294RUNLEVEL_AC="default"
253RUNLEVEL_BATTERY="battery" 295RUNLEVEL_BATTERY="battery"
296<comment># END configuration</comment>
254 297
255function on_ac () { 298
256 if which on_ac_power &amp;> /dev/null 299if [ ! -d "/etc/runlevels/${RUNLEVEL_AC}" ]
300then
301 logger "${0}: Runlevel ${RUNLEVEL_AC} does not exist. Aborting."
302 exit 1
303fi
304
305if [ ! -d "/etc/runlevels/${RUNLEVEL_BATTERY}" ]
306then
307 logger "${0}: Runlevel ${RUNLEVEL_BATTERY} does not exist. Aborting."
308 exit 1
309fi
310
311if on_ac_power
312then
313 if [[ "$(&lt;/var/lib/init.d/softlevel)" != "${RUNLEVEL_AC}" ]]
257 then 314 then
258 on_ac_power 315 logger "Switching to ${RUNLEVEL_AC} runlevel"
259 else 316 /sbin/rc ${RUNLEVEL_AC}
260 grep --quiet on-line /proc/acpi/ac_adapter/*/state
261 fi 317 fi
262}
263
264function SwitchRunlevel () {
265
266 if [ ! -d "/etc/runlevels/${RUNLEVEL_AC}" ]
267 then
268 logger "${0}: Runlevel ${RUNLEVEL_AC} does not exist. Aborting."
269 exit 1
270 fi
271
272
273 if [ ! -d "/etc/runlevels/${RUNLEVEL_BATTERY}" ]
274 then
275 logger "${0}: Runlevel ${RUNLEVEL_BATTERY} does not exist. Aborting."
276 exit 1
277 fi
278
279 if on_ac
280 then if [[ "$(cat /var/lib/init.d/softlevel)" != "${RUNLEVEL_AC}" ]]
281 then
282 logger "Switching to ${RUNLEVEL_AC} runlevel"
283 /sbin/rc ${RUNLEVEL_AC}
284 fi
285 elif [[ "$(cat /var/lib/init.d/softlevel)" != "${RUNLEVEL_BATTERY}" ]] 318elif [[ "$(&lt;/var/lib/init.d/softlevel)" != "${RUNLEVEL_BATTERY}" ]]
286 then 319then
287 logger "Switching to ${RUNLEVEL_BATTERY} runlevel" 320 logger "Switching to ${RUNLEVEL_BATTERY} runlevel"
288 /sbin/rc ${RUNLEVEL_BATTERY} 321 /sbin/rc ${RUNLEVEL_BATTERY}
289 fi 322fi
290} 323</pre>
324
325<p>
326Dont forget to run <c>chmod +x /etc/acpi/actions/pmg_switch_runlevel.sh</c> to
327make the script executable. The last thing that needs to be done is calling the
328script whenever the power source changes. That's done by catching ACPI events
329with the help of <c>acpid</c>. First you need to know which events are
330generated when the power source changes. The events are called
331<c>ac_adapter</c> and <c>battery</c> on most laptops, but it might be different
332on yours.
291</pre> 333</p>
334
335<pre caption="Determining ACPI events for changing the power source">
336# <i>tail -f /var/log/acpid | grep "received event"</i>
337</pre>
338
339<p>
340Run the command above and pull the power cable. You should see something like
341this:
342</p>
343
344<pre caption="Sample output for power source changes">
345[Tue Sep 20 17:39:06 2005] received event "ac_adapter AC 00000080 00000000"
346[Tue Sep 20 17:39:06 2005] received event "battery BAT0 00000080 00000001"
347</pre>
348
349<p>
350The interesting part is the quoted string after <c>received event</c>. It will
351be matched by the event line in the files you are going to create below. Don't
352worry if your system generates multiple events or always the same. As long as
353any event is generated, runlevel changing will work.
354</p>
292 355
293<pre caption="/etc/acpi/events/pmg_ac_adapter"> 356<pre caption="/etc/acpi/events/pmg_ac_adapter">
357<comment># replace "ac_adapter" below with the event generated on your laptop</comment>
358<comment># For example, ac_adapter.* will match ac_adapter AC 00000080 00000000</comment>
294event=ac_adapter.* 359event=ac_adapter.*
295action=/etc/acpi/actions/pmg_ac_adapter.sh %e 360action=/etc/acpi/actions/pmg_switch_runlevel.sh %e
296</pre> 361</pre>
297 362
298<pre caption="/etc/acpi/events/pmg_battery"> 363<pre caption="/etc/acpi/events/pmg_battery">
364<comment># replace "battery" below with the event generated on your laptop</comment>
365<comment># For example, battery.* will match battery BAT0 00000080 00000001</comment>
299event=battery.* 366event=battery.*
300action=/etc/acpi/actions/pmg_battery.sh %e 367action=/etc/acpi/actions/pmg_switch_runlevel.sh %e
301</pre> 368</pre>
302 369
303<pre caption="/etc/acpi/actions/pmg_ac_adapter.sh">
304#!/bin/bash
305
306source /etc/acpi/switch_runlevel.sh
307SwitchRunlevel
308</pre>
309
310<pre caption="/etc/acpi/actions/pmg_battery.sh">
311#!/bin/bash
312
313source /etc/acpi/switch_runlevel.sh
314SwitchRunlevel
315</pre>
316
317<p> 370<p>
318Some of these files must be executable. Last not least restart acpid to have 371Finally acpid has to be restarted to recognize the changes.
319it recognize the changes.
320</p> 372</p>
321 373
322<pre caption="Finishing runlevel switching with acpid"> 374<pre caption="Finishing runlevel switching with acpid">
323<i># chmod +x /etc/acpi/switch_runlevel.sh</i>
324<i># chmod +x /etc/acpi/actions/pmg_*</i>
325<i># /etc/init.d/acpid restart</i> 375# <i>/etc/init.d/acpid restart</i>
326</pre> 376</pre>
327 377
328<p> 378<p>
329Give it a try: Plug AC in and out and watch syslog for the "Switching to AC 379Give it a try: Plug AC in and out and watch syslog for the "Switching to AC
330mode" or "Switching to battery mode" messages. See the Troubleshooting 380mode" or "Switching to battery mode" messages. See the <uri
331section if the script is not able to detect the power source correctly. 381link="#doc_chap8">Troubleshooting section</uri> if the script is not able to
382detect the power source correctly.
332</p> 383</p>
333 384
334<p> 385<p>
335Due to the nature of the event mechanism, your laptop will boot into runlevel 386Due to the nature of the event mechanism, your laptop will boot into runlevel
336<e>default</e> regardless of the AC/battery state. You can add another entry 387<c>default</c> regardless of the AC/battery state. This is fine when running
337to the boot loader with <c>softlevel=battery</c>, but it's likely to forget 388from AC, but we'd like to boot into the battery runlevel otherwise. One
338choosing it. A better way is faking an ACPI event in the end of the boot 389solution would be to add another entry to the boot loader with the parameter
339process and let the <path>/etc/acpi/default.sh</path> script decide whether a 390<c>softlevel=battery</c>, but it's likely to forget choosing it. A better way
391is faking an ACPI event in the end of the boot process and letting
392<path>pmg_switch_runlevel.sh</path> script decide whether a runlevel change is
340runlevel change is necessary. Open <path>/etc/conf.d/local.start</path> in your 393necessary. Open <path>/etc/conf.d/local.start</path> in your favourite editor
341favourite editor and add these lines: 394and add these lines:
342</p> 395</p>
343 396
344<pre caption="Runlevel switch at boot time by editing local.start"> 397<pre caption="Runlevel adjustment at boot time by editing local.start">
345<comment># Fake acpi event to switch runlevel if running on batteries</comment> 398<comment># Fake acpi event to switch runlevel if running on batteries</comment>
346/etc/acpi/actions/pmg_battery.sh "battery/battery" 399/etc/acpi/actions/pmg_switch_runlevel.sh "battery/battery"
347</pre> 400</pre>
348 401
349<p> 402<p>
350Prepared like this you can activate Power Management policies for individual 403Prepared like this you can activate Power Management policies for individual
351devices. 404devices.
352</p> 405</p>
353 406
354</body> 407</body>
355</section> 408</section>
356</chapter> 409</chapter>
357 410
358<chapter> 411<chapter>
359<title>CPU Power Management</title> 412<title>CPU Power Management</title>
360<section> 413<section>
414<body>
415
416<p>
417Mobile processors can operate at different frequencies. Some allow changing
418voltage as well. Most of the time your CPU doesn't need to run at full speed
419and scaling it down will save much energy - often without any performance
420decrease.
421</p>
422
423</body>
424</section>
425<section>
361<title>Some technical terms</title> 426<title>Some Technical Terms</title>
362<body> 427<body>
363 428
364<p> 429<p>
365CPU frequency scaling brings up some technical terms that might be unknown to 430CPU frequency scaling brings up some technical terms that might be unknown to
366you. Here's a quick introduction. 431you. Here's a quick introduction.
367</p> 432</p>
368 433
369<p> 434<p>
370First of all, the kernel has to be able to change the processor's frequency. The 435First of all, the kernel has to be able to change the processor's frequency.
371<e>CPUfreq processor driver</e> knows the commands to do it on your CPU. Thus 436The <b>CPUfreq processor driver</b> knows the commands to do it on your CPU.
372it's important to choose the right one in your kernel. You should already have 437Thus it's important to choose the right one in your kernel. You should already
373done it above. Once the kernel knows how to change frequencies, it has to know 438have done it above. Once the kernel knows how to change frequencies, it has to
374which frequency it should set. This is done according to the <e>policy</e> which 439know which frequency it should set. This is done according to the <b>policy</b>
375consists of <e>CPUfreq policy</e> and a <e>governor</e>. A CPUfreq policy are 440which consists of a <b>CPUfreq policy</b> and a <b>governor</b>. A CPUfreq
376just two numbers which define a range the frequency has to stay between - 441policy are just two numbers which define a range the frequency has to stay
377minimal and maximal frequency. The governor now decides which of the available 442between - minimal and maximal frequency. The governor now decides which of the
378frequencies in between minimal and maximal frequency to choose. For example, the 443available frequencies in between minimal and maximal frequency to choose. For
379<e>powersave governor</e> always chooses the lowest frequency available, the 444example, the <b>powersave governor</b> always chooses the lowest frequency
380<e>performance governor</e> the highest one. The <e>userspace governor</e> makes 445available, the <b>performance governor</b> the highest one. The <b>userspace
381no decision but chooses whatever the user (or a program in userspace) wants - 446governor</b> makes no decision but chooses whatever the user (or a program in
382which means it reads the frequency from 447userspace) wants - which means it reads the frequency from
383<path>/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed</path>. 448<path>/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed</path>.
384</p> 449</p>
385 450
386<p> 451<p>
387This doesn't sound like dynamic frequency changes yet and in fact it isn't. 452This doesn't sound like dynamic frequency changes yet and in fact it isn't.
388Dynamics however can be accomplished with various approaches. For example, 453Dynamics however can be accomplished with various approaches. For example, the
389the <e>ondemand governor</e> makes its decisions depending on the current CPU 454<b>ondemand governor</b> makes its decisions depending on the current CPU load.
390load. The same is done by various userland tools like <c>cpudyn</c>, 455The same is done by various userland tools like <c>cpudyn</c>, <c>cpufreqd</c>,
391<c>speedfreq</c>, <c>powernowd</c> and many more. ACPI events can be used to 456<c>powernowd</c> and many more. ACPI events can be used to enable or disable
392enable or disable dynamic frequency changes depending on power source. 457dynamic frequency changes depending on power source.
393</p> 458</p>
394 459
395</body> 460</body>
396</section>
397<section> 461</section>
462<section>
398<title>Setting the frequency manually</title> 463<title>Setting The Frequency Manually</title>
399<body> 464<body>
400 465
401<p> 466<p>
402Decreasing CPU speed and voltage has two advantages: On the one hand less 467Decreasing CPU speed and voltage has two advantages: On the one hand less
403energy is consumed, on the other hand there is thermal improvement as your 468energy is consumed, on the other hand there is thermal improvement as your
406between performance loss and energy saving. 471between performance loss and energy saving.
407</p> 472</p>
408 473
409<note> 474<note>
410Not every laptop supports frequency scaling. If unsure, have a look at the list 475Not every laptop supports frequency scaling. If unsure, have a look at the list
411of supported processors in the <e>Troubleshooting</e> section to verify your's 476of supported processors in the <uri link="#doc_chap8">Troubleshooting</uri>
412is supported. 477section to verify yours is supported.
413</note> 478</note>
414 479
415<p> 480<p>
416It's time to test whether CPU frequency changing works. To get comfortable with 481It's time to test whether CPU frequency changing works. Let's install another
417the interface to the kernel, first do some manual speed modifications. To set 482tool which is very handy for debugging purposes: <c>sys-power/cpufrequtils</c>
418another CPU speed, use:
419</p>
420
421<pre caption="Manual CPU speed modifications">
422<comment>(Get current frequency)</comment>
423# <i>grep "cpu MHz" /proc/cpuinfo</i>
424
425<comment>(Lists supported frequencies. This might fail.)</comment>
426# <i>cd /sys/devices/system/cpu/cpu0/cpufreq/</i>
427# <i>cat scaling_available_frequencies</i>
428
429<comment>(Change frequency to 1 GHz (1000000 KHz)
430Replace with a frequency your laptop supports.)</comment>
431# <i>echo -n userspace > scaling_governor</i>
432# <i>echo -n 1000000 > scaling_setspeed</i>
433
434<comment>(Verify frequency was changed)</comment>
435# <i>grep "cpu MHz" /proc/cpuinfo</i>
436</pre>
437
438<p> 483</p>
439If you are getting error messages, please refer to the <e>Troubleshooting</e> 484
440chapter in the end of this guide. 485<pre caption="Checking CPU frequency">
486# <i>emerge cpufrequtils</i>
487# <i>cpufreq-info</i>
488</pre>
489
441</p> 490<p>
442 491Here is an example output:
443<p> 492</p>
444You can also write to <path>scaling_max_freq</path> and 493
445<path>scaling_min_freq</path> to set boundaries the frequency should stay in 494<pre caption="Sample output from cpufreq-info">
446between. 495cpufrequtils 0.3: cpufreq-info (C) Dominik Brodowski 2004
496Report errors and bugs to linux@brodo.de, please.
497analyzing CPU 0:
498 driver: centrino
499 CPUs which need to switch frequency at the same time: 0
500 hardware limits: 600 MHz - 1.40 GHz
501 available frequency steps: 600 MHz, 800 MHz, 1000 MHz, 1.20 GHz, 1.40 GHz
502 available cpufreq governors: conservative, ondemand, powersave, userspace, performance
503 current policy: frequency should be within 924 MHz and 1.40 GHz.
504 The governor "performance" may decide which speed to use
505 within this range.
506 current CPU frequency is 1.40 GHz.
507</pre>
508
447</p> 509<p>
448 510Now play around with <c>cpufreq-set</c> to make sure frequency switching works.
449<note> 511Run <c>cpufreq-set -g ondemand</c> for example to activate the ondemand
450Some kernel seem to be buggy about updating <path>/proc/cpuinfo</path>. If you 512governor and verify the change with <c>cpufreq-info</c>. If it doesn't work as
451don't see any change there, this doesn't neccessarily mean the CPU frequency 513expected, you might find help in the <uri link="#doc_chap8">Troubleshooting
452wasn't changed. If this happens to you, run <c>emerge x86info</c>, update your 514section</uri> in the end of this guide.
453kernel as asked and check the current frequency with <c>x86info -mhz</c>. 515</p>
454</note>
455 516
456</body> 517</body>
457</section> 518</section>
458<section> 519<section>
459<title>Automated frequency adaption</title> 520<title>Automated frequency adaption</title>
460<body> 521<body>
461 522
462<p> 523<p>
463The above is quite nice, but not doable in daily life. Better let your system 524The above is quite nice, but not doable in daily life. Better let your system
464set the appropriate frequency automatically. There are many different approaches 525set the appropriate frequency automatically. There are many different
465to do this. The following table gives a quick overview to help you decide on one 526approaches to do this. The following table gives a quick overview to help you
466of them. It's roughly seperated in three categories <e>kernel</e> for approaches 527decide on one of them. It's roughly separated in three categories <b>kernel</b>
467that only need kernel support, <e>daemon</e> for programs that run in the 528for approaches that only need kernel support, <b>daemon</b> for programs that
468background and <e>graphical</e> for programs that provide a GUI for easy 529run in the background and <b>graphical</b> for programs that provide a GUI for
469configuration and changes. 530easy configuration and changes.
470</p> 531</p>
471 532
472<table> 533<table>
473<tr> 534<tr>
474 <th>Name</th> 535 <th>Name</th>
483 <ti>Kernel</ti> 544 <ti>Kernel</ti>
484 <ti>CPU load</ti> 545 <ti>CPU load</ti>
485 <ti>N.A.</ti> 546 <ti>N.A.</ti>
486 <ti>N.A.</ti> 547 <ti>N.A.</ti>
487 <ti> 548 <ti>
549 Chooses maximal frequency on CPU load and slowly steps down when the CPU is
550 idle. Further tuning through files in
551 <path>/sys/devices/system/cpu/cpu0/cpufreq/ondemand/</path>. Still requires
552 userland tools (programs, scripts) if governor switching or similar is
553 desired.
554 </ti>
555</tr>
556<tr>
557 <ti>'conservative' governor</ti>
558 <ti>Kernel</ti>
559 <ti>CPU load</ti>
560 <ti>N.A.</ti>
561 <ti>N.A.</ti>
562 <ti>
563 Unlike the ondemand governor, conversative doesn't jump to maximum
564 frequency when CPU load is high, but increases the frequency step by step.
488 Further tuning through files in 565 Further tuning through files in
489 <path>/sys/devices/system/cpu/cpu0/cpufreq/ondemand/</path>. Still requires 566 <path>/sys/devices/system/cpu/cpu0/cpufreq/ondemand/</path>. Still requires
490 userland tools (programs, scripts) if governor switching or similar is 567 userland tools (programs, scripts) if governor switching or similar is
491 desired. 568 desired.
492 </ti> 569 </ti>
493</tr> 570</tr>
494<tr> 571<tr>
495 <ti><uri link="http://mnm.uib.es/~gallir/cpudyn/">cpudyn</uri></ti> 572 <ti><uri link="http://mnm.uib.es/~gallir/cpudyn/">cpudyn</uri></ti>
496 <ti>Daemon</ti> 573 <ti>Daemon</ti>
497 <ti>CPU load</ti> 574 <ti>CPU load</ti>
498 <ti>None</ti> 575 <ti>Performance, powersave</ti>
499 <ti>Dynamic</ti> 576 <ti>Dynamic</ti>
500 <ti> 577 <ti>
501 Also supports disk standby - notice however that <e>laptop mode</e> in most 578 Also supports disk standby - notice however that <e>laptop mode</e> in most
502 cases will do a better job. 579 cases will do a better job.
503 </ti> 580 </ti>
504</tr> 581</tr>
505<tr> 582<tr>
506 <ti><uri link="http://sourceforge.net/projects/cpufreqd/">cpufreqd</uri></ti> 583 <ti><uri link="http://sourceforge.net/projects/cpufreqd/">cpufreqd</uri></ti>
507 <ti>Daemon</ti> 584 <ti>Daemon</ti>
508 <ti>Battery state, CPU load, running programs</ti> 585 <ti>Battery state, CPU load, temperature, running programs and more</ti>
509 <ti>All available</ti> 586 <ti>All available</ti>
510 <ti>None</ti> 587 <ti>None</ti>
511 <ti> 588 <ti>
512 Sophisticated (but also complicated) setup. An optimal configuration 589 Sophisticated (but somewhat complicated) setup. Extendible through plugins
513 requires detailed knowledge of your system. 590 like sensor monitoring (lm_sensors) or coordinating some NVidia based
591 graphics card memory and core. Cpufreqd is SMP aware and can optionally be
592 controlled manually at runtime.
514 </ti> 593 </ti>
515</tr> 594</tr>
516<tr> 595<tr>
517 <ti> 596 <ti>
518 <uri link="http://www.deater.net/john/powernowd.html">powernowd</uri> 597 <uri link="http://www.deater.net/john/powernowd.html">powernowd</uri>
524 <ti> 603 <ti>
525 Supports SMP. 604 Supports SMP.
526 </ti> 605 </ti>
527</tr> 606</tr>
528<tr> 607<tr>
608 <ti>
609 <uri
610 link="http://fatcat.ftj.agh.edu.pl/~nelchael/index.php?cat=projs&amp;subcat=ncpufreqd&amp;language=en">ncpufreqd</uri>
611 </ti>
612 <ti>Daemon</ti>
613 <ti>Temperature</ti>
614 <ti>None</ti>
615 <ti>Powersave, performance</ti>
616 <ti>
617 Toggles the used governor between performance and powersave depending on
618 system temperature. Very useful on laptops with notorious heat problems.
619 </ti>
620</tr>
621<tr>
529 <ti><uri link="http://www.goop.org/~jeremy/speedfreq/">speedfreq</uri></ti> 622 <ti><uri link="http://www.goop.org/~jeremy/speedfreq/">speedfreq</uri></ti>
530 <ti>Daemon</ti> 623 <ti>Daemon</ti>
531 <ti>CPU load</ti> 624 <ti>CPU load</ti>
532 <ti>None</ti> 625 <ti>None</ti>
533 <ti>Dynamic, powersave, performance, fixed speed</ti> 626 <ti>Dynamic, powersave, performance, fixed speed</ti>
534 <ti> 627 <ti>
535 Small yet powerful with an useful client/server interface. Requires a 2.6 628 Easy to configure with a nice client/server interface. Requires a 2.6
536 kernel. 629 kernel. Unmaintained, broken and thus removed from Portage. Please switch
630 to cpufreqd if you're still using it.
537 </ti> 631 </ti>
538</tr> 632</tr>
539<tr> 633<tr>
540 <ti><uri link="http://cpuspeedy.sourceforge.net/">gtk-cpuspeedy</uri></ti> 634 <ti><uri link="http://cpuspeedy.sourceforge.net/">gtk-cpuspeedy</uri></ti>
541 <ti>Graphical</ti> 635 <ti>Graphical</ti>
542 <ti>None</ti> 636 <ti>None</ti>
543 <ti>None</ti> 637 <ti>None</ti>
544 <ti>None</ti> 638 <ti>None</ti>
545 <ti> 639 <ti>
546 Gnome application, a graphical tool to set CPU frequency manually. It does 640 Gnome application, a graphical tool to set CPU frequency manually. It does
547 not offer any automation and is mainly listed for the sake of completeness. 641 not offer any automation.
548 </ti> 642 </ti>
549</tr> 643</tr>
550<tr> 644<tr>
551 <ti>klaptopdaemon</ti> 645 <ti>klaptopdaemon</ti>
552 <ti>Graphical</ti> 646 <ti>Graphical</ti>
558 </ti> 652 </ti>
559</tr> 653</tr>
560</table> 654</table>
561 655
562<p> 656<p>
563While adjusting the frequency to the current load looks simple on the first 657While adjusting the frequency to the current load looks simple at a first
564view, it's not such a trivial task. A bad algorithm can cause switching between 658glance, it's not such a trivial task. A bad algorithm can cause switching
565two frequencies all the time or wasting energy when setting frequency to an 659between two frequencies all the time or wasting energy when setting frequency
566unnecessary high level. 660to an unnecessary high level.
567</p>
568
569<p> 661</p>
662
663<p>
570Which one to choose? If you have no idea about it, first try <c>speedfreq</c>: 664Which one to choose? If you have no idea about it, try <c>cpufreqd</c>:
571</p> 665</p>
572 666
573<pre caption="Installing speedfreq"> 667<pre caption="Installing cpufreqd">
574# <i>emerge speedfreq</i> 668# <i>emerge cpufreqd</i>
575# <i>rc-update add speedfreq battery</i>
576</pre> 669</pre>
577 670
578<p>
579<c>speedfreq</c> can be configured by editing
580<path>/etc/conf.d/speedfreq</path>. For example, if you like users to be able
581to change the policy, modify <c>SPEEDFREQ_OPTS=""</c> to
582<c>SPEEDFREQ_OPTS="-u"</c>. Having done your changes, start the daemon.
583</p> 671<p>
672<c>cpufreqd</c> can be configured by editing <path>/etc/cpufreqd.conf</path>.
673The default one that ships with cpufreqd may look a bit confusing. I recommend
674replacing it with the one from Gentoo developer Henrik Brix Andersen (see
675below). Please notice that you need cpufreqd-2.0.0 or later. Earlier versions
676have a different syntax for the config file.
677</p>
584 678
679<pre caption="/etc/cpufreqd.conf (cpufreqd-2.0.0 and later)">
680[General]
681pidfile=/var/run/cpufreqd.pid
682poll_interval=3
683enable_plugins=acpi_ac, acpi_battery
684enable_remote=1
685remote_group=wheel
686verbosity=5
687[/General]
688
689[Profile]
690name=ondemand
691minfreq=0%
692maxfreq=100%
693policy=ondemand
694[/Profile]
695
696[Profile]
697name=conservative
698minfreq=0%
699maxfreq=100%
700policy=conservative
701[/Profile]
702
703[Profile]
704name=powersave
705minfreq=0%
706maxfreq=100%
707policy=powersave
708[/Profile]
709
710[Profile]
711name=performance
712minfreq=0%
713maxfreq=100%
714policy=performance
715[/Profile]
716
717[Rule]
718name=battery
719ac=off
720profile=conservative
721[/Rule]
722
723[Rule]
724name=battery_low
725ac=off
726battery_interval=0-10
727profile=powersave
728[/Rule]
729
730[Rule]
731name=ac
732ac=on
733profile=ondemand
734[/Rule]
735</pre>
736
737<p>
738Now you can start the cpufreqd daemon. Add it to the <c>default</c> and
739<c>battery</c> runlevel as well.
740</p>
741
585<pre caption="Starting speedfreq"> 742<pre caption="Starting cpufreqd">
586# <i>/etc/init.d/speedfreq start</i> 743# <i>rc-update add cpufreqd default battery</i>
744# <i>rc</i>
587</pre> 745</pre>
588 746
589<p> 747<p>
590Setting up cpufreqd is a little bit more complicated. 748Sometimes it can be desirable to select another policy than the daemon chooses,
749for example when battery power is low, but you know that AC will be available
750soon. In that case you can turn on cpufreqd's manual mode with <c>cpufreqd-set
751manual</c> and select one of your configured policies (as listed by
752<c>cpufreqd-get</c>). You can leave manual mode by executing <c>cpufreqd-set
753dynamic</c>.
591</p> 754</p>
592 755
593<warn> 756<warn>
594Do not run more than one of the above programs at the same time. It may cause 757Do not run more than one of the above programs at the same time. It may cause
595confusion like switching between two frequencies all the time. If you just 758confusion like switching between two frequencies all the time.
596installed speedfreq, skip cpufreqd now.
597</warn> 759</warn>
598 760
599<pre caption="Installing cpufreqd">
600# <i>emerge cpufreqd</i>
601# <i>rc-update add cpufreqd battery</i>
602</pre>
603
604<p>
605<c>cpufreqd</c> comes with a default configuration in
606<path>/etc/cpufreqd.conf</path>.
607Change the config file to fit your needs. The following will save more energy
608than the default one - at the cost of less performance, of course.
609</p>
610
611<pre caption="A sample cpufreqd config file">
612[General]
613pidfile=/var/run/cpufreqd.pid
614poll_interval=2
615pm_type=acpi
616<comment># Uncomment the following line to enable ACPI workaround (see cpufreqd.conf(5))
617# acpi_workaround=1</comment>
618verbosity=4 <comment>#(if you want a minimal logging set to 5)</comment>
619
620<comment># Full performance</comment>
621[Profile]
622name=ac
623minfreq=600000
624maxfreq=1400000
625policy=performance
626
627<comment># Maximum power saving</comment>
628[Profile]
629name=battery
630minfreq=600000
631maxfreq=900000
632policy=powersave
633
634<comment># Constant frequency</comment>
635[Profile]
636name=dvd
637minfreq=900000
638maxfreq=1100000
639policy=powersave
640
641<comment># Full performance when running on AC</comment>
642[Rule]
643name=ac_on
644ac=on
645profile=ac
646
647<comment># Compiling should be fast if battery state is ok</comment>
648[Rule]
649name=compiling
650ac=off
651battery_interval=30-100
652programs=emerge,make,gcc,cpp
653cpu_interval=0-100
654profile=ac
655
656<comment># watching DVD's gets sluggish with slow CPU frequency
657# Can also be used for games etc.</comment>
658[Rule]
659name=dvd_watching
660ac=off
661battery_interval=15-100
662programs=xine,mplayer,avidemux,kaffeine,kmplayer
663cpu_interval=0-100
664profile=dvd
665
666<comment># If above doesn't apply, maximise power saving</comment>
667[Rule]
668name=battery_on
669ac=off
670battery_interval=0-100
671cpu_interval=0-100
672profile=battery
673</pre>
674
675<p>
676<c>cpudyn</c> and <c>powernowd</c> are installed in the same way as
677<c>speedfreq</c>.
678</p>
679
680</body> 761</body>
681</section> 762</section>
682
683<section> 763<section>
684<title>Verifying the result</title> 764<title>Verifying the result</title>
685
686<body> 765<body>
687 766
688<p> 767<p>
689The last thing to check is that your new policies do a good job. An easy way to 768The last thing to check is that your new policies do a good job. An easy way to
690do so is monitoring CPU speed while working with your laptop: 769do so is monitoring CPU speed while working with your laptop:
691</p> 770</p>
692 771
693<pre caption="Monitoring CPU speed"> 772<pre caption="Monitoring CPU speed">
694# <i>watch -n 1 'grep "cpu MHz" /proc/cpuinfo'</i> 773# <i>watch grep \"cpu MHz\" /proc/cpuinfo</i>
695</pre> 774</pre>
696 775
697<p> 776<p>
698If <path>/proc/cpuinfo</path> doesn't get updated (see above), monitor the CPU 777If <path>/proc/cpuinfo</path> doesn't get updated (see <uri
699frequency with: 778link="#doc_chap8">Troubleshooting</uri>), monitor the CPU frequency with:
700</p> 779</p>
701 780
702<pre caption="Alternative CPU speed monitoring"> 781<pre caption="Alternative CPU speed monitoring">
703# <i>watch -n 1 x86info -mhz</i> 782# <i>watch x86info -mhz</i>
704</pre> 783</pre>
705 784
706<p> 785<p>
707Depending on your setup, CPU speed should increase on heavy load, decrease on 786Depending on your setup, CPU speed should increase on heavy load, decrease on
708no activity or just stay at the same level. 787no activity or just stay at the same level. When using <c>cpufreqd</c> and
788verbosity set to 5 or higher in <path>cpufreqd.conf</path> you'll get
789additional information about what's happening reported to <c>syslog</c>.
709</p> 790</p>
710 791
711</body> 792</body>
712</section> 793</section>
713</chapter> 794</chapter>
714 795
715<chapter> 796<chapter>
716<title>LCD Power Management</title> 797<title>LCD Power Management</title>
717<section> 798<section>
718<title>Energy consumer no. 1</title>
719<body> 799<body>
720 800
721<p> 801<p>
722As you can see in <uri link="#doc_chap1_fig1">figure 1.1</uri>, the LCD display 802As you can see in <uri link="#doc_chap1_fig1">figure 1.1</uri>, the LCD
723consumes the biggest part of energy (might not be the case for non-mobile 803display consumes the biggest part of energy (might not be the case for
724CPU's). Thus it's quite important not only to shut the display off when not 804non-mobile CPU's). Thus it's quite important not only to shut the display off
725needed, but also to reduce it's backlight if possible. Most laptops offer the 805when not needed, but also to reduce it's backlight if possible. Most laptops
726possibility to control the backlight dimming. 806offer the possibility to control the backlight dimming.
727</p>
728
729<p> 807</p>
808
809</body>
810</section>
811<section>
812<title>Standby settings</title>
813<body>
814
815<p>
730First thing to check is the standby/suspend/off timings of the display. As this 816The first thing to check is the standby/suspend/off timings of the display. As
731depends heavily on your windowmanager, I'll let you figure it out yourself. 817this depends heavily on your windowmanager, I'll let you figure it out
732Just two common places: Blanking the terminal can be done with <c>setterm 818yourself. Just two common places: Blanking the terminal can be done with
733-blank &lt;number-of-minutesM&gt;</c>, <c>setterm -powersave on</c> and 819<c>setterm -blank &lt;number-of-minutesM&gt;</c>, <c>setterm -powersave on</c>
734<c>setterm -powerdown &lt;number-of-minutesM&gt;</c>. 820and <c>setterm -powerdown &lt;number-of-minutesM&gt;</c>. For X.org, modify
735For Xorg, modify <path>/etc/X11/xorg.conf</path> similar to this: 821<path>/etc/X11/xorg.conf</path> similar to this:
736</p> 822</p>
737 823
738<pre caption="LCD suspend settings in Xorg and XFree86"> 824<pre caption="LCD suspend settings in X.org and XFree86">
739Section "ServerLayout" 825Section "ServerLayout"
740 Identifier [...] 826 Identifier [...]
741 [...] 827 [...]
742 Option "BlankTime" "5" <comment># Blank the screen after 5 minutes (Fake)</comment> 828 Option "BlankTime" "5" <comment># Blank the screen after 5 minutes (Fake)</comment>
743 Option "StandbyTime" "10" <comment># Turn off screen after 10 minutes (DPMS)</comment> 829 Option "StandbyTime" "10" <comment># Turn off screen after 10 minutes (DPMS)</comment>
757 843
758<p> 844<p>
759This is the same for XFree86 and <path>/etc/X11/XF86Config</path>. 845This is the same for XFree86 and <path>/etc/X11/XF86Config</path>.
760</p> 846</p>
761 847
848</body>
849</section>
850<section>
851<title>Backlight dimming</title>
852<body>
853
762<p> 854<p>
763Probably more important is the backlight dimming. If you have access to the 855Probably more important is the backlight dimming. If you have access to the
764dimming settings via a tool, write a small script that dims the backlight in 856dimming settings via a tool, write a small script that dims the backlight in
765battery mode and place it in your <e>battery</e> runlevel. 857battery mode and place it in your <c>battery</c> runlevel. The following script
858should work on most IBM Thinkpads and Toshiba laptops. You've got to enable the
859appropriate option in your kernel (IBM Thinkpads only). For Toshiba laptops,
860install <c>app-laptop/acpitool</c> and skip configuration of <c>ibm_acpi</c> as
861described below.
862</p>
863
864<warn>
865Support for setting brightness is marked experimental in ibm-acpi. It accesses
866hardware directly and may cause severe harm to your system. Please read the
867<uri link="http://ibm-acpi.sourceforge.net/">ibm-acpi website</uri>
868</warn>
869
766</p> 870<p>
871To be able to set the brightness level, the ibm_acpi module has to be loaded
872with the experimental parameter.
873</p>
874
875<pre caption="automatically loading the ibm_acpi module">
876<comment>(Please read the warnings above before doing this!)</comment>
877# <i>echo "options ibm_acpi experimental=1" >> /etc/modules.d/ibm_acpi</i>
878# <i>/sbin/modules-update</i>
879# <i>echo ibm_acpi >> /etc/modules.autoload.d/kernel-2.6</i>
880# <i>modprobe ibm_acpi</i>
881</pre>
882
883<p>
884This should work without error messages and a file
885<path>/proc/acpi/ibm/brightness</path> should be created after loading the
886module. An init script will take care of choosing the brightness according to
887the power source.
888</p>
889
890<pre caption="/etc/conf.d/lcd-brightness">
891<comment># See /proc/acpi/ibm/brightness for available values</comment>
892<comment># Please read /usr/src/linux/Documentation/ibm-acpi.txt</comment>
893
894<comment># brigthness level in ac mode. Default is 7.</comment>
895BRIGHTNESS_AC=7
896
897<comment># brightness level in battery mode. Default is 4.</comment>
898BRIGHTNESS_BATTERY=4
899</pre>
900
901<pre caption="/etc/init.d/lcd-brightness">
902#!/sbin/runscript
903
904set_brightness() {
905 if on_ac_power
906 then
907 LEVEL=${BRIGHTNESS_AC:-7}
908 else
909 LEVEL=${BRIGHTNESS_BATTERY:-4}
910 fi
911
912 if [ -f /proc/acpi/ibm/brightness ]
913 then
914 ebegin "Setting LCD brightness"
915 echo "level ${LEVEL}" > /proc/acpi/ibm/brightness
916 eend $?
917 elif [[ -e /usr/bin/acpitool &amp;&amp; -n $(acpitool -T | grep "LCD brightness") ]]
918 then
919 ebegin "Setting LCD brightness"
920 acpitool -l $LEVEL >/dev/null || ewarn "Unable to set lcd brightness"
921 eend $?
922 else
923 ewarn "Setting LCD brightness is not supported."
924 ewarn "For IBM Thinkpads, check that ibm_acpi is loaded into the kernel"
925 ewarn "For Toshiba laptops, you've got to install app-laptop/acpitool"
926 fi
927}
928
929start() {
930 set_brightness
931}
932
933stop () {
934 set_brightness
935}
936</pre>
937
938<p>
939When done, make sure brightness is adjusted automatically by adding it to the
940battery runlevel.
941</p>
942
943<pre caption="Enabling automatic brightness adjustment">
944# <i>chmod +x /etc/init.d/lcd-brightness</i>
945# <i>rc-update add lcd-brightness battery</i>
946# <i>rc</i>
947</pre>
767 948
768</body> 949</body>
769</section> 950</section>
770</chapter> 951</chapter>
771 952
772<chapter> 953<chapter>
773<title>Disk Power Management</title> 954<title>Disk Power Management</title>
774<section> 955<section>
775<title>Sleep when idle</title> 956<body>
957
958<p>
959Hard disks consume less energy in sleep mode. Therefore it makes sense to
960activate power saving features whenever the hard disk is not used for a certain
961amount of time. I'll show you two alternative possibilities to do it. First,
962laptop-mode will save most energy due to several measures which prevent or at
963least delay write accesses. The drawback is that due to the delayed write
964accesses a power outage or kernel crash will be more dangerous for data loss.
965If you don't like this, you have to make sure that there are no processes which
966write to your hard disk frequently. Afterwards you can enable power saving
967features of your hard disk with <c>hdparm</c> as the second alternative.
968</p>
969
776<body> 970</body>
971</section>
972<section>
973<title>Increasing idle time - laptop-mode</title>
974<body>
777 975
778<p>
779Let's bring the hard disk to sleep as early as possible whenever it is not
780needed. I'll show you two possibilities to do it. First <c>cpudyn</c> supports
781Disk Power Management. Uncomment the lines in the "Disk Options" section in
782<path>/etc/conf.d/cpudyn</path>. To put your first disk to sleep after 60
783seconds of no activity, you would modify it like this:
784</p> 976<p>
785 977Recent kernels (2.6.6 and greater, recent 2.4 ones and others with patches)
786<pre caption="Using cpudyn for disk standby"> 978include the so-called <c>laptop-mode</c>. When activated, dirty buffers are
787<comment>################################################ 979written to disk on read calls or after 10 minutes (instead of 30 seconds). This
788# DISK OPTIONS 980minimizes the time the hard disk needs to be spun up.
789# (disabled by default)
790################################################
791
792#
793# Timeout to put the disk in standby mode if there was no
794# io during that period (in seconds)
795#
796</comment>
797TIMEOUT=60
798<comment>
799#
800# Specified disks to spindown (comma separated devices)
801#
802</comment>
803DISKS=/dev/hda
804</pre>
805
806<p> 981</p>
982
983<pre caption="Automated start of laptop-mode">
984# <i>emerge laptop-mode-tools</i>
985</pre>
986
987<p>
988<c>laptop-mode-tools</c> has its configuration file in
989<path>/etc/laptop-mode/laptop-mode.conf</path>. Adjust it the way you like it,
990it's well commented. Run <c>rc-update add laptop_mode battery</c> to start it
991automatically.
992</p>
993
994<p>
995Recent versions (1.11 and later) of laptop-mode-tools include a new tool
996<c>lm-profiler</c>. It will monitor your system's disk usage and running
997network services and suggests to disable unneeded ones. You can either disable
998them through laptop-mode-tools builtin runlevel support (which will be reverted
999by Gentoo's <c>/sbin/rc</c>) or use your <c>default</c>/<c>battery</c>
1000runlevels (recommended).
1001</p>
1002
1003<pre caption="Sample output from running lm-profiler">
1004# <i>lm-profiler</i>
1005Profiling session started.
1006Time remaining: 600 seconds
1007[4296896.602000] amarokapp
1008Time remaining: 599 seconds
1009[4296897.714000] sort
1010[4296897.970000] mv
1011Time remaining: 598 seconds
1012Time remaining: 597 seconds
1013[4296900.482000] reiserfs/0
1014</pre>
1015
1016<p>
1017After profiling your system for ten minutes, lm-profiler will present a list of
1018services which might have caused disk accesses during that time.
1019</p>
1020
1021<pre caption="lm-profiler suggests to disable some services">
1022Program: "atd"
1023Reason: standard recommendation (program may not be running)
1024Init script: /etc/init.d/atd (GUESSED)
1025
1026Do you want to disable this service in battery mode? [y/N]: <i>n</i>
1027</pre>
1028
1029<p>
1030To disable atd as suggested in the example above, you would run <c>rc-update
1031del atd battery</c>. Be careful not to disable services that are needed for
1032your system to run properly - <c>lm-profiler</c> is likely to generate some
1033false positives. Do not disable a service if you are unsure whether it's
1034needed.
1035</p>
1036
1037</body>
1038</section>
1039<section>
1040<title>Limiting Write Accesses</title>
1041<body>
1042
1043<p>
1044If you don't want to use laptop-mode, you must take special care to disable
1045services that write to your disk frequently - <c>syslogd</c> is a good
1046candidate, for example. You probably don't want to shut it down completely, but
1047it's possible to modify the config file so that "unnecessary" things don't get
1048logged and thus don't create disk traffic. <c>Cups</c> writes to disk
1049periodically, so consider shutting it down and only enable it manually when
1050needed.
1051</p>
1052
1053<pre caption="Disabling cups in battery mode">
1054# <i>rc-update del cupsd battery</i>
1055</pre>
1056
1057<p>
1058You can also use <c>lm-profiler</c> from laptop-mode-tools (see above) to find
1059services to disable. Once you eliminated all of them, go on with configuring
1060hdparm.
1061</p>
1062
1063</body>
1064</section>
1065<section>
1066<title>hdparm</title>
1067<body>
1068
1069<p>
807The second possibility is using a small script and hdparm. Create 1070The second possibility is using a small script and <c>hdparm</c>. Skip this if
808<path>/etc/init.d/pm.hda</path> like this: 1071you are using laptop-mode. Otherwise, create <path>/etc/init.d/pmg_hda</path>:
809</p> 1072</p>
810 1073
811<pre caption="Using hdparm for disk standby"> 1074<pre caption="Using hdparm for disk standby">
812#!/sbin/runscript 1075#!/sbin/runscript
1076
1077depend() {
1078after hdparm
1079}
1080
813start() { 1081start() {
814 ebegin "Activating Power Management for Hard Drives" 1082ebegin "Activating Power Management for Hard Drives"
815 hdparm -q -S12 /dev/hda 1083hdparm -q -S12 /dev/hda
816 eend $? 1084eend $?
817} 1085}
818 1086
819stop () { 1087stop () {
820 ebegin "Deactivating Power Management for Hard Drives" 1088ebegin "Deactivating Power Management for Hard Drives"
821 hdparm -q -S253 /dev/hda 1089hdparm -q -S253 /dev/hda
822 eend $? 1090eend $?
823} 1091}
824</pre> 1092</pre>
825 1093
826<p> 1094<p>
827See <c>man hdparm</c> for the options. If your script is ready, add it to the 1095See <c>man hdparm</c> for the options. If your script is ready, add it to the
828battery runlevel. 1096battery runlevel.
829</p> 1097</p>
830 1098
831<pre caption="Automate disk standby settings"> 1099<pre caption="Automate disk standby settings">
832# <i>chmod +x /etc/init.d/pm.hda</i> 1100# <i>chmod +x /etc/init.d/pmg_hda</i>
833# <i>/sbin/depscan.sh</i> 1101# <i>/sbin/depscan.sh</i>
834# <i>rc-update add pm.hda battery</i> 1102# <i>rc-update add pmg_hda battery</i>
835</pre> 1103</pre>
836 1104
837<impo> 1105<impo>
838Be careful with sleep/spin down settings of your hard drive. Setting it to 1106Be careful with sleep/spin down settings of your hard drive. Setting it to
839small values might wear out your drive and lose warranty. 1107small values might wear out your drive and lose warranty.
840</impo> 1108</impo>
841 1109
842</body> 1110</body>
843</section> 1111</section>
844<section> 1112<section>
845<title>Increasing idle time - laptop-mode</title>
846<body>
847
848<p>
849Recent kernels (2.6.6 and greater, recent 2.4 ones and others with patches)
850include the so-called <e>laptop-mode</e>. When activated, dirty buffers are
851written to disk on read calls or after 10 minutes (instead of 30 seconds). This
852minimizes the time the hard disk needs to be spun up.
853</p>
854
855<p>
856<!-- TODO: bug #45593 -->
857Besides kernel support you also need a script that controls starting and
858stopping of laptop-mode. You kernel documentation in
859<path>/usr/src/linux/Documentation/laptop-mode.txt</path> contains one as well
860as the package <c>laptop-mode-tools</c>. None of them is easy to install
861though.
862</p>
863
864<p>
865Ebuilds for laptop-mode-tools are not in Portage, because Gentoo developers
866don't think they are production ready yet. Take that into consideration
867before using the ebuilds which can be found in <uri
868link="http://bugs.gentoo.org/show_bug.cgi?id=45593">Bugzilla</uri>. The Gentoo
869Handbook tells you how to use external ebuilds if you don't know where to put
870them. Once your PORTDIR_OVERLAY contains the ebuilds, install the
871script:
872</p>
873
874<warn>
875This package is not seen as production ready and installing custom ebuilds from
876Bugzilla is not recommended. Please don't use laptop-mode-tools if you're
877unsure.
878</warn>
879
880<pre caption="Automated start of laptop-mode">
881# <i>emerge laptop-mode-tools</i>
882</pre>
883
884<p>
885<c>laptop-mode-tools</c> has it's configuration file in
886<path>/etc/laptop-mode/laptop-mode.conf</path>. Adjust it the way you like it,
887it's well commented. If you have <e>apm</e> or <e>acpi</e> in your USE flags,
888laptop-mode will be started automatically in battery mode. Otherwise you can
889automate it by running <c>rc-update add laptop-mode battery</c>.
890</p>
891
892</body>
893</section>
894<section>
895<title>Other tricks</title> 1113<title>Other tricks</title>
896<body> 1114<body>
897
898<p>
899Besides putting your disk to sleep state as early as possible, it is a good
900idea to minimize disk accesses. Have a look at processes that write to your
901disk frequently - the syslogd is a good candidate. You probably don't want to
902shut it down completely, but it's possible to modify the config file so that
903"unnecessary" things don't get logged and thus don't create disk traffic. Cups
904writes to disk periodically, so consider shutting it down and only enable it
905manually when needed.
906</p>
907
908<pre caption="Disabling cups in battery mode">
909# <i>rc-update del cupsd battery</i>
910</pre>
911 1115
912<p> 1116<p>
913Another possibility is to deactivate swap in battery mode. Before writing a 1117Another possibility is to deactivate swap in battery mode. Before writing a
914swapon/swapoff switcher, make sure there is enough RAM and swap isn't used 1118swapon/swapoff switcher, make sure there is enough RAM and swap isn't used
915heavily, otherwise you'll be in big problems. 1119heavily, otherwise you'll be in big problems.
916</p> 1120</p>
917 1121
918<p> 1122<p>
919If you don't want to use laptop-mode, it's still possible to minimize disk 1123If you don't want to use laptop-mode, it's still possible to minimize disk
920access by mounting certain directories as <e>tmpfs</e> - write accesses are not 1124access by mounting certain directories as <c>tmpfs</c> - write accesses are not
921stored on a disk, but in main memory and get lost with unmounting. Often it's 1125stored on a disk, but in main memory and get lost with unmounting. Often it's
922useful to mount <path>/tmp</path> like this - you don't have to pay special 1126useful to mount <path>/tmp</path> like this - you don't have to pay special
923attention as it gets cleared on every reboot regardless whether it was mounted 1127attention as it gets cleared on every reboot regardless whether it was mounted
924on disk or in RAM. Just make sure you have enough RAM and no program (like a 1128on disk or in RAM. Just make sure you have enough RAM and no program (like a
925download client or compress utility) needs extraordinary much space in 1129download client or compress utility) needs extraordinary much space in
931none /tmp tmpfs size=32m 0 0 1135none /tmp tmpfs size=32m 0 0
932</pre> 1136</pre>
933 1137
934<warn> 1138<warn>
935Pay attention to the size parameter and modify it for your system. If you're 1139Pay attention to the size parameter and modify it for your system. If you're
936unsure, don't try this at all, it can become a perfomance bottleneck easily. In 1140unsure, don't try this at all, it can become a performance bottleneck easily. In
937case you want to mount <path>/var/log</path> like this, make sure to merge the 1141case you want to mount <path>/var/log</path> like this, make sure to merge the
938log files to disk before unmounting. They are essential. Don't attempt to mount 1142log files to disk before unmounting. They are essential. Don't attempt to mount
939/var/tmp like this. Portage uses it for compiling... 1143<path>/var/tmp</path> like this. Portage uses it for compiling...
940</warn> 1144</warn>
941 1145
942</body> 1146</body>
943</section> 1147</section>
944</chapter> 1148</chapter>
945 1149
946<chapter> 1150<chapter>
947<title>Power Management for other devices</title> 1151<title>Power Management For Other Devices</title>
1152<section>
1153<title>Graphics Cards</title>
1154<body>
1155
1156<p>
1157In case you own an ATI graphics card supporting PowerPlay (dynamic clock
1158scaling for the the graphics processing unit GPU), you can activate this
1159feature in X.org. Open <path>/etc/X11/xorg.conf</path> and add (or enable) the
1160<c>DynamicClocks</c> option in the Device section. Please notice that this
1161feature will lead to crashes on some systems.
1162</p>
1163
1164<pre caption="Enabling ATI PowerPlay support in X.org">
1165Section "Device"
1166[...]
1167Option "DynamicClocks" "on"
1168EndSection
1169</pre>
1170
1171</body>
1172</section>
948<section> 1173<section>
949<title>Wireless Power Management</title> 1174<title>Wireless Power Management</title>
950<body> 1175<body>
951 1176
952<p> 1177<p>
953Wireless LAN cards consume quite a few energy. Put them in Power Management 1178Wireless LAN cards consume quite a bit of energy. Put them in Power Management
954mode in analogy to the pm.hda script. 1179mode in analogy to the <c>pmg_hda</c> script.
955</p> 1180</p>
1181
1182<note>
1183This script assumes your wireless interface is called <c>wlan0</c>; replace
1184this with the actual name of your interface.
1185</note>
956 1186
957<pre caption="WLAN Power Management automated"> 1187<pre caption="WLAN Power Management automated">
958#!/sbin/runscript 1188#!/sbin/runscript
959start() { 1189start() {
960 ebegin "Activating Power Management for Wireless LAN" 1190 ebegin "Activating Power Management for Wireless LAN"
961 iwconfig wlan0 power on power max period 3 1191 iwconfig wlan0 power on
962 eend $? 1192 eend $?
963} 1193}
964 1194
965stop () { 1195stop () {
966 ebegin "Deactivating Power Management for Wireless LAN" 1196 ebegin "Deactivating Power Management for Wireless LAN"
968 eend $? 1198 eend $?
969} 1199}
970</pre> 1200</pre>
971 1201
972<p> 1202<p>
973Starting this script will put wlan0 in Power Management mode, going to sleep at 1203Starting this script will activate power saving features for wlan0. Save it as
974the latest three seconds after no traffic.
975Save it as <path>/etc/init.d/pm.wlan0</path> and add it to the battery runlevel 1204<path>/etc/init.d/pmg_wlan0</path> and add it to the battery runlevel like the
976like the disk script above. See <c>man iwconfig</c> for details and more 1205disk script above. See <c>man iwconfig</c> for details and more options like
977options. If your driver and access point support changing the beacon time, this 1206the period between wakeups or timeout settings. If your driver and access point
978is a good starting point to save even more energy. 1207support changing the beacon time, this is a good starting point to save even
1208more energy.
979</p> 1209</p>
980 1210
981<pre caption="Power Management for WLAN"> 1211<pre caption="Power Management for WLAN">
982# <i>chmod +x /etc/init.d/pm.wlan0</i> 1212# <i>chmod +x /etc/init.d/pmg_wlan0</i>
983# <i>/sbin/depscan.sh</i> 1213# <i>/sbin/depscan.sh</i>
984# <i>rc-update add pm.wlan0 battery</i> 1214# <i>rc-update add pmg_wlan0 battery</i>
985</pre> 1215</pre>
986 1216
987</body> 1217</body>
988</section> 1218</section>
989<section> 1219<section>
994There are two problems with USB devices regarding energy consumption: First, 1224There are two problems with USB devices regarding energy consumption: First,
995devices like USB mice, digital cameras or USB sticks consume energy while 1225devices like USB mice, digital cameras or USB sticks consume energy while
996plugged in. You cannot avoid this (nevertheless remove them in case they're not 1226plugged in. You cannot avoid this (nevertheless remove them in case they're not
997needed). Second, when there are USB devices plugged in, the USB host controller 1227needed). Second, when there are USB devices plugged in, the USB host controller
998periodically accesses the bus which in turn prevents the CPU from going into 1228periodically accesses the bus which in turn prevents the CPU from going into
999C3/4 sleep mode. The OS answer to this problem is the so called "USB selective 1229sleep mode. The kernel offers an experimental option to enable suspension of
1000suspend", which has not yet been implemented in the kernel. USB selective 1230USB devices through driver calls or one of the <path>power/state</path> files
1001suspend only allows bus accesses in case the device is in use. The cruel 1231in <path>/sys</path>.
1002workaround until it's implemented is as following: Compile USB support and 1232</p>
1003devices as modules and remove them via a script while they are not in use (e.g. 1233
1004when closing the lid). 1234<pre caption="Enabling USB suspend support in the kernel">
1235Device Drivers
1236 USB support
1237 [*] Support for Host-side USB
1238 [*] USB suspend/resume (EXPERIMENTAL)
1005</p> 1239</pre>
1006 1240
1007</body> 1241</body>
1008</section> 1242</section>
1009</chapter> 1243</chapter>
1010 1244
1011<chapter> 1245<chapter>
1012<title>Sleep states: sleep, standby, suspend to disk</title> 1246<title>Sleep States: sleep, standby, and suspend to disk</title>
1013<section> 1247<section>
1014<title>Overview</title>
1015<body> 1248<body>
1016 1249
1017<p> 1250<p>
1018ACPI defines different sleep states. The more important ones are 1251ACPI defines different sleep states. The more important ones are
1019</p> 1252</p>
1020 1253
1021<ul> 1254<ul>
1022 <li>S1 aka Standby</li> 1255 <li>S1 aka Standby</li>
1023 <li>S3 aka Suspend to RAM aka Sleep</li> 1256 <li>S3 aka Suspend to RAM aka Sleep</li>
1024 <li>S4 aka Suspend to Disk aka Hibernate</li> 1257 <li>S4 aka Suspend to Disk aka Hibernate</li>
1025</ul> 1258</ul>
1026 1259
1030</p> 1263</p>
1031 1264
1032</body> 1265</body>
1033</section> 1266</section>
1034<section> 1267<section>
1035<title>Sleep, Standby &amp; Hibernate</title> 1268<title>Sleep (S3)</title>
1036<body> 1269<body>
1037 1270
1038<p> 1271<p>
1039The ACPI support for these sleep states is marked as experimental for good 1272The ACPI support for these sleep states is marked experimental for good reason.
1040reason. APM sleep states seem to be more stable, however you can't use APM and 1273APM sleep states seem to be more stable, however you can't use APM and ACPI
1041ACPI together. 1274together.
1275</p>
1276
1277<pre caption="Kernel configuration for the various suspend types">
1278 Power Management Options ---&gt;
1279 [*] Power Management support
1280 ACPI (Advanced Configuration and Power Interface) Support ---&gt;
1281 [*] ACPI Support
1282 [*] Sleep States
1283</pre>
1284
1285<p>
1286Once your kernel is properly configured, you can use the
1287<c>hibernate-script</c> to activate suspend or sleep mode. Let's install that
1288first.
1289</p>
1290
1291<pre caption="Installing the hibernate-script">
1292# <i>emerge hibernate-script</i>
1293</pre>
1294
1295<p>
1296Some configuration has to be done in <path>/etc/hibernate</path> The default
1297package introduces two configuration files <path>hibernate.conf</path> and
1298<path>ram.conf</path>.
1299</p>
1300
1301<p>
1302To configure sleep, edit <path>ram.conf</path> in <path>/etc/hibernate</path>.
1303<c>UseSysfsPowerState mem</c> is already setup correctly, but you have to go
1304through the rest of the configuration file and set it up for your system. The
1305comments and option names will guide you. If you use nfs or samba shares over
1306the network, make sure to shutdown the appropriate init scripts to avoid
1307timeouts.
1308</p>
1309
1310<p>
1311Ready? Now is the last chance to backup any data you want to keep after
1312executing the next command. Notice that you probably have to hit a special key
1313like <c>Fn</c> to resume from sleep.
1314</p>
1315
1316<pre caption="Calling sleep">
1317# <i>hibernate-ram</i>
1318</pre>
1319
1320<p>
1321If you're still reading, it seems to work. You can also setup standby (S1) in a
1322similar way by copying <path>ram.conf</path> to <path>standby.conf</path> and
1323creating a symlink <path>/usr/sbin/hibernate-standby</path> pointing to
1324<path>/usr/sbin/hibernate</path>. S3 and S4 are the more interesting sleep
1325states due to greater energy savings however.
1326</p>
1327
1328</body>
1329</section>
1330<section>
1331<title>Hibernate (S4)</title>
1332<body>
1333
1334<p>
1335This section introduces hibernation, where a snapshot of the running system is
1336written to disk before powering off. On resume, the snapshot is loaded and you
1337can go on working at exactly the point you called hibernate before.
1042</p> 1338</p>
1043 1339
1044<warn> 1340<warn>
1045Altough sleep state support is improving much, it's still rather experimental. 1341Don't exchange non hot-pluggable hardware when suspended. Don't attempt to load
1046At last I got swsusp2 and suspend to RAM to work, but be warned: This will very 1342a snapshot with a different kernel image than the one it was created with.
1047likely not work but damage your data/system. 1343Shutdown any NFS or samba server/client before hibernating.
1048</warn> 1344</warn>
1049 1345
1050<p> 1346<p>
1051There are currently three implementations for S4. The original one is swsusp, 1347There are two different implementations for S4. The original one is swsusp,
1052then there is swsusp2 which has the nicest interface (including bootsplash 1348then there is the newer suspend2 with a nicer interface (including fbsplash
1053support), but requires manual kernel patching. Last not least we have 1349support). A <uri link="http://suspend2.net/features.html#compare"> feature
1054Suspend-to-Disk, a fork of swsusp. 1350comparison</uri> is available at the <uri link="http://suspend2.net"> suspend2
1055</p> 1351Homepage</uri>. There used to be Suspend-to-Disk (pmdisk), a fork of swsusp,
1056 1352but it has been merged back.
1057<p> 1353</p>
1058If this confused you, have a look at a <uri 1354
1059link="http://softwaresuspend.berlios.de/features.html#compare">feature
1060comparison</uri>. If you still are confused and don't know which one to choose,
1061first give swsusp2 a try, it looks most promising.
1062</p> 1355<p>
1063 1356Suspend2 is not included in the mainline kernel yet, therefore you either have
1357to patch your kernel sources with the patches provided by <uri
1358link="http://suspend2.net">suspend2.net</uri> or use
1359<c>sys-kernel/suspend2-sources</c>.
1064<p> 1360</p>
1065The kernel part for this is as following: 1361
1362<p>
1363The kernel part for both swusp and suspend2 is as follows:
1066</p> 1364</p>
1067 1365
1068<pre caption="Kernel configuration for the various suspend types"> 1366<pre caption="Kernel configuration for the various suspend types">
1069Power Management Options ---&gt; 1367Power Management Options ---&gt;
1070
1071 <comment>(sleep and standby)</comment>
1072 ACPI( Advanced Configuration and Power Interface ) Support --->
1073 [*] ACPI Support
1074 [*] Sleep States
1075
1076 <comment>(hibernate with swsusp)</comment> 1368 <comment>(hibernate with swsusp)</comment>
1077 [*] Software Suspend (EXPERIMENTAL) 1369 [*] Software Suspend
1078 1370 <comment>(replace /dev/SWAP with your swap partition)</comment>
1371 (/dev/SWAP) Default resume partition
1372
1079 <comment>(hibernate with swsusp2)</comment> 1373 <comment>(hibernate with suspend2)</comment>
1080 Software Suspend 2 1374 Software Suspend 2
1081 --- Image Storage (you need at least one writer) 1375 --- Image Storage (you need at least one writer)
1376 [*] File Writer
1082 [*] Swap Writer 1377 [*] Swap Writer
1083 --- Page Transformers 1378 --- General Options
1084 [*] LZF image compression 1379 [*] LZF image compression
1380 <comment>(replace /dev/SWAP with your swap partition)</comment>
1085 (/dev/"your-swap-here") Default resume device name 1381 (swap:/dev/SWAP) Default resume device name
1086 1382 [ ] Allow Keep Image Mode
1087 <comment>(hibernate with Suspend-to-Disk)</comment>
1088 [*] Suspend-to-Disk Suport
1089 (/dev/"your-swap-here") Default resume partition
1090</pre> 1383</pre>
1091 1384
1092<p>
1093Compile your kernel with the appropriate options enabled and issue <c>cat
1094/proc/acpi/sleep</c> for 2.4 series respectively <c>cat /sys/power/state</c>
1095for 2.6 to find out what is supported. The latter gives me <c>standby mem
1096disk</c>. For swsusp, the kernel parameter <c>resume=/dev/"your-swap-here"</c>
1097has to be appended. If booting is not possible due to a broken image, use
1098<c>noresume</c> for swsusp, <c>pmdisk=off</c> for Suspend-to-Disk and
1099<c>noresume2</c> for swsusp2.
1100</p> 1385<p>
1101 1386The configuration for swsusp is rather easy. If you didn't store the location
1387of your swap partition in the kernel config, you can also pass it as a
1388parameter with the <c>resume=/dev/SWAP</c> directive. If booting is not
1389possible due to a broken image, use the <c>noresume</c> kernel parameter. The
1390<c>hibernate-cleanup</c> init script invalidates swsusp images during the boot
1391process.
1102<p> 1392</p>
1103To put your system in one of the sleep states, use 1393
1394<pre caption="Invalidating swsusp images during the boot process">
1395# <i>rc-update add hibernate-cleanup boot</i>
1396</pre>
1397
1104</p> 1398<p>
1105 1399To activate hibernate with swsusp, use the hibernate script and set
1106<pre caption="Activating sleep states"> 1400<c>UseSysfsPowerState disk</c> in <path>/etc/hibernate/hibernate.conf</path>.
1107<comment>(kernel 2.4 series)</comment>
1108# <i>echo 1 &gt; /proc/acpi/sleep</i> <comment>(standby)</comment>
1109# <i>echo 3 &gt; /proc/acpi/sleep</i> <comment>(sleep)</comment>
1110
1111<comment>(kernel 2.6 series)</comment>
1112# <i>echo -n standby &gt; /sys/power/state</i> <comment>(standby)</comment>
1113# <i>echo -n mem &gt; /sys/power/state</i> <comment>(sleep)</comment>
1114
1115<comment>(swsusp)</comment>
1116# <i>echo 4 &gt; /proc/acpi/sleep</i> <comment>(hibernate)</comment>
1117
1118<comment>(Suspend-to-Disk)</comment>
1119# <i>echo -n disk &gt; /sys/power/state</i> <comment>(hibernate)</comment>
1120
1121<comment>(swsusp2)</comment>
1122# <i>/usr/sbin/hibernate</i> <comment>(hibernate, see below)</comment>
1123</pre> 1401</p>
1124 1402
1125<warn> 1403<warn>
1126Backup your data before doing this. Run <c>sync</c> before executing one of the 1404Backup your data before doing this. Run <c>sync</c> before executing one of the
1127commands to have cached data written to disk. First try it outside of X, then 1405commands to have cached data written to disk. First try it outside of X, then
1128with X running, but not logged in. 1406with X running, but not logged in.
1129</warn> 1407</warn>
1130 1408
1131<p> 1409<p>
1132If you experience kernel panics due to uhci or similar, try to compile USB 1410If you experience kernel panics due to uhci or similar, try to compile USB
1133support as module and unload the modules before sending your laptop to sleep 1411support as module and unload the modules before sending your laptop to sleep
1134mode. 1412mode. There are configuration options for this in <path>hibernate.conf</path>
1135</p>
1136
1137<p> 1413</p>
1138While the above should be sufficient to get swsusp and Suspend-to-Disk running
1139(I didn't say working), swsusp2 needs special care.
1140The first thing to do is patching the kernel with the patches provided at <uri
1141link="http://softwaresuspend.berlios.de/">
1142http://softwaresuspend.berlios.de/</uri>. Additionally you've got to emerge
1143<c>hibernate-script</c>. Once it is installed, configure
1144<path>/etc/hibernate/hibernate.conf</path> and try whether it works:
1145</p>
1146 1414
1415<pre caption="Hibernating with swsusp">
1416# <i>nano -w /etc/hibernate.conf</i>
1417<comment>(Make sure you have a backup of your data)</comment>
1418# <i>hibernate</i>
1147<pre> 1419</pre>
1148<i># emerge hibernate-script</i> 1420
1149<i># $EDITOR /etc/hibernate/hibernate.conf</i> 1421<p>
1150<comment>(Last chance to backup any data)</comment> 1422The following section discusses the setup of suspend2 including fbsplash
1423support for a nice graphical progress bar during suspend and resume.
1424</p>
1425
1426<p>
1427The first part of the configuration is similar to the configuration of swsusp.
1428In case you didn't store the location of your swap partition in the kernel
1429config, you have to pass it as a kernel parameter with the
1430<c>resume2=swap:/dev/SWAP</c> directive. If booting is not possible due to a
1431broken image, append the <c>noresume2</c> parameter. Additionally, the
1432<c>hibernate-cleanup</c> init script invalidates suspend2 images during the
1433boot process.
1434</p>
1435
1436<pre caption="Invalidating suspend2 images during the boot process">
1437# <i>rc-update add hibernate-cleanup boot</i>
1438</pre>
1439
1440<p>
1441Now edit <path>/etc/hibernate/hibernate.conf</path>, enable the <c>suspend2</c>
1442section and comment everything in the <c>sysfs_power_state</c> and
1443<c>acpi_sleep</c> sections. Do not enable the <c>fbsplash</c> part in global
1444options yet.
1445</p>
1446
1447<pre caption="Hibernating with suspend2">
1448# <i>nano -w /etc/hibernate.conf</i>
1449<comment>(Make sure you have a backup of your data)</comment>
1151<i># hibernate</i> 1450# <i>hibernate</i>
1451</pre>
1452
1453<p>
1454Please configure <c>fbsplash</c> now if you didn't do already. To enable
1455fbsplash support during hibernation, the <c>sys-apps/suspend2-userui</c>
1456package is needed. Additionally, you've got to enable the <c>fbsplash</c> USE
1457flag.
1152</pre> 1458</p>
1459
1460<pre caption="Installing suspend2-userui">
1461# <i>mkdir -p /etc/portage</i>
1462# <i>echo "sys-apps/suspend2-userui fbsplash" >> /etc/portage/package.use</i>
1463# <i>emerge suspend2-userui</i>
1464</pre>
1465
1466<p>
1467The ebuild tells you to make a symlink to the theme you want to use. For
1468example, to use the <c>livecd-2005.1</c> theme, run the following command:
1469</p>
1470
1471<pre caption="Using the livecd-2005.1 theme during hibernation">
1472# <i>ln -sfn /etc/splash/livecd-2005.1 /etc/splash/suspend2</i>
1473</pre>
1474
1475<p>
1476If you don't want a black screen in the first part of the resume process, you
1477have to add the <c>suspend2ui_fbsplash</c> tool to your initrd image. Assuming
1478you created the initrd image with <c>splash_geninitramfs</c> and saved it as
1479<path>/boot/fbsplash-emergence-1024x768</path>, here's how to do that.
1480</p>
1481
1482<pre caption="Adding suspend2ui_fbsplash to an initrd image">
1483# <i>mount /boot</i>
1484# <i>mkdir ~/initrd.d</i>
1485# <i>cp /boot/fbsplash-emergence-1024x768 ~/initrd.d/</i>
1486# <i>cd ~/initrd.d</i>
1487# <i>gunzip -c fbsplash-emergence-1024x768 | cpio -idm --quiet -H newc</i>
1488# <i>rm fbsplash-emergence-1024x768</i>
1489# <i>cp /usr/sbin/suspend2ui_fbsplash sbin/</i>
1490# <i>find . | cpio --quiet --dereference -o -H newc | gzip -9 > /boot/fbsplash-suspend2-emergence-1024x768</i>
1491</pre>
1492
1493<p>
1494Afterwards adjust <path>grub.conf</path> respectively <path>lilo.conf</path> so
1495that your suspend2 kernel uses
1496<path>/boot/fbsplash-suspend2-emergence-1024x768</path> as initrd image. You
1497can now test a dry run to see if everything is setup correctly.
1498</p>
1499
1500<pre caption="Test run for fbsplash hibernation">
1501# <i>suspend2ui_fbsplash -t</i>
1502</pre>
1503
1504<p>
1505Afterwards open <path>/etc/hibernate/hibernate.conf</path> again and activate
1506the fbsplash options. Execute <c>hibernate</c> and enjoy.
1507</p>
1153 1508
1154</body> 1509</body>
1155</section> 1510</section>
1156</chapter> 1511</chapter>
1157 1512
1158<chapter> 1513<chapter>
1159<title>Troubleshooting</title> 1514<title>Troubleshooting</title>
1160<section> 1515<section>
1161<title>If things go wrong...</title>
1162<body> 1516<body>
1163 1517
1164<p> 1518<p>
1165<e>Q:</e> I'm trying to change the CPU frequency, but 1519<e>Q:</e> I'm trying to change the CPU frequency, but
1166<path>/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor</path> does not 1520<path>/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor</path> does not
1191Try to update the BIOS, especially if a broken DSDT is reported. You can also 1545Try to update the BIOS, especially if a broken DSDT is reported. You can also
1192try to fix it yourself (which is beyond the scope of this guide). 1546try to fix it yourself (which is beyond the scope of this guide).
1193</p> 1547</p>
1194 1548
1195<p> 1549<p>
1196<e>Q:</e> My laptop supports frequency scaling, but according to /proc/cpuinfo 1550<e>Q:</e> My laptop supports frequency scaling, but according to
1197the speed never changes. 1551<path>/proc/cpuinfo</path> the speed never changes.
1198</p> 1552</p>
1199 1553
1200<p> 1554<p>
1201<e>A:</e> Probably you have activated symmetric multiprocessing support 1555<e>A:</e> Probably you have activated symmetric multiprocessing support
1202(CONFIG_SMP) in your kernel. Deactivate it and it should work. Some older 1556(CONFIG_SMP) in your kernel. Deactivate it and it should work. Some older
1203kernels had a bug causing this. In that case, run <c>emerge x86info</c>, 1557kernels had a bug causing this. In that case, run <c>emerge x86info</c>, update
1204update your kernel as asked and check the current frequency with 1558your kernel as asked and check the current frequency with
1205<c>x86info -mhz</c>. 1559<c>x86info -mhz</c>.
1206</p> 1560</p>
1207 1561
1208<p> 1562<p>
1209<e>Q:</e> I can change the CPU frequency, but the range is not as wide as in 1563<e>Q:</e> I can change the CPU frequency, but the range is not as wide as in
1229<e>A:</e> The ondemand governor is only included in recent kernel sources. Try 1583<e>A:</e> The ondemand governor is only included in recent kernel sources. Try
1230updating them. 1584updating them.
1231</p> 1585</p>
1232 1586
1233<p> 1587<p>
1234<e>Q:</e> Runlevel switching doesn't work - the script is not able to determine
1235the power source correctly.
1236</p>
1237
1238<p>
1239<e>A:</e> On some systems, the power source can't be determined by reading
1240<path>/proc/acpi/ac_adapter/*/state</path>. If it fails for you, create a
1241custom script <c>on_ac_power</c> or use the one from <c>powermgmt-base</c>.
1242An ebuild can be found in <uri
1243link="http://bugs.gentoo.org/show_bug.cgi?id=76516">Bug #76516</uri>. You
1244only have to emerge it, it works transparently with the above script.
1245</p>
1246
1247<p>
1248<e>Q:</e> Battery life time seems to be worse than before. 1588<e>Q:</e> Battery life time seems to be worse than before.
1249</p> 1589</p>
1250 1590
1251<p> 1591<p>
1252<e>A:</e> Check your BIOS settings. Maybe you forgot to re-enable some of the 1592<e>A:</e> Check your BIOS settings. Maybe you forgot to re-enable some of the
1262<e>A:</e> Check that battery support is compiled into your kernel. If you use 1602<e>A:</e> Check that battery support is compiled into your kernel. If you use
1263it as a module, make sure the module is loaded. 1603it as a module, make sure the module is loaded.
1264</p> 1604</p>
1265 1605
1266<p> 1606<p>
1607<e>Q:</e> My system logger reports things like "logger: ACPI group battery /
1608action battery is not defined".
1609</p>
1610
1611<p>
1612<e>A:</e> This message is generated by the <path>/etc/acpi/default.sh</path>
1613script that is shipped with acpid. You can safely ignore it. If you like to get
1614rid of it, you can comment the appropriate line in
1615<path>/etc/acpi/default.sh</path> as shown below:
1616</p>
1617
1618<pre caption="Disabling warnings about unknown acpi events">
1619 *) # logger "ACPI action $action is not defined"
1620</pre>
1621
1622<p>
1267<e>Q:</e> I have a Dell Inspiron 51XX and I don't get any ACPI events. 1623<e>Q:</e> I have a Dell Inspiron 51XX and I don't get any ACPI events.
1268</p> 1624</p>
1269 1625
1270<p> 1626<p>
1271<e>A:</e> This seems to be a kernel bug. Read on <uri 1627<e>A:</e> This seems to be a kernel bug. Read on <uri
1272link="http://bugme.osdl.org/show_bug.cgi?id=1752">here</uri>. 1628link="http://bugme.osdl.org/show_bug.cgi?id=1752">here</uri>.
1273</p> 1629</p>
1274 1630
1275<p> 1631<p>
1632<e>Q:</e> I activated the <c>DynamicClocks</c> option in <path>xorg.conf</path>
1633and now X.org crashes / the screen stays black / my laptop doesn't shutdown
1634properly.
1635</p>
1636
1637<p>
1638<e>A:</e> This happens on some systems. You have to disable
1639<c>DynamicClocks</c>.
1640</p>
1641
1642<p>
1643<e>Q:</e> I want to use suspend2, but it tells me my swap partition is too
1644small. Resizing is not an option.
1645</p>
1646
1647<p>
1648<e>A:</e> If there is enough free space on your system, you can use the
1649filewriter instead of the swapwriter. The <c>hibernate-script</c> supports it
1650as well. More information can be found in
1651<path>/usr/src/linux/Documentation/power/suspend2.txt</path>.
1652</p>
1653
1654<p>
1276<e>Q:</e> I just bought a brand new battery, but it only lasts for some 1655<e>Q:</e> I just bought a brand new battery, but it only lasts for some
1277minutes! What am I doing wrong? 1656minutes! What am I doing wrong?
1278</p> 1657</p>
1279 1658
1280<p> 1659<p>
1281<e>A:</e> First follow your manufacturer's advice on how to charge the battery 1660<e>A:</e> First follow your manufacturer's advice on how to charge the battery
1282correctly. 1661correctly.
1283</p> 1662</p>
1284 1663
1285<p> 1664<p>
1286<e>Q:</e> The above didn't help. What should I do then? 1665<e>Q:</e> The above didn't help. What should I do then?
1287</p> 1666</p>
1304<p> 1683<p>
1305<e>Q:</e> My problem is not listed above. Where should I go next? 1684<e>Q:</e> My problem is not listed above. Where should I go next?
1306</p> 1685</p>
1307 1686
1308<p> 1687<p>
1309<e>A:</e> Don't fear to contact me, <mail link="fragfred@gmx.de">Dennis 1688<e>A:</e> Don't fear to contact me, <mail link="earthwings@gentoo.org">Dennis
1310Nienhüser</mail>, directly. 1689Nienhüser</mail>, directly. The <uri link="http://forums.gentoo.org">Gentoo
1690Forums</uri> are a good place to get help as well. If you prefer IRC, try the
1691<c>#gentoo-laptop</c> channel at <uri
1692link="irc://irc.freenode.net">irc.freenode.net</uri>.
1311</p> 1693</p>
1312 1694
1313</body> 1695</body>
1314</section> 1696</section>
1315</chapter> 1697</chapter>

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.21

  ViewVC Help
Powered by ViewVC 1.1.20