KVM虚拟机网卡和QAT SR-IOV 配置要点

本文来记录Centos KVM下高性能虚拟机网卡以及QAT加速卡SR-IOV的配置简要,技术含量不高,主要是方便以后在项目中可以快速搭建。

配置环境:

intel X710 DA/intel QAT 8950/Centos 7/C610 Chipset(X99)/ Xeon CPU E5-2678/Mellanox CX3/Centos7/F5 BIGIP V15.1.3

以上硬件都是闲鱼+ebay的二手货

BIOS部分配置:

Hyper-Threading  : disable

intel 超线程下,机器算力没有增加,只减少了CPU切换时的上下文切换消耗,分配给虚拟机的算力根据实际物理核计算,额外的线程vcore并不能提升性能,反而在分配QAT VF的时候要额外增加配置,故取消,本次配置为一个物理core对应一个QAT VF,一台虚拟机使用一张高性能10G X710,两口都用上做线路冗余。

SR-IOV Support : enable

这个参数一般在服务器主板上存在,比如前一代的X99,这一代C62X芯片,一般PC的芯片组上没有SR-IOV的相关功能。

intel VT-x : enable

speed-stepping :disable
Power Management : Performance 
Workload Configuration:Performance 
NUMA :enable 
Sub-NUMA Clustering:diable

遇到操作系统上显示numa组的数量不对基本上都是这个Sub-NUMA Clustering弄的,如果找不到就是服务器主板不支持,pass掉就可以了。

5司有KB有提到,CPU C state中关于电源控制的部分建议关闭:

CPU C state 来源于DELL的解释是:



 
In order to save energy when the CPU is idle, you can command the CPU to enter a low-power mode. Each CPU has several power modes, which are collectively called "C-states" or "C-modes." In this article, we explain what these modes are, what they do, and which processors support which modes.

The lower-power mode was first introduced with the 486DX4 processor, so this concept is far from new. Newer modes have been enhanced to allow the CPU to consume even less power.

These modes work by cutting the clock signal and power from idle units inside the CPU. The more units that you stop by cutting the clock, reducing the voltage, or even completely shutting down, the more energy you save. However, it takes more time for the CPU to fully "wake up" from sleep mode.

These modes or "C-states" start at C0, which is the normal CPU operating mode (the CPU is 100% activated). The higher the C number is, the deeper into sleep mode the CPU goes. In other words, more circuits and signals are turned off, and the CPU takes more time to fully wake up into C0 mode.

Each C-state has a name, and several of them have submodes with different power-saving levels and wake-up times.

也就是通过设定C state调整CPU的功耗.BIOS里有就disbale ,类似C6 report。

Linux 部分配置:

新装linux,以centos为例,第一步非常重要:


yum update

通过上述命令更新系统内核和相关周边到当前发行版的最新版本,不做这个步骤后面会有很多莫名其妙的问题。

安装编译软件包和相关工具

yum install pciutils systemd-libs kernel-devel-$(uname -r) zlib-devel openssl-devel elfutils-libelf-devel boost-devel systemd-devel numactl

yum groupinstall "Development Tools" "Development Libraries"

安装KVM

yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install virt-manager

kernel启动参数增加

grubby --update-kernel=ALL --args="intel_iommu=on iommu=pt"

运行后
cat /boot/efi/EFI/centos/grub.cfg 核对是否在kernel启动参数中已经包含
intel_iommu=on
iommu=pt

reboot 服务器,在boot memu 在菜单里按E键确认是否已经在启动项目中包含上述参数

安装图形化界面(如在安装Centos时有勾选就可以不用特别安装)

yum groupinstall "GNOME Desktop" "Graphical Administration Tools"

下载QAT驱动:

https://01.org/sites/default/files/downloads/qat1.7.l.4.7.0-00006.tar.gz

mkdir QAT 
mv qat1.7.l.4.7.0-00006.tar.gz ./QAT
tar -xzvf qat1.7.l.4.7.0-00006.tar.gz 
./configure --enable-icp-sriov=host
make all 
make install 

编译完成后修改qat的配置文件。
8950: /etc/dh895xcc_dev0.conf
8960/8970 :/etc/c6xx_dev[0-9].conf

文件修改kernel instance 部分,下属参数为0

##############################################
# Kernel Instances Section
##############################################
[KERNEL]
NumberCyInstances = 0
NumberDcInstances = 0

删除user process 部分的所有参数内容

##############################################
# User Process Instance Section
##############################################

使用下面的命令把其他文件link到刚才修改的文件里

cd /etc
# for file in $(ls c6xx_dev[1-9].conf); do ln -f -s /etc/c6xx_dev0.conf $file; done


vi /lib/modprobe.d/quickassist-blacklist.conf
添加下面的内容:
# Lewisburg QAT PF
blacklist qat_c62x

# Common QAT driver
blacklist intel_qat

启动QAT服务:

sudo /etc/init.d/qat_service start

输出如下

estarting all devices.
Processing /etc/dh895xcc_dev0.conf
enable sriov
Checking status of all devices.
There is 1 QAT acceleration device(s) in the system:
 qat_dev0 - type: dh895xcc,  inst_id: 0,  node_id: 0,  bsf: 0000:07:00.0,  #accel: 6 #engines: 12 state: up

验证qat状态命令:

sudo /etc/init.d/qat_service status

输出如下

hecking status of all devices.
There is 1 QAT acceleration device(s) in the system:
 qat_dev0 - type: dh895xcc,  inst_id: 0,  node_id: 0,  bsf: 0000:07:00.0,  #accel: 6 #engines: 12 state: up

至此X710/QAT以及KVM环境基本ready.

配置网卡SR-IOV

sudo vi /etc/rc.d/rc.local
#添加下面的启动命令,接口名称根据实际情况修改
echo 2 > /sys/class/net/ens2f0/device/sriov_numvfs
echo 2 > /sys/class/net/ens2f1/device/sriov_numvfs
ip link set ens2f0 vf 0 trust on
ip link set ens2f0 vf 0 spoofchk off
ip link set ens2f0 vf 1 trust on
ip link set ens2f0 vf 1 spoofchk off

ip link set ens2f1 vf 0 trust on
ip link set ens2f1 vf 0 spoofchk off
ip link set ens2f1 vf 1 trust on
ip link set ens2f1 vf 1 spoofchk off


ip link set ens2f0 vf 0 mac 3c:fd:fe:9e:90:91
ip link set ens2f0 vf 1 mac 3c:fd:fe:9e:90:92
ip link set ens2f1 vf 0 mac 3c:fd:fe:9e:90:93
ip link set ens2f1 vf 1 mac 3c:fd:fe:9e:90:94

之后查看下QAT和网卡的VF数量以及numa node的设定
PCI地址根据实际情况修改

cat /sys/bus/pci/devices/0000:07:00.0/sriov_numvfs
cat /sys/bus/pci/devices/0000:07:00.0/numa_node
cat  /sys/class/net/ens2f0/device/sriov_numvfs
cat  /sys/class/net/ens2f0/device/numa_node

对同一张卡的numa node是一致的,所以就不必要看ens2f1的了。
如果一台服务器插了两张qat和两张网卡,出现qat和网卡全部都在一个numa node的情况
需要重新分配卡的slot ,做到每个numa node 有一个qat和一张网卡。

确定CPU的Numa node 分布情况

numactl --hardware

记下cpu numa和网卡/qat卡的numa关系,启动centos图形化界面,启动virt-manager创建虚拟机


startx

鼠标右键点开"open Terminal"后,输入virt-manager ,创建虚拟机,此时倒入vm镜像的qcow文件,在虚拟机中“Add Hardware”,选择PCI Host Device,分别将网卡-1/接口1的vf0和网卡-1/接口2的 VF添加到虚拟机,同时把同一个numa组的QAT 的VF也添加到虚拟机,QAT的VF数量和虚拟机的VCPU数量保持一致。保存后启动虚拟机,在虚拟机的bash 命令行中输入

  dmesg |grep i40evf
  dmesg |grep qat

可以看到网卡VF驱动和qat 的VF驱动是否在虚拟机中正常启动。

注意: 如果创建虚拟机出现Host不支持PCI passthrought的情况,一般来说检查bios vt-x/sr-iov是否启动,同时kernel启动参数中intel_iommu=on iommu=pt这两个是否正常。
理论上普通虚拟机还要在里面安装VF驱动,本次使用的是F5 的VE,就不需要额外做驱动安装,内置QAT和网卡的VF驱动。

接下来shutdown虚拟机,在hypervisor 界面中通过virsh命令修改vm的vcpu 的numa分配

virsh 
edit BIGIPV15_1
#在XML文件中vcpu部分修改为类似如下,根据所分配的网卡和QAT所在的numa,以及numactl命令的输出,确定使用的cpu id
8
  
    
    
    
    
    
    
    
    
  

再次启动虚拟机后,激活虚拟机的license ,一般来说就可以正常使用,如果出现PF通信异常,或者网卡第二个接口的VF工作不正常,又或者低流量下ping包延迟固定间隔3/2/1sec,个人建议升级网卡firmware,有的X710有这些小问题,有的就没有,大概率是和固件有关。

处于线路冗余的考虑,每台虚拟机使用一个网卡上的两个接口,两个接口分别提供一个VF,在虚拟机上看到两个VF,在虚拟机内部做bond ,借用mellanox的一张图:

rtaImage.png

BIGIP上的trunk配置:


Screen Shot 2021-06-10 at 6.38.00 PM.png

Screen Shot 2021-06-10 at 6.38.09 PM.png

此时交换机上不要配置LACP即可,上述配置经过实际测试,不建议使用跨网卡的bond,如果土豪到一个numa放两个X710给一个虚拟机,可以考虑跨网卡建立bond。

SSL部分只要虚拟机里dmesg显示qat正常识别就没问题。

以上是intel X710部分,下面补充一下mellanox CX3(我穷人买不起CX5做测试)的简单做法,QAT是一致的,由于具体项目不会用CX3,就写简单一些。

英伟达官网下载
MLNX_OFED_LINUX-4.9-2.2.4.0-rhel7.9-x86_64.tgz
mft-4.16.1-9-x86_64-rpm.tgz
接下来快速过一下

yum install tk tcl
tar -xzvf MLNX_OFED_LINUX-4.9-2.2.4.0-rhel7.9-x86_64.tgz
tar -xzvf mft-4.16.1-9-x86_64-rpm.tgz
cd mft-4.16.1-9-x86_64-rpm/
./install.sh 
sudo mst start
sudo mlxconfig -d /dev/mst/mt4103_pciconf0 set SRIOV_EN=1 NUM_OF_VFS=4
reboot 
mlxconfig -d /dev/mst/mt4103_pciconf0 query

./mlnxofedinstall

Vi /etc/modprobe.d/mlx4_core.conf
options mlx4_core num_vfs=2,2,0 port_type_array=2,2 probe_vf=0

mellanox和intel 最大的不同在于mellanox 是用port_type_array来指定每个接口上的vf类型
同时可以支持infiniband和以太网 ,用num_vfs来指定每个物理interface上的VF数量,概念上有一些不同,部分配置是落在pciconf设备上而不像intel,intel每个口都是单独的pci设备并且独立配置,另外mellanox有probe的概念,可以一个vf probe在两个口上,mac地址的配置模式也有一些不同,就不详细写了。

mellanox的文档:
https://community.mellanox.com/s/article/howto-configure-sr-iov-for-connectx-3-with-kvm--ethernet-x
https://community.mellanox.com/s/article/howto-configure-sr-iov-vfs-on-different-connectx-3-ports

最后简单记录一下压测命令

ulimit -n 1000000

taskset -c 0 ab -n 100000000 -c 600  -Z ECDHE-RSA-AES256-GCM-SHA384 -f TLSv1.2 -B 192.168.123.50 https://xxxx/ &
./wrk -t1000 -c2000 -d300s http://xxx.com

流量模型上,ab为1-1,wrk为1-n,一个测试新建和ssl,一个测试rps。

你可能感兴趣的:(KVM虚拟机网卡和QAT SR-IOV 配置要点)