This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

電力管理/ガイド

From Gentoo Wiki (test)
Jump to:navigation Jump to:search
This page is a translated version of the page Power management/Guide and the translation is 45% complete.
Outdated translations are marked like this.

近年は電力管理が、完全なラップトップを探求する際の判断基準のひとつになっています。しかしながらオペレーティングシステムは、さまざまな省電力機能もサポートしなければなりません。このガイドでは、電力の少ないリソースでも柔軟にかつ自動的な方法で管理する Gentoo 環境のセットアップ方法を示します。

はじめに

この文書について

この文書では、あなたのラップトップに電力管理機能をセットアップする方法を説明しています。このガイドのいくつかの情報は、サーバの電力管理にも当てはまるかもしれません。しかしこの文書はそのような場合を意図していませんので、このガイドをラップトップシステム以外に当てはめる際には留意してください。

この文書中では、laptop mode tools について主に着目しています。各機能が完全に揃っているからです。しかしながら個々の設定においては、より詳細なアプローチができるであろう他のツールにも言及しています。そのようなときには、laptop mode tools の機能を無効にして、双方のツールが同じリソースの制御を取り合わないようにしなければなりません。

laptop_mode について

laptop_mode の設定では、カーネル内のコンフィグレーション設定で、ディスクの回転を適切に抑える(また、要求された処理の直後すぐに始動しないようにする)入出力の最適化を行います。

laptop-mode-tools について

Laptop Mode Tools は、ソフトウェアパッケージ ( app-laptop/laptop-mode-tools ) で、ユーザは省電力機能を最適化することができます。Linux カーネル内の laptop_mode の設定を管理することができますし、システムの電力関連設定を調整するその他の機能も利用することができます。

Linux カーネル コンフィグレーション

最小限のカーネルセットアップ

Portage には、異なるカーネルソースが複数あります。sys-kernel の利用をおすすめしますが、もしも高度な休止状態(ハイバネーション)のサポートを求めるのならば sys-kernel/tuxonice-sources が必要かもしれません。Linuxカーネルにおいて適切な電力管理機能を有効化するには、以下の設定を有効にします。

KERNEL 電力管理のための最小限のカーネルセットアップ
'"`UNIQ--pre-00000001-QINU`"'

Do not forget to enable the CPU frequency scaling driver for the CPU. For the SandyBridge and higher Intel core series of processors, userspace, ondemand, and conservative governors are unnecessary; performance should be selected as the default, and Intel P state control should be selected instead of ACPI Processor P-States driver. [1]

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

(必要ならば)Template:Kernel/Rebuildをして、再起動します。

Laptop Mode Tools の利用

インストール

Laptop mode tools ソフトウェアのインストールが次のように容易にできることは驚くに値しないでしょう:

root #emerge --ask app-laptop/laptop-mode-tools

しかしながら、このパッケージは追加の設定をUSEフラグで行うことができます。まずはサポートされているUSEフラグと、それぞれの意味を見てみましょう。

USE フラグ 説明 この場合におすすめ
acpi sys-power/acpid を使ってシステムの変化を捕捉し、省電力機能を自動的に有効・無効にします。 ラップトップがそれほど古くない場合(2003年ごろ以降)
apm sys-apps/apmd を使ってシステムの変化を捕捉し、省電力機能を自動的に有効および無効にします。 ラップトップがとても古い場合
bluetooth net-wireless/bluez を使った、laptop-mode-tools の bluetooth 設定管理を有効にします。(電池の状態に応じて、サービスを有効・無効にします。) ラップトップ(およびカーネル)が bluetooth に対応している場合
scsi sys-apps/sdparm にもとづいて、laptop-mode-tools の SCSI ディスク (ここでは SATA を含まない) の管理を有効にします。 ラップトップがSCSIディスクを利用している場合

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

  • apm USE フラグは、Advanced Power Management をサポートします。これは、より古い(2000年以前)のシステム電力管理機能の標準でした。
  • acpi USE フラグは、 Advanced Configuration and Power Interface をサポートします。APM の後継です。現在的なすべてのラップトップが ACPI に対応しています。

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

さて、 USE フラグをセットしたら、 laptop-mode-tools をインストールしましょう。

root #emerge --ask laptop-mode-tools

設定

laptop-mode-toolsをシステムにインストールするだけでは、必要であろう電源管理の機能は自動的に有効にはなりません。 /etc/laptop-mode/laptop-mode.confを見て、まずはこのパッケージの設定をしてください。 このファイルはメインの設定ファイルで(コメントで)説明が豊富に付いています。

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 /etc/laptop-mode/conf.d and are named after the module they represent (such as intel-sata-powermgmt.conf).

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 cpufreqd. In this example case, CONTROL_CPU_FREQUENCY=0 must be set:

Collapse
File/etc/laptop-mode/conf.d/cpufreq.conf

'"`UNIQ--pre-00000005-QINU`"'

This is a deprecated template. Help us update this template!

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.

With OpenRC:

root #rc-service laptop_mode start
root #rc-update add laptop_mode default

With systemd:

root #systemctl laptop-mode.service enable --now

laptop-mode-tools はどのように動作するのか

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 BATT_ prefix for settings related to this state;
  • AC, which is active when the system is running on AC power; the configuration files use the AC_ prefix for settings related to this state;
  • Laptop Mode, which is active when laptop mode is enabled; the configuration files use the LM_ prefix for settings related to this state;
  • No Laptop Mode, which is active when laptop mode is disabled; the configuration files use the NOLM_ 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 ENABLE_LAPTOP_MODE_ON_BATTERY=1 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 LM_, LM_BATT_, BATT_LM_, and BATT_ 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 CPU_MAXFREQ) is valid, but the second one (for CPU_GOVERNOR) is not.

CODE Colliding settings
## Valid set
BATT_CPU_MAXFREQ=fastest
LM_AC_CPU_MAXFREQ=fastest
NOLM_AC_CPU_MAXFREQ=fastest
  
## Invalid set
BATT_CPU_MINFREQ=fastest
LM_AC_CPU_MINFREQ=fastest
# The following includes AC and BATT, but BATT is already defined
NOLM_CPU_MINFREQ=fastest

CPU 周波数管理の設定

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 /etc/laptop-mode/conf.d/cpufreq.conf

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:

  • performance always picks the highest frequency;
  • powersave always picks the lowest frequency;
  • userspace does not pick anything, but lets the user decide (or any process that the user is running that will decide for the user);
  • ondemand will scale the CPU frequency up to the highest frequency when load is available;
  • conservative 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.

ディスプレイの明るさの設定

With /etc/laptop-mode/conf.d/lcd-brightness.conf, the laptop mode tools can govern the brightness of the LCD screen.

The file currently uses the /proc/acpi/video/VID/LCD/brightness file (bug 499544) to set brightness values. Recent kernels do not provide this anymore; it will need to adjust this to /sys/class/backlight/acpi_video0/brightness instead.

The possible values that can be used are between 0 and the value in /sys/class/backlight/acpi_video0/max_brightness, with 0 being the lowest brightness value.

その他のサービスを設定する

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 /etc/laptop-mode/conf.d/configuration-file-control.conf

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

cpufreqd の利用

Warning
Package sys-power/cpufreqd is deprecated and has been removed from the Portage tree. sys-power/ncpufreqd can still be used for 2.6.x kernels.

インストール

The cpufreqd 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 cpufreqd, let us first look at the USE flags it supports.

USE flag Description Suggested when...
acpi Enable support for ACPI, allowing cpufreqd to be notified about specific events as well as govern power through the ACPI interface the laptop is not very old (around year 2003 and later)
apm Enable support for APM, allowing cpufreqd to be notified about specific events as well as govern power through the APM interface the laptop is very old
lm_sensors Enable support for the Linux hardware sensors (through sys-apps/lm_sensors), allowing to switch profiles based on hardware sensor results using advanced events through lm_sensors
nforce2 Enable support for NForce, allowing cpufreqd to change the NForce FSB clock and video card frequency an NVidia graphics card based on the NForce chipset is present
nvidia Enable support for NVidia graphical card configuration (through the NVidia nvclock interface), allowing cpufreqd to change the video card frequency of NVidia graphical cards an NVidia graphics card is present
pmu Enable the Power Management Unit plug-in of cpufreqd. This allows the software to poll the Linux kernel Power Supply interface, getting more detailed information on battery charge the laptop does not support ACPI or APM

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

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

root #emerge --ask cpufreqd

設定

The cpufreqd 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.

cpufreqd can be configured by editing /etc/cpufreqd.conf. It contains three different sections:

  1. The [General]...[/General] section contains general configuration information.
  2. The [Profile]...[/Profile] 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 [Rule]...[/Rule] 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.

Collapse
File/etc/cpufreqd.confSample cpufreqd rule

'"`UNIQ--pre-00000008-QINU`"'

This is a deprecated template. Help us update this template!

In the above example, cpufreqd 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 cpufreqd 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 cpufreqd 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!

root #rc-update add cpufreqd default
root #/etc/init.d/cpufreqd start

See also

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).

References