歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> ArchLinux 的CPU和顯卡的節能設置

ArchLinux 的CPU和顯卡的節能設置

日期:2017/2/28 16:00:24   编辑:Linux教程

默認下Arch Linux系統是沒有開啟電源節能功能,CPU和顯卡(指獨立顯卡,下同)以最大性能運行,而作為家用或者辦公用計算機並不總需要最大性能,所以這會造成一定的能源浪費。本文目標有:

  • 查看系統硬件的溫度、電壓和風扇轉速等狀態信息。
  • 打開CPU的節能功能。
  • 打開顯卡的節能功能。

1、安裝 Linux-monitoring sensors (lm_sensors)

這是一個 Linux 下的開源工具,用於監控系統硬件的溫度、電壓、風扇轉速等狀態信息。首先安裝它:

$ sudo pacman -S lm_sensors

安裝完畢之後要進行一次硬件探測:

$ sudo sensors-detect

程序會詢問很多問題,一般情況下一路按回車直至完成即可。

現在可以手動啟動 lm_sensors 的守護程序:

$ sudo /etc/rc.d/sensors start

然後運行 sensors 顯示硬件狀態信息:

$ sensors

(注意,上面的 sensors 是一個程序,而 /etc/rc.d/sensors 是一個守護程序控制腳本。)

沒問題的話應該可以看到諸如系統溫度、顯卡溫度、CPU電壓和溫度、風扇轉速等信息,大致如下:

k10temp-pci-00c3

 Adapter: PCI adapter

temp1: +38.9°C (high = +70.0°C)

 (crit = +72.0°C, hyst = +70.0°C)

radeon-pci-0100

 Adapter: PCI adapter

 temp1: +53.0°C

 it8718-isa-0228

 Adapter: ISA adapter

 in0: +1.14 V (min = +0.00 V, max = +4.08 V)

 in1: +1.60 V (min = +0.00 V, max = +4.08 V)

 in2: +3.28 V (min = +0.00 V, max = +4.08 V)

 +5V: +3.02 V (min = +0.00 V, max = +4.08 V)

 in4: +3.09 V (min = +0.00 V, max = +4.08 V)

in5: +3.30 V (min = +0.00 V, max = +4.08 V)

 in6: +4.08 V (min = +0.00 V, max = +4.08 V)

 in7: +2.11 V (min = +0.00 V, max = +4.08 V)

 Vbat: +3.14 V

 fan1: 1717 RPM (min = 10 RPM)

fan2: 0 RPM (min = 0 RPM)

fan3: 0 RPM (min = 0 RPM)

 fan5: 0 RPM (min = 0 RPM)

 temp1: +47.0°C (low = +127.0°C, high = +127.0°C) sensor = thermistor

temp2: +42.0°C (low = +127.0°C, high = +70.0°C) sensor = thermal diode

 temp3: +46.0°C (low = +127.0°C, high = +127.0°C) sensor = thermistor

 cpu0_vid: +1.050 V

上面數據當中的 +53.0°C 是顯卡溫度,最後的三個溫度應該是CPU相關溫度,因為下面准備打開顯卡和CPU的節能功能,為了對比效果,可以用筆記下這兩項。

最後別忘了將 lm_sensors 守護程序加入 rc.conf ,讓系統啟動時自動運行。即編輯 /etc/rc.conf 文件,在DAEMONS後面加上“sensors”,如下:

DAEMONS=(syslog-ng dbus networkmanager sensors)

2、打開CPU頻率動態調節功能

現在新產的CPU和主板一般支持CPU頻率動態調節功能,我們可以通過讓系統在任務輕松時降低CPU頻率以達到節能目的。這個功能可能叫作“Speedstep, Cool and Quiet, PowerNow!, ACPI.” 等,要先在BIOS裡打開此項功能(我的主板是技嘉AMD主板,對應的名稱是“Cool and Quiet”)。

然後安裝CPU頻率調節工具:

$ sudo pacman -S cpufrequtils

下面我們需要載入頻率調節的內核模塊(驅動),通過下面命令可以查看有哪些內核可用:

$ ls /lib/modules/$(uname -r)/kernel/drivers/cpufreq/

對於 intel CPU 可以嘗試:

$ sudo modprobe acpi-cpufreq

對於 AMD CPU 可以嘗試:

$ sudo modprobe powernow-k8

假如有錯誤可以換其他的試試。

一旦載入成功,可以使用 cpufreq-info 命令查看當前CPU狀態:

$ cpufreq-info

結果大致如下:

cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009

 Report errors and bugs to [email protected], please.

 analyzing CPU 0:

 driver: powernow-k8

 CPUs which run at the same hardware frequency: 0

 CPUs which need to have their frequency coordinated by software: 0

 maximum transition latency: 8.0 us.

 hardware limits: 800 MHz - 2.80 GHz

 available frequency steps: 2.80 GHz, 2.10 GHz, 1.60 GHz, 800 MHz

 available cpufreq governors: ondemand, conservative, userspace, powersave, performance

 current policy: frequency should be within 800 MHz and 2.80 GHz.

 The governor "ondemand" may decide which speed to use

 within this range.

 current CPU frequency is 800 MHz.

上面的數據列出每個CPU(或者核心)的最小和最大頻率、可選的頻率、當前工作頻率以及調速器(Scaling governors)等信息。

其中調速器(Scaling governors)有如下幾種:

  • cpufreq_performance (默認,最大性能)
  • cpufreq_ondemand (推薦,按需調節)
  • cpufreq_conservative (也是按需調節,不過較為保守)
  • cpufreq_powersave (最低頻率,節能模式)
  • cpufreq_userspace (手動模式)

注意調速器也是內核模塊,需要先載入才能使用。比如:

$ sudo modprobe cpufreq_ondemand

然後更改各個CPU(或核心)選用的調速器(默認是最大性能):

$ sudo cpufreq-set -c 0 -g ondemand
 
$ sudo cpufreq-set -c 1 -g ondemand
 
$ sudo cpufreq-set -c 2 -g ondemand
 
$ sudo cpufreq-set -c 3 -g ondemand

現在你可以再次運行 cpufreq-info 查看CPU的當前頻率和調速器是否正確,過1、2分鐘之後再次運行 sensors 查看CPU溫度是否有所下降。如果都是的話,則可以把加載的內核模塊名稱添加到 rc.conf 的 MODULES 一行讓系統啟動時自動載入,大致如下:

MODULES=(vboxdrv vboxnetflt powernow-k8 cpufreq_ondemand)

最後,因為 cpufreq-set 程序的作用在系統重啟後會自動消失,所以需要將掌管它的守護程序 cpufreq 寫入到 rc.conf 的 DAEMONS 裡,大致如下:

DAEMONS=(syslog-ng dbus networkmanager sensors @cpufreq)

然後修改配置文件 /etc/conf.d/cpufreq,去掉 governor=”ondemand” 一行的注釋,內容大致如下:

#configuration for cpufreq control
 
 # valid governors:
 
# ondemand, performance, powersave,
 
 # conservative, userspace
 
 governor="ondemand"
 
 # limit frequency range (optional)
 
 # valid suffixes: Hz, kHz (default), MHz, GHz, THz
 
 #min_freq="2.25GHz"
 
 #max_freq="3GHz"
 
 # use freq to set up the exact cpu frequency using it with userspace governor
 
 #freq=

3、降低顯卡運作頻率

這個操作會根據不同的顯卡有所不同,這裡只以ATI Radeon HD 5750作為示例說明。我的系統安裝了 ATI 開源的顯卡驅動 xf86-video-ati,通過如下命令可以查看當前顯卡電源管理模式:

$ cat /sys/class/drm/card0/device/power_profile

默認的是“default”,也就是最大性能模式,我們可以把它更改為 auto,low,mid,high 等模式,其中auto是根據是否使用電池供電(指筆記本電腦電池)來自動切換low和high模式,這個對於台式計算機來說是無效的,所以我們如果不是經常運行3D程序的話可以冒進一點設置為low模式。切換到 root 帳號,然後運行下面命令即可;

# echo low>/sys/class/drm/card0/device/power_profile

過1分鐘左右使用 sensors 命令查看顯卡溫度是否有所降低,是的話則說明起效了,然後可以將上面一行命令寫入 /etc/rc.local 文件,讓系統啟動時自動運行。

總結

通過上面的操作一般可以將CPU和顯卡溫度降低10攝氏度左右,當然也節省不少電能和電費。

Copyright © Linux教程網 All Rights Reserved