CPUのクロック制御

CPUの周波数設定、パフォーマンス、省電力などの動作モードの変更について。

cpufrequtilsで情報を確認する

cpufrequtilsをまずはインストールする。Debianの場合aptコマンドで導入する。

$ sudo apt install cpufrequtils

次に、cpufreq-infoでCPUの情報を確認する。AMD A12 9800B環境の場合、以下のような情報が出力される。

$ cpufreq-info
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: acpi-cpufreq
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 4.0 us.
  hardware limits: 1.40 GHz - 2.70 GHz
  available frequency steps: 2.70 GHz, 2.30 GHz, 1.80 GHz, 1.40 GHz
  available cpufreq governors: conservative, powersave, userspace, ondemand, performance, schedutil
  current policy: frequency should be within 1.40 GHz and 2.70 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 1.53 GHz.
  cpufreq stats: 2.70 GHz:4.27%, 2.30 GHz:4.43%, 1.80 GHz:15.72%, 1.40 GHz:75.59%  (413867)
analyzing CPU 1:
  driver: acpi-cpufreq
  CPUs which run at the same hardware frequency: 1
  CPUs which need to have their frequency coordinated by software: 1
  maximum transition latency: 4.0 us.
  hardware limits: 1.40 GHz - 2.70 GHz
  available frequency steps: 2.70 GHz, 2.30 GHz, 1.80 GHz, 1.40 GHz
  available cpufreq governors: conservative, powersave, userspace, ondemand, performance, schedutil
  current policy: frequency should be within 1.40 GHz and 2.70 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 1.45 GHz.
  cpufreq stats: 2.70 GHz:4.32%, 2.30 GHz:4.08%, 1.80 GHz:14.69%, 1.40 GHz:76.91%  (389630)
analyzing CPU 2:
  driver: acpi-cpufreq
  CPUs which run at the same hardware frequency: 2
  CPUs which need to have their frequency coordinated by software: 2
  maximum transition latency: 4.0 us.
  hardware limits: 1.40 GHz - 2.70 GHz
  available frequency steps: 2.70 GHz, 2.30 GHz, 1.80 GHz, 1.40 GHz
  available cpufreq governors: conservative, powersave, userspace, ondemand, performance, schedutil
  current policy: frequency should be within 1.40 GHz and 2.70 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 1.52 GHz.
  cpufreq stats: 2.70 GHz:4.30%, 2.30 GHz:4.30%, 1.80 GHz:16.12%, 1.40 GHz:75.27%  (414031)
analyzing CPU 3:
  driver: acpi-cpufreq
  CPUs which run at the same hardware frequency: 3
  CPUs which need to have their frequency coordinated by software: 3
  maximum transition latency: 4.0 us.
  hardware limits: 1.40 GHz - 2.70 GHz
  available frequency steps: 2.70 GHz, 2.30 GHz, 1.80 GHz, 1.40 GHz
  available cpufreq governors: conservative, powersave, userspace, ondemand, performance, schedutil
  current policy: frequency should be within 1.40 GHz and 2.70 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 2.10 GHz.
  cpufreq stats: 2.70 GHz:4.15%, 2.30 GHz:4.11%, 1.80 GHz:15.14%, 1.40 GHz:76.59%  (373476)

4コアCPUのため、analyzing CPU 0〜analyzing CPU 3までの4つの情報が確認できる。

  • hardware limits CPUの動作周波数の範囲

  • available frequency steps 設定可能な動作周波数の段階

  • current policy 現在の動作設定

  • current CPU freqency 現在の動作周波数

  • cpufreq stats 現在のCPU使用率

利用可能なCPUの動作モードを取得

$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
conservative userspace powersave ondemand performance schedutil
  • convservative 負荷の状況に応じて動作周波数を動的に変更。ondemandと異なり、段階的に周波数を変更。

  • userspace

  • powersave 最低の動作周波数で動作

  • ondemand 負荷の状況に応じて動作周波数を最高、最低に設定する。

  • performance 最高の動作周波数で動作

  • schedutil スケジューラーによる動作周波数の変更

利用可能なCPUの動作周波数を取得

cpufreq-infoコマンドでもavailable frequency stepsの項目で確認できるが、以下のコマンドでも設定可能な動作周波数の数値を確認できる。

$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
2700000 2300000 1800000 1400000

動作設定を記述する

まず、cpufrequtilsの設定ファイルサンプルを、/etc/default/cpufrequtilsにコピーする。

$ sudo cp /usr/share/doc/cpufrequtils/examples/cpufrequtils.sample /etc/default/cpufrequtils
$ sudo vi /etc/default/cpufrequtils

cpufrequtilsの設定ファイルに記述する内容は以下のようにする。GOVERNOR、MAX_SPEED、MIN_SPEEDの値は好みの設定に変更する。

ENABLE="true"
GOVERNOR="ondemand"
MAX_SPEED=2700000
MIN_SPEED=1400000

最後に設定を有効化するため、サービスを再起動する。

$ sudo service cpufrequtils restart

参考