/[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.17 - (hide annotations) (download) (as text)
Sun Feb 12 11:53:08 2006 UTC (8 years, 7 months ago) by nightmorph
Branch: MAIN
Changes since 1.16: +253 -123 lines
File MIME type: application/xml
Power management guide updated for bug 122017

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

  ViewVC Help
Powered by ViewVC 1.1.20