/[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.50 - (show annotations) (download) (as text)
Fri Sep 30 15:07:46 2011 UTC (2 years, 11 months ago) by cam
Branch: MAIN
Changes since 1.49: +2 -2 lines
File MIME type: application/xml
typo fixed (Chema Alonso)

1 <?xml version='1.0' encoding="UTF-8"?>
2 <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
3 <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/power-management-guide.xml,v 1.49 2011/09/23 18:41:52 swift Exp $ -->
4
5 <guide>
6 <title>Power Management Guide</title>
7
8 <author title="Author">
9 <mail link="swift"/>
10 </author>
11
12 <abstract>
13 In recent years, power management has become one of the differentiating
14 features in the quest for finding the perfect laptop. Yet, the operating system
15 must support the various power saving functionalities too. In this guide, we
16 cover how to setup your Gentoo installation so it manages power-hungry resources
17 in a flexible yet automated manner.
18 </abstract>
19
20 <!-- The content of this document is licensed under the CC-BY-SA license -->
21 <!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
22 <license/>
23
24 <version>5</version>
25 <date>2011-09-22</date>
26
27 <chapter>
28 <title>Introduction</title>
29 <section>
30 <title>About this document...</title>
31 <body>
32
33 <p>
34 This document describes the setup of power management features on your laptop.
35 Although some of the information in this guide can be applied to power
36 management for servers, it is not the intention of this document to go that
37 route. Please be careful when applying this on a non-laptop system.
38 </p>
39
40 <p>
41 Within this document, we will focus primarily on the laptop mode tools since it
42 offers a complete set of functionalities. However, we will also refer to other
43 tools that might offer a more detailed approach on individual settings. In such
44 cases, you will need to disable the feature from the laptop mode tools so that
45 both tools do not fight over the same resource control.
46 </p>
47
48 </body>
49 </section>
50 <section>
51 <title>About laptop_mode</title>
52 <body>
53
54 <p>
55 The <c>laptop_mode</c> setting is an in-kernel configuration setting that
56 optimizes I/O, allowing disks to spin down properly (and not be woken up
57 immediately afterwards for queued operations).
58 </p>
59
60 </body>
61 </section>
62 <section>
63 <title>About laptop-mode-tools</title>
64 <body>
65
66 <p>
67 The <e>Laptop Mode Tools</e> is a software package
68 (<c>app-laptop/laptop-mode-tools</c>) which allows the user to optimize power
69 saving functions. It allows managing the <c>laptop_mode</c> setting in the Linux
70 kernel, but has additional features allowing you to tweak other power-related
71 settings on the system.
72 </p>
73
74 </body>
75 </section>
76 </chapter>
77
78 <chapter>
79 <title>Linux Kernel Configuration</title>
80 <section>
81 <title>Minimum kernel setup</title>
82 <body>
83
84 <p>
85 There are different kernel sources in Portage. We recommend using
86 <c>gentoo-sources</c>, but if you want advanced hibernation support you might
87 need <c>tuxonice-sources</c>. To enable proper power management features in the
88 Linux kernel, enable at least the following settings:
89 </p>
90
91 <pre caption="Minimum kernel setup for Power Management (Kernel 2.6)">
92 <![CDATA[
93 General setup --->
94 [*] Configure standard kernel features (expert users) --->
95
96 Power management and ACPI options --->
97 [*] ACPI (Advanced Configuration and Power Interface) Support --->
98 <*> AC Adapter
99 <*> Battery
100 -*- Button
101 -*- Video
102 <*> Fan
103 <*> Processor
104 <*> Thermal Zone
105 [*] Power Management Timer Support
106
107 [*] CPU Frequency scaling --->
108 [*] CPU Frequency scaling
109 <*> 'performance' governor
110 <*> 'powersave' governor
111 <*> 'userspace' governor
112 <*> 'ondemand' governor
113 <*> 'conservative' governor
114 <*> ACPI Processor P-States driver
115 ]]>
116 </pre>
117
118 <p>
119 Don't forget to enable the CPU frequency scaling driver for your CPU, located
120 right after the <e>ACPI Processor P-States driver</e> mentioned above.
121 </p>
122
123 <p>
124 Build and install the new kernel (if necessary) and reboot.
125 </p>
126
127 </body>
128 </section>
129 <!--
130 <section id="kernelconfig">
131 <title>Additional kernel configuration entries</title>
132 <body>
133
134 <p>
135 Further down this guide, additional kernel settings might be suggested. To
136 lessen the effort to maintain the guide, and to make sure settings are correctly
137 identified, we will use the kernel configuration short-hand notations. These
138 notations are simple strings, like <c>CONFIG_USB_SUSPEND</c>. But how to read
139 this?
140 </p>
141
142 <p>
143 Well, then you configure your kernel (through <c>make menuconfig</c>), you can
144 search through the configuration settings for a particular entry. Press <c>/</c>
145 while configuring the Linux kernel and type the setting
146 (<c>CONFIG_USB_SUSPEND</c>). The software will tell you what the setting is,
147 what it is for, when you can select it (i.e. on which settings it depends before
148 you can see it) but most importantly, where you can find it.
149 </p>
150
151 <pre caption="Result of a search operation during menuconfig">
152 <![CDATA[Symbol: USB_SUSPEND [=n]
153 Type : boolean
154 Prompt: USB runtime power management (autosuspend) and wakeup
155 Defined at drivers/usb/core/Kconfig:93
156 Depends on: USB_SUPPORT [=y] && USB [=y] && PM_RUNTIME [=n]
157 Location:
158 -> Device Drivers
159 -> USB support (USB_SUPPORT [=y])
160 -> Support for Host-side USB (USB [=y]) ]]>
161 </pre>
162
163 </body>
164 </section>
165 -->
166 </chapter>
167
168 <chapter>
169 <title>Using Laptop Mode Tools</title>
170 <section>
171 <title>Installation</title>
172 <body>
173
174 <p>
175 It comes to no surprise that installation of the <e>Laptop Mode Tools</e>
176 software is easily done through <c>emerge laptop-mode-tools</c>. However, this
177 package takes on additional, optional settings through USE flag configuration.
178 So let's first take a look at the supported USE flags and what they mean to the
179 package.
180 </p>
181
182 <table>
183 <tr>
184 <th>USE flag</th>
185 <th>Description</th>
186 <th>Suggested when...</th>
187 </tr>
188 <tr>
189 <ti>acpi</ti>
190 <ti>
191 Depend on <c>sys-power/acpid</c> so that changes in the system are
192 captured and power saving features are automatically enabled/disabled.
193 </ti>
194 <ti>your laptop is not too old (~ year 2003 and later)</ti>
195 </tr>
196 <tr>
197 <ti>apm</ti>
198 <ti>
199 Depend on <c>sys-apps/apmd</c> so that changes in the system are captured
200 and power saving features are automatically enabled/disabled.
201 </ti>
202 <ti>your laptop is very old</ti>
203 </tr>
204 <tr>
205 <ti>bluetooth</ti>
206 <ti>
207 Depend on <c>net-wireless/bluez</c>, enabling the <c>laptop-mode-tools</c>
208 to manage bluetooth settings (enabling/disabling the service based on
209 battery availability)
210 </ti>
211 <ti>your laptop (and kernel) supports bluetooth</ti>
212 </tr>
213 <tr>
214 <ti>scsi</ti>
215 <ti>
216 Depend on <c>sys-apps/sdparm</c>, enabling the <c>laptop-mode-tools</c> to
217 manage SCSI (<e>and not</e> SATA) disk parameters.
218 </ti>
219 <ti>your laptop uses SCSI disks</ti>
220 </tr>
221 </table>
222
223 <p>
224 As you can see, there are two USE flags that seem to collide: <c>acpi</c> and
225 <c>apm</c>. So what's the deal there?
226 </p>
227
228 <ul>
229 <li>
230 The <c>apm</c> USE flag enables support for <e>Advanced Power
231 Management</e>, an older (before year 2000) standard for power management
232 features within a system.
233 </li>
234 <li>
235 The <c>acpi</c> USE flag enables support for <e>Advanced Configuration and
236 Power Interface</e>, the successor of APM. All modern laptops support ACPI.
237 </li>
238 </ul>
239
240 <p>
241 Depending on your system, you will either need <c>acpi</c> or <c>apm</c> set. In
242 the remainder of this guide, we assume that your laptop is recent enough to use
243 ACPI.
244 </p>
245
246 <p>
247 So, with the USE flags set, let's install <c>laptop-mode-tools</c>.
248 </p>
249
250 <note>
251 If you have USE="acpi" set, the installation will pull in <c>acpid</c>. However,
252 the current stable ACPI daemon (2.0.9) does not support the new ACPI interfaces
253 within the Linux kernel (using the netlink interface). As such, we recommend
254 unmasking <c>sys-power/acpid-2.0.12</c> (or higher). For more information about
255 unmasking packages, please read
256 <uri link="/doc/en/handbook/handbook-amd64.xml?part=3&amp;chap=3">Mixing Software
257 Branches</uri> in the Gentoo Handbook.
258 </note>
259
260 <pre caption="Installing laptop-mode-tools">
261 # <i>emerge laptop-mode-tools</i>
262 </pre>
263
264 </body>
265 </section>
266 <section>
267 <title>Configuration</title>
268 <body>
269
270 <p>
271 Having <c>laptop-mode-tools</c> installed on your system does not automatically
272 enable the power management features that you might need. To configure the
273 package, first take a look at <path>/etc/laptop-mode/laptop-mode.conf</path>.
274 This is the main configuration file for the package and is pretty well described
275 (through comments).
276 </p>
277
278 <p>
279 But it is not the only configuration file to work with. The Laptop Mode Tools
280 package supports plugins (or modules) which have their own configuration
281 file(s). These files are located in <path>/etc/laptop-mode/conf.d</path> and are
282 named after the module they represent (such as
283 <path>intel-sata-powermgmt.conf</path>).
284 </p>
285
286 <p>
287 Now, one of the important settings in each configuration file is if the Laptop
288 Mode Tools package should govern a particular setting or not. This is important
289 when you want to combine <c>laptop-mode-tools</c> with other services like
290 <c>cpufreqd</c>. In this example case, you will need to set
291 <c>CONTROL_CPU_FREQUENCY=0</c>:
292 </p>
293
294 <pre caption="Editing /etc/laptop-mode/conf.d/cpufreq.conf">
295 # <i>nano -w /etc/laptop-mode/conf.d/cpufreq.conf</i>
296 CONTROL_CPU_FREQUENCY=<i>0</i>
297 </pre>
298
299 <p>
300 The next few sections will help you configure <c>laptop-mode-tools</c> to suit
301 your needs. When you are finished, start the <c>laptop_mode</c> service and make
302 sure it is started when you boot up your system.
303 </p>
304
305 <pre caption="Starting the laptop_mode service">
306 # <i>/etc/init.d/laptop_mode start</i>
307 # <i>rc-update add laptop_mode default</i>
308 </pre>
309
310 </body>
311 </section>
312 <section>
313 <title>How does laptop-mode-tools work</title>
314 <body>
315
316 <p>
317 When running the <c>laptop_mode</c> service, the software will check in which
318 state your system is in. The states are defined as:
319 </p>
320
321 <ul>
322 <li>
323 <e>Battery</e>, in the configuration files using the <c>BATT_</c> prefix, is
324 active when the system is running on battery power
325 </li>
326 <li>
327 <e>AC</e>, in the configuration files using the <c>AC_</c> prefix, is active
328 when the system is running on AC power
329 </li>
330 <li>
331 <e>Laptop Mode</e>, in the configuration files using the <c>LM_</c> prefix,
332 is active when <e>laptop mode</e> is enabled
333 </li>
334 <li>
335 <e>No Laptop Mode</e>, in the configuration files using the <c>NOLM_</c>
336 prefix, is active when <e>laptop mode</e> is disabled
337 </li>
338 </ul>
339
340 <p>
341 The <c>AC/BATT_</c> and <c>LM/NOLM_</c> prefixes can be combined (so you can
342 have a <c>AC_LM_</c> prefix).
343 </p>
344
345 <p>
346 When the <c>laptop_mode</c> service is started, it will switch modes based on
347 events that occur (and of course based on the configuration settings). For
348 instance, the setting <c>ENABLE_LAPTOP_MODE_ON_BATTERY=1</c> will make sure that
349 the laptop mode tools switch to <e>laptop mode</e> when battery power is used.
350 If that is the case, then the settings starting with <c>LM_</c>,
351 <c>LM_BATT_</c>, <c>BATT_LM_</c> and <c>BATT_</c> will be used.
352 </p>
353
354 <p>
355 To make sure settings to not collide, it is not allowed to have overlapping
356 settigns. In the next example, the first set (for <c>CPU_MAXFREQ</c>) is valid,
357 but the second one (for <c>CPU_GOVERNOR</c>) isn't.
358 </p>
359
360 <pre caption="Colliding settings">
361 <comment>## Valid set</comment>
362 BATT_CPU_MAXFREQ=fastest
363 LM_AC_CPU_MAXFREQ=fastest
364 NOLM_AC_CPU_MAXFREQ=fastest
365
366 <comment>## Invalid set</comment>
367 BATT_CPU_MINFREQ=fastest
368 LM_AC_CPU_MINFREQ=fastest
369 <comment># The following includes AC and BATT, but BATT is already defined</comment>
370 NOLM_CPU_MINFREQ=fastest
371 </pre>
372
373 </body>
374 </section>
375 <section>
376 <title>Configuring CPU frequency management</title>
377 <body>
378
379 <p>
380 The support for CPU frequency management in the laptop mode tools allows
381 switching frequencies. It supports setting the CPU frequency governor, minimum
382 frequency and maximum frequency. The configuration file used here is
383 <path>/etc/laptop-mode/conf.d/cpufreq.conf</path>.
384 </p>
385
386 <p>
387 The <e>CPU frequency governor</e> is a kernel-level policy that defines how the
388 kernel will select the CPU frequency. We already selected the governors we want
389 to use in the kernel configuration earlier. Let's recap:
390 </p>
391
392 <ul>
393 <li>
394 <c>performance</c> always picks the highest frequency
395 </li>
396 <li>
397 <c>powersave</c> always picks the lowest frequency
398 </li>
399 <li>
400 <c>userspace</c> does not pick anything, but let the user decide (or any
401 process that the user is running that will decide for the user)
402 </li>
403 <li>
404 <c>ondemand</c> will scale the CPU frequency up to the highest frequency
405 when load is available
406 </li>
407 <li>
408 <c>conservative</c> will scale the CPU frequency up gradually when load is
409 available
410 </li>
411 </ul>
412
413 <p>
414 When switching between AC or battery, or (no) laptop mode, the appropriate
415 governor (as well as its minimum and maximum frequency) is selected.
416 </p>
417
418 </body>
419 </section>
420 <section>
421 <title>Configuring display brightness</title>
422 <body>
423
424 <p>
425 With <path>/etc/laptop-mode/conf.d/lcd-brightness.conf</path>, you can have the
426 laptop mode tools govern the brightness of your LCD screen.
427 </p>
428
429 <p>
430 The file currently uses the <path>/proc/acpi/video/VID/LCD/brightness</path>
431 file to set brightness values. Recent kernels do not provide this anymore -
432 you will need to adjust this to <path>/sys/class/backlight/acpi_video0/brightness</path>
433 instead.
434 </p>
435
436 <p>
437 The values you can use are between 0 and 15, with 0 being the lowest brightness
438 value.
439 </p>
440
441 </body>
442 </section>
443 <section>
444 <title>Configuring other services</title>
445 <body>
446
447 <p>
448 An interesting feature of <c>laptop-mode-tools</c> is to support reloading
449 particular services (like the system logger) after switching its configuration
450 file. This is handled through
451 <path>/etc/laptop-mode/conf.d/configuration-file-control.conf</path>.
452 </p>
453
454 <p>
455 If enabled, the <c>laptop_mode</c> application will switch the configuration
456 file(s) of the mentioned services with the same file, but suffixed with
457 <path>-nolm-ac</path>, <path>-lm-ac</path> or <path>-batt</path>. It willl then
458 signal or reload the appropriate services so they can use the new configuration
459 file.
460 </p>
461
462 </body>
463 </section>
464 </chapter>
465
466 <chapter>
467 <title>Using cpufreqd</title>
468 <section>
469 <title>Installation</title>
470 <body>
471
472 <p>
473 The <c>cpufreqd</c> application allows you to manage CPU frequencies in a more
474 granular approach then what <c>laptop-mode-tools</c> supports. But before we
475 dive into the installation of <c>cpufreqd</c>, let's first look at the USE flags
476 it supports.
477 </p>
478
479 <table>
480 <tr>
481 <th>USE flag</th>
482 <th>Description</th>
483 <th>Suggested when...</th>
484 </tr>
485 <tr>
486 <ti>acpi</ti>
487 <ti>
488 Enable support for ACPI, allowing <c>cpufreqd</c> to be notified about
489 specific events as well as govern power through the ACPI interface
490 </ti>
491 <ti>your laptop is not too old (~ year 2003 and later)</ti>
492 </tr>
493 <tr>
494 <ti>apm</ti>
495 <ti>
496 Enable support for APM, allowing <c>cpufreqd</c> to be notified about
497 specific events as well as govern power through the APM interface
498 </ti>
499 <ti>your laptop is very old</ti>
500 </tr>
501 <tr>
502 <ti>lm_sensors</ti>
503 <ti>
504 Enable support for the Linux hardware sensors (through
505 <c>sys-apps/lm_sensors</c>), allowing to switch profiles based on hardware
506 sensor results
507 </ti>
508 <ti>
509 you want to use advanced events through lm_sensors
510 </ti>
511 </tr>
512 <tr>
513 <ti>nforce2</ti>
514 <ti>
515 Enable support for NForce, allowing <c>cpufreqd</c> to change the NForce FSB
516 clock and video card frequency
517 </ti>
518 <ti>
519 you have an NVidia graphical card based on the NForce chipset
520 </ti>
521 </tr>
522 <tr>
523 <ti>nvidia</ti>
524 <ti>
525 Enable support for NVidia graphical card configuration (through the NVidia
526 <e>nvclock</e> interface), allowing <c>cpufreqd</c> to change the video card
527 frequency of NVidia graphical cards
528 </ti>
529 <ti>
530 you have an NVidia graphical card
531 </ti>
532 </tr>
533 <tr>
534 <ti>pmu</ti>
535 <ti>
536 Enable the Power Management Unit plug-in of <c>cpufreqd</c>. This allows the
537 software to poll the Linux kernel Power Supply interface, getting more
538 detailed information on battery charge.
539 </ti>
540 <ti>
541 your laptop does not support ACPI or APM
542 </ti>
543 </tr>
544 </table>
545
546 <p>
547 The USE flags <c>acpi</c>, <c>apm</c> and <c>pmu</c> overlap, so you should only
548 have one active. If your laptop is sufficiently recent, <c>acpi</c> is your best
549 bet. If not, <c>apm</c> offers all that is needed. When even APM isn't
550 supported, you can try <c>pmu</c>.
551 </p>
552
553 <p>
554 With the USE flags configured, it is time to install <c>cpufreqd</c>.
555 </p>
556
557 <pre caption="Installing cpufreqd">
558 # <i>emerge cpufreqd</i>
559 </pre>
560
561 </body>
562 </section>
563 <section>
564 <title>Configuration</title>
565 <body>
566
567 <p>
568 The <c>cpufreqd</c> application monitors the status of the system through
569 several plugins. Based on the feedback it receives from those plugins, it will
570 adjust the policy used to govern the CPU frequency.
571 </p>
572
573 <p>
574 <c>cpufreqd</c> can be configured by editing <path>/etc/cpufreqd.conf</path>. It
575 contains three different sections:
576 </p>
577
578 <ol>
579 <li>
580 The <c>[General]...[/General]</c> section contains general configuration
581 information
582 </li>
583 <li>
584 The <c>[Profile]...[/Profile]</c> section defines the policies that the
585 <c>cpufreqd</c> daemon can switch to. The section is very similar to the
586 information you use when manually setting the CPU frequency policy using
587 <c>cpufreq-set</c>.
588 </li>
589 <li>
590 The <c>[Rule]...[/Rule]</c> section is the work-horse of the <c>cpufreqd</c>
591 daemon, defining when the daemon decides to switch to a different profile.
592 </li>
593 </ol>
594
595 <p>
596 Let's take a quick look at an example rule.
597 </p>
598
599 <pre caption="Sample cpufreqd rule">
600 [Profile]
601 name=On Demand High
602 minfreq=40%
603 maxfreq=100%
604 policy=ondemand
605 [/Profile]
606
607 [Rule]
608 name=AC Off - High Power
609 ac=off
610 battery_interval=70-100
611 profile=On Demand High
612 [/Rule]
613 </pre>
614
615 <p>
616 In the above example, <c>cpufreqd</c> will switch the system to the <e>On Demand
617 High</e> profile (also shown in the above excerpt). This profile by itself uses
618 the <c>ondemand</c> governor with a minimum frequency of 40% (iow, a CPU of 2Ghz
619 will have by this policy a minimum frequency of 800Mhz).
620 </p>
621
622 <p>
623 As you can see, the <c>cpufreqd</c> application can offer a more granular
624 approach on CPU frequency scaling. But not only that, you can tweak the CPU
625 frequency scaling based on various other metrics available. The default
626 configuration offers a sample rule for when you watch a movie, where you want
627 maximum performance, unless the CPU temperature is getting too high.
628 </p>
629
630 <p>
631 When you have configured <c>cpufreqd</c>, it is time to start it (and make sure
632 the service is loaded automatically). Make sure that CPU frequency handling by
633 other tools (like <c>laptop-mode-tools</c>) is disabled!
634 </p>
635
636 <pre caption="Starting cpufreqd">
637 # <i>rc-service add cpufreqd default</i>
638 # <i>/etc/init.d/cpufreqd start</i>
639 </pre>
640
641 </body>
642 </section>
643 </chapter>
644
645 <chapter>
646 <title>Resources</title>
647 <section>
648 <title>Tools</title>
649 <body>
650
651 <ul>
652 <li>
653 <uri link="http://samwel.tk/laptop_mode/">Laptop Mode Tools Homepage</uri>,
654 includes <uri link="http://samwel.tk/laptop_mode/laptop_mode">About laptop
655 mode</uri>.
656 </li>
657 <li>
658 <uri link="http://www.lesswatts.org/projects/powertop/">PowerTOP</uri>, an
659 interactive application helping users to find out which processes are
660 forcing wakeups on the CPU most often.
661 </li>
662 </ul>
663
664 </body>
665 </section>
666 <section>
667 <title>Articles and Guides</title>
668 <body>
669
670 <ul>
671 <li>
672 A ThinkWiki article on <uri
673 link="http://www.thinkwiki.org/wiki/How_to_reduce_power_consumption">How to
674 reduce power consumption</uri> (on Linux). This article offers an exhaustive
675 list of measures one can take. However, it should be noted that the laptop
676 mode tools implements the majority of these (if properly configured).
677 </li>
678 </ul>
679
680 </body>
681 </section>
682 </chapter>
683 </guide>

  ViewVC Help
Powered by ViewVC 1.1.20