问题描述
我正在使用双端口NIC Mellanox ConnectX-5,而DPDK版本是dpdk-stable-19.1.1.3。配置完成后,对rte_eth_dev_count_avail()
的调用将返回2
。但是我的ConnectX-5 NIC的一个端口仅连接到另一台计算机。我所能找到的就是像这样初始化所有可用的端口。
RTE_ETH_FOREACH_DEV(portid)
if (port_init(portid,mbuf_pool) != 0)
rte_exit(EXIT_FAILURE,"Cannot init port %u\n",portid);
dpdk可以选择性地初始化端口吗?还是有什么方法可以使rte_eth_dev_count_avail()
返回1
?
解决方法
是的,可以通过传递正确的PCIe Bus:Device:Function
地址作为白名单来选择性地初始化端口。因此,只有所需的端口会在应用程序中弹出。
操作方法:
- 创建一个虚拟应用程序以占用所有DPDK端口。
- 初始化并启动dpdk端口。检查链接状态并创建在应用程序逻辑中进行过滤的端口掩码(全局变量)。
- 调用
rte_eth_dev_stop & rte_eth_dev_close
进行链接断开端口。 - 调用rte_eal_cleanup。
- 使用端口掩码作为
execv
的参数来调用所需的DPDK应用程序。
这样,您可以使用有效端口运行应用程序。
但是依靠rte_eth_link_get
是很棘手的,因为
- 如果另一端连接到dpdk-pktgen,则首先您的DPDK应用程序必须在本地初始化NIC。
- 如果已连接到linux box,则必须先使用
ifconfig [other nic] up
来购买nic - 有时需要检查
link.link_speed
是否有效。 - 某些PMD需要写入PCIe映射的寄存器,因此必须进行dev_configure和port_init才能获得可靠的链路状态读数。
因此,最安全和推荐的使用方法是identify the NIC PCIe B:D:F in Linux driver and then whitelist the ports by using option -w for the desired port under igb_uio/virtio-pci
。可以通过以下方式将所有NIC绑定回linux中:
-
lshw -c network -businfo
将列出NIC和PCIeBus:Device:Function
以及内核设备名称和驱动程序。 - 使用
ethtool [eth device name] | grep Link
来确定链接已连接。
作为参考,您可以使用https://github.com/vipinpv85/DPDK-APP_SAMPLES/blob/master/auto-baseaddr-selector.c作为虚拟应用模板。
,另一种通过使用DPDK工具dpdk-devbind.py将所有可用端口分配给DPDK应用程序的特定端口,而EAL端口初始化将选择分配给UIO / VFIO内核驱动程序的端口。以下是devbind脚本步骤,用于识别端口当前状态以及如何将所需端口绑定到DPDK。
[root@linux usertools]# ./dpdk-devbind.py --status
Network devices using kernel driver
===================================
0000:00:03.0 '82540EM Gigabit Ethernet Controller 100e' if= drv=e1000 unused=vfio-pci
0000:00:04.0 '82540EM Gigabit Ethernet Controller 100e' if= drv=e1000 unused=vfio-pci
[root@linux usertools]# ./dpdk-devbind.py --bind=vfio-pci 00:04.0
[root@linux usertools]# ./dpdk-devbind.py --status
Network devices using DPDK-compatible driver
============================================
0000:00:04.0 '82540EM Gigabit Ethernet Controller 100e' drv=vfio-pci unused=e1000
Network devices using kernel driver
===================================
0000:00:03.0 '82540EM Gigabit Ethernet Controller 100e' if= drv=e1000 unused=vfio-pci