電源管理/プロセッサ

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 90% complete.
Other languages:
Resources
This article has some todo items:
  • 残りの CPU 周波数ドライバのカーネル設定についての手順を追加する
  • AMD P-state EPP について完全に説明する

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

CPUの周波数スケーリング

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

ACPI 仕様は、パフォーマンスステート - P-state またはプロセッサパフォーマンスステート - としてスケーリング機構を記述しています。[1] P0 としてラベルされているステートは、プロセッサの可能な最高の周波数に使用され、P1 から Pn のステートはより低い周波数のために使用されます。

メモ
プロセッサ周波数を低くすることは、単位時間当たりに処理される命令の数が減る結果につながります。これは、周波数とパフォーマンスの間のバランスを見つけることが必要になることを意味します。

カーネルの CPUFreq サブシステム[2]は、周波数スケーリングの操作に責任を持ちます。このサブシステムは、スケーリングの挙動を変更するための 2 つの基本的な手段を提供します:

  • スケーリングガバナー - 異なるスケーリングアルゴリズムを使用して、理想のプロセッサ周波数を推定するための異なるアプローチを提供します。
  • スケーリングドライバ - スケーリングガバナーと特定のハードウェアの間のインターフェースを提供します。スケーリングドライバはガバナーに代わって、ハードウェア固有の値を読み書きすることができます。


CPUFreq サブシステムは複数の sysfs インターフェースを公開します。最も使用されるものは、プロセッサ毎に作成される /sys/devices/system/cpu/cpu*/cpufreq/ です。このディレクトリは以下のような様々なファイルを含みます:

  • cpuinfo_cur_freq - プロセッサによって報告される KHz 単位での現在の周波数。
  • cpuinfo_min_freq - プロセッサによって報告される KHz 単位での可能な最小の周波数。
  • cpuinfo_max_freq - プロセッサによって報告される KHz 単位での可能な最大の周波数。
  • scaling_governor - 現在使用されているスケーリングガバナー。このファイルに書き込むことで変更することができます。
  • scaling_driver - 現在使用されているスケーリングドライバ。このファイルに書き込むことで変更することができます。
  • scaling_min_freq - ガバナーによって使用される KHz 単位での最小のプロセッサ周波数。このファイルに書き込むことで設定することができます。
  • scaling_max_freq - ガバナーによって使用される KHz 単位での最大のプロセッサ周波数。このファイルに書き込むことで設定することができます。

インストール

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

使用しているガバナーの挙動は、sysfs インターフェースとして公開されているチューナブルを介して、さらに設定することができます。さらなる情報については特化したドキュメンテーションを参照してください。よく使用される sysfs チューナブルには以下のものが含まれます:

  • schedutil - /sys/devices/system/cpu/cpufreq/schedutil/rate_limit_us は、ガバナーの連続実行間の最小間隔を μs 単位で設定します。
  • ondemand - /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate は、負荷サンプリングの連続実行間隔を μs 単位で設定します。
  • conservative - /sys/devices/system/cpu/cpufreq/conservative/freq_step は、最大の周波数変更ステップを scaling_max_freq に対する % として設定します。


CPU 周波数スケーリングドライバ
オプション モジュール / カーネルシンボル サポートされる CPU 備考
Intel P state control intel_pstate (CONFIG_X86_INTEL_PSTATE) 近年の (Sandy Bridge+) Intel Core 内部スケーリングガバナーを実装します。Hardware P-States (HWP) (hwp CPU flag) サポートを持たない Intel プロセッサでは intel_cpufreq として表示されます。[6]
AMD Processor P-State driver[7] amd-pstate (X86_AMD_PSTATE). AMD Zen 2 以降 標準の acpi-cpufreq ドライバと比較してより細かい周波数ステップを提供します。[7] 内部スケーリングガバナー実装がアクティブな場合、amd_pstate_epp として表示されます。カーネル v5.17 以降を必要とします。
ACPI Processor P-States driver acpi-cpufreq (CONFIG_X86_ACPI_CPUFREQ) AMD Zen 1 ベースの EPYC/Ryzen、古い Intel Core (Sandy Bridge より前)/Xeon、AMD Opteron/Phenom、Intel Atom、Intel Pentium M 汎用 CPUFreq ドライバとして動作します。ACPI パフォーマンスステートを利用します。AMD プロセッサでは amd-pstate とは異なり、3 個の周波数ステップのみに制限されていることに注意してください。[7]
AMD Opteron/Athlon64 PowerNow! powernow-k8 (CONFIG_X86_POWERNOW_K8) K8 ベースの AMD Opteron、AMD Athlon 64、AMD Turion 64 古い AMD K8 ベースのプロセッサをサポートします。
Intel Enhanced SpeedStep (deprecated) speedstep-centrino (CONFIG_X86_SPEEDSTEP_CENTRINO) Intel Pentium M (Centrino)/Xeon 問題があります、ACPI Processor P-States driverを代わりに使用してください。
Intel Pentium 4 clock modulation p4-clockmod (CONFIG_X86_P4_CLOCKMOD) Intel Pentium 4/Xeon 推奨されません - 深刻な低速化と認知可能なほどの遅延の原因となります。
Processor Clocking Control interface driver pcc-cpufreq (CONFIG_X86_PCC_CPUFREQ) Processor Clocking Control (PCC) インターフェースをサポートする x86 プロセッサ PCC インターフェースのためのサポートを追加します。このインターフェースをサポートする HP サーバで有用かもしれません。[8]
メモ
ドライバの利用可能性はプロセッサアーキテクチャによって異なります。
ヒント
ネイティブ CPUFreq ドライバの名前は /sys/devices/system/cpu/cpu*/cpufreq/scaling_driver で利用可能です。

CPU 固有のスケーリングドライバ設定

Intel P-state

このドライバは 内部スケーリングガバナー (おおよそ CPUFreq の powersave および performance と似たもの) を実装しており、プロセッサの負荷に基づいて動作します。近年の (Sandy Bridge 以降のマイクロアーキテクチャに基づく) Intel Core シリーズプロセッサを想定しています。

このドライバは、Hardware P-States (HWP) 機能を持つプロセッサのためのアクティブモード (intel_pstate) か、パッシブモード (intel_cpufreq) の、どちらかとして動作します。パッシブモードは、Skylake マイクロアーキテクチャより前の世代の、HWP をサポートしない - hwp CPU フラグを持たない - プロセッサを考慮します。

アクティブモードでは、提供される CPUFreq パラメータに基づいて、プロセッサが自律的に周波数を設定します。これは、周波数スケーリングの制御をプロセッサ自身に渡します。一方でパッシブモードでは、ドライバは汎用 acpi-cpufreq ドライバと同じように振る舞います - 通常のスケーリングガバナーと協働します。ですが、周波数ステップの全範囲を使用することができます。[9]

アクティブモードの場合、userspaceondemand、および conservative スケーリングガバナーは不要です。performance ガバナーはデフォルトとして選択されるべきです。[10]

カーネル Intel Sandy Bridge 以降の Intel Core プロセッサのためのセットアップ
Power management and ACPI options ---> 
  [*] CPU Frequency scaling --->
        Default CPUFreq governor (performance)  --->
    -*- 'performance' governor
    <*> Intel P state control

ドライバによって公開される sysfs インターフェースがあります。そのルートは /sys/devices/system/cpu/intel_pstate/ ディレクトリに配置されます。以下のようなファイルがあります:

  • no_turbo - Intel Turbo Boost 機能を無効化します (1 が無効化、0 が有効化を意味します)。状態はこのファイルに書き込むことで変更することができます。
  • status - ドライバのステータスを表示します。値は offpassive、または active のいずれかです。


AMD P-State

このドライバはカーネル v5.17 以降で利用可能です[11]。汎用的な acpi-cpufreq ドライバに対するより効率的な代替を提供することを目標としています。より細かい周波数ステップを提供するために、Collaborative Processor Performance Control (CPPC)[12]を基にしています。これは acpi-cpufreq が、周波数制御オプションを 3 個しか提供せず、典型的には最低の周波数が amd-pstate を使用するときに利用可能になるものよりも高く、そのためバッテリー寿命を最大化するための方法としてより非効率であることから動機付けられました。

これは Zen 2 以降のマイクロアーキテクチャに基づく AMD Ryzen/EPYC プロセッサを対象として想定しています。ハードウェアサポートと構成が一致しない場合、スケーリングドライバはフォールバックとして acpi-cpufreq に設定されます。

ヒント
現在使用されちえるドライバが acpi-cpufreq にフォールバックしていないか確認するためには、/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver を読んでください。
重要
このドライバを使用するためには、"CPPC"、"ACPI CPPC"、または類似の BIOS 設定を enabled または auto に設定しなくてはなりません。
カーネル amd-pstate のためのカーネルセットアップ (Zen 2 以降)
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

ドライバによって公開される sysfs インターフェースがあります。そのルートは /sys/devices/system/cpu/amd_pstate/ ディレクトリに配置されます。以下のようなファイルがあります:

  • status - ドライバのステータスを表示します。値は activepassiveguided、または disable のいずれかです。


現在使用されているドライバが acpi-cpufreq ドライバにフォールバックしている場合、以下のカーネルコマンドライン引数で amd-pstate ドライバのロードを修正することができます:

  • Zen 2 プロセッサ: amd-pstate を、その共有メモリ実装を使用して有効化するために、amd_pstate.shared_mem=1 を追加してください。[13]
  • Zen 3 以降のプロセッサ: amd-pstate=passive を追加してください。Zen 3 以降は CPPC もサポートしています。[12]


Kernel 6.3 further developed available AMD P-State options in the form of Energy Preference Performance (EPP) modes.[14] 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.

AMD P-state ドライバに関するさらなる詳細については、上流で利用可能なドキュメンテーションを参照してください。

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

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

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

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

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

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

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

スケジューリングクロックティック

プロセッサはより長く省電力モードになっていればいるほど、エネルギー消費を抑えられるので、プロセッサを起こすアクションの量を減らすのが望ましいです。こうしたアクションの 1 つとして、"tick" としても知られるスケジューリングクロック割り込みがあります。利用可能な "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. [16] 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[17] 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[18] 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

sys-power/cpupower パッケージは、モニタおよびプロセッサの省電力機能を快適に管理するための一連のツールを提供します。ツールには cpupower frequency-infocpupower frequency-set、および cpupower monitor が含まれます。

hprofile

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

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

関連項目

外部資料

参照

  1. 8. Processor Configuration and Control — ACPI Specification 6.4 documentation、UEFI Forum, Inc。2023 年 9 月 9 日取得。
  2. CPU Performance Scaling、The kernel development community。2023 年 9 月 9 日取得。
  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、kernel.org、Rafael J. Wysocki。2022 年 1 月 12 日取得。
  7. 7.0 7.1 7.2 amd-pstate CPU Performance Scaling Driver、The kernel development community。2023 年 9 月 9 日取得。
  8. Platform-based Power Management and Linux、Bdale Garbee and Naga Chumbalkar。2023 年 9 月 9 日取得。
  9. intel_pstate CPU Performance Scaling Driver、The kernel development community。2023 年 9 月 9 日取得。
  10. Dominik Brodowski. Intel P-State driverCPU frequency and voltage scaling code in the Linux(TM) kernel。2016 年 6 月 12 日取得。
  11. AMD P-State Driver To Premiere In Linux 5.17 With Aim To Deliver Better Power Efficiency、Michael Larabel。2023 年 9 月 9 日取得。
  12. 12.0 12.1 Collaborative Processor Performance Control (CPPC)、The kernel development community。2023 年 9 月 9 日取得。
  13. How to enable amd-pstate?、Manjaro.org。2023 年 9 月 9 日取得。
  14. Ryzen Mobile Power/Performance With Linux 6.3's New AMD P-State EPP Driver, Michael Larabel. Retrieved 9 September 2023.
  15. The kernel’s command-line parameters, The kernel development community. Retrieved 9 September 2023.
  16. 8.1. Processor Power States — ACPI Specification 6.4 documentation, UEFI Forum, Inc. Retrieved 10 September 2023.
  17. CPU Idle Time Management, The kernel development community. Retrieved 10 September 2023.
  18. intel_idle CPU Idle Time Management Driver, The kernel development community. Retrieved 10 September 2023.