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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (hide annotations) (download) (as text)
Thu Jul 27 08:13:32 2006 UTC (8 years, 4 months ago) by rane
Branch: MAIN
Changes since 1.18: +133 -132 lines
File MIME type: application/xml
#123776, fixed the coding style a lot

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

  ViewVC Help
Powered by ViewVC 1.1.20