ubuntu 筆記本電源管理優化指南
作者:yuk
版本:1.0
免責聲明:以下操作可能會引起數據丟失,本人不承擔任何責任。
版權聲明:可以自由轉載,但原作者請務必保留;
論壇里看到許多朋友抱怨linux電源管理很糟糕,說什么電池使用比win下短了很多。實際上linux提供很多電源優化的功能,只不過默認情況下的設置沒有考慮電源使用罷了。下面我以ubuntu edgy為例,系統的討論一下筆記本電源管理優化。
目標:最長的電池使用時間
概述
筆記本由許多不同的組件組成,各個組件的耗電不用,引用gentoo power management的一張圖,其耗電比重如下圖所示:
Power Budget For Each Component
?
?
?
?
?
?
?
?
?
?
?
?
從上圖我們可以看到主要的耗電部件是液晶顯示器、CPU、芯片組和硬盤。雖然我們可以在BIOS里面設置操作系統無關的電源管理模式,但是在操作系統之上我們可以設置一些更smart的電源管理模式自動適應各種環境。
本文分下面幾個部分分別討論各個部件的電源管理優化。
0. 前提
在討論各個設備的電源管理優化之前,先確定我們是否滿足下面一些前提條件。
BOIS
首先你要檢查一下你的BOIS的電源管理設置,先關閉所有bois支持的電源管理方式,只通過操作系統設置電源管理,然后再恢復BOIS的電源管理。
kernel
acpi支持,edgy默認內核是支持acpi的,如果你自定義編譯了內核,記住要把電源管理相關的模塊選上
Power Management Options ---> [*] Power Management Support [ ] Software Suspend ACPI( Advanced Configuration and Power Interface ) Support ---> [*] ACPI Support [ ] Sleep States [ ] /proc/acpi/sleep (deprecated) [*] AC Adapter [*] Battery <M> Button <M> Video [ ] Generic Hotkey <M> Fan <M> Processor <M> Thermal Zone < > ASUS/Medion Laptop Extras < > IBM ThinkPad Laptop Extras < > Toshiba Laptop Extras (0) Disable ACPI for systems before Jan 1st this year [ ] Debug Statements [*] Power Management Timer Support < > ACPI0004,PNP0A05 and PNP0A06 Container Driver (EXPERIMENTAL) CPU Frequency Scaling ---> [*] CPU Frequency scaling [ ] Enable CPUfreq debugging < > CPU frequency translation statistics [ ] CPU frequency translation statistics details Default CPUFreq governor (userspace) <*> 'performance' governor <*> 'powersave' governor <*> 'ondemand' cpufreq policy governor <*> 'conservative' cpufreq governor <*> CPU frequency table helpers <M> ACPI Processor P-States driver <*> CPUFreq driver for your processor
?1.顯示器
如上圖所示,LCD是最耗電的部件,這一節我們討論如何降低LCD的耗電
首先,盡可能調低亮度,這個不多說手動調節就可以了;
然后設置 DPMS(Display Power Management Signaling)
修改sudo vi /etc/X11/xorg.conf文件
Section "ServerLayout" Identifier [...] [...] Option "BlankTime" "5" # Blank the screen after 5 minutes (Fake) Option "StandbyTime" "10" # Turn off screen after 10 minutes (DPMS) Option "SuspendTime" "20" # Full suspend after 20 minutes Option "OffTime" "30" # Turn off after half an hour [...] EndSection [...] Section "Monitor" Identifier [...] Option "DPMS" "true" [...] EndSection
?但似乎xorg的dpms有bug不能關閉LCD,只能把屏幕變黑
google搜索了一下發現是和acpi沖突只要重新啟動acpi就可以了
手動設置屏幕關閉,
sudo /etc/init.d/acpid restart xset dpms force off
?2.cpu
移動版本的CPU支持頻率和電壓的動態調整,在大多數情況下你的CPU是沒必要全速運行的,尤其在電池支持下,我們可以強制使CPU運行在最低頻率。
在linux 2.6以后的內核就支持cpu頻率的動態調整,有下面5種模式
-
performance 將CPU頻率設定在支持的最高頻率,而不動態調節.
powersave 將CPU頻率設置為最低
ondemand 快速動態調整CPU頻率, Pentuim M的CPU可以使用
conservative 與ondemand不同,平滑地調整CPU頻率,適合于用電池工作時.
userspace 用戶模式,也就是長期以來都在用的那個模式。可以通過手動編輯配置文件進行配置
先安裝相關軟件cpufrequtils
sudo apt-get install cpufrequtils
?查看你的cpu所支持的頻率
cpufreq-info
?
Report errors and bugs to linux@brodo.de, please.
analyzing CPU 0:
driver: powernow-k8
CPUs which need to switch frequency at the same time: 0
hardware limits: 800 MHz - 1.60 GHz
available frequency steps: 1.60 GHz, 800 MHz
available cpufreq governors: userspace, powersave, ondemand, conservative, performance
current policy: frequency should be within 800 MHz and 1.60 GHz.
The governor "ondemand" may decide which speed to use
within this range.
current CPU frequency is 800 MHz.
?需要進入那個模式直接修改proc文件,比如要進入powersave模式
echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
?其實有個實用程序laptop-mode可以方便的設置,在后面硬盤一節統一介紹
如果是用迅馳cpu,支持多個頻率,你可以用powernowd更細化的調節cpu頻率
3.顯卡
各類顯卡有自己的電源管理方式,我這里主要介紹ati powerplay,
首先要安裝ati的fgrlx,請參考論壇wiki
運行aticonfig --lsp顯示顯卡可以運行的頻率,選最低的就行了
我的輸出:
core/mem [flags]
-----------------
* 1: 100/150 MHz
2: 301/200 MHz [default state]
aticonfig --set-powerstate=0
?使顯卡運行在最低頻率上
也可以設置顯卡動態調整頻率
修改sudo vi /etc/X11/xorg.conf
[...]
Option "DynamicClocks" "on"
EndSection
?4.硬盤
我們先做一個粗略的計算,你的筆記本如果硬盤在節能模式下運行,能延長多少時間。
cat /proc/acpi/battery/BATx/info
design capacity: 6000 mAh
last full capacity: 3808 mAh
battery technology: rechargeable
design voltage: 14800 mV
design capacity warning: 209 mAh
design capacity low: 133 mAh
capacity granularity 1: 10 mAh
capacity granularity 2: 25 mAh
model number: JM-6
serial number: xxxxxxxxxxxxxxx
battery type: LION
OEM info: Hewlett-Packard
?電池功率為 3808 mAh x 14800 mV = 56.3584 Wh == 56wh
電池支持時間4小時
移動硬盤正常功率: 2.4w
移動硬盤standby功率: 0.25w
(根據自己型號google自己搜索)
56/4 = 14 w
14 - (2.4-0.25) = 11.85 w
56 / 11.85 = 4.725738397 小時
延長了0.73 小時,大約44分鐘
硬盤是不可能一直處于standby狀態的,實際的情況肯定會短一些。
下面我們討論如何使硬盤更長時間的處于standby模式下
我們可以laptop-mode 軟件達到這個效果,
首先我們啟動laptop-mode,edgy默認設置是禁止laptop-mode運行的
修改 /etc/default/acpi-support
?sudo /etc/init.d/laptop-mode start
好了現在我們來詳細配置,有中文注釋的地方是我修改過的地方
修改/etc/laptop-mode/laptop-mode.conf
# 在電池模式下啟動laptop_mode
ENABLE_LAPTOP_MODE_ON_BATTERY=1
# Disable all data loss sensitive features when the battery level (in % of the
# battery capacity) reaches this value.
# 在低電量的情況下禁止laptop-mode
MINIMUM_BATTERY_CHARGE_PERCENT=10
# Disable data loss sensitive features when the battery reports its state
# as "critical".
# 在極底電量下禁止laptop_mode
DISABLE_LAPTOP_MODE_ON_CRITICAL_BATTERY_LEVEL=8
# The drives that laptop mode controls.
# Separate them by a space, e.g. HD="/dev/hda /dev/hdb". The default is a
# wildcard, which will get you all your IDE and SCSI/SATA drives.
# HD="/dev/[hs]d[abcdefgh]"
# 設定需要控制的硬盤
HD="/dev/hda"
# Should laptop mode tools control readahead?
# 啟動 readahead
CONTROL_READAHEAD=1
# Read-ahead, in kilobytes. You can spin down the disk while playing MP3/OGG
# by setting the disk readahead to a reasonable size, e.g. 3072 (3 MB).
# Effectively, the disk will read a complete MP3 at once, and will then spin
# down while the MP3/OGG is playing. Don't set this too high, because the
# readahead is applied to _all_ files that are read from disk.
# 設定laptop_mode下的readahead buffer,如果是聽mp3 3-5M,如果是看電影 8-10M
LM_READAHEAD=4096
NOLM_READAHEAD=128
# Should laptop mode tools control the maximum CPU frequency?
# 啟動CPU頻率控制
CONTROL_CPU_FREQUENCY=1
# Legal values are "slowest" for the slowest speed that your
# CPU is able to operate at, "fastest" for the fastest speed,
# "medium" for some value in the middle, or any value listed in
# /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_frequencies.
# 設定電池模式下的CPU頻率
BATT_CPU_MAXFREQ=slowest
BATT_CPU_MINFREQ=slowest
BATT_CPU_GOVERNOR=ondemand
?現在可以通過下面命令查看laptop-mode的狀態
sudo /etc/init.d/laptop-mode status
使用tmpfs把臨時文件放入內存中。tmpfs 就象虛擬磁盤(ramdisk),但又不完全一樣。象虛擬磁盤一樣,tmpfs 可以使用您的 RAM,但它也可以使用您的交換分區來存儲。而且傳統的虛擬磁盤是個塊設備,并需要一個 mkfs 之類的命令才能真正地使用它,tmpfs 是一個文件系統,而不是塊設備;您只是安裝它,它就可以使用了。總而言之,這讓 tmpfs 成為我有機會遇到的最好的基于 RAM 的文件系統。
修改/etc/fstab,把tmpfs mount 到/tmp上,并設置最大上限為32M。
tmpfs /tmp tmpfs size=32m 0 0
?如果你內存很多(1G以上)你完全可關閉swap
?現在你的硬盤應該把讀寫操作降得很低了。
5.其他優化
降低顏色深度
修改xorg.conf 改為16位色
修改sudo vi /etc/X11/xorg.conf
DefaultDepth 16
?盡量少使用光驅
盡量不啟動X,使用console
比如看片子的話可以在console下用mplayer -vo fbdev your.movie.file
聽音樂可以使用mpg123 ogg123等等
無線網卡
在不使用wlan的時候關閉它
?6. 讓上面優化實現自動化
acpi能截獲電源適配器事件
/etc/acpi/events/ac
在這個腳本中我們可以看到實際上調用的是/etc/acpi/power.sh腳本
grep -q off-line $x/state
if [ $? = 0 ] && [ x$1 != xstop ]; then
for SCRIPT in /etc/acpi/battery.d/*.sh; do
. $SCRIPT
done
if [ x$ENABLE_LAPTOP_MODE = xtrue ]; then
(sleep 5 && laptop_mode_enable)&
fi
else
for SCRIPT in /etc/acpi/ac.d/*.sh; do
. $SCRIPT
done
if [ x$ENABLE_LAPTOP_MODE = xtrue ]; then
(sleep 5 && laptop_mode_disable)&
fi
fi
done
?在這段腳本中我們看到如果要讓腳本在bettary模式下運行就放在/etc/acpi/battery.d/目錄下,要讓腳本在電源模式下于虛擬就把腳本放在/etc/acpi/ac.d/目錄下
好了既然腳本能自動執行,要實現什么樣的節能效果就看你的想象力了。
另附一些實用工具軟件
查看硬盤溫度
sudo hddtemp -n /dev/hda
查看cpu信息
sudo x86info
查看硬件信息
lshw
案例,本人hp ze22xx
在windows下便攜模式下能運行大概2小時20分
在ubuntu下未優化能運行2小時左右
優化過后能運行2小時30分
參考
gentoo power management guide
http://www.gentoo.org/doc/en/power-management-guide.xml
Extending Battery Life with Laptop Mode
http://www.linuxjournal.com/article/7539
?
?
?
?
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
