Linux 3.1已经将cpupower-utils中放入内核的tools目录,见:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=tree;f=tools/power;h=f6a98ba17528ed7645f53bb8cb67f59112adf346;hb=c3b92c8787367a8bb53d57d9789b558f1295cc96
在其中有一个工具叫cpufreq-bench,可以用于测试ondemand等cpufreq策略的使用对系统性能的影响,譬如:
# /usr/sbin/cpufreq-bench -l 50000 -s 100000 -x 50000 -y 100000 -g ondemand -r 5 -n 5 -v loading defaults parsing: sleep -> 50000 parsing: load -> 50000 parsing: cpu -> 0 parsing: priority -> LOW parsing: output -> /var/log/cpufreq-bench logilename: /var/log/cpufreq-bench/benchmark_localhost_2.6.38.8-xxx_1686167.log Logfile: /var/log/cpufreq-bench/benchmark_localhost_2.6.38.8-xxx_1686167.log parsing: sleep_step -> 50000 parsing: load_step -> 50000 parsing: cycles -> 20 parsing: rounds -> 40 parsing: verbose -> 0 parsing: governor -> ondemand user load time -> 50000 user sleep time -> 100000 user load_step -> 50000 user sleep_step -> 100000 user governor -> ondemand user rounds -> 5 user cycles -> 5 verbose output enabled starting benchmark with parameters: config: sleep=100000 load=50000 sleep_step=100000 load_step=50000 cpu=0 cycles=5 rounds=5 governor=ondemand approx. test duration: 0m set cpu affinity to cpu #0 set affinity to cpu #0 low priority condition requested set scheduler priority to 0 set performance as cpufreq governor calibrating load of 50000us, please wait... calibrating with 6 rounds calibrating with 6 rounds calibrating with 6 rounds calibrating with 6 rounds calibration done _round 1: doing 5 cycles with 6 calculations for 50000us avarage: 8333us, rps:120 performance cycle took 147613us, sleep: 100000us, load: 50000us, rounds: 6 performance cycle took 211700us, sleep: 100000us, load: 50000us, rounds: 6 performance cycle took 147747us, sleep: 100000us, load: 50000us, rounds: 6 performance cycle took 147537us, sleep: 100000us, load: 50000us, rounds: 6 performance cycle took 147482us, sleep: 100000us, load: 50000us, rounds: 6 set ondemand as cpufreq governor powersave cycle took 149627us, sleep: 100000us, load: 50000us, rounds: 6 powersave cycle took 243281us, sleep: 100000us, load: 50000us, rounds: 6 powersave cycle took 288620us, sleep: 100000us, load: 50000us, rounds: 6 powersave cycle took 288554us, sleep: 100000us, load: 50000us, rounds: 6 powersave cycle took 290043us, sleep: 100000us, load: 50000us, rounds: 6 performance is at 39.74% set performance as cpufreq governor calibrating load of 100000us, please wait... calibrating with 12 rounds calibrating with 12 rounds calibrating with 12 rounds calibrating with 12 rounds calibration done _round 2: doing 5 cycles with 12 calculations for 100000us avarage: 8333us, rps:120 performance cycle took 296126us, sleep: 200000us, load: 100000us, rounds: 12 performance cycle took 296454us, sleep: 200000us, load: 100000us, rounds: 12 performance cycle took 296068us, sleep: 200000us, load: 100000us, rounds: 12 performance cycle took 296026us, sleep: 200000us, load: 100000us, rounds: 12 performance cycle took 295887us, sleep: 200000us, load: 100000us, rounds: 12 set ondemand as cpufreq governor powersave cycle took 479989us, sleep: 200000us, load: 100000us, rounds: 12 powersave cycle took 464829us, sleep: 200000us, load: 100000us, rounds: 12 powersave cycle took 389619us, sleep: 200000us, load: 100000us, rounds: 12 powersave cycle took 514207us, sleep: 200000us, load: 100000us, rounds: 12 powersave cycle took 473326us, sleep: 200000us, load: 100000us, rounds: 12 performance is at 36.35% set performance as cpufreq governor calibrating load of 150000us, please wait... calibrating with 18 rounds calibrating with 18 rounds calibrating with 18 rounds calibrating with 18 rounds calibration done _round 3: doing 5 cycles with 18 calculations for 150000us avarage: 8333us, rps:120 performance cycle took 445176us, sleep: 300000us, load: 150000us, rounds: 18 performance cycle took 445219us, sleep: 300000us, load: 150000us, rounds: 18 performance cycle took 444955us, sleep: 300000us, load: 150000us, rounds: 18 performance cycle took 445073us, sleep: 300000us, load: 150000us, rounds: 18 performance cycle took 445084us, sleep: 300000us, load: 150000us, rounds: 18 set ondemand as cpufreq governor powersave cycle took 563155us, sleep: 300000us, load: 150000us, rounds: 18 powersave cycle took 598616us, sleep: 300000us, load: 150000us, rounds: 18 powersave cycle took 614820us, sleep: 300000us, load: 150000us, rounds: 18 powersave cycle took 618511us, sleep: 300000us, load: 150000us, rounds: 18 powersave cycle took 619225us, sleep: 300000us, load: 150000us, rounds: 18 performance is at 47.91% set performance as cpufreq governor calibrating load of 200000us, please wait... calibrating with 24 rounds calibrating with 25 rounds calibrating with 25 rounds calibrating with 25 rounds calibration done _round 4: doing 5 cycles with 25 calculations for 200000us avarage: 8000us, rps:125 performance cycle took 602496us, sleep: 400000us, load: 200000us, rounds: 25 performance cycle took 602759us, sleep: 400000us, load: 200000us, rounds: 25 performance cycle took 602782us, sleep: 400000us, load: 200000us, rounds: 25 performance cycle took 602688us, sleep: 400000us, load: 200000us, rounds: 25 performance cycle took 602433us, sleep: 400000us, load: 200000us, rounds: 25 set ondemand as cpufreq governor powersave cycle took 756766us, sleep: 400000us, load: 200000us, rounds: 25 powersave cycle took 774079us, sleep: 400000us, load: 200000us, rounds: 25 powersave cycle took 778619us, sleep: 400000us, load: 200000us, rounds: 25 powersave cycle took 779616us, sleep: 400000us, load: 200000us, rounds: 25 powersave cycle took 779655us, sleep: 400000us, load: 200000us, rounds: 25 performance is at 54.22% set performance as cpufreq governor calibrating load of 250000us, please wait... calibrating with 30 rounds calibrating with 31 rounds calibrating with 31 rounds calibrating with 31 rounds calibration done _round 5: doing 5 cycles with 31 calculations for 250000us avarage: 8064us, rps:124 performance cycle took 752761us, sleep: 500000us, load: 250000us, rounds: 31 performance cycle took 751929us, sleep: 500000us, load: 250000us, rounds: 31 performance cycle took 752054us, sleep: 500000us, load: 250000us, rounds: 31 performance cycle took 751597us, sleep: 500000us, load: 250000us, rounds: 31 performance cycle took 751791us, sleep: 500000us, load: 250000us, rounds: 31 set ondemand as cpufreq governor powersave cycle took 958276us, sleep: 500000us, load: 250000us, rounds: 31 powersave cycle took 928743us, sleep: 500000us, load: 250000us, rounds: 31 powersave cycle took 921301us, sleep: 500000us, load: 250000us, rounds: 31 powersave cycle took 920670us, sleep: 500000us, load: 250000us, rounds: 31 powersave cycle took 920122us, sleep: 500000us, load: 250000us, rounds: 31 performance is at 58.64% 上述测试结果可以看出,被测试平台ondemand采用后,性能下降很大:
Round 1 - 39.74% Round 2 - 36.35% Round 3 - 47.91% Round 4 - 54.22% Round 5 - 58.64%
比较理想的结果是,ondemand采用后性能维持在performance策略的90%左右:
cpufreq-bench results with optimization on OMAP:Round 1 - 90.24%Round 2 - 94.48%Round 3 - 96.06%Round 4 - 96.6%Round 5 - 86.89% cpufreq-bench results on X86 platform:Round 1 - 88.67%Round 2 - 94.71%Round 3 - 95.53%Round 4 - 96.34%Round 5 - 98.03%
由此可见,被测平台的cpufreq驱动相关参数还需要深度调整。
我们在同样的平台上测试Android添加的interactive这个cpufreq策略的性能:
#/usr/sbin/cpufreq-bench -l 50000 -s 100000 -x 50000 -y 100000 -g interactive -
r 5 -n 5 -v
loading defaults
parsing: sleep ->50000
parsing: load ->50000
parsing: cpu -> 0
parsing: priority-> LOW
parsing: output ->/var/log/cpufreq-bench
logilename:/var/log/cpufreq-bench/benchmark_localhost_2.6.38.8-xxx_6470.log
Logfile:/var/log/cpufreq-bench/benchmark_localhost_2.6.38.8-xxx_6470.log
parsing: sleep_step-> 50000
parsing: load_step-> 50000
parsing: cycles ->20
parsing: rounds ->40
parsing: verbose-> 0
parsing: governor-> ondemand
user load time ->50000
user sleep time ->100000
user load_step ->50000
user sleep_step ->100000
user governor ->interactive
user rounds -> 5
user cycles -> 5
verbose outputenabled
starting benchmarkwith parameters:
config:
sleep=100000
load=50000
sleep_step=100000
load_step=50000
cpu=0
cycles=5
rounds=5
governor=interactive
approx. testduration: 0m
set cpu affinity tocpu #0
set affinity to cpu#0
low prioritycondition requested
set schedulerpriority to 0
set performance ascpufreq governor
calibrating load of50000us, please wait...
calibrating with 6rounds
calibrating with 6rounds
calibrating with 6rounds
calibrating with 6rounds
calibration done
_round 1: doing 5cycles with 6 calculations for 50000us
avarage: 8333us,rps:120
performance cycletook 147635us, sleep: 100000us, load: 50000us, rounds: 6
performance cycletook 147506us, sleep: 100000us, load: 50000us, rounds: 6
performance cycletook 147590us, sleep: 100000us, load: 50000us, rounds: 6
performance cycletook 147755us, sleep: 100000us, load: 50000us, rounds: 6
performance cycletook 147563us, sleep: 100000us, load: 50000us, rounds: 6
set interactive ascpufreq governor
powersave cycle took166866us, sleep: 100000us, load: 50000us, rounds: 6
powersave cycle took164004us, sleep: 100000us, load: 50000us, rounds: 6
powersave cycle took165926us, sleep: 100000us, load: 50000us, rounds: 6
powersave cycle took163750us, sleep: 100000us, load: 50000us, rounds: 6
powersave cycle took165789us, sleep: 100000us, load: 50000us, rounds: 6
performance is at 72.95%
set performance ascpufreq governor
calibrating load of100000us, please wait...
calibrating with 12rounds
calibrating with 12rounds
calibrating with 12rounds
calibrating with 12rounds
calibration done
_round 2: doing 5cycles with 12 calculations for 100000us
avarage: 8333us,rps:120
performance cycletook 296382us, sleep: 200000us, load: 100000us, rounds: 12
performance cycletook 296349us, sleep: 200000us, load: 100000us, rounds: 12
performance cycletook 296266us, sleep: 200000us, load: 100000us, rounds: 12
performance cycletook 296152us, sleep: 200000us, load: 100000us, rounds: 12
performance cycletook 295848us, sleep: 200000us, load: 100000us, rounds: 12
set interactive ascpufreq governor
powersave cycle took314330us, sleep: 200000us, load: 100000us, rounds: 12
powersave cycle took308119us, sleep: 200000us, load: 100000us, rounds: 12
powersave cycle took309546us, sleep: 200000us, load: 100000us, rounds: 12
powersave cycle took309942us, sleep: 200000us, load: 100000us, rounds: 12
powersave cycle took309673us, sleep: 200000us, load: 100000us, rounds: 12
performance is at 87.20%
set performance ascpufreq governor
calibrating load of150000us, please wait...
calibrating with 18rounds
calibrating with 18rounds
calibrating with 18rounds
calibrating with 18rounds
calibration done
_round 3: doing 5cycles with 18 calculations for 150000us
avarage: 8333us,rps:120
performance cycletook 445460us, sleep: 300000us, load: 150000us, rounds: 18
performance cycletook 445368us, sleep: 300000us, load: 150000us, rounds: 18
performance cycletook 445724us, sleep: 300000us, load: 150000us, rounds: 18
performance cycletook 445194us, sleep: 300000us, load: 150000us, rounds: 18
performance cycletook 445266us, sleep: 300000us, load: 150000us, rounds: 18
set interactive ascpufreq governor
powersave cycle took457701us, sleep: 300000us, load: 150000us, rounds: 18
powersave cycle took462000us, sleep: 300000us, load: 150000us, rounds: 18
powersave cycle took457623us, sleep: 300000us, load: 150000us, rounds: 18
powersave cycle took461664us, sleep: 300000us, load: 150000us, rounds: 18
powersave cycle took458122us, sleep: 300000us, load: 150000us, rounds: 18
performance is at 91.21%
set performance ascpufreq governor
calibrating load of200000us, please wait...
calibrating with 24rounds
calibrating with 25rounds
calibrating with 25rounds
calibrating with 25rounds
calibration done
_round 4: doing 5cycles with 25 calculations for 200000us
avarage: 8000us,rps:125
performance cycletook 602273us, sleep: 400000us, load: 200000us, rounds: 25
performance cycletook 602022us, sleep: 400000us, load: 200000us, rounds: 25
performance cycletook 602541us, sleep: 400000us, load: 200000us, rounds: 25
performance cycletook 602642us, sleep: 400000us, load: 200000us, rounds: 25
performance cycletook 603079us, sleep: 400000us, load: 200000us, rounds: 25
set interactive ascpufreq governor
powersave cycle took616433us, sleep: 400000us, load: 200000us, rounds: 25
powersave cycle took613765us, sleep: 400000us, load: 200000us, rounds: 25
powersave cycle took616331us, sleep: 400000us, load: 200000us, rounds: 25
powersave cycle took614218us, sleep: 400000us, load: 200000us, rounds: 25
powersave cycle took615348us, sleep: 400000us, load: 200000us, rounds: 25
performance is at 94.10%
set performance ascpufreq governor
calibrating load of250000us, please wait...
calibrating with 30rounds
calibrating with 31rounds
calibrating with 31rounds
calibrating with 31rounds
calibration done
_round 5: doing 5cycles with 31 calculations for 250000us
avarage: 8064us,rps:124
performance cycletook 752050us, sleep: 500000us, load: 250000us, rounds: 31
performance cycletook 751701us, sleep: 500000us, load: 250000us, rounds: 31
performance cycletook 751966us, sleep: 500000us, load: 250000us, rounds: 31
performance cycletook 752029us, sleep: 500000us, load: 250000us, rounds: 31
performance cycletook 752338us, sleep: 500000us, load: 250000us, rounds: 31
set interactive ascpufreq governor
powersave cycle took768047us, sleep: 500000us, load: 250000us, rounds: 31
powersave cycle took763706us, sleep: 500000us, load: 250000us, rounds: 31
powersave cycle took766064us, sleep: 500000us, load: 250000us, rounds: 31
powersave cycle took763898us, sleep: 500000us, load: 250000us, rounds: 31
powersave cycle took765694us, sleep: 500000us, load: 250000us, rounds: 31
performance is at 94.93%
可见它的结果为:
Round 1 - 72.95%
Round 2 - 87.20%
Round 3 - 91.21%
Round 4 - 94.10%
Round 5 - 94.93%
interactive为UI或者说IO更好的响应而设计,测试结果也显示它在性能方面的考量更加aggressive一些。