電源管理/CPU

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Power management/Processor and the translation is 54% complete.
Outdated translations are marked like this.
Other languages:
Resources
This article has some todo items:
  • 残りの CPU 周波数ドライバのカーネル設定についての手順を追加する
  • AMD P-state EPP について完全に説明する

この記事はプロセッサ電源管理について説明しています。

CPUの周波数スケーリング

CPU 周波数スケーリングは、プロセッサの周波数 (および電圧) を自動的に電力を節約するために、「オンザフライ」で調整することができる技術です。これはモバイルデバイスのバッテリ寿命の改善に役立ち、チップの発熱量を低減して冷却の要求性能を抑えます。スケーリングは、システム負荷に反応させたり、ユーザ空間ツールによって制御したり、ACPI イベントに反応させたりすることができます。

The ACPI specification describes the scaling mechanism as performance states - P-states or Processor Performance States.[1] The state labeled as P0 is used for the processor's highest possible frequency and P1-Pn states are used for lower frequencies.

メモ
Lower processor frequency leads to lower number of instruction processed over a unit of time. This means finding a balance between frequency and performance is necessary.

The kernel CPUFreq subsystem[2] is responsible for handling the frequency scaling. This subsystem provides two basic means of changing the scaling behavior:

  • Scaling Governors - provide different approaches to estimate the desired processor frequency using different scaling algorithms.
  • Scaling Drivers - provide an interface between scaling governors and the specific hardware. Scaling driver can read/write hardware-specific values on behalf of the governor.


The CPUFreq subsystem exposes multiple sysfs interfaces. The most useful is created per-processor /sys/devices/system/cpu/cpu*/cpufreq/. This directory contains various files, like:

  • cpuinfo_cur_freq - current frequency in KHz as reported by the processor.
  • cpuinfo_min_freq - minimal possible frequency in KHz as reported by the processor.
  • cpuinfo_max_freq - maximal possible frequency in KHz as reported by the processor.
  • scaling_governor - currently used scaling governor. It can be changed by writing to this file.
  • scaling_driver - currently used scaling driver. It can be changed by writing to this file.
  • scaling_min_freq - minimal processor frequency in KHz to be used by the governor. It can be set by writing to this file.
  • scaling_max_freq - maximum processor frequency in KHz to be used by the governor. It can be set by writing to this file.

インストール

BIOS

いくつかの機能は BIOS で有効化もしくは無効化できます。次の機能が、もし利用可能であれば、有効化されている事を確認してください。

  • "Processor C1E support"
  • "Enhanced Intel SpeedStep (EIST)"
  • "AMD Cool'n'Quiet (C&Q)"
  • "AMD PowerNow!"

カーネル

次のカーネルオプションを有効化してください

カーネル CPU 電源管理オプションを有効化する (CONFIG_ACPI_PROCESSOR, CONFIG_CPU_FREQ_STAT)
Power management and ACPI options  --->
     [*] ACPI (Advanced Configuration and Power Interface) Support  --->
         <*>   Processor
     CPU Frequency scaling  --->
         -*- CPU Frequency scaling
             [*]   CPU frequency transition statistics
             Default CPUFreq governor (ondemand)  --->
                 Select a default governor; see below table
                 Default is 'ondemand'
             *** CPU frequency scaling drivers ***
                 Select a driver; see below table

CPUFreq ガバナーとドライバを有効化する必要があります:

デフォルトのCPUFreq governor
オプション モジュール サポートされるCPU 備考
'performance' ガバナー cpufreq_performance /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq ファイルによって定義される、利用できる最も高いプロセッサ周波数に静的に設定します。 近年の Intel の Core プロセッサに対して、このオプションはデフォルトとして設定されるべきです。[3] [4]
'powersave' ガバナー cpufreq_powersave /sys/devices/system/cpu/cpu*/cpufreq/scaling_min_freq ファイルによって定義される、利用できる最も低いプロセッサ周波数に静的に設定します。 デフォルトとして設定できません。
'userspace' ガバナー: ユーザ空間における周波数スケーリング cpufreq_userspace (/sys/devices/system/cpu/cpu*/cpufreq/scaling_setspeed ファイルによって) 周波数を手動で設定するとき、もしくはユーザ空間のプログラムが動的にプロセッサ周波数を変更できるようにする時に設定します。
'ondemand' 周波数ポリシーガバナー cpufreq_ondemand 定期的なポーリングを行い、プロセッサの負荷に応じてただちに周波数を変更します。 Intel Core 以外に対して、このオプションはデフォルトとして設定されるべきです。
'conservative' 周波数ガバナー cpufreq_conservative 'ondemand' に似ています。高い処理速度が要求された時に、100% に直接ジャンプするのではなく段階的に周波数を上げるように、なめらかに周波数を上下させます。
'schedutil' 周波数ポリシーガバナー cpufreq_schedutil カーネルスケジューラによる周波数変更を駆動させることを目標としています。[5]
ヒント
使用しているガバナーは次のファイルを参照することで確認できます: /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

Behavior of active governor can be further configured via tunables exposed as sysfs interface. For more details see the dedicated documentation. Commonly used sysfs tunables include:

  • schedutil - /sys/devices/system/cpu/cpufreq/schedutil/rate_limit_us sets minimal interval in μs between consecutive governor runs.
  • ondemand - /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate sets the interval in μs between consecutive load sampling runs.
  • conservative - /sys/devices/system/cpu/cpufreq/conservative/freq_step sets the maximal frequency change step as % of scaling_max_freq.


CPUの周波数スケーリングドライバー
オプション モジュール サポートされるCPU 備考
Intel P state control intel_pstate SandyBridgeよりも新しいIntel Core
Processor Clocking Control interface driver pcc-cpufreq
ACPI Processor P-States driver acpi-cpufreq 古いIntel Core, Intel Atom, Intel Pentium M
AMD Opteron/Athlon64 PowerNow! powernow-k8 AMD Opteron, AMD Athlon 64, AMD Turion 64
Intel Enhanced SpeedStep (deprecated) speedstep-centrino Intel Pentium M (Centrino), Intel Xeon 問題があります, ACPI Processor P-States driverを代わりに使用してください。
Intel Pentium 4 clock modulation p4-clockmod Intel Pentium 4, Intel XEON 深刻な低速化と認知可能なほどの遅延の原因となります。
メモ
Availability of drivers depend on the processor architecture.
ヒント
Name of the active CPUFreq driver is available in: /sys/devices/system/cpu/cpu*/cpufreq/scaling_driver

Specific CPU scaling drivers settings

Intel P-state

This driver implements internal scaling governors (roughly similar to CPUFreq's powersave and performance) and works based on the processor load. It is intended for recent Intel Core series of processors (based on the Sandy Bridge microarchitecture or newer).

This driver works in either active mode (intel_pstate), for processors featuring Hardware P-States (HWP), or passive mode (intel_cpufreq). The passive mode concerns the processors not supporting HWP which are generations prior the Skylake microarchitecture - no hwp CPU flag is present.

In the active mode the processor autonomously sets the frequency based on provided CPUFreq parameters. This passes the control of frequency scaling to the processor itself. On the other hand, in the passive mode the driver behaves similarly to the generic acpi-cpufreq driver - it collaborates with the regular scaling governors. Although, it can use the full range of frequency steps.[6]

In the active mode case, the userspace, ondemand, and conservative scaling governors are unnecessary. The performance governor should be selected as the default. [7]

カーネル Setup for Intel Sandy Bridge and newer Intel Core processors
Power management and ACPI options ---> 
  [*] CPU Frequency scaling --->
        Default CPUFreq governor (performance)  --->
    -*- 'performance' governor
    <*> Intel P state control

There is a sysfs interface exposed by the driver. Its root is located at the /sys/devices/system/cpu/intel_pstate/ directory. There are files like:

  • no_turbo - disables the Intel Turbo Boost feature (1 means disabled and 0 means enabled). The state can be changed by writing to this file.
  • status - displays the status of the driver. Values are either - off, passive, or active.


AMD P-State

This driver is available in kernel v5.17 or newer[8]. It aims to provide a more effective alternative to the generic acpi-cpufreq driver. It is based on Collaborative Processor Performance Control (CPPC)[9] to provide fine grained frequency steps. This was motivated by acpi-cpufreq providing only 3 frequency control options, and the lowest frequency is typically higher than what is made available when using amd-pstate thus being less effective than it might otherwise be as a way to maximize battery life.

It is intended for AMD Ryzen/EPYC processors based on the Zen 2 or newer microarchitecture. In case of hardware support and configuration mismatch the scaling driver gets set to the acpi-cpufreq as a fallback.

ヒント
To verify the currently used driver did not fall back to acpi-cpufreq read: /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver.
重要
In order to use this driver, "CPPC", "ACPI CPPC", or similar BIOS setting must be set to enabled or auto.
カーネル Kernel setup for amd-pstate (for Zen 2 or newer)
Power management and ACPI options --->
  [*] CPU Frequency scaling --->
         Default CPUFreq governor (performance)  --->
  -*-  'performance' governor
  [*]   AMD Processor P-State driver
  <M>   selftest for AMD Processor P-State driver

There is a sysfs interface exposed by the driver. Its root is located at the /sys/devices/system/cpu/amd_pstate/ directory. There are files like:

  • status - displays the status of the driver. Values are either - active, passive, guided, or disable.


When the currently used driver falls back to the acpi-cpufreq driver the following kernel command-line parameters can fix loading the amd-pstate driver:

  • Zen 2 processors: Add amd_pstate.shared_mem=1 to enable amd-pstate using its shared memory implementation.[10]
  • Zen 3 or newer processors: Add amd-pstate=passive. Zen 3 or newer also supports CPPC.[9]


Kernel 6.3 further developed available AMD P-State options in the form of Energy Preference Performance (EPP) modes.[11] This new driver is referred as amd_pstate_epp. It allows new combinations of drivers and governors such as "amd_pstate_epp powersave performance" or "amd_pstate_epp performance performance". Some benchmarks are available.

For further details on the AMD P-state driver see the documentation available upstream.

ガバナー/ドライバの手動変更

単純なコマンドを使って、アクティブな CPU ガバナーおよび/またはドライバを変更することができます:

root #echo ondemand | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

システムの init システムを利用して、このコマンドを起動時に実行することができます。

ブート時にガバナーを設定する

cpufreq.default_governor カーネルコマンドライン引数を利用してデフォルトガバナーを設定することができます。

重要
このパラメータはカーネル v5.9 以降を必要とします。[12]

ティック

プロセッサはより長く省電力モードになっていればいるほど、エネルギー消費を抑えられるので、プロセッサを起こすティックの量を減らしてください。利用可能な tickless モードについての詳細はカーネルのドキュメントで読むことができます。

インストール

BIOS

いくつかの機能は BIOS 内で有効あるいは無効にすることができます。以下の機能が有効になっているか確認してください:

  • "High Precision Event Timer"
  • "HPET"
  • "Multimedia timer"

カーネル

省電力機能のためには、次のカーネルオプションを有効化してください:

カーネル カーネルでティック最適化機能を有効化する (CONFIG_NO_HZ_IDLE, CONFIG_HIGH_RES_TIMERS, CONFIG_HPET)
General setup  --->
   Timers subsystem  --->
      [*] Idle dynticks system (tickless idle)
      [*] High Resolution Timer Support
Device Drivers  --->
   Character devices  --->
      [*] HPET Timer Support

CPU Idle

Modern multi-core processors are often not fully loaded which brings an opportunity to suspend the unused parts and save power. The hardware transitions the unused parts to idle states. The kernel then does not schedule regular tasks to the idle parts but only special idle tasks.

The ACPI specification describes those idle states as C-states or Processor Power States. [13] There are usually multiple C-states implemented. Starting from the C0 state for a regularly running processor to C1, C2, and deeper idle states. The deeper the idle state, greater power saving but also a longer transition back to the running state.

The kernel CPUIdle subsystem[14] is responsible for handling the idle state management. Similarly to CPUFreq, this subsystem provides two basic means of idle state management - governor and driver. The governor attempts to predict the optimal C-state and driver to perform the operation on the hardware.

The CPUIdle subsystem exposes a sysfs interface. It is available at /sys/devices/system/cpu/cpuidle/. This directory contains various files, like:

  • current_governor - currently used idle governor. It can be changed by writing to this file.
  • available_governors - list of available idle governors.
  • current_driver - currently used idle driver information.

インストール

BIOS

以下の設定が BIOS で有効化されているか確認してください:

  • "C-States"
  • "ACPI C states"

カーネル

CPU idle drivers
Name Module / Kernel symbol Supported Processors Note
Intel Idle Time Driver intel_idle (CONFIG_INTEL_IDLE) recent (Nehalem+) Intel Core[15] Asks the processor part to enter the idle state using the MWAIT instruction.
ACPI Idle Driver acpi_idle (CONFIG_ACPI_PROCESSOR_IDLE) AMD processors, old Intel processors Generic idle driver
CPU idle governors
Name Module / Kernel symbol Note
Ladder Governor ladder (CONFIG_CPU_IDLE_GOV_LADDER) Default governor for systems with allowed scheduler ticks in idle - CONFIG_NO_HZ_IDLE=n.
Menu Governor menu (CONFIG_CPU_IDLE_GOV_MENU) Default governor for tickless systems - CONFIG_NO_HZ_IDLE=y.
Timer events oriented (TEO) governor TEO (CONFIG_CPU_IDLE_GOV_TEO) Alternative governor for tickless systems - CONFIG_NO_HZ_IDLE=y.

ツール

PowerTOP

PowerTOP は、コンピュータの電力消費を計測し、説明し、最小化するために設計されたユーティリティです。

実行すると、実行中のプロセスを、プロセッサを起こした頻度順にソートして表示します。インストール、設定そして使用法についての詳細は、個別の PowerTOP 記事を参照してください。

cpupower

The sys-power/cpupower package provides a set of tools to comfortably manage and monitor processor powersaving features. The tools include cpupower frequency-info, cpupower frequency-set, and cpupower monitor.

hprofile

CPU 周波数ガバナーの決定を一部自動化することができます。例えば、AC 電源に接続されていないときは、多くのユーザはシステムを省電力モードにしたいでしょう。

ここで Hprofile の出番です。さらなる情報と設定については記事を参照してください。

関連項目

外部資料

参照

  1. 8. Processor Configuration and Control — ACPI Specification 6.4 documentation, UEFI Forum, Inc. Retrieved 9 September 2023.
  2. CPU Performance Scaling, The kernel development community. Retrieved 9 September 2023.
  3. Dominik Brodowski. Intel P-State driver, CPU frequency and voltage scaling code in the Linux(TM) kernel. Retrieved 12 June 2016.
  4. Michael Larabel. Linux's "Ondemand" Governor Is No Longer Fit. Retrieved 15 October 2016.
  5. Improvements in CPU frequency management, LWN.net, Neil Brown, 6 April 2016. Retrieved 12 January 2022.
  6. intel_pstate CPU Performance Scaling Driver, The kernel development community. Retrieved 9 September 2023.
  7. Dominik Brodowski. Intel P-State driver, CPU frequency and voltage scaling code in the Linux(TM) kernel. Retrieved 12 June 2016.
  8. AMD P-State Driver To Premiere In Linux 5.17 With Aim To Deliver Better Power Efficiency, Michael Larabel. Retrieved 9 September 2023.
  9. 9.0 9.1 Collaborative Processor Performance Control (CPPC), The kernel development community. Retrieved 9 September 2023.
  10. How to enable amd-pstate?, Manjaro.org. Retrieved 9 September 2023.
  11. Ryzen Mobile Power/Performance With Linux 6.3's New AMD P-State EPP Driver, Michael Larabel. Retrieved 9 September 2023.
  12. The kernel’s command-line parameters, The kernel development community. Retrieved 9 September 2023.
  13. 8.1. Processor Power States — ACPI Specification 6.4 documentation, UEFI Forum, Inc. Retrieved 10 September 2023.
  14. CPU Idle Time Management, The kernel development community. Retrieved 10 September 2023.
  15. intel_idle CPU Idle Time Management Driver, The kernel development community. Retrieved 10 September 2023.