Laptop computers need to be able to efficiently manage battery power to be effective tools. Besides settings used for manipulation in your laptop's BIOS, there are several utilities that come with Fedora Core and other Linux systems that can be used to monitor power use on your laptop and respond to power events that occur, such as:
Low battery power-The computer can send warnings, display low-battery icons, or even suspend hardware activity.
Inactivity-If there has been no activity on the computer for a set amount of time, you can extend battery life by spinning down disks and turning off services (such as audio and network services).
By detecting whether your laptop is running on AC power or battery, your computer can go into different levels of power savings for each of those states. Tools for managing and troubleshooting power problems on laptop computers in Fedora include:
Advanced Power Management (APM)-The APM software in Fedora consists of the a pmd daemon (which monitors battery use) and several utilities for displaying and reacting to battery activity. These features are contained in the apmd software package.
Advanced Configuration and Power Interface (ACPI)-The acpid event daemon monitors power management events and allows you to set up rules to react to those events. Those rules can do things such as turn off hardware components or power down the system. ACPI is meant to replace APM power management with more generic tools. At the moment, however, ACPI has not yet lived up to its potential.
hdparm command-The hdparm command can be used to turn power management features on and off. There are options to do things such as spin down your hard drive or put it in a standby state.
With ACPI, the operating system and not the BIOS is responsible for handling power management. Although ACPI will allow greater power and flexibility in managing power issues, APM currently has more user-level features built around it. With ACPI, you currently have to tell it yourself what power events to look for and how to respond to those events.
Note |
If you want to have a visual representation of your battery power on your GNOME desktop, you can add a Battery Charge Monitor applet to your panel. Right-click on the panel, select Add to Panel ⇨ Utility ⇨ Battery Charge Monitor. By default, the applet will change colors from green (charged) to yellow (40%), orange (25%), and red (15%) to show battery levels. Figure 9-2 shows the Battery Charge Monitor icon for a computer currently running on AC power. |
APM is configured in Fedora to detect certain power events and respond to them. It does this by running a daemon process (/usr/sbin/apmd) that listens for events, and in turn responds to those events, based on settings in a configuration file that comes with the service (/etc/sysconfig/apmd).
To configure APM to run (which it already may be, but it won't hurt to do it again), type the following:
# chkconfig apmd on # service apmd restart
Note |
Both apmd and acpid should not be trying to control power services at the same time. So, turn off the service you don't want by changing on and restart to off and stop for that service (you'd turn off acpid in this case). |
If APM starts successfully, you should see messages in the /var/log/messages file that show the service starting and listing the current battery charge. By default, the a pmd daemon runs based on settings in the /etc/sysconfig/apmd file. You can list the running process to see what options apmd is running by default:
# ps ax | grep apmd /usr/sbin/apmd -p 10 -w 5 -W -P /etc/sysconfig/apm-scripts/apmscript
Based on these settings, here is how the apmd daemon behaves in Fedora Core:
Logs battery power changes-If the battery power changes by 10% or more, a message is sent to the system log file (/var/log/messages by default). This based on the -p 10 option.
Logs low battery-When the battery power falls below 5% and is not being charged, a warning message is sent to the system log file. This is based on the -w 5 option.
Warns users-If battery power falls below the value set by the -w option, a warning message is sent to all users currently logged into the computer (using the wall command). This is based on the -W option.
Uses apmscript to respond to events-When power events occur, apmd forwards those events to a script that is set up to respond to those events. As shown in the command line above, the script that is run is the /etc/sysconfig/apm-scripts/apmscript shell script (based on that file being used as an option to - P).
Besides the low-battery and power change settings just described, most of the responses to power events are handled within the apmscript file just mentioned. I recommend you review the contents of that file if you are interested in seeing what power management is being done on your computer.
If you want to add your own responses to power events in Fedora Core, you can create your own script. By default, the existing apmscript points to the file /etc/sysconfig/apm-scripts/apmcontinue. The apmscript file currently handles the following events:
suspend-If your computer goes into a suspend or standby state, the apmscript file stops all sound programs, suspends operation of all hard drives, stops any NFS connections, shuts down network connections, and turns off pcmcia card services.
resume-In resume state, apmscript tries to restore everything that was stopped during the suspend actions.
change power-If the power source changes, the script changes the laptop to operate with better performance on AC power and more efficient battery use if the laptop is running off the battery.
change battery-If the power of battery is low, this event gives apm the opportunity to stop services and go into an extreme powersaving mode.
start-When the computer starts up, apmscript doesn't do anything special except checking whether you have any events you entered yourself to be run at startup in the apmcontinue file.
stop-Likewise, when the computer shuts down, apmscript just checks whether you have any events you entered yourself to be run at shutdown time in the apmcontinue file.
All other events are directed to the apmcontinue file (which doesn't exist by default), giving you the opportunity to respond to those events any way you choose. Here you have the option to create a/etc/sysconfig/apm-scripts/apmcontinue script that can be set up to respond to events in the same way as the apmscript file does.
If you want to just poke around or make any real-time changes to your APM service, you can use the apm command. With no options, the apm command reports whether power is plugged in and the status of your battery charging:
# apm AC on-line, battery charging: 100%
You can also put your laptop in suspend mode (apm-s) or standby mode (apm-S). If you are running on AC power, you can tell the laptop to ignore any suspend and standby events generated by APM (apm-i).
Like APM, ACPI operates by having a daemon listen for power events, and then pass those events to a program that can respond to them. In this case, the acpid daemon runs by starting the acpid service as follows:
# chkconfig acpid on # service acpid restart
Note |
Again, remember to turn off the power management service you don't want. In this case, turn off apmd (chkconfig apmd off and service apmd stop). |
ACPI will only work on Linux systems that have ACPI enabled in the kernel. You may have to enable ACPI by force by adding ACPI=force as a boot option. You also need to enable ACPI in the BIOS. If ACPI is working, you should see a /proc/acpi/event file that contains ACPI events.
The acpid daemon monitors each event it receives from /proc/acpi/events and tries to match it against entries in files in the /etc/acpi/events directory. By default, only one file exists: sample.conf. The contents of that file show a simple form of an ACPI event and action:
# This is a sample ACPID configuration event=button/power.* action=/sbin/shutdown -h now
In this example, when a button/power.* event is received, the shutdown command is run immediately (- h now). To configure your own actions to ACPI events, you can add your own files (owned by the root user) to the /etc/acpi/events directory that contains entries in the same format. (Type man acpid to see the exact format of these configuration files.) When the event you listed occurs, any command you listed on the action= line is run as root user.
To find the names of events, type cat/proc/acpi/event. To track acpid activities, you should view the contents of the /var/log/acpid file. Try changing power states a few times (unplug, plug in again, press suspend, and so on) and see how each of these events are logged into the log file.
If you are using a laptop computer, there are options to hdparm you can use to control power consumption. Some of these options allow you to take immediate actions (such as putting a hard drive into sleep mode), while others set actions to occur after a certain period of time (such as spinning down the hard disk after a period of inactivity).
To see the IDE power mode status for your computer, type:
# hdparm -C /dev/hda /dev/hda: drive state is: active/idle
This shows the power mode set for normal operation. If the drive doesn't support this feature, the drive state is listed as unknown.
One of the most widely used ways of gaining power savings is to set the spindown mode (- S) to a low value. Some believe that even the minimum of a spindown after 5 seconds of idle time can improve overall battery life without drastically affecting performance. Spindown is set in 5-second increments using the -S option of hdparm and you can set the value from 0 (off) to 240 (20 minutes). So, for example, the following value of 3 tells the disk drive to go into standby mode (spindown) after 15 seconds:
# hdparm -S3 /dev/hda /dev/hda: sotting standby to 3 (15 seconds)
Note |
You can also set the disk to spindown at increments higher than 20 minutes. Values of -S from 41 t0 251 each signify 30-minute increments, so 241 sets the spindown value to 30 minutes, while 251 sets it to 5.5 hours. |
You can send a hard disk immediately into standby mode using the -y option as follows:
# hdparm -y /dev/hda /dev/hda: issuing standby command
Alternatively, you can enter sleep mode (the lowest power mode) using the -Y option:
# hdparm -Y /dev/hda /dev/hda: issuing sleep command
The next time the hard drive is needed, Linux will automatically reset to start the disk drive again.