天天看点

Cyclictest测试Linux内核的实时性概述1. 编译RT内核2. Debian系统更换RT内核:3. Cyclictest测试实时性:

概述

本文主要介绍了如何编译测试Linux实时内核的实时性的流程及方法。

1. 编译RT内核

RT-patch

内核源码

给内核打补丁:

cd linux-4.19
patch -p1 < ../patch....
           

编译内核:

make menuconfig
General setup----Preemption ModelFully Preemptible Kernel(RT)
make 
sudo make modules_install
sudo make install
sudo update-grub
           

出现的问题:

make modules_install 出错,提示如下:

/bin/sh:1:scripts/sign-file: Exec format error
           

解决方法:

在内核源码目录下执行 make scripts

KVM虚拟机容量不足:

#只能转换raw格式的,所以先将qcow2装换为raw
qemu-img convert -p -f vmdk -O qcow2 centos6.9.vmdk centos6.9.qcow2

上述命令中各参数对应的说明如下:

    -p标识转换的进度条。
    -f后面为源镜像格式。
    -O(必须是大写)后面的参数为转换出来的镜像格式 + 源镜像文件名称 + 目标文件名称。
转换完成后,目标文件会出现在源镜像文件所在的目录下。

回显信息如下所示:
#查看原磁盘大小
qemu-img info  kvm-win10_add.raw
#增加容量20G
qemu-img resize kvm-win10_add.raw +150G
           

2. Debian系统更换RT内核:

sudo apt-get update
apt-cache search linux-image
sudo apt-get install linux-image-xxxxx
           

3. Cyclictest测试实时性:

参考

原理:

在线程中,通过clock_gettime()函数获取当前时间,根据该时间算出下次间隔的时间,然后在下次循环中获取当前时间与计算出的时间作对比,差值就是延迟。

安装:

#安装
sudo apt-get install rt-tests
#使用
sudo cyclictest -t1 -p 80 -n -i 10000 -l 10000
           

指定参数含义:

-t: 创建线程的数目

-p: 最高优先级线程的优先级

-n: --nanosleep

-i: 基本线程间隔,默认1000us

-l: 循环的次数,默认为0,即无穷次

-m: 锁定当前和未来的内存分配

输出结果含义:

T: 0 序号为0的线程

P: 0 线程优先级为0

C: 9397 计数器。线程的时间间隔每达到一次,计数器加1

I: 1000 时间间隔为1000微秒(us)

Min: 最小延时(us)

Act: 最近一次的延时(us)

Avg:平均延时(us)

Max: 最大延时(us)

3.1 压力测试工具stress-ng的使用:

参考

安装:

sudo apt-get install stress stress-ng
           

使用:

#产生2个worker做圆周率算法压力
stress-ng  -c 2 --cpu-method pi
#产生2个worker迭代使用30多种不同的压力算法
stress-ng  -c 2 --cpu-method all
#读取TSC产生压力
stress-ng --tsc 2
           
  • -c N :运行N worker CPU压力测试进程
  • –cpu-method all :worker从迭代使用30多种不同的压力算法,包括pi, crc16, fft等等
  • -tastset N:将压力加到指定核心上
  • -d N:运行N worker HDD write/unlink测试
  • -i N:运行N worker IO测试

3.2 实验设置:

我们实验采用主机+虚拟机的测试环境

注意:

  1. 有无负载指在VM中是否使用stress-ng工具为CPU加压
  2. RT-KVM指KVM运行的Host的系统采用打了Preempt-RT补丁的内核
  3. GP-KVM:Host采用一般内核
  4. RT-VM: Guest采用RT内核
  5. GP-VM:Guest采用GP内核

工具使用:

#stress-ng 产生5个worker线程,使用全部的算法为CPU加压
sudo stress-ng -c 5 --cpu-method all
#cyclictest 产生5个线程,优先级为80,采用clock_nanonsleep,运行10000次,线程间隔为默认1000us
sudo cyclictest -t5 -p80 -n -l10000
           

几组对照:

  • 无负载 + RT-KVM + RT-VM
  • 无负载 + RT-KVM + GP-VM
  • 有负载 + RT-KVM + RT-VM
  • 有负载 + RT-KVM + GP-VM
  • 无负载 + GP-KVM + RT-VM
  • 无负载 + GP-KVM + GP-VM
  • 有负载 + GP-KVM + RT-VM
  • 有负载 + GP-KVM + GP-VM

3.3 实验环境:

Host(KVM) Guest(VM)
系统: Ubuntu Debian
内核版本: 5.4.0 4.19.0
添加负载工具: stress-ng stress-ng
延迟测试工具: cyclictest cyclictest

3.4 实验结果:

无负载,kvm GP-Kernel, VM RT-Kernel:

Cyclictest测试Linux内核的实时性概述1. 编译RT内核2. Debian系统更换RT内核:3. Cyclictest测试实时性:

有负载,kvm GP-Kernel, VM RT-Kernel:

Cyclictest测试Linux内核的实时性概述1. 编译RT内核2. Debian系统更换RT内核:3. Cyclictest测试实时性:

无负载,kvm GP-Kernel, VM Non-RT-Kernel

Cyclictest测试Linux内核的实时性概述1. 编译RT内核2. Debian系统更换RT内核:3. Cyclictest测试实时性:

有负载,kvm GP-Kernel, VM Non-RT-Kernel

Cyclictest测试Linux内核的实时性概述1. 编译RT内核2. Debian系统更换RT内核:3. Cyclictest测试实时性:

无负载,kvm RT-Kernel, VM RT-Kernel

Cyclictest测试Linux内核的实时性概述1. 编译RT内核2. Debian系统更换RT内核:3. Cyclictest测试实时性:

有负载,kvm RT-Kernel, VM RT-Kernel

Cyclictest测试Linux内核的实时性概述1. 编译RT内核2. Debian系统更换RT内核:3. Cyclictest测试实时性:

无负载,kvm RT-Kernel, VM Non-RT-Kernel

Cyclictest测试Linux内核的实时性概述1. 编译RT内核2. Debian系统更换RT内核:3. Cyclictest测试实时性:

有负载,kvm RT-Kernel, VM Non-RT-Kernel

Cyclictest测试Linux内核的实时性概述1. 编译RT内核2. Debian系统更换RT内核:3. Cyclictest测试实时性:
Cyclictest测试Linux内核的实时性概述1. 编译RT内核2. Debian系统更换RT内核:3. Cyclictest测试实时性:

结论:

  1. 有负载的情况下,RT_kernel的延迟< Non_RT_kernel
  2. 无负载的情况下,两者的延迟差不多
  3. 采用实时内核的KVM中VM的延迟< 没有采用实时内核的KVM中VM的延迟

3.5 使用Gnuplot结合cyclictest的结果绘图:

参考:

gnuplot的使用

cyclictest原理及使用

cyclictest的使用:

sudo cyclictest -t1 -p 80 -n -h 100 -q -i 10000 -l 10000  >  /tmp/log
#-h 100 指只统计100us内的延迟发生的次数
#-q:不提示信息
           

结果:

000001 000000
000002 000000
000003 000000
000004 000000
000005 000000
000006 000000
000007 000000
000008 000002  表示延迟为8us的发生了2次
000009 000000
000010 000001
000011 000002
.........
           

gnuplot的使用:

#安装
sudo apt-get install gnuplot
#使用
gnuplot
#在打开的gnuplot的界面中绘图
plot "/tmp/log" with lines
#自动调整x,y轴的坐标
set logscale x
set logscale y
#退出
exit
           

结果如下图所:

Cyclictest测试Linux内核的实时性概述1. 编译RT内核2. Debian系统更换RT内核:3. Cyclictest测试实时性:

继续阅读