ページへ戻る

− Links

 印刷 

Gentoo Linuxな生活​/CPU省電力で悩む :: Nest Of Hawk

xpwiki:Gentoo Linuxな生活/CPU省電力で悩む

ページ内コンテンツ
  • 時代はエコ
  • 技術背景
  • 設定
    • Linuxカーネル
    • CPU周波数変更用のツール類
      • cpufrequtils
      • cpufreqd
  • 動作検証

時代はエコ anchor.png[1]

最近は省電力化がうるさいですね。で、CPUも暇なときは動作周波数を下げるなどの動作をWindows君はしてくれます。Linuxでも、そういうことが最近出来る*1ということを知りまして、設定してみました。

Page Top

技術背景 anchor.png[2]

昔から、ノートPCあたりでは、周波数自動調整機能などは、結構ありましたよね。Intel SpeedStepとか、AMDだとPowerNow!とか。で、最近のCPUは、デスクトップでもそういう機能を持っているらしい。で、今はどうかってーと

Intel
EIST(Enhanced Intel SpeedStep Technorogy) Core2Duoなんかが搭載している。うちにあるやつだと、Atom N330以外は対応。
AMD
PowerNow! Athron64以降が対応しているみたい。おいちゃんはしらんけど
Page Top

設定 anchor.png[3]

Page Top

Linuxカーネル anchor.png[4]

まずは、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

うちの設定ですと、こんな感じ。ポイントは、

  • ACPIを有効にする
  • ProcessorのACPIをONにする
  • CPU Frequency scalingのgovernorを選択する。その際使用したいgovernerのオプションをONにする
  • CPU周波数変更用のドライバをチョイスする。

さて、governorってなんやねん?これは、動作時のCPU周波数変更ポリシーです。

performance
選択周波数内の最大値を選択
powersave
選択周波数内の最小値を選択
userspace
ユーザーが動作周波数を手動で設定
ondemand
CPU負荷や、センサー温度などを判定して自動的に周波数をセンシティブに変更
conservative
ondemandと似ているが、いきなり変更ではなく、徐々に周波数を上げたり下げたりする

CPU周波数変更用ドライバは

Intel Core2以上(EIST)
ACPI Processor P-States driver
AMD
AMD Opteron/Athlon64 PowerNow!
Intel EIST非対応(Pentium4等)
Intel Pentium 4 clock modulation

を選択します

Page Top

CPU周波数変更用のツール類 anchor.png[5]

Page Top

cpufrequtils anchor.png[6]

こいつらは、CPU周波数情報のモニタツールです。

# emerge cpufrequtils

でインストール。

  • cpufreq-info
  • cpufreq-set

といったツール群がインストールされます

Page Top

cpufreqd anchor.png[7]

ユーザーランド常駐型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周波数の変更動作は、起動時から有効でも問題なさそうですしね。

Page Top

動作検証 anchor.png[8]

# 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で動いてるのがわかりますね~


*1 いや、実は結構昔から?

Last-modified: 2010-02-20 (土) 02:09:27 (JST) (5150d) by maruo