[完全用 GNU/Linux 工作] 08. 電源管理 - PowerTOP

PowerTOP 是個分析、監控電力消秏的節能工具程式,它是由 Intel 於 2007 年以 GPLv2 授權釋出的開放原始碼專案。我們可以使用它找出 GNU/Linux 上秏電的套件,並透過停用不必要的功能以達到省電的效果,是筆記型電腦 (Laptop) 必裝的實用工具。

2013-09-25-powertop-01.png
▲ PowerTOP 的起始畫面。

1. 開始前請先安裝 powertop。
[ jonny@linux ~ ]
# Debian, Ubuntu
$ sudo aptitude install powertop Enter

# CentOS, RHEL, Fedora
$ sudo yum install powertop Enter

# Arch Linux
$ sudo pacman -S powertop Enter

2. 請使用 Tab, Shift + Tab 或方向鍵 , 切換至 Tunables 分頁 1,並使用 , 上下移動,於欲調校的項目按下 Enter 進行調校,當所有狀態顯示為 Good 後即可按下 Q 離開。

2013-09-25-powertop-02.png
▲ 調校前的 Tunables

2013-09-25-powertop-03.png
▲ 調校後的 Tunables

3. PowerTOP 本身並無儲存功能,但我們可以藉由 powertop '--html' 產生的報告來調校系統,甚至於開機時載入這些設定。
[ jonny@linux ~ ]
$ sudo powertop --html Enter
Loaded 58 prior measurements
Cannot load from file /var/cache/powertop/saved_parameters.powertop
Preparing to take measurements
Measuring 1 time(s) for 20 seconds each
PowerTOP outputing using base filename powertop-20130915-231821.html

2013-09-25-powertop-04.png
▲ 此報告將依個人環境而有所不同,其各項目的詳細說明可參考 Power saving - ArchWiki 一文。

4. 接著將調校的指令貼到一個 shell script 打包起來。
[ jonny@linux ~ ]
$ sudo vi /usr/local/bin/powersave Enter
 1 #!/bin/bash
 2 
 3 # Filename: powersave
 4 # Info: PowerTop conifg for ThinkPad T410 on Debian Wheezy.
 5 
 6 # Wireless Power Saving for interface wlan0
 7 iw dev wlan0 set power_save off
 8 
 9 # Enable SATA link power management for /dev/sda
10 echo 'min_power' > '/sys/class/scsi_host/host0/link_power_management_policy';
11 
12 # NMI watchdog should be turned off
13 echo '0' > '/proc/sys/kernel/nmi_watchdog';
14 
15 # VM writeback timeout
16 echo '1500' > '/proc/sys/vm/dirty_writeback_centisecs';
17 
18 # Enable Audio codec power management   
19 echo '1' > '/sys/module/snd_hda_intel/parameters/power_save';
20 
21 # Autosuspend for USB device Biometric Coprocessor [UPEK]   
22 echo 'auto' > '/sys/bus/usb/devices/1-1.3/power/control';
23 
24 # Runtime PM for PCI Device Ricoh Co Ltd MMC/SD Host Controller
25 echo 'auto' > '/sys/bus/pci/devices/0000:0d:00.0/power/control';
26 
27 # Runtime PM for PCI Device Intel Corporation Core Processor PCI Express x16 Root Port  
28 echo 'auto' > '/sys/bus/pci/devices/0000:00:01.0/power/control';
29 
30 # Runtime PM for PCI Device Intel Corporation 82577LM Gigabit Network Connection    
31 echo 'auto' > '/sys/bus/pci/devices/0000:00:19.0/power/control';
32 
33 # Runtime PM for PCI Device Intel Corporation 5 Series/3400 Series Chipset USB2 Enhanced Host Controller    
34 echo 'auto' > '/sys/bus/pci/devices/0000:00:1a.0/power/control';
35 
36 # Runtime PM for PCI Device Intel Corporation 5 Series/3400 Series Chipset High Definition Audio    
37 echo 'auto' > '/sys/bus/pci/devices/0000:00:1b.0/power/control';
38 
39 # Runtime PM for PCI Device Intel Corporation 5 Series/3400 Series Chipset PCI Express Root Port 4  
40 echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.3/power/control';
41 
42 # Runtime PM for PCI Device Ricoh Co Ltd R5C832 PCIe IEEE 1394 Controller   
43 echo 'auto' > '/sys/bus/pci/devices/0000:0d:00.3/power/control';
44 
45 # Runtime PM for PCI Device Intel Corporation Centrino Wireless-N 1000 [Condor Peak]    
46 echo 'auto' > '/sys/bus/pci/devices/0000:03:00.0/power/control';
47 
48 # Runtime PM for PCI Device Intel Corporation 5 Series/3400 Series Chipset SMBus Controller 
49 echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.3/power/control';
50 
51 # Runtime PM for PCI Device Intel Corporation 5 Series/3400 Series Chipset Thermal Subsystem    
52 echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.6/power/control';
53 
54 # Runtime PM for PCI Device Intel Corporation 5 Series/3400 Series Chipset 6 port SATA AHCI Controller  
55 echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.2/power/control';
56 
57 # Runtime PM for PCI Device NVIDIA Corporation GT218 [NVS 3100M]    
58 echo 'auto' > '/sys/bus/pci/devices/0000:01:00.0/power/control';
59 
60 # Runtime PM for PCI Device Intel Corporation 5 Series/3400 Series Chipset USB2 Enhanced Host Controller    
61 echo 'auto' > '/sys/bus/pci/devices/0000:00:1d.0/power/control';
62 
63 # Runtime PM for PCI Device Intel Corporation 5 Series/3400 Series Chipset PCI Express Root Port 1
64 echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.0/power/control';
65 
66 # Runtime PM for PCI Device Intel Corporation 5 Series/3400 Series Chipset PCI Express Root Port 5  
67 echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.4/power/control';
68 
69 # Runtime PM for PCI Device NVIDIA Corporation High Definition Audio Controller 
70 echo 'auto' > '/sys/bus/pci/devices/0000:01:00.1/power/control';
71 
72 # Runtime PM for PCI Device Intel Corporation 5 Series/3400 Series Chipset PCI Express Root Port 2  
73 echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.1/power/control';
74 
75 # Wake-on-lan status for device eth0
76 #ethtool -s eth0 wol d;
77 

5. 給予執行權限。
[ jonny@linux ~ ]
$ sudo chmod +x /usr/local/bin/powersave Enter

6. 因調校指令皆需管理者權限才可執行,若想省下打密碼的功夫可參考 Firestarter 開機甭再次輸入密碼 一文修改。
[ jonny@linux ~ ]
$ sudo visudo Enter
......
jonny ALL=NOPASSWD:/usr/local/bin/powersave

7. 現在開機時只需使用 sudo powersave 即可手動切換至省電模式

若想加入開機自動啟動可以參考 安裝 indicator-virtualbox on Ubuntu 12.04 | 4. 加入開機自動啟動 一文或使用較進階的 udevsysctl

※ 註:請依個人需求自行調整,若造成系統不穩還請自行斟酌。

1 感謝 theJian 回報,powertop v2.5 之後切換 Tunables 分頁的功能鍵已從方向鍵 , 改為 TabShift + Tab

本文同步發佈於 iT 邦幫忙

資料來源:
PowerTOP - Wikipedia
Powertop - ArchWiki
2.2. PowerTOP - Red Hat Customer Portal
冷靜: Powertop

留言

Popular Articles

sudo 指令使用說明