个人工具

UbuntuHelp:PowerManagement/ReducedPower

来自Ubuntu中文

跳转至: 导航, 搜索

Introduction

There are many ways to reduce power consumption and extend battery life in Ubuntu. By default, most of these are not enabled because they are be unreliable. With a little experimentation, you can get your power consumption down to a minimum. The best resource for tricks to reduce power in GNU/Linux is the website lesswatts.org.

Measure power consumption with powertop

Before you start making any changes, it is a good idea to first get a base line for what your current power consumption is:

sudo aptitude install powertop
sudo powertop

You must be running on batter power for powertop to get the machine's current watt usage.

Using less power with pm-powersave

The pm-utils package comes with scripts for managing low power.

sudo aptitude install pm-utils

In order to enter low power mode, run this:

sudo pm-powersave true

In order to leave low power mode, run this:

sudo pm-powersave false

These commands will run the hooks in /etc/pm/power.d and /usr/lib/pm-utils/power.d, passing the argument true when entering power save and false when leaving. When you run pm-powersave it combines the scripts in these two directories and executes them in sorted order. If both directories contain a script with the same name, the one in /etc/pm/power.d/ has a higher precedence and only this one will be executed. Therefore to disable a script from /usr/lib/pm-utils/power.d/ simply create an empty file in /etc/pm/power.d/ with the same name and without the execute bit set.

An example power.d hook

#!/bin/sh
#
# A script to agressively toggle power management between high performance and very low power usage.
# For more information on each of these options, see http://www.lesswatts.org
#
# To install:
#
# sudo install 99-savings /etc/pm/sleep.d
# sudo install 99-savings /etc/pm/power.d
#


ac_power()
{
  ##
  ## DISK and FILESYSTEMS
  ##

  # Set the drive to mostly stay awake.  Some may want to change -B 200
  # to -B 255 to avoid accumulating Load_Cycle_Counts
  # -S 240 => put in standby after 20 minutes idle
  # -B 200 => do not permit spindown
  # -M => not supported by my drive
  hdparm -B 200 -S 240 /dev/sda

  # Remount ext3/4 filesystems so the journal commit only happens every 60
  # seconds.  By default this is 5 but, I prefer to reduce the disk
  # activity a bit.
  mount -o remount,commit=60,atime /

  # Turn off the laptop mode disk optimization
  echo 0 > /proc/sys/vm/laptop_mode

  # Set the SATA to max performance
  echo max_performance > /sys/class/scsi_host/host0/link_power_management_policy
  echo max_performance > /sys/class/scsi_host/host1/link_power_management_policy

  ##
  ## NETWORK
  ##

  # set the wifi to no power savings.
  iwconfig wlan0 power off

  ##
  ## CPU AND MEMORY
  ##

  # Set kernel dirty page value back to default
  echo 10 > /proc/sys/vm/dirty_ratio
  echo 5 > /proc/sys/vm/dirty_background_ratio

  # Only wakeup every 60 seconds to see if we need to write dirty pages
  # By default this is every 5 seconds but, I prefer 60 to reduce disk
  # activity.
  echo 6000 > /proc/sys/vm/dirty_writeback_centisecs

  # Make sure ondemand governor is set
  echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

  ##
  ## SOUND AND VIDEO
  ##

  # Turn off sound card power savings
  echo 0 > /sys/module/snd_hda_intel/parameters/power_save

  # Enable the webcam driver
  modprobe uvcvideo
}


battery_power()
{
  ##
  ## DISK and FILESYSTEMS
  ##

  # Set the disks to aggressively save power.
  # Some might find these settings too aggressive.  If so, change
  # "-S 4" to something larger like -S 24 (two minutes) and -B 1 to -B 255.
  # -S 4 => put in standby after 20 seconds idle
  # -B 1 => highest degree of power savings
  # -M => not supported by my drive
  hdparm -B 1 -S 4 /dev/sda

  # Change ext3/ext4 filesystem settings to reduce disk activity.
  # noatime => disable updates to a file's access time when the file is read.
  # commit=600 => Change the commit times to 10 minutes.
  mount -o remount,noatime,commit=600 /

  # Set laptop disk write mode
  echo 5 > /proc/sys/vm/laptop_mode

  # Set SATA to minimum power
  echo min_power > /sys/class/scsi_host/host0/link_power_management_policy
  echo min_power > /sys/class/scsi_host/host1/link_power_management_policy

  ##
  ## NETWORK
  ##

  # set the wifi to power savings.
  iwconfig wlan0 power on

  ##
  ## CPU AND MEMORY
  ##

  # Make sure ondemand governor is set
  echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

  # Reduce disk activity by waiting up to 10 minutes before doing writes
  echo 90 > /proc/sys/vm/dirty_ratio
  echo 1 > /proc/sys/vm/dirty_background_ratio
  echo 60000 > /proc/sys/vm/dirty_writeback_centisecs

  ##
  ## SOUND AND VIDEO
  ##

  # Set sound card power savings
  echo 10 > /sys/module/snd_hda_intel/parameters/power_save

  # Remove the webcam driver
  modprobe -r uvcvideo
}


case "$1" in
  false) ac_power ;;
  true) battery_power ;;
esac

Related Links

Debugging pm-powersave

sudo tail -f /var/log/pm-powersave.log &
sudo pm-powersave true

Using less power with laptop-mode-tools

It is confusing: laptop_mode is a state that the kernel may be in, but laptop-mode-tools is a collection of scripts which attempt to reduce power consumption and allows you to tweak a number of power-related settings using a simple configuration file.

aptitude install laptop-mode-tools

If laptop-mode-tools is present, pm-utils will not manage disk settings but will assume that laptop-mode-tools is going to handle it (/usr/lib/pm-utils/power.d/95hdparm-apm). However, pm-utils will not automatically start and stop laptop-mode-tools. To do so, we need to create a hook for pm-utils:

sudo touch /etc/pm/sleep.d/10-laptop-mode-tools
sudo chmod a+x /etc/pm/sleep.d/10-laptop-mode-tools
sudo gedit /etc/pm/sleep.d/10-laptop-mode-tools
#!/bin/bash
case $1 in
    hibernate)
        /etc/init.d/laptop-mode stop
        ;;
    suspend)
        /etc/init.d/laptop-mode stop
        ;;
    thaw)
        /etc/init.d/laptop-mode start
        ;;
    resume)
        /etc/init.d/laptop-mode start
        ;;
    *)
        echo Something is not right.
        ;;
esac

lm-profiler

Recent versions (1.11 and later) of laptop-mode-tools include a new tool lm-profiler. It will monitor your system's disk usage and running network services and suggests to disable unneeded ones. TODO: what is the best way to disable services that are hogging power?

Related Links