Power management/Guide/zh-cn

在最近几年，良好的电源管理成为一个用户寻求完美的笔记本的一个重要条件. 同时操作系统也要支持电源管理/节能. 在这篇向导中，我们将会介绍如何在 Gentoo Linux 中以一种灵活的，自动化的方式设置好电源管理.

关于本文档
本文档描述了如何为笔记本型电脑设置电源管理. 尽管这当中的一部分设置可被用于其它类型的平台的电源管理，但是这并不是本文的目的. 如果你要在非笔记本的系统上执行这些设定，请小心，以免带来不可预期的影响.

在本文档中，主要是介绍  这个工具，它提供了许多相关的功能. 不过我们也会介绍一些别的能提供更详细的，更有针对性的设置的工具. 在这种情况下，为了避免造成冲突，  提供的相同的功能必须被禁用.

关于 laptop_mode
laptop_mode 是一种由内核内置的用于管理输入/输出的设置，比如使硬盘在合适的时候进行休眠（并且在队操作之后不会立刻被唤醒）来节能.

关于 laptop-mode-tools
Laptop Mode Tools 由 提供，它使用户可以调整电源管理功能，也可以用于管理上文中提到的 Linux 内核中的 laptop_mode 设置，同时还有一些附加的功能用于管理系统中与电源管理有关的设置.

Minimum kernel setup
There are different kernel sources in Portage. We recommend using, but if advanced hibernation support is desired, might be needed. To enable proper power management features in the Linux kernel, enable the following settings:

Do not forget to enable the CPU frequency scaling driver for the CPU, located right after the ACPI Processor P-States driver mentioned above.

For a more detailed description see the Power management/Processor article.

Build and install the new kernel (if necessary) and reboot.

Installation
It comes to no surprise that installation of the Laptop Mode Tools software is easily done via:

.

However, this package takes on additional, optional settings through USE flag configuration. So let's first take a look at the supported USE flags and what they mean to the package.

Observe there are two USE flags that seem to collide:  and. So what is the deal?


 * The  USE enables support for Advanced Power Management, an older (before year 2000) standard for power management features within a system.
 * The  USE enables support for Advanced Configuration and Power Interface, the successor of APM. All modern laptops support ACPI.

Depending on the system, either  or   will need to be set. In the remainder of this guide, it is assumed the laptop is recent enough to use ACPI.

So, with the USE flags set, install laptop-mode-tools:

Configuration
Having laptop-mode-tools installed on the system does not automatically enable the power management features that may be needed. To configure the package, first take a look at. This is the main configuration file for the package and is pretty well described (through comments).

But it is not the only configuration file to work with. The laptop-mode-tools package supports plugins (or modules) which have their own configuration file(s). These files are located in and are named after the module they represent (such as ).

Now, one of the important settings in each configuration file is if the laptop-mode-tools package should govern a particular setting or not. This is important when combining laptop-mode-tools with other power management services such as. In this example case,  must be set:

The next few sections will help the user configure laptop-mode-tools to suit specific needs. When finished, start the laptop_mode service and make sure it is started upon system boot.

How does laptop-mode-tools work
When running the laptop_mode service, the software will check in which state the system is in. The states are defined as:


 * Battery, which is active when the system is running on battery power; the configuration files use the  prefix for settings related to this state;
 * AC, which is active when the system is running on AC power; the configuration files use the  prefix for settings related to this state;
 * Laptop Mode, which is active when laptop mode is enabled; the configuration files use the  prefix for settings related to this state;
 * No Laptop Mode, which is active when laptop mode is disabled; the configuration files use the  prefix for settings related to this state.

The AC/BATT_ and LM/NOLM_ prefixes can be combined to have a AC_LM_ prefix.

When the laptop_mode service is started, it will switch modes based on events that occur (and of course based on the configuration settings). For instance, the setting  will make sure that the laptop mode tools switch to laptop mode when battery power is used. If that is the case, then the settings starting with,  ,  , and   will be used.

To make sure settings to not collide, it is not allowed to have overlapping settings. In the next example, the first set (for ) is valid, but the second one (for  ) is not.

Configuring CPU frequency management
The support for CPU frequency management in the laptop mode tools allows switching frequencies. It supports setting the CPU frequency governor, minimum frequency and maximum frequency. The configuration file used here is

The CPU frequency governor is a kernel-level policy that defines how the kernel will select the CPU frequency. We already selected the governors we want to use in the kernel configuration earlier. Let's recap:


 * always picks the highest frequency;
 * always picks the lowest frequency;
 * does not pick anything, but lets the user decide (or any process that the user is running that will decide for the user);
 * will scale the CPU frequency up to the highest frequency when load is available;
 * will scale the CPU frequency up gradually when load is available.

When switching between AC or battery, or (no) laptop mode, the appropriate governor (as well as its minimum and maximum frequency) is selected.

Configuring display brightness
With, the laptop mode tools can govern the brightness of the LCD screen.

The file currently uses the file (bug 499544) to set brightness values. Recent kernels do not provide this anymore; it will need to adjust this to instead.

The possible values that can be used are between 0 and the value in, with 0 being the lowest brightness value.

Configuring other services
An interesting feature of laptop-mode-tools is to support reloading particular services (like the system logger) after switching its configuration file. This is handled through

If enabled, the laptop_mode application will switch the configuration file(s) of the mentioned services with the same file, but suffixed with,  or. It will then signal or reload the appropriate services so they can use the new configuration file.

Installation
The application allows the user to manage CPU frequencies in a more granular approach than what laptop-mode-tools supports. But before we dive into the installation of, let us first look at the USE flags it supports.

The,  , and   USE overlap, so only one should be active. If the laptop is sufficiently recent,  is the best bet. If not,  offers all that is needed. When even APM isn't supported, try using.

With the USE flags configured, it is time to install.

Configuration
The application monitors the status of the system through several plugins. Based on the feedback it receives from those plugins, it will adjust the policy used to govern the CPU frequency.

can be configured by editing. It contains three different sections:


 * 1) The   section contains general configuration information.
 * 2) The   section defines the policies that the cpufreqd daemon can switch to. The section is very similar to the information used when manually setting the CPU frequency policy using cpufreq-set.
 * 3) The   section is the work-horse of the cpufreqd daemon, defining when the daemon decides to switch to a different profile.

Take a quick look at an example rule.

In the above example, will switch the system to the On Demand High profile (also shown in the above excerpt). This profile by itself uses the ondemand governor with a minimum frequency of 40% (iow, a CPU of 2 GHz will have by this policy a minimum frequency of 800 MHz).

The application can offer a more granular approach on CPU frequency scaling. But not only that, but the CPU frequency scaling can be tweaked based on various other metrics available. The default configuration offers a sample rule: when a movie is watched, maximum performance is desired (unless the CPU temperature is getting too high).

When has been configured, it is time to start it (and make sure the service is loaded automatically). Make sure that CPU frequency handling by other tools (like laptop-mode-tools) is disabled!

External resources

 * Laptop Mode Tools Homepage, includes About laptop mode.
 * PowerTOP, an interactive application helping users to find out which processes are forcing wakeups on the CPU most often.
 * A ThinkWiki article on How to reduce power consumption (on Linux). This article offers an exhaustive list of measures one can take. However, it should be noted that the laptop mode tools implements the majority of these (if properly configured).