Power Management
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
Before emerging any new packages, you may also want to confirm you have everything you need enabled in your kernel settings.
Power management and ACPI options ---> [*] ACPI (Advanced Configuration and Power Interface) Support ---> ... <*> AC Adapter <*> Battery <*> Button <*> Video <*> Fan ... <*> Processor < > Processor Aggregator <*> Thermal Zone
If it hasn't been installed already, you'll want to install the acpi (Advanced Configuration and Power Interface) daemon.
$ sudo emerge -av acpid
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 Gentoo power management guide suggests you create a battery runlevel to manage your system while running on battery mode. The drawback to this is having to manage multiple runlevels, and having to add new services to both runlevels. Thankfully, power management can be done fairly easily using the default script provided.
$ sudo nano -w /etc/acpi/default.sh
/etc/acpi/default.sh
By default, the only action set for the acpi deamon is to initiate shutdown when the power button is pressed. This isn't ideal, especially from within X, where you can use features from your window manager to control your power settings; it's much better to ask what to do in this case. Comment the line containing /sbin/init 0 out, and when doing so, be sure to add a comment as to why.
... button) case "$action" in power) # the following line commented out so xfce power manager prompts for action when power button is pressed # /sbin/init 0 ;; ...
If you are using a laptop, chances are you will want to perform some actions when you close the lid, such as turn off the display or go into sleep mode by suspending the system to ram. This can be done manually in this file, but most users will find it preferable to leverage a graphical application to manage detailed power settings. However, you can manually set commands by editing the corresponding section. I have added some commented commands for reference.
... lid) # xset dpms force off # if [ "x" != "x$(grep -o open /proc/acpi/button/lid/LID/state)" ] # logger "lid opened" # fi # /usr/sbin/pm-suspend ;; ...
If you followed the advice in the CPU frequency scaling section, you probably chose to use the ondemand CPU governor, which will provide more power to the CPU as needed. In the case that you'd rather throttle the CPU to its lowest level when running on batteries, you'll want to edit the ac_adapter section of the file. The following example also dims the LCD backlight when running on battery, and restores it to full brightness when running on ac power. Substitute for the location of your LCD brightness setting file. You may need to explore the subfolders of /proc/acpi/video/ for a file called brightness to find yours. You can use the command cat brightness to see the levels you can set.
... ac_adapter) case "$value" in # Add code here to handle when the system is unplugged *0) cpufreq-set -g powersave logger "Running on battery." echo -n 50 > /proc/acpi/video/GFX0/LCDD/brightness ;; # Add code here to handle when the system is plugged in *1) cpufreq-set -g ondemand logger "Running on ac power." echo -n 100 > /proc/acpi/video/GFX0/LCDD/brightness ;; ...
After making any changes to the default.sh file, it is wise to restart the acpi daemon.
$ sudo /etc/init.d/acpid restart
When running xfce, managing power actions and events can be simplified by leveraging xfce4-power-manager.
$ sudo emerge -av xfce4-power-manager
Once the emerge has completed, you can access your power settings via Settings -> Xfce 4 Power Manager from your menu. You can easily set the icon to display on ac or battery power, and set actions for things such as closing the lid when the ac adapter is unplugged, or after running on batteries for a certain time period.