Linux 上で負荷に応じて CPU 周波数を変える (AMD A10-5700)
最近の暑さのせいか、メインで使っている PC がよく落ちる。 タワー型の筐体が邪魔くさくて昨年スリム型筐体に変更し、空冷能力が低くなったのも一因。
最近の Linux なら何もしなくても省電力設定はされているよな…と勝手に思っていたら、大間違い。
やっぱり AMD の APU (CPU+GPU) ではそうはいかなかった。
クロックは最高速でブン回っていたし、 governor は ondemand
に設定されていても scaling_max_freq
/ scaling_min_freq
の両方とも最高速に張り付いていた。これでは熱くなるわけだ。
そんなわけで、ようやく重い腰を上げて CPU 周波数の設定をすることにした。
昔の Linux ならば cpufreqd
とか powernowd
とかのデーモンを動かすところだが、今は負荷に応じた周波数調整だけなら kernel でやってくれる。
kernel が調整してくれるようお膳立てをするだけだ。
Debian Stretch の場合、これは cpufrequtils
パッケージが担う。
まずはパッケージのインストールから。
# apt-get install cpufrequtils
続いて CPU がサポートしている動作モードを調べる。
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
conservative userspace powersave ondemand performance schedutil
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
3400000 3000000 2600000 2300000 1900000 1400000
そう、この AMD の CPU は設定可能な周波数が離散的なのだ。 最近の Intel CPU はだいたい一定範囲内でリニアに周波数を変えられるので、このあたりの違いが自動的に設定されない理由なのだろう。
上記で調べたモードを基に設定ファイルを作成する。
雛形を /usr/share/doc/cpufrequtils/examples/cpufrequtils.sample
からコピーして修正してもいいし、イチから作成しても構わない。
# vi /etc/default/cpufrequtils
ENABLE="true"
GOVERNOR="ondemand"
MAX_SPEED="3400000"
MIN_SPEED="1400000"
あとは PC を reboot するなり、以下のようにその場で適用してもいい。
# service cpufrequtils restart
こうすることで、大半の時間は最低周波数で動くようだ。
# 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 - 3.40 GHz
available frequency steps: 3.40 GHz, 3.00 GHz, 2.60 GHz, 2.30 GHz, 1.90 GHz, 1.40 GHz
available cpufreq governors: conservative, userspace, powersave, ondemand, performance, schedutil
current policy: frequency should be within 1.40 GHz and 3.40 GHz.
The governor "ondemand" may decide which speed to use
within this range.
current CPU frequency is 1.40 GHz (asserted by call to hardware).
cpufreq stats: 3.40 GHz:3.06%, 3.00 GHz:0.97%, 2.60 GHz:1.38%, 2.30 GHz:3.57%, 1.90 GHz:13.46%, 1.40 GHz:77.56% (77310)
...
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 - 3.40 GHz
available frequency steps: 3.40 GHz, 3.00 GHz, 2.60 GHz, 2.30 GHz, 1.90 GHz, 1.40 GHz
available cpufreq governors: conservative, userspace, powersave, ondemand, performance, schedutil
current policy: frequency should be within 1.40 GHz and 3.40 GHz.
The governor "ondemand" may decide which speed to use
within this range.
current CPU frequency is 1.40 GHz (asserted by call to hardware).
cpufreq stats: 3.40 GHz:3.50%, 3.00 GHz:1.01%, 2.60 GHz:1.41%, 2.30 GHz:4.21%, 1.90 GHz:16.79%, 1.40 GHz:73.09% (68222)
本当なら thermald も動かして高温時には周波数を下げたりファンの回転数を上げたりしたいところだが、これも AMD だとハードルが高い。
systemd[1]: Starting Thermal Daemon Service...
systemd[1]: Started Thermal Daemon Service.
thermald[500]: NO RAPL sysfs present
thermald[500]: Unsupported cpu model, use thermal-conf.xml file or run with --ignore-cpuid-check
thermald[500]: THD engine start failed
Ubuntu の Wiki によれば
By default, thermald runs in zero configuration mode. This is is normally sufficient for most systems.
とのことだが、その most systems には入らなかったようだ。 これはあとで時間が取れたときに設定をしてみよう。
« xRDP からログインした時の「カラープロファイルを作成するには認証が必要です」ダイアログを消す | トップページ | kmscon で Linux コンソールを日本語対応に »
「Linux」カテゴリの記事
- Debian Linux を Secure Boot 環境で使う(2023.03.06)
- コンテナで GUI / GPU を使う(2022.10.19)
- 仮想環境のイメージ格納場所の移動(2022.09.10)
- Kodi の設定(2019.12.02)
- メインマシンを AMD Ryzen 5 2400G に(2019.06.24)
« xRDP からログインした時の「カラープロファイルを作成するには認証が必要です」ダイアログを消す | トップページ | kmscon で Linux コンソールを日本語対応に »
コメント