文書の過去の版を表示しています。


FreeBSD WikiのTuningPowerConsumptionの日本語訳

Alexandar Motin 記す:

I would like to summarize some of my knowledge on reducing FreeBSD power consumption and describe some new things implemented in FreeBSD 8.x/9.x. The main character of this story is my 12“ Acer TravelMate 6292 laptop with C2D T7700 2.4GHz CPU, 965GM chipset and SATA HDD.

Modern systems, especially laptops, are implementing big number of power-saving technologies. Some of them are working automatically, other have significant requirements and need special system tuning or trade-offs to be effectively used.

So here is the steps:

CPUはシステムで最も消費する部分です。 フル稼働下ではそれだけで40W以上1)の電力を消費しますが、実際のラップトップ利用で最も重要なのはアイドル消費電力です。 Core2Duo T7700 CPUは2つのコアを持ち、2.4GHzで動作し、2400, 2000, 1600, 1200, 800MHzの段階のPステートを使うEISTテクノロジーをサポートし、C1, C2, C3の待機Cステートと加えてスロットリングをサポートします。 では、どうやってそれを使うのでしょうか:

Pステートとスロットリング

powerdを有効にすると、CPU負荷に応じてCPUの周波数/電圧を効率的に制御出来るようになります。 最近のシステムではpowerdがそれらを完全に透過的に扱うことが可能です。 デフォルトでは、周波数はEISTとスロットリングテクノロジーの絡み合いを通じて制御されます。 前者はコア周波数と電圧の両方を制御し、後者はコア周波数のみを制御します。 両テクノロジーは確かな省電力効果を生みます。 しかし、スロットリングの効果は小さく、またC2ステートを使うことで完全に隠れてしまいます。そんなわけで、スロットリング制御を無効化するために/boot/loader.confへの設定追加をオススメします:

hint.p4tcc.0.disabled=1
hint.acpi_throttle.0.disabled=1

この後のsysctlはEIST周波数だけを報告します:

dev.cpu.0.freq_levels: 2400/35000 2000/28000 1600/22000 1200/16000 800/14000

Intel Turbo Boost機能の制御のために、ACPIは公称値より1MHz上の余分な性能レベルを報告するかもしれません。 例えば、Core i7-870では下記のようなレポートを見るでしょう:

dev.cpu.0.freq_levels: 2934/106000 2933/95000 2800/82000 ...

ここで2933は2.93GHzを意味しますが、2934はシチュエーションに依存し、3.2~3.6GHzを表します。

私のケースでは、周波数/電圧制御はアイドル電力を約5W節約します。

Cステート

C1は非アクティブの間、CPUコアの幾つかの部分のクロックを止めます。 これは安全で安上がりであり、長いことCPUにサポートされてきました。 システムは標準でC1ステートを使用します。

C2は待機時に全コアクロックの停止をCPUに許可します。 これもまた安価ですが、使用にはACPI-チップセット-CPUの正確な協調動作が求められます。 C2ステートの使用は/etc/rc.confに追加することで有効にできます:

performance_cx_lowest="Cmax"
economy_cx_lowest="Cmax"

powerdが使われている時は、このステートの影響はそれほど大きくはありませんが、依然として注目に値します。

C3ステートは、CPUが全ての内部クロックを完全に停止し、電圧を下げ、システムバスからの切り離しを許可します。 このステートは更なる省エネ効果をもたらしますが、安くはなくトレードオフを必要とします。 C3ステートでCPUが完全に止まるや否や、FreeBSDがSMPでイベントタイマーとして使用する各CPUコア内のローカルAPICタイマーは機能しなくなります。 それはシステムタイマーを止め、スケジューリングを破壊し、これはシステムを死へと誘います。 この問題に対する唯一の解決策は幾つかの外部タイマーを使うことです。

C1Eとして知られる擬似ステートもあります。 これはCステート対応のないOSで、モダンなCPUがより上手く動くための次善策です。 BIOSで有効にすると、そのOSによってC1ステートを要求された際に、CPUが幾つかのより深いCステートに入る事を可能にします。

通常、AMDのCPUとBIOSは実際のCステートをOSに見せませんが、代わりにC1Eメカニズムだけを使います。 例えば、それはこのように動くかもしれません:OSが幾つかのCPUコアにC1を要求した時、コアはC2に入りますが、幾つかのCPUパッケージの全コアがC2の時は、そのパッケージ全体がC3に入ります。 あいにく、この動きはOSから完全に隠蔽されています。

FreeBSD 8.x

当初、SMP時代の前、FreeBSDはi8254(周波数用)とRTC(ステート用)チップセットタイマーを使いました。 FreeBSD 8.2はそれらをSMPシステム用に蘇らせます。 それらを使うために、/boot/loader.confを編集しローカルAPICタイマーを無効化できます:

hint.apic.0.clock=0

同様に、C3における電圧昇降のために、CPUは時間を必要とします(私のシステムでは57us)。 これはシステムがしばしば目覚める場合、C3ステートが効率的に利用されない事を意味します。 非アクティブ期間を増加させるには、loader.confに設定を追加することで割り込みレートを可能な限り削減するべきです:

kern.hz=100

これによりシステム応答時間が僅かに増加するかもしれませんが、ラップトップにとって重要なことではありません。 Also we may avoid additional 128 interrupts per second per core, by the cost of scheduling precision, with using i8254 timer also for statistic collection purposes instead of RTC clock, by using another newly added option:

hint.atrtc.0.clock=0

結果として、システムはコア毎に100割り込みを持つだけとなり、CPUは高効率でC3を使っています:

%sysctl dev.cpu |grep cx
dev.cpu.0.cx_supported: C1/1 C2/1 C3/57
dev.cpu.0.cx_lowest: C3
dev.cpu.0.cx_usage: 0.00% 0.00% 100.00% last 7150us
dev.cpu.1.cx_supported: C1/1 C2/1 C3/57
dev.cpu.1.cx_lowest: C3
dev.cpu.1.cx_usage: 0.00% 0.00% 100.00% last 2235us

効果的なC3ステート使用の結果、C2+powerdと比較して約2Wの削減です。

As soon as entering C1E on AMD CPUs may result in unexpected and uncontrolled entering C3 and resulting local APIC timer stop, FreeBSD 8.x blocks C1E functionality completely.

FreeBSD 9.x

FreeBSD 9.xは新しいイベントタイマーサブシステムeventtimers(4)を持ち、現代的なチップセットの殆どに存在しCPU電源管理に左右されない、HPETを含む更なる種類のタイマーハードウェアをサポートを可能にします。 システムは最適と思われるタイマーを自動的に選択しますが、sysctlを通してタイマーを確認し動的に変更することも可能です。

また、eventtimers(4)はワンショットタイマー操作モードの対応を追加しまし、そしてそれは何か行う事がある時だけ割り込みを生成します。 That allows to not reduce kern.hz variable – even multicore system should have only about 50-100 interrupts per second total when idle. But you still may want to do it, to reduce effect of some power-ineffectively written applications.

FreeBSD 9.x adds check whether it safe to use specific C-state with present event timer and may automatically block C2/C3 states, making it mostly safe. それでもなお、ある種の作業負荷において性能低下の原因となるため、Cステートの使用は今も標準では有効になっておらず、手動で有効にしなければなりません。 と同時に新しいCPUでは、より深いCステートの有効化はTurboBoostテクノロジーの利用を可能にし、これによりシングルスレッドアプリケーション性能が増加するでしょう。

AMD CPUでは、FreeBSD 9.xはローカルAPICタイマーが使われている時に限りC1Eをブロックします。 もし起動時からずっとそのローカルAPICタイマーが使われていた場合、次の再起動までC1Eはブロックされます。 C1E動作を許可するために、強制的にその他のタイマーを使うのがよいかもしれません。

画面のバックライトは多くの電力を消費する可能性があります。

私のラップトップでは最低輝度の1.5Wから最大輝度の4Wでした。 従って、(ハードウェアやソフトウェアで)輝度を制御する方法を見つけ、状況に応じた最低輝度レベルの調整を行うべきです。 私の場合、ハードウェアのボタンで制御しました。 acpi_video(4)がサポートするsysctlhw.acpi.video.lcd0.brightness経由で制御できるラップトップもあります。 グラフィックチップはかなりの量の電力を消費する可能性があり、それは使用するドライバとその設定によって決まるかもしれません。

Intel GPUs

SandyBridge/IvyBridge CPUを持つラップトップにおいて、新しいKMSベースの”intel“ドライバを使うグラフィックは、その”vesa“ドライバと比較して3Wの消費電力増加を招きます。 /boot/loader.confに次の行を追加して下さい:

drm.i915.enable_rc6=7

GPUの電力節約待機ステートの使用を有効にし、消費電力を削減します。

NVIDIA Optimus

If you have a Laptop with an NVIDIA Optimus GPU where you cannot switch off either GPU off in the Laptop's BIOS, there is a handy script that will probe all known ACPI calls used to disable the dedicated NVIDIA GPU:

% fetch https://people.freebsd.org/~xmj/turn_off_gpu.sh % make -C /usr/ports/sysutils/acpi_call install clean % vim turn_off_gpu.sh # read it before executing! % sh turn_off_gpu.sh # as root user

Once successful, it will store the succeeded call in

/root/.gpu_method

and use it on subsequent tries. On an ASUS UltraBook, this saves about 6-8W and raises battery lifetime by a third at least. It can be put into rc.local or other custom rc.d scripts to disable the GPU on boot. It can be used in addition to the /boot/loader.conf line mentioned above in the Intel GPU section.

このラップトップは2枚の1GB DDR2-667 SODIMMメモリモジュールが取り付けられています。 そのうちの1枚を外すと約1Wの節電、2枚の1GBモジュールを1枚の2GBモジュールに置き換えると0.5Wの節電です。

PCIバスはデバイス電力を制御する仕組みを提供します。 例えば、私はFireWireコントローラは全く使用せず、殆どの時間においてEHCI USBコントローラも同様です。 それらを無効にする事で約3Wの節電が可能です。 不要な全てのPCIデバイスの無効化には、それらのドライバを抜いてカーネルをビルドしなければなりません。そしてloader.confに追加します:

hw.pci.do_power_nodriver=3

デバイス再有効のためにしなければならない事は、それらのドライバをモジュールとしてただ読み込む事だけです。 8.xの新しいEHCI USBドライバは以前のものより少ない電力を消費します。

WiFiとBluetoothのアダプタは、使用時(当方のiwm(4)のWiFiがつながっている時は最大2W)ないし有効にしただけ(0.5W)で有意に電力を消費します。

いくつかのWiFiアダプタ(当方のiwm(4)のような)は、未使用時に無線回路を無効にするといった、省電力モードに対応します。 これを有効にするには、以下のオプションをifconfigインタフェースに設定します。

powersave

この有意義なWiFi消費電力の削減は、リンク遅延の若干の増加と引き換えに行われる可能性があります。

私は驚いたのですが、内蔵HDAモデムは未使用時でさえ約1Wの電力を消費していました。 私は最も過激な解決策を用いました─物理的にソケットから外したのです。 その場所にあたるケースの表面の温度が以前より下がりました。

サウンド生成割り込みの数を減らすため、私はloader.confに追加しました:

hw.snd.latency=7

2012-03-10以前のFreeBSD 9-STABLEでは、最大バッファサイズを増やす事も有益かもしれません:

hint.pcm.0.buffersize=65536
hint.pcm.1.buffersize=65536

First common recommendation is use tmpfs for temporary files. RAM is cheap, fast and anyway with you. Also you may try to setup automatic idle drive spin-down, but if it is the only system drive you should be careful, as every spin-up reduces drive's life time. For several months (until I have bought SATA SSD) I have successfully used SDHC card in built-in PCI sdhci card reader as main file system. On random read requests it is much faster then HDD, but it is very slow on random write. Same time it consumes almost nothing. USB drives could also be used, but effect is much less as EHCI USB controller consumes much power. Spinning-down my 2.5” Hitachi SATA HDD saves about 1W of power. Removing it completely saves 2W.

Comparing to PATA, SATA interface uses differential signaling for data transfer. To work properly it has to transmit pseudo-random scrambled sequence even when idle. As you understand, that requires power. But SATA implements two power saving modes: PARTIAL and SLUMBER. These modes could be activated by either host or device if both sides support them. PARTIAL mode just stops scrambling, but keeps neutral link state, resume time is 50-100us. SLUMBER mode powers down interface completely, but respective resume time is 3-10ms.

The ata(4) driver has support for the SATA power management. There are hint.ata.X.pm_level loader tunables can be used to control it. Setting it to 1 allows drive itself to initiate power saving, when it wish. Values 2 and 3 make AHCI-compatible controller to initiate PARTIAL and SLUMBER transitions after every command completion. New ahci(4) driver also has hint.ahcich.X.pm_level tunable. It also support modes 4 and 5 for minimal performance degradation. Note that SATA power saving complicates drive hot-swap, as controller may be unable to detect drive presence when link is powered-down.

In my case PARTIAL mode saves 0.5W and SLUMBER - 0.8W of power.

USB devices can individually be switched to and from power save mode by running the following commands:

# This command will enable automatic suspend of the USB device when no data traffic is pending. usbconfig -d X.Y power_save

# This command will disable USB power save for the given device. usbconfig -d X.Y power_on

The default for all devices except USB HUBs is power on. You should check the configuration descriptor of your device, that the “bmAttributes” field indicates that the device supports remote wakeup before enabling power save on a random USB device. It is not recommended to set the system timer tick rate below 250 HZ and enable USB power save, due to some USB suspend and resume delays which must comply to the USB specification. The power save feature also applies in the same way to USB device/gadget mode.

So what have I got? To monitor real system power consumption I am using information provided by ACPI battery via acpiconf -i0 command:

Original system:

Design capacity: 4800 mAh Last full capacity: 4190 mAh Technology: secondary (rechargeable) Design voltage: 11100 mV Capacity (warn): 300 mAh Capacity (low): 167 mAh Low/warn granularity: 32 mAh Warn/full granularity: 32 mAh Model number: Victoria Serial number: 292 Type: LION OEM info: SIMPLO State: discharging Remaining capacity: 93% Remaining time: 2:24 Present rate: 1621 mA Voltage: 12033 mV

Tuned system:

%acpiconf -i0 Design capacity: 4800 mAh Last full capacity: 4190 mAh Technology: secondary (rechargeable) Design voltage: 11100 mV Capacity (warn): 300 mAh Capacity (low): 167 mAh Low/warn granularity: 32 mAh Warn/full granularity: 32 mAh Model number: Victoria Serial number: 292 Type: LION OEM info: SIMPLO State: discharging Remaining capacity: 94% Remaining time: 4:47 Present rate: 826 mA Voltage: 12231 mV

So I have really doubled my on-battery time by this tuning - 4:47 hours instead of 2:24 with default settings. Cooling fan, previously running all the time, now idle most of time, when system is idle. Preinstalled vendor-tuned Windows XP on the same system, provides maximum 3:20 hours.

– Alexander Motin


1)
原文ではconsume more then 40W of powerとなっているが、more than 40Wの間違いか?
  • freebsd/tuning_power_consumption.1427427096.txt.gz
  • 最終更新: 2015-03-27 12:31
  • by Decomo