• Ubuntu22.04 虚拟机中搭建 DPDK 开发环境


    系统环境

    操作系统: Win10

    虚拟机软件:VMware Workstation 16

    虚拟机系统:Ubuntu22.04,CPU个数 8,内存 4 G,网卡个数 4

    要安装的 DPDK 版本:22.07

    编译安装 DPDK

    先安装一些依赖的软件包:

    apt-get install meson
    apt install python3-pyelftools
    apt-get install pkg-config
    
    • 1
    • 2
    • 3

    再编译安装 DPDK:

    wget https://fast.dpdk.org/rel/dpdk-22.07.tar.xz
    tar xf dpdk-22.07.tar.xz
    cd dpdk-22.07
    meson  build
    cd build
    ninja
    ninja install
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    执行完之后所有的库都安装在 /usr/local/lib/x86_64-linux-gnu/ 目录。

    可执行程序和脚本都安装在 /usr/local/bin/ 目录。

    要卸载只需执行 ninja uninstall 即可。

    编译裁剪

    默认编译时,会默认编译不需要的驱动,导致编译很慢。由于我们是在虚拟机中,很多驱动都可以不需要,因此可以做裁剪。具体在执行 meson build 之前,

    • 修改 drivers/meson.build 文件,subdirs 里只保留 ‘bus’,‘mempool’,‘net’ 即可。

    • 修改 drivers/bus/meson.build 文件,drivers 里只保留 ‘pci’,‘vdev’ 即可。

    • 修改 drivers/mempool/meson.build 文件,drivers 里只保留 ‘ring’,‘stack’ 即可。

    • 修改 drivers/net/meson.build 文件,drivers 里只保留 ‘e1000’ 即可【因为虚拟机网卡使用的是 e1000 驱动】。

    接着执行 meson build ,会看到如下信息:

    Message: 
    ===============
    Drivers Enabled
    ===============
    
    bus:
            pci, vdev, 
    mempool:
            ring, stack, 
    net:
            e1000, 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    之后编译就很快了。

    编译 igb uio 驱动

    git clone http://dpdk.org/git/dpdk-kmods
    cd dpdk-kmods/linux/igb_uio
    make
    
    • 1
    • 2
    • 3

    编译出来 igb_uio.ko。

    验证环境是否OK

    为了验证我们的环境是没问题的,先编译出 l2fwd 程序:

    cd examples/l2fwd
    make
    
    • 1
    • 2

    接着加载 igb_uio 驱动:

    cd dpdk-kmods/linux/igb_uio
    modprobe uio
    insmod igb_uio.ko intr_mode=legacy
    
    • 1
    • 2
    • 3

    注意: 加载驱动时要带着参数intr_mode=legacy,如果不加参数,将会有问题!

    分配一些大页内存【这里是1G】:

    echo 512 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
    
    • 1

    绑定两个网卡【虚拟机有 4 个网卡,最后两个网卡供 DPDK 使用】:

    ifconfig ens34 down
    ifconfig ens35 down
    dpdk-devbind.py -b igb_uio ens34 ens35
    
    • 1
    • 2
    • 3

    运行 l2fwd 程序:

    cd examples/l2fwd/build/
    ./l2fwd -l 0-1 -- -p 0x3 -T 1
    
    • 1
    • 2

    如果看到以下信息,说明 DPDK 环境没问题!

    EAL: Detected CPU lcores: 8
    EAL: Detected NUMA nodes: 1
    EAL: Detected shared linkage of DPDK
    EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
    EAL: Selected IOVA mode 'PA'
    EAL: VFIO support initialized
    EAL: Probe PCI driver: net_e1000_em (8086:100f) device: 0000:02:02.0 (socket 0)
    EAL: Error reading from file descriptor 20: Input/output error
    EAL: Probe PCI driver: net_e1000_em (8086:100f) device: 0000:02:03.0 (socket 0)
    EAL: Error reading from file descriptor 6: Input/output error
    TELEMETRY: No legacy callbacks, legacy socket not created
    MAC updating enabled
    Lcore 0: RX port 0 TX port 1
    Lcore 1: RX port 1 TX port 0
    Initializing port 0... EAL: Error enabling interrupts for fd 20 (Input/output error)
    done: 
    Port 0, MAC address: 00:0C:29:0C:53:91
    
    Initializing port 1... EAL: Error enabling interrupts for fd 6 (Input/output error)
    done: 
    Port 1, MAC address: 00:0C:29:0C:53:9B
    
    
    Checking link statusdone
    Port 0 Link up at 1 Gbps FDX Autoneg
    Port 1 Link up at 1 Gbps FDX Autoneg
    L2FWD: entering main loop on lcore 1
    L2FWD:  -- lcoreid=1 portid=1
    L2FWD: entering main loop on lcore 0
    L2FWD:  -- lcoreid=0 portid=0
    
    Port statistics ====================================
    Statistics for port 0 ------------------------------
    Packets sent:                        0
    Packets received:                    0
    Packets dropped:                     0
    Statistics for port 1 ------------------------------
    Packets sent:                        0
    Packets received:                    0
    Packets dropped:                     0
    Aggregate statistics ===============================
    Total packets sent:                  0
    Total packets received:              0
    Total packets dropped:               0
    ====================================================
    ^C
    
    Signal 2 received, preparing to exit...
    EAL: Error disabling interrupts for fd 20 (Input/output error)
    Closing port 0... Done
    EAL: Error disabling interrupts for fd 6 (Input/output error)
    Closing port 1... Done
    Bye...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53

    EAL: Error enabling interrupts for fd 20 (Input/output error) 等错误可以忽略。

    解绑网卡

    两个网卡 ens34 和 ens35 被 DPDK 占用后,ifconfig 里是没有的,要恢复请进行如下操作。

    首先查看两个网卡 pci 设备号:

    root@ubuntu2204:~# lspci | grep Eth
    02:00.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
    02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
    02:02.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
    02:03.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
    
    • 1
    • 2
    • 3
    • 4
    • 5

    可看到最后两个网卡设备号是 02:02.0 和 02.03.0。

    然后解绑两个网卡的 igb_uio 驱动,绑定 e1000 驱动:

    dpdk-devbind.py -u 02:02.0 02:03.0
    dpdk-devbind.py -b e1000  02:02.0 02:03.0
    
    • 1
    • 2

    最后将网卡up起来:

    ifconfig ens34 up
    ifconfig ens35 up
    
    • 1
    • 2
  • 相关阅读:
    Java 在Word文档中添加艺术字
    Spring 源码阅读 74:事务管理的原理 - BeanFactoryTransactionAttributeSourceAdvisor 分析
    大数据(一)背景和概念
    深入浅出Scala之函数式编程、静态类型语言(P4-P9)
    可燃气体报警器:户外工地安全预警先锋,定期检定保障安全无忧
    oracle创建数据库,导入dmp操作全家桶
    掌握深度学习利器——TensorFlow 2.x实战应用与进阶
    PC调试手机微信浏览器
    Yolov5 转换成 RKNN模型
    Node.js -- fs模块
  • 原文地址:https://blog.csdn.net/woay2008/article/details/126899996