在安装成功Preempt-RT之后,需要对系统进行了详细的时延测试,以判定该系统是否满足实时性需求。在安装Preempt-RT一文中已经简要介绍了时延的测试方法,本文将进行更为详细的时延测试工作。需要说明的是,短时间的运行cyclictest得出的结果是无意义的,再就是测试系统上没有合适负载的情况下运行cyslictest所得到的延时统计也是无意义的。本文分别在CPU空载和满负载的情况下对Preempt-RT的时延进行测试。
1. 模拟负载
- 安装stress压力测试工具:
sudo apt-get install stress
- 查看自己电脑的核心数:
cd /sys/devices/system/cpu
ls
我的结果显示cpu标号从cpu0~cpu7,因此核心数为8个
- 让CPU满载运行:
strss --cpu 8
- 查看结果:
sudo apt-get install htop
htop
2. 运行测试程序
- 安装绘图工具gnuplot:
sudo apt-get install gnuplot
- 空载测试
- 不使用stress工具
- 运行测试指令:
sudo cyclictest -m -Sp90 -i1000 -h400 -D 30m -q >ouput #为了方便,我只运行了30分钟,实际测试应为1-2天,且不间断运行
- 运行脚本:
#!/bin/bash
echo "ready for plot \n"
# get maximum latency
max=`grep "Max Latencies" output | tr " " "\n" | sort -n | tail -1 | sed s/^0*//`
echo "max Latency is $max"
# Grep data lines, remove empty lines and create a common field separator
grep -v -e "^#" -e "^$" output | tr " " "\t" >histogram
# set the number of cores, for example
cores=8
# Create two-column data sets with latency classes and frequency values for each core
for i in `seq 1 $cores`
do
column=`expr $i + 1`
cut -f1,$column histogram >histogram$i
done
# Create plot command header
echo -n "set title \"Latency plot(No load)\"\n\
set terminal png\n\
set xlabel \"Latency (us), max $max us\"\n\
set logscale y\n\
set xrange [0:400]\n\
set yrange [0.8:*]\n\
set ylabel \"Number of latency samples\"\n\
set output \"Noloadplot.png\"\n\
plot " >plotcmd
# Append plot command data references
for i in `seq 1 $cores`
do
if test $i != 1
then
echo -n ", " >>plotcmd
fi
cpuno=`expr $i - 1`
if test $cpuno -lt 10
then
title=" CPU$cpuno"
else
title="CPU$cpuno"
fi
echo -n "\"histogram$i\" using 1:2 title \"$title\" with histeps" >>plotcmd
done
#Execute plot command
gnuplot -persist <plotcmd
# enjoy
firefox plot.png
- 满载测试
- 使用stress工具
stress --cpu 8 #我的cpu核心数为8个
- 运行测试指令:
sudo cyclictest -m -Sp90 -i1000 -h400 -D 30m -q >ouput
- 运行脚本:
#!/bin/bash
echo "ready for plot \n"
# get maximum latency
max=`grep "Max Latencies" output | tr " " "\n" | sort -n | tail -1 | sed s/^0*//`
echo "max Latency is $max"
# Grep data lines, remove empty lines and create a common field separator
grep -v -e "^#" -e "^$" output | tr " " "\t" >histogram
# set the number of cores, for example
cores=8
# Create two-column data sets with latency classes and frequency values for each core
for i in `seq 1 $cores`
do
column=`expr $i + 1`
cut -f1,$column histogram >histogram$i
done
# Create plot command header
echo -n "set title \"Latency plot(Full load)\"\n\
set terminal png\n\
set xlabel \"Latency (us), max $max us\"\n\
set logscale y\n\
set xrange [0:400]\n\
set yrange [0.8:*]\n\
set ylabel \"Number of latency samples\"\n\
set output \"Fullloadplot.png\"\n\
plot " >plotcmd
# Append plot command data references
for i in `seq 1 $cores`
do
if test $i != 1
then
echo -n ", " >>plotcmd
fi
cpuno=`expr $i - 1`
if test $cpuno -lt 10
then
title=" CPU$cpuno"
else
title="CPU$cpuno"
fi
echo -n "\"histogram$i\" using 1:2 title \"$title\" with histeps" >>plotcmd
done
#Execute plot command
gnuplot -persist <plotcmd
# enjoy
firefox plot.png
上述程序参考自:
Create a latency plot from cyclictest histogram data
3. 观察结果
空载时延测试结果:
满载时延测试结果: