最近は省電力化がうるさいですね。で、CPUも暇なときは動作周波数を下げるなどの動作をWindows君はしてくれます。Linuxでも、そういうことが最近出来る*1ということを知りまして、設定してみました。
昔から、ノートPCあたりでは、周波数自動調整機能などは、結構ありましたよね。Intel SpeedStepとか、AMDだとPowerNow!とか。で、最近のCPUは、デスクトップでもそういう機能を持っているらしい。で、今はどうかってーと
まずは、Linuxカーネル側を設定します。おなじみmake menuconfigで。
Power management and ACPI options ---> [*] ACPI (Advanced Configuration and Power Interface) Support ---> <*> Processor <*> Thermal Zone CPU Frequency scaling ---> Default CPUFreq governor (ondemand) ---> -*- 'performance' governor <M> 'powersave' governor <M> 'userspace' governor for userspace frequency scaling -*- 'ondemand' cpufreq policy governor <*> 'conservative' cpufreq governor *** CPUFreq processor drivers *** <*> ACPI Processor P-States driver < > AMD Opteron/Athlon64 PowerNow! < > Intel Enhanced SpeedStep (deprecated) < > Intel Pentium 4 clock modulation
うちの設定ですと、こんな感じ。ポイントは、
さて、governorってなんやねん?これは、動作時のCPU周波数変更ポリシーです。
CPU周波数変更用ドライバは
を選択します
こいつらは、CPU周波数情報のモニタツールです。
# emerge cpufrequtils
でインストール。
といったツール群がインストールされます
ユーザーランド常駐型CPU周波数変更用ポリシーを可変させてくれるデーモンです。
# emerge cpufreqd
でインストール。 /etc cpufreqd.confに設定ファイルがあります。うちではこんな感じ
# this is a comment # see CPUFREQD.CONF(5) manpage for a complete reference [General] pidfile=/var/run/cpufreqd.pid poll_interval=2 verbosity=4 enable_remote=1 remote_group=wheel [/General] [Profile] name=On Demand High minfreq=0% maxfreq=100% up_threshold=60 policy=ondemand [/Profile] [Profile] name=Performance High minfreq=100% maxfreq=100% policy=performance #exec_post=echo 8 > /proc/acpi/sony/brightness [/Profile] [Profile] name=Performance Low minfreq=1596000 maxfreq=1596000 policy=performance [/Profile] [Rule] name=Default cpu_interval=0-100 profile=On Demand High [/Rule] [Rule] name=Compile programs=gcc cpu_interval=0-100 profile=Performance High [/Rule]
[General]タグには、汎用設定を。
[Profile]タグには、CPU動作変更ポリシーをいくつか並べます。On Demand Highというプロファイルでは、CPUは0%~100%までの範囲でondemand governerを使用して可変。CPU負荷60%を越えたら動作変更という意味。Core2Duo E6600では、1.6Gと2.4Gの2段しかないので、Performance Lowでは下の周波数だけなんですよね。
[Rule]タグには、どういう状態のときに、どのプロファイル動作で動かすかを指定します。Defaultルールでは、CPU負荷0%~100%時は、On Demand Highプロファイルを使用、gccが動くときにはPerformance Highプロファイルを使用します。
こんな風に、デフォルトはこうだが、ある特定のプログラムが動くときは違うプロファイル、ACPIの状態をみて、ACパワーの時は高いCPUにするけど、バッテリー動作時はCPU抑えめ、バッテリーが減ってきたら最低周波数動作にする、センサー温度が上昇したらCPU周波数を下げるとかっていう設定もできます。 詳細はmanとか見てね~。デフォルトのcpufreqd.confにも設定例のってます。
設定できたら
# rc-update add cpufreqd boot
私はboot runlevelへ設定。CPU周波数の変更動作は、起動時から有効でも問題なさそうですしね。
# watch 'grep "cpu MHz" /proc/cpuinfo'
なんて打ってみると、周期的に現在動作中CPUを出してくれます。で、負荷がかかる処理を動かしてみましょう。ぴょこ、ぴょこと周波数がコア毎に上がったり下がったりします。これは消費電力も下がりそうね!!。来月の電気代はどうなってるのかしら…
# cpufreq-info cpufrequtils 005: cpufreq-info (C) Dominik Brodowski 2004-2006 Report errors and bugs to cpufreq@vger.kernel.org, please. analyzing CPU 0: driver: acpi-cpufreq CPUs which need to switch frequency at the same time: 0 hardware limits: 1.60 GHz - 2.39 GHz available frequency steps: 2.39 GHz, 1.60 GHz available cpufreq governors: conservative, ondemand, performance current policy: frequency should be within 1.60 GHz and 2.39 GHz. The governor "ondemand" may decide which speed to use within this range. current CPU frequency is 1.60 GHz (asserted by call to hardware). analyzing CPU 1: driver: acpi-cpufreq CPUs which need to switch frequency at the same time: 1 hardware limits: 1.60 GHz - 2.39 GHz available frequency steps: 2.39 GHz, 1.60 GHz available cpufreq governors: conservative, ondemand, performance current policy: frequency should be within 1.60 GHz and 2.39 GHz. The governor "ondemand" may decide which speed to use within this range. current CPU frequency is 1.60 GHz (asserted by call to hardware).
このコマンドで、現在の動作状態を見ることもできます。ん~、ちゃんとondemand governorで動いてるのがわかりますね~
(This host) = https://femt.ddo.jp