从Ubuntu15的某个版本开始,在使用intel某些cpu的pc上默认使用intel_pstatecpufreq driver。后果就是只有performance和powersave两个governor可用。可通过下面命令确认:
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governor
powersave performance
或者用 cpufreq-info
$ cpufreq-info
cpufrequtils 008: cpufreq-info (C) DominikBrodowski 2004-2009
Report errors and bugs tocpufreq@vger.kernel.org,please.
analyzing cpu 0:
driver: intel_pstate
cpus which run at the same hardware frequency: 0
cpus which need to have their frequency coordinated by software: 0
maximum transition latency: 0.97 ms.
hardware limits: 1.20 GHz - 2.80 GHz
available cpufreq governors: performance,powersave
current policy: frequency should be within 1.20 GHz and 2.80 GHz.
The governor"powersave" may decide which speed to use
within this range.
current cpu frequency is 1.21 GHz.
…
注: 要使用cpufreq-info和后面要提到的cpufreq-set,请先安装cpufrequtils,后面会提到。
在使用intel_pstate cpufreq driver的情况下,即使governor是powersave或者performance,但观测发现scaling_cur_freq是一直变化的,而不是像它们的含义一样,使用最低或者最高频率。
如果要测试系统或者软件的性能,我们需要固定cpu频率。本文讲述如何在这种的pc上固定cpu频率。
1. 安装cpufrequtils
sudo apt-get install cpufrequtils
2. Disableintel_pstate driver
in /etc/default/grub,change
GRUB_CMDLINE_LINUX_DEFAULT="quietsplash"
to
GRUB_CMDLINE_LINUX_DEFAULT="quietsplash intel_pstate=disable"
sudo update-grub
after reboot,then acpi-cpufreq driver willbe used.
3. 固定频率
这时sysfs下cpufreq相关的节点就是我们熟悉的文件了。
可使用powersave来使用固定的最低频率,
sudo cpufreq-set -g performance
也可使用performance governor来使用固定的最高频率
sudo cpufreq-set -g powersave
推荐使用userspace governor,然后设置我们期望的频率(这里假设我们要设置cpu频率为2GHz).
sudo cpufreq-set -g userspace
sudo cpufreq-set -f 2000000