CPUfreq 的一般設定
我們先來介紹 Linux CPUfreq 子系統的使用設定並提供一些介面選項,看看使用它是多麼容易。先討論一些一般設定:
/sys 介面
cpuspeed 設定檔案
cpufreq-utils
使用 /sys 介面
/sys 檔案系統為 CPUfreq 提供使用者介面,起點是 /sys/devices/system/cpu/。其中一些檔案是可寫的由根使用者寫),其他檔案是唯讀。
首先,看看 /sys/devices/system/cpu/。在這裡會找到每個邏輯 CPU 的目錄和 sched_mc_power_savings 可調項,如果在系統上可用的話,還會找到 sched_smt_power_savings 可調項稍後討論)。
清單 1. 檢查 /sys/devices/system/cpu/ 的內容
[root@systemx ~]# cd /sys/devices/system/cpu/
[root@systemx cpu]# ls
cpu0 cpu1 cpu2 cpu3 cpu4 cpu5 cpu6 cpu7 sched_mc_power_savings
在每個處理器的目錄內是一個 cpufreq 目錄,它包含 CPUfreq 介面:
清單 2. 檢查 cpufreq 目錄
[root@systemx cpu]# cd cpu0/cpufreq/
[root@systemx cpufreq]# ls -l
total 0
-r--r--r-- 1 root root 4096 Oct 31 14:53 affected_cpus
-r-------- 1 root root 4096 Oct 31 14:53 cpuinfo_cur_freq
-r--r--r-- 1 root root 4096 Oct 31 14:53 cpuinfo_max_freq
-r--r--r-- 1 root root 4096 Oct 31 14:53 cpuinfo_min_freq
-r--r--r-- 1 root root 4096 Oct 31 14:53 scaling_available_frequencies
-r--r--r-- 1 root root 4096 Oct 31 14:53 scaling_available_governors
-r--r--r-- 1 root root 4096 Oct 31 14:53 scaling_cur_freq
-r--r--r-- 1 root root 4096 Oct 31 14:53 scaling_driver
-rw-r--r-- 1 root root 0 Nov 5 11:44 scaling_governor
-rw-r--r-- 1 root root 4096 Oct 31 14:53 scaling_max_freq
-rw-r--r-- 1 root root 4096 Oct 31 14:53 scaling_min_freq
加入 My developerWorks 上的綠色組
在 GReen IT Report space 和 My developerWorks 上的 Green computing group 討論與能源、效率和環境相關的主題並分享參考資料。
如果調控器設定為 conservative 或 ondemand,還會在這裡看到與調控器同名的目錄。我們稍後討論如何改變調控器。
對於每個調控器,都可以使用這些檔案。我們將討論每個設定的意義以及如何修改它們;然後討論這個介面之外與調控器相關的一些設定。注意,對於每個處理器,cpufreq 目錄下的設定可以不一樣,因此要想跨處理器應用一致的策略,就必須按照後面的說明修改每個處理器的設定值。
首先,affected_cpus 顯示修改頻率會影響哪些處理器。由於硬體和/或軟體的關聯,一些處理器的頻率是相互依賴的,必須同時修改頻率。例如,可能會看到這種設定:
清單 3. 檢查修改頻率會影響哪些處理器
[root@systemx ~]# cd /sys/devices/system/cpu
[root@systemx cpu]# grep . cpu*/cpufreq/affected_cpus
cpu0/cpufreq/affected_cpus:0 1
cpu1/cpufreq/affected_cpus:0 1
cpu2/cpufreq/affected_cpus:2 3
cpu3/cpufreq/affected_cpus:2 3
接下來,cpuinfo_cur_freq 顯示處理器當前的運行頻率。scaling_cur_freq 檔案列出調控器當前使用的擴充頻率。
清單 4. 檢查頻率
[root@systemx cpufreq]# cat cpuinfo_cur_freq
2997000
[root@systemx cpufreq]# cat scaling_cur_freq
2997000
這個介面中列出的所有頻率都以 KHz 為單位。
下面一些檔案提供可用處理器頻率的相關資訊。cpuinfo_max_freq 和 cpuinfo_min_freq 檔案包含系統可用的最大和最小頻率;scaling_available_frequencies 顯示所有可用頻率。