旅游网站建设和实现,巧克力网站模板,佛山关键词搜索排名,网站主页样式一、简述 DPDK支持几种方式让用户空间的报文重新进入内核协议栈(这种dpdk和kernel直接通信的路径叫做exception path)#xff0c;例如tap/tun设备使用#xff0c;kni#xff0c;Virtio-user。这里主要讲Virtio-user使用#xff0c;Virtio-user是virtio PMD的虚拟设备例如tap/tun设备使用kniVirtio-user。这里主要讲Virtio-user使用Virtio-user是virtio PMD的虚拟设备启动DPDK virtio-user系统就会创建一个内核态的虚拟设备tap。下面介绍Virtio-user的使用和使用前驱动的安装。
二、驱动安装过程
现在内核基本都自带vfio-pci或者uio_pci_generic驱动基本不需要igb_uioigb_uio在20.11版本已经从dpdk目录内移除Virtio-user依赖vfio-pci.ko驱动安装好驱动后需要将网卡绑定到该驱动。
2.1 vfio-pci.ko驱动安装
在安装驱动前需要注意看下系统是否支持虚拟IO技术例如intelVT-d或是否支持并开启了IOMMU(Input/Output Memory Management Unit)如果支持IOMMU那么使用2.1.1小节中的安装方式如果不支持使用2.1.2小节中的安装方式。Linux是否支持虚拟IO技术可使用下面的命令查看
cat /proc/cpuinfo | grep vmx #有结果说明支持intel-vt虚拟化
cat /proc/cpuinfo | grep svm #有结果说明支持amd-vt虚拟化
如果不支持虚拟化则建议换no-IOMMU的方式启动。如果是虚拟机环境在虚拟机的cpu选项中可以将虚拟化引擎都进行勾选。
2.1.1 IOMMU模式驱动安装
使用IOMMU模式安装驱动在驱动安装之前需要设置或者启用iommu需要在linux启动配置中添加intel_iommuon iommupt如果是amd的cpu使用amd_iommuon iommupt置方式如下
$ sudo vim /etc/default/grub # 在GRUB_CMDLINE_LINUX行添加intel_iommuon iommupt
$ sudo update-grub #更新linux启动配置文件这里是Ubuntu环境若centos使用命令grub2-mkconfig -o /boot/grub2/grub.cfg
$ sudo reboot #重启系统
#重启之后可以使用cat /proc/cmdline查看有“intel_iommuon iommupt”标识
待iommu设置好了之后按照下面的命令安装驱动即可。
sudo modprobe vfio-pci
2.1.2 no-IOMMU模式驱动安装
如果设备硬件不支持IO虚拟化那么就不能够使用IOMMU模式加载驱动需要使用下面的方式加载驱动。如果之前已经使用安装了vfio-pci了那需要卸载所有vfio相关的驱动然后重新按照下面的方式安装
将vfio相关的驱动都卸载掉
rmmod vfio_iommu_type1
rmmod vfio-pci
rmmod vfio#重新安装驱动
modprobe vfio enable_unsafe_noiommu_mode1
modprobe vfio-pci
2.2 绑定网卡
使用脚本查看当前的网卡设备绑定情况
root#./usertools/dpdk-devbind.py -s# Network devices using kernel driver0000:00:03.0 82540EM Gigabit Ethernet Controller 100e ifenp0s3 drve1000 unusedvfio-pci *Active*
0000:00:08.0 82540EM Gigabit Ethernet Controller 100e ifenp0s8 drve1000 unusedvfio-pci *Active*
0000:00:09.0 82540EM Gigabit Ethernet Controller 100e ifenp0s9 drve1000 unusedvfio-pci *Active*No Baseband devices detected... ...
从上面可以看到系统有3张网卡这里使用第三个enp0s9 网卡因为该设备是在使用状态所以需要将网卡down之后再绑定操作命令如下
ifconfig enp0s9 down #将要绑定的网卡状态设置为down
./usertools/dpdk-devbind.py -b vfio-pci 0000:00:09.0 #将网卡和驱动绑定这里填写的网卡的pci地址
./usertools/dpdk-devbind.py -s #再次查看绑定的情况Network devices using DPDK-compatible driver0000:00:09.0 82540EM Gigabit Ethernet Controller 100e drvvfio-pci unusede1000Network devices using kernel driver0000:00:03.0 82540EM Gigabit Ethernet Controller 100e ifenp0s3 drve1000 unusedvfio-pci *Active*
0000:00:08.0 82540EM Gigabit Ethernet Controller 100e ifenp0s8 drve1000 unusedvfio-pci *Active*No Baseband devices detected... ...
当“Network devices using DPDK-compatible driver”下出现需要的Ethernet设备之后就表示绑定成功后面dpdk程序就可以使用该网络设备Network devices。
三、启动并使用
在启动程序前假设大页内存等都已经设置好。
3.1 使用启动参数添加虚拟网卡
dpdk应用程序都会有EAL环境初始化使用rte_eal_init初始化中可以解析入参是否需要增加虚拟设备例如使用testpmd启动方式如下
形式如下
./dpdk-testpmd -l cores -a pci BDF --vdevvirtio_user0,path/dev/vhost-net,queuesnum,queue_sizesize
例如
./dpdk-testpmd -a 0000:00:09.0 --vdevvirtio_user0,path/dev/vhost-net,queues1,queue_size512
其中涉及到的启动参数主要是
--vdev 启动程序时添加一个虚拟设备。
在--vdev参数后面还可以接 path 内核vhost-net设备的路径。 queue_size 默认是256以防度队列过短我们可以最大设置到1024。 queues 虚拟队列的数量每个队列由一个内核线程管理。 iface 虚拟设备的名字
启动程序之后可以使用ifconfig -a命令看到有个设备名为tap0即表示虚拟设备添加成功如下
rootubuntu:~/dpdk/dpdk-stable-21.11.1/usertools#
... ...
tap0: flags4098BROADCAST,MULTICAST mtu 1500ether ca:6f:0b:ac:36:4c txqueuelen 1000 (Ethernet)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0... ...
3.2 使用代码添加虚拟网卡
如果不使用启动参数也可以在程序中添加代码的方式增加虚拟设备具体代码如下
#define RX_RING_SIZE 1024
nb_ports rte_eth_dev_count_avail(); /* 获取所有可用的网卡 *//* Create a vhost_user port for each physical port */
unsigned port_count 0;
RTE_ETH_FOREACH_DEV(portid) {char portname[32];char portargs[256];struct rte_ether_addr addr {0};/* once we have created a virtio port for each physical port, stop creating more */if (port_count nb_ports)break;/* get MAC address of physical port to use as MAC of virtio_user port */rte_eth_macaddr_get(portid, addr);/* set the name and arguments */snprintf(portname, sizeof(portname), virtio_user%u, portid);snprintf(portargs, sizeof(portargs),path/dev/vhost-net,queues1,queue_size%u,iface%s,mac RTE_ETHER_ADDR_PRT_FMT,RX_RING_SIZE, portname, RTE_ETHER_ADDR_BYTES(addr)); //这里的portname名字可以更改为其他标识例如tap/* add the vdev for virtio_user */if (rte_eal_hotplug_add(vdev, portname, portargs) 0) //这里的portname必须是virtio_user0virtio_user1...rte_exit(EXIT_FAILURE, Cannot create paired port for port %u\n, portid);
}
添加上述代码需要添加头文件
#include rte_dev.h
#include rte_ethdev.h
四、参考文档
dpdk官方文档参考9. Virtio_user as Exception Path — Data Plane Development Kit 23.07.0 documentation
VFIO驱动安装参考7. Linux Drivers — Data Plane Development Kit 23.07.0 documentation
虚拟机设置dpdk环境DPDK-1概述 - 墨天轮
virtio 与vhost_net介绍virtio 与vhost_net介绍_virtio vhost-CSDN博客