Task 2.7: Use Power Management Features
Computers run on electricity, but this power source isn't infinite. This limitation is particularly relevant on laptop computers, which often run on batteries. Thus, hardware manufacturers provide options to help minimize a computer's use of energy, and Linux provides software tools to help you manage power use. Most of these options enable you to automatically shut down power-hungry devices, such as hard disks and monitors, when they're not in use.
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
You've installed Linux on a laptop computer, but now you need to check power management options to improve battery life when the computer is taken on the road. To do so, you'll have to determine whether your system is using Advanced Power Management (APM) or the newer Advanced Configuration and Power Interface (ACPI)subsystem.
Scope of Task
This task requires investigating your system with a few commands. You may then want to edit some configuration files or startup scripts. You'll need to use either APM or ACPI, and in either case you should also investigate options for managing your hard disk's power consumption.
This task should take half an hour to an hour to complete. If you need to configure power management on many systems, each one will take just a few minutes—more time if the systems are substantially different from each other, but very little time if they're nearly identical to one another.
Log into the computer and acquire root privileges. No special hardware or software configuration is required, although if you're running a particularly old or bare-bones Linux distribution, you might need to install APM or ACPI software. Although the scenario describes a laptop computer, you can investigate power management features even on a desktop computer.
As always, working as rootcan be dangerous. Power management tools are unlikely to cause catastrophic problems, although you could accidentally set some inconvenient options, such as a too-short hard disk power-down time, which will cause sluggish and erratic performance.
To use power management features, you'll need to activate kernel support and then investigate APM and ACPI options on your system. You'll also want to modify your hard disk options for managing hard disk power consumption.
Distributions and GUI environments are increasingly providing point-and-click interfaces to power management tools. These interfaces can be convenient and useful, but they differ from one distribution or environment to another.
Activating Kernel Support
Both APM and ACPI rely on kernel features to work. General kernel configuration procedures are described earlier, in Task 2.6, "Configure and Compile a Kernel." The power management features can be compiled into the kernel by activating appropriate options under the Power Management Options menu—both APM and ACPI have their own submenus with options to enable assorted specific features, such as support for fan control, or to enable basic support at system boot time. Generally speaking, enabling an option will do no harm, even if it doesn't apply to your system. You should read the description to see if it applies, though. A few APM options in particular can cause problems. The RTC Stores Time In GMT option can cause your system time to be set strangely after a suspend operation if it's set incorrectly, and a few other options can cause problems with some hardware, as detailed in their descriptions.
When you configure your kernel, keep in mind that Linux will use APM or ACPI, but not both. In practice, whichever kernel system loads first will control the computer's power management. The simplest way to deal with this situation is to compile support for one protocol or another, not both. Another approach is to compile both systems as modules and load only the desired modules at boot time. In practice, if you try to use APM or ACPI features, as described in the next couple of sections, and they don't work, the cause could be the presence of support for the other system in the kernel.
If you're using your distribution's stock configuration, chances are it includes a reasonable default APM/ACPI configuration. It may try loading ACPI and then use APM as a fallback, for instance. In any event, you can try using one set of tools and then the other if that doesn't work. You may need to consult distribution-specific documentation to learn the details of how it's configured on your system, though.
To use APM features effectively, you need some way to tell the computer when to enter power-conserving states. This task is accomplished with the apmd package, which ships with most Linux distributions and may be installed automatically. The main apmd program is a daemon, which means that it runs in the background waiting for some event to occur. Most daemons, including apmd, should be started when the computer boots. Once running, apmd monitors the system's battery status, and if the battery's charge gets too low, apmdkicks the system into a suspend mode in which most functions are shut down and only the system's RAM is maintained. The apmd program will also suspend the hard disk if it's gone unused for a long enough time. (You can also use the hdparm utility to control hard disk power management more directly.)
If you want to manually control APM features, you can do so with the apmutility. Typing this command presents basic power management information, such as how much battery power is left. The -sand -Sparameters cause the system to go into suspend and standby modes, respectively. Suspend mode shuts off power to most devices, leaving only the CPU and memory operating, and those at minimum power. Standby mode leaves more devices powered up, so the system can recover more quickly, but there's less power savings in this mode. A fully charged laptop can usually last several hours in standby mode and a day or more in suspend mode. Many laptops include a key sequence that will force the system into suspend or standby mode. In most cases, apmdwill detect such a keystroke and honor the request. Consult your laptop's documentation for details.
Linux's ACPI handling is similar to its APM handling in broad strokes, but of course the details differ. In particular, an ACPI daemon runs instead of an APM daemon. The acpidprogram is a common ACPI daemon. This daemon is controlled through files in /etc/acpi/events. All the files in this directory whose names do not begin with a dot (.) are parsed and interpreted as sets of events and actions to be taken in response to each event. Each event line begins with the string event=, and each action line begins with action=. The actions point to scripts or Linux commands.
One simple ACPI configuration file contains nothing but comments and a very simple action/event pair, as seen here:
event=.* action=/etc/acpi/default.sh %e
This configuration essentially passes all responsibility over to a shell script, /etc/acpi/ default.sh. A shell script can be more complex than the simple default ACPI parser, but this approach may be overkill for you.
You can use files in the /proc/acpi directory to monitor your system and to change defaults. Try using cat to view the contents of some of these files, as in cat /proc/acpi/ event to view recent ACPI events. Various tools can link into these files to provide you with useful information, such as your CPU's temperature and battery status. The acpiprogram is one of these tools; type acpi -V to have the system display all the information it can.
Setting Hard Disk Options
You can use the hdparm utility to tell hard disks to enter a low-power suspend mode after a specified period of inactivity. To do so, use the -Soption to hdparm, which takes a value from Table 2.4 to specify the idle time before the drive enters suspend mode.
TABLE 2.4 hdparm -S Options
|0||Power-saving mode disabled; disk doesn't power down.|
|1–240||Suspend mode entered in multiples of 5 seconds; for instance, 12means to enter suspend mode after 60 seconds of inactivity.|
|241–251||Enter suspend mode after 1 to 11 units of 30 minutes of inactivity.|
|252||Enter suspend mode after 21 minutes of inactivity.|
|253||Enter suspend mode after a vendor-defined time.|
|255||Enter suspend mode after 21 minutes and 15 seconds of inactivity.|
Phase 2 Managing Hardware and the Kernel
Suppose you want to configure the laptop to enter suspend mode after 5 minutes (300 seconds) of disk inactivity. That's 60 5-second units, so you'd pass a value of 60 to hdparm:
# hdparm -S 60 /dev/hda /dev/hda: setting standby to 60 (5 minutes)
As with tuning hard disk performance, any change you enter at the command line will be lost once you reboot. To make your change permanent, you should enter an appropriate hdparm command in a local startup script, as described earlier, in "Tweaking Disk Performance" in Task 2.5.
One important caveat regarding hard disk power management is that Linux tends to generate a lot of disk activity on a regular basis. Certain Linux tools check system files very frequently to be sure they've not changed, and other tools generate log file entries on a regular basis—sometimes even when nothing's happened. Thus, it's possible that you won't see much benefit from using hard disk power management features. If your hard disk doesn't seem to be shutting down, or if it comes back to life very frequently, you may want to try to track down the source of the activity. You may be able to modify a program's configuration to keep it from generating so much disk activity.
Criteria for Completion
To complete this task, you should have investigated your power management options. Your system probably uses APM or ACPI, but not both. In either case, you can also minimize power use by configuring your system's hard disk to power down after an appropriate period of inactivity.
Use the following table of contents to navigate to chapter excerpts, or click here to view Chapter 2 in its entirety.
|ABOUT THE BOOK:|
|Hit the ground running with the street-smart training you'll find in Linux Administrator Street Smarts: A Real World Guide to Linux Certification Skills. Using a "year in the life" approach, it gives you an inside look at Linux administration, with key information organized around the actual day-to-day tasks, scenarios, and challenges you'll face in the field. This valuable training tool is loaded with hands-on, step-by-step exercises covering all phases of Linux administration. Purchase the book from Wiley Publishing|
|ABOUT THE AUTHOR:|
|Roderick W. Smith left a career in academia to pursue his passion for computers. He is particularly interested in Linux and Open Source Software, and has written several books.|