Power Management

From Gentoo Linux Wiki

(Redirected from ACPI/Power Management)
Jump to: navigation, search

The Gentoo Power Management Guide covers setting up power management. Read it first, and refer to this guide for clarifications and methods not mentioned there. Note, some options may vary depending on your laptop model.

Contents

[edit] LCD Power Management

Explanation of the X config settings mentioned in the official guide's LCD Power Management section:

  • BlankTime (Default: 10 minutes) is not actually a power saving level. Either the screen is sent a "fake" blanking effect, or a screensaver is activated. This setting has nothing to do with DPMS.
Note: The following options require DPMS support in both monitor and display adapter
  • StandbyTime (Default: 20 minutes) is a very minor power saving level. This feature usually involves blanking the screen by turning off the electron (RGB) gun. However, the power supply is left on and the tube filaments energized. When you need to use the monitor again, the monitor will turn back on very quickly. This is also known as "hsync suspend mode", since the horizontal sync signal is turned off to signal this power management state to the monitor.
  • SuspendTime (Default: 30 minutes) is a very strong low power alternative. This setting usually involves the same power conservation as StandbyTime, however in addition the power supply is turned off. Also known as vsync suspend mode, since the vertical sync signal is turned off to signal this power management state to the monitor.
  • OffTime (Default: 40 minutes) usually means just that. The computer monitor is completely turned off. A small auxiliary circuit stays on to monitor the signals from the computer to turn the monitor back on when data needs to be displayed to the screen. Obviously, this keeps power consumption to a bare minimum. While the power saving is substantial, reactivating the monitor may take up to 8-10 seconds. Both the horizontal and vertical sync signals are turned off to signal this power management state to the monitor.

How to set these options can be found here.

DPMS may also be managed using xscreensaver (or its counteparts gnome-screensaver and kscreensaver in gnome and kde).

emerge -av x11-misc/xscreensaver

Note that many 3D screensavers can cause increased power consumption. You may want to use

$ <xscreensaver-command> --throttle

to only blank the screen instead when running on battery. A good idea is to attach this command to the ACPI action "lid closed."

[edit] Adjust LCD brightness

As of Linux kernel 2.6.10, there is a generic ACPI video driver:

Linux Kernel Configuration: Power Management video support
 Power management options (ACPI, APM)  --->
    ACPI (Advanced Configuration and Power Interface) Support  --->
       <*>   Video
 Device Drivers  --->
    Graphics support  --->
       <*> Lowlevel video output switch controls
       [*] Backlight & LCD device support  --->
          <*>   Lowlevel Backlight controls

To see what states your LCD supports:

# cat /proc/acpi/video/(Laptop dependent)/LCD/brightness

the (Laptop dependent) section depends on your model (specifically the DSDT tables of your computer). This is often "VGA" or "GRFX".

If the driver is loaded and your display device is supported, the above command should show the supported brightness levels. To change the brightness in a script, or on the command line, use:

# echo N > /proc/acpi/video/.../LCD/brightness

The N is a number from the supported levels provided by the 'cat' command above.

[edit] Hard disk

The hard disk is a large consumer of power within your laptop. In order to save power you would want to minimize your hard disk activity. This can be done by combining a couple of techniques:

  • Optimize the hard disk throughput to increase performance
  • Reduce write activities to the disk by tweaking your swap, tmp and syslog behaviour
  • Increase read ahead behaviour to group hard disk activity into moments instead of spreading them resulting in continuous use
  • Spin down the hard disk when it is not used for a while

These goals can be achieved using the following means:

[edit] Hard disk performance

hdparm is used to tweak hard disk settings. Starting with kernel 2.6, most of these improvements are turned on by default (unless your hardware is problematic).

One of these settings disabled by default (set to 0) is the sleep time (support for this depends on your hard disk model). Use:

# hdparm -S12 <hard disk device file> 

These the number in the switch is multiples of 5 seconds. After that time the hard disk will spin down.

# hdparm -S0 <hard disk device file>

disabled this behavior.

Warning: This should not be used in combination with the laptop mode.

[edit] SysLog tuning

Examine your system logger's config file for unnecessary logging activity and minimize its activity. If you don't want to log any system activity, consider disabling it entirely.

[edit] Laptop mode

Introduced in the official guide. For more information read /usr/src/linux/Documentation/laptop-mode.txt and the laptop-mode website

[edit] Swap space

swapoff -a can be used to turn off swap. Use swapon -a to turn it back on.

One way to tell if you need your swap file is to enable it and use your system for a period of time. Examine /proc/meminfo and /proc/swaps to determine the amount of free memory, and whether or not your swap file is even being utilized.

Another, easier way to see if you have a swapfile is to do free -m if you have a swap file enabled it will tell be listed there.

See swappiness for another tip on using swap files with a laptop.

[edit] Filesystem

Filesystem types have an impact on CPU utilization and so on battery life (http://forums.gentoo.org/viewtopic-t-347574-start-0-postdays-0-postorder-asc-highlight-love.html suggests you use JFS or Ext3).

[edit] CPU frequency scaling

In addition to the kernel settings mention in the official guide, you might need to enable "Relaxed speedstep Capability Checks" if your processor isn't detected as a speedstepping-capable CPU.

Warning: Make sure your CPU actually supports speedstep. If it isn't this could be harmful!
Linux Kernel Configuration: Relaxed speedstep Capability Checks
Power management options (ACPI, APM)  --->
   [*] Power Management support
        CPU Frequency scaling  --->
           [*] Relaxed speedstep Capability Checks

[edit] Suspend to Disk (Hibernate)

Suspend to disk is the Linux equivalent of Windows' hibernate functionality. It saves the contents of memory to disk and powers down. When the computer is started up again, it reloads the contents and the user can continue from where they left off. No documents need to be reloaded or applications reopened and the process is much faster than a normal shutdown and start up.

At this time, July 2007, Software Suspend v2 is not yet included in the mainstream or Gentoo Kernel (vanilla-sources or gentoo-sources). It is however included in suspend2-sources which is the same as gentoo-sources with the swsusp2 patch applied on top.

HOWTO Software Suspend v2 contains an extended guide to this feature. The following includes the minimum you need to get things working :

Kernel Settings

Linux Kernel Configuration: Software suspend 2
Power management options (ACPI, APM)  --->
   [*] Power Management support
   [ ] Software Suspend
   <*> Suspend 2  --->
      <*> Swap Allocator
      <*> File Allocator
      <*> Userspace User Interface support
      <*> Compression support
      [*] Replace swsusp by default

Application

  • sys-power/hibernate-script - Config file : /etc/hibernate/hibernate.conf
  • add resume2=/dev/hdxX to your kernel’s boot parameters, where /dev/hdxX is your swap device.

[edit] Suspend to RAM and Standby

The laptop can be placed into a minimal power consumption mode. Kernel Settings

Linux Kernel Configuration: Sleep states
 Power management options  --->
   ACPI (Advanced Configuration and Power Interface) Support  --->
     [*] ACPI Support
     [*] Sleep States

Usage

To see what capabilities your system has:

cat /sys/power/state

Example output:

 standby mem disk

Enable Standby with:

 echo -n "standby" > /sys/power/state

or Suspend to RAM with:

 echo -n "mem" > /sys/power/state

Suspend to RAM might need the kernel parameter acpi_sleep=s3_bios if the monitor doesn't wake up on resume.

Application

[edit] Other power saving methods

  • Examine crontab settings to see if anything unnecessary is being run on a regular basis. Don't forget to examine every user's crontab, including the user 'nobody'. If you don't need to schedule any background activity, consider disabling crond alltogether. The same goes for atd.
  • If you run an apache http (for example to test and/or develop web pages), try altering the values of MinSpareServers and StartServers to 1. Don't define any CustomLogging or at least increase the value of LogLevel to warn. If you don't require it, you can change the ErrorLog directive to point to /dev/null.
  • Use DistCC to compile when available.

[edit] Finding power draining devices

The following script will allow you to get an accurate handle on how much power your machine is drawing. Start by fully charging the battery and unplug it with all external devices enabled. Run the test again after each of these steps:

  • Run once to get a baseline,
  • Disable external devices
  • Lower monitor brightness
  • Any other action that can conserve power.

It is best to run this in terminal mode without a graphical environment running. If using graphical environment, make sure not to touch the mouse or keyboard during the test to prevent skewing the results.

Code: power_test.sh
 #! /bin/bash
 # /usr/bin/batterydraw
 # Copyright 2007        Morgan McClure <mtm28@case.edu>
 # License GPLv2
 # 1-25-2007
 # Power draw isolation script
 
 REGEXP='[0-9]+'
 case $# in
 0 )
   echo "usage: batterydraw SAMPLES [SLEEPTIME] [PRETESTCYCLES]"
   exit
 ;;
 1 ) SLEEPTIME=1
 ;;
 2 ) SLEEPTIME=$2
 ;;
 3 )
 # This is a trick to avoid the first few cycles so as to level
 # the draw on the battery and get a more accurate reading
   SLEEPTIME=$2
   N=0
   while [ $N != $3 ]
     do
       cat /proc/acpi/battery/BAT0/state|grep "present rate"|grep -Eo $REGEXP
       ((N++))
       sleep $SLEEPTIME
     done
 ;;
 esac
 
 N=0
 S=0
 X=0
 while [ $N != $1 ]
   do
     ((X= "$(cat /proc/acpi/battery/BAT0/state|grep "present rate"|grep -Eo $REGEXP)"))
     ((S += X))
     ((N++))
     echo $X $N
     sleep $SLEEPTIME
   done
 ((S=S/N))
 echo -e "\E[0;34mAverage draw:\E[0m"
 echo -e "\E[0;32m$S\E[0m"


Note: The /proc/acpi/battery directory is deprecated in newer kernels, but still available if configured. To use the new sysfs, remove the REGEXP variable and change the 'cat | grep | grep' commands to
cat /sys/class/power_supply/BAT0/current_now
. This gives the current in microamperes and not in milliamperes as the script above. To make it easier to read, you can also replace ((S=S/N)) with ((S=S/1000/N)).
Personal tools