Difference between revisions of "Power Management"
(Created page with "== Configuring Hardware - Power Management == If you have a laptop, you will probably want to make a few measures to extend your battery life, such as throttling down your CPU, …") |
|||
| Line 48: | Line 48: | ||
We'll also need to make this script executable. | We'll also need to make this script executable. | ||
'''$''' chmod 755 /etc/acpi/actions/pmg_switch_runlevel.sh | '''$''' chmod 755 /etc/acpi/actions/pmg_switch_runlevel.sh | ||
| + | Next we will need to determine what events are thrown when you unplug or plug in your AC adapter. | ||
| + | '''$''' sudo tail -f /var/log/messages | grep "ACPI event" | ||
| + | You should see something like this: | ||
| + | Dec 7 18:10:30 moonbase3 logger: ACPI event unhandled: ac_adapter AC0 00000080 00000000 | ||
| + | Dec 7 18:10:30 moonbase3 logger: ACPI event unhandled: processor CPU0 00000081 00000000 | ||
| + | Dec 7 18:10:31 moonbase3 logger: ACPI event unhandled: processor CPU1 00000081 00000000 | ||
| + | Dec 7 18:10:31 moonbase3 logger: ACPI event unhandled: processor CPU2 00000081 00000000 | ||
| + | Dec 7 18:10:31 moonbase3 logger: ACPI event unhandled: processor CPU3 00000081 00000000 | ||
| + | Dec 7 18:10:31 moonbase3 logger: ACPI event unhandled: battery BAT0 00000080 00000001 | ||
| + | Dec 7 18:10:33 moonbase3 logger: ACPI event unhandled: ac_adapter AC0 00000080 00000001 | ||
| + | Dec 7 18:10:33 moonbase3 logger: ACPI event unhandled: processor CPU0 00000081 00000000 | ||
| + | Dec 7 18:10:33 moonbase3 logger: ACPI event unhandled: processor CPU1 00000081 00000000 | ||
| + | Dec 7 18:10:33 moonbase3 logger: ACPI event unhandled: processor CPU2 00000081 00000000 | ||
| + | Dec 7 18:10:34 moonbase3 logger: ACPI event unhandled: processor CPU3 00000081 00000000 | ||
| + | Dec 7 18:10:34 moonbase3 logger: ACPI event unhandled: battery BAT0 00000080 00000001 | ||
| + | What we're interested in is the info for the AC adapter and battery. We can see in the output above that events for the AC adapter are called ac_adapter, and battery events are called, well, battery. We'll create two files in ''/etc/acpi/actions/'' to intercept the events. | ||
| + | '''$''' sudo nano -w /etc/acpi/actions/pmg_ac_adapter | ||
| + | Add the following from the gentoo handbook: | ||
| + | # replace "ac_adapter" below with the event generated on your laptop | ||
| + | # For example, ac_adapter.* will match ac_adapter AC 00000080 00000000 | ||
| + | event=ac_adapter.* | ||
| + | action=/etc/acpi/actions/pmg_switch_runlevel.sh %e | ||
| + | Do the same for the battery. | ||
| + | '''$''' sudo nano -w /etc/acpi/actions/pmg_battery | ||
| + | Add the following from the gentoo handbook: | ||
| + | # replace "battery" below with the event generated on your laptop | ||
| + | # For example, battery.* will match battery BAT0 00000080 00000001 | ||
| + | event=battery.* | ||
| + | action=/etc/acpi/actions/pmg_switch_runlevel.sh %e | ||
| + | We'll need to restart the daemon for the changes to take effect. | ||
Revision as of 19:33, 7 December 2010
Configuring Hardware - Power Management
If you have a laptop, you will probably want to make a few measures to extend your battery life, such as throttling down your CPU, dimming your LCD backlight, and other things. In this case you will want to make sure the laptop USE flag is set in your /etc/make.conf. If you have a dell laptop, you will also want to add the dell USE flag. Chances are you have already built some of the packages that accept these USE flags, so you may want to rebuild all affected packages on your system.
$ sudo emerge -avDN world
If it hasn't been installed already, you'll want to install the acpi (Advanced Configuration and Power Interface) daemon.
$ sudo emerge -av apcid
Once the package is emerged, we'll start the apci daemon and add it to startup.
$ sudo /etc/init.d/acpid start $ sudo rc-update add acpid default
The next we'll create a "battery" runlevel for your system.
$ cd /etc/runlevels $ sudo cp -a default battery
This action creates a copy of the default runlevel called battery. From now on, whenever you add a service to the default runlevel, if you want it to start up when you are running only on your battery, you will need to add it to the battery runlevel as well. The next step will be to create a script that can intercept from the acpid whether or not your system is running on batteries and be able to switch to the appropriate runlevel. This script was blatantly stolen from the gentoo handbook.
$ sudo mkdir /etc/acpi/actions $ sudo nano -w /etc/acpi/actions/pmg_switch_runlevel.sh
/etc/acpi/actions/pmg_switch_runlevel.sh
#!/bin/bash
# BEGIN configuration
RUNLEVEL_AC="default"
RUNLEVEL_BATTERY="battery"
# END configuration
if [ ! -d "/etc/runlevels/${RUNLEVEL_AC}" ]
then
logger "${0}: Runlevel ${RUNLEVEL_AC} does not exist. Aborting."
exit 1
fi
if [ ! -d "/etc/runlevels/${RUNLEVEL_BATTERY}" ]
then
logger "${0}: Runlevel ${RUNLEVEL_BATTERY} does not exist. Aborting."
exit 1
fi
if on_ac_power
then
if [[ "$(</var/lib/init.d/softlevel)" != "${RUNLEVEL_AC}" ]]
then
logger "Switching to ${RUNLEVEL_AC} runlevel"
/sbin/rc ${RUNLEVEL_AC}
fi
elif [[ "$(</var/lib/init.d/softlevel)" != "${RUNLEVEL_BATTERY}" ]]
then
logger "Switching to ${RUNLEVEL_BATTERY} runlevel"
/sbin/rc ${RUNLEVEL_BATTERY}
fi
We'll also need to make this script executable.
$ chmod 755 /etc/acpi/actions/pmg_switch_runlevel.sh
Next we will need to determine what events are thrown when you unplug or plug in your AC adapter.
$ sudo tail -f /var/log/messages | grep "ACPI event"
You should see something like this:
Dec 7 18:10:30 moonbase3 logger: ACPI event unhandled: ac_adapter AC0 00000080 00000000 Dec 7 18:10:30 moonbase3 logger: ACPI event unhandled: processor CPU0 00000081 00000000 Dec 7 18:10:31 moonbase3 logger: ACPI event unhandled: processor CPU1 00000081 00000000 Dec 7 18:10:31 moonbase3 logger: ACPI event unhandled: processor CPU2 00000081 00000000 Dec 7 18:10:31 moonbase3 logger: ACPI event unhandled: processor CPU3 00000081 00000000 Dec 7 18:10:31 moonbase3 logger: ACPI event unhandled: battery BAT0 00000080 00000001 Dec 7 18:10:33 moonbase3 logger: ACPI event unhandled: ac_adapter AC0 00000080 00000001 Dec 7 18:10:33 moonbase3 logger: ACPI event unhandled: processor CPU0 00000081 00000000 Dec 7 18:10:33 moonbase3 logger: ACPI event unhandled: processor CPU1 00000081 00000000 Dec 7 18:10:33 moonbase3 logger: ACPI event unhandled: processor CPU2 00000081 00000000 Dec 7 18:10:34 moonbase3 logger: ACPI event unhandled: processor CPU3 00000081 00000000 Dec 7 18:10:34 moonbase3 logger: ACPI event unhandled: battery BAT0 00000080 00000001
What we're interested in is the info for the AC adapter and battery. We can see in the output above that events for the AC adapter are called ac_adapter, and battery events are called, well, battery. We'll create two files in /etc/acpi/actions/ to intercept the events.
$ sudo nano -w /etc/acpi/actions/pmg_ac_adapter
Add the following from the gentoo handbook:
# replace "ac_adapter" below with the event generated on your laptop # For example, ac_adapter.* will match ac_adapter AC 00000080 00000000 event=ac_adapter.* action=/etc/acpi/actions/pmg_switch_runlevel.sh %e
Do the same for the battery.
$ sudo nano -w /etc/acpi/actions/pmg_battery
Add the following from the gentoo handbook:
# replace "battery" below with the event generated on your laptop # For example, battery.* will match battery BAT0 00000080 00000001 event=battery.* action=/etc/acpi/actions/pmg_switch_runlevel.sh %e
We'll need to restart the daemon for the changes to take effect.