DPDK — TestPMD

目录

前文列表

DPDK — 安装部署

DPDK APP 的指令行参数

DPDK App 都是可以接受输入指令行参数的,如下:

./rte-app -c COREMASK [-n NUM] [-b <domain:bus:devid.func>] \
          [--socket-mem=MB,...] [-m MB] [-r NUM] [-v] [--file-prefix] \
          [--proc-type <primary|secondary|auto>] [-- xen-dom0]
  • -c COREMASK:要运行的内核的十六进制掩码。注意,平台之间编号可能不同,需要事先确定。
  • -n NUM:每个处理器 Socket 的内存通道数目。
  • -b domain:bus:devid.func:端口(网卡)黑名单,避免 EAL 使用指定的 PCI 设备。
  • –use-device:仅使用指定的以太网设备。使用逗号分隔 [domain:]bus:devid.func 值,不能与 -b 选项一起使用。
  • –socket-mem:从特定的处理器 Socket 上的 hugepage 分配内存。建议使用。
  • -m MB:从 hugepage 分配内存,不考虑处理器 Socket。不建议使用。
  • -r NUM:内存数量。
  • -v:显示启动时的版本信息。
  • –huge-dir:挂载 hugetlbfs 的目录。
  • –file-prefix:用于 hugepage 文件名的前缀文本。
  • –proc-type:App 的类型。
  • –xen-dom0:支持在 Xen Domain0 上运行,但不具有 hugetlbfs 的程序。
  • –vmware-tsc-map:使用 VMware TSC 映射而不是本地 RDTSC。
  • –base-virtaddr:指定基本虚拟地址。
  • –vfio-intr:指定要由 VFIO 使用的中断类型(如果不支持 VFIO,则配置无效)。

注 1:其中 -c 是强制性的,其他为可选配置。
注 2:选项 --proc-type 和 --file-prefix 用于运行多个 DPDK 进程。

指定 DPDK App 使用的 lcore(逻辑核)

-c coremask 选项参数可以使用指定的 lcore 来运行 DPDK 应用程序,是一个十六进制的掩码,掩码的每个位对应于 Linux 提供的 lcore ID。例如:-c f 表示 1111 对应 lcore 0, 1, 2, 3;-c 1 表示 01 对应 lcore 0;-c 6 标识 110 对应 lcore 1, 2。可以看出,掩码的二进制和 lcore 的顺序是调转的,这里需要注意。

在指定 lcpu mask 参数之前,需要了解平台的 CPU 布局,可以通过 hwloc 来查看:

yum install hwloc -y

在这里插入图片描述
如果没有图形化界面则使用指令:

$ lstopo-no-graphics
Machine (9835MB)
  Package L#0 + L3 L#0 (16MB) + L2 L#0 (4096KB) + L1d L#0 (32KB) + L1i L#0 (32KB) + Core L#0 + PU L#0 (P#0)
  Package L#1 + L3 L#1 (16MB) + L2 L#1 (4096KB) + L1d L#1 (32KB) + L1i L#1 (32KB) + Core L#1 + PU L#1 (P#1)
  Package L#2 + L3 L#2 (16MB) + L2 L#2 (4096KB) + L1d L#2 (32KB) + L1i L#2 (32KB) + Core L#2 + PU L#2 (P#2)
  Package L#3 + L3 L#3 (16MB) + L2 L#3 (4096KB) + L1d L#3 (32KB) + L1i L#3 (32KB) + Core L#3 + PU L#3 (P#3)
  Package L#4 + L3 L#4 (16MB) + L2 L#4 (4096KB) + L1d L#4 (32KB) + L1i L#4 (32KB) + Core L#4 + PU L#4 (P#4)
  Package L#5 + L3 L#5 (16MB) + L2 L#5 (4096KB) + L1d L#5 (32KB) + L1i L#5 (32KB) + Core L#5 + PU L#5 (P#5)
  Misc(MemoryModule)
  HostBridge L#0
    PCI 8086:7010
    PCI 1013:00b8
    PCI 1af4:1000
    PCI 1af4:1001
    3 x { PCI 15b3:1018 }

也可以使用 DPDK 自带的 CPU layout 工具:

$ cd ${RTE_SDK}/usertools/

$ ./cpu_layout.py
======================================================================
Core and Socket Information (as reported by '/sys/devices/system/cpu')
======================================================================

cores =  [0]
sockets =  [0, 1, 2, 3, 4, 5]

       Socket 0    Socket 1    Socket 2    Socket 3    Socket 4    Socket 5
       --------    --------    --------    --------    --------    --------
Core 0 [0]         [1]         [2]         [3]         [4]         [5]

指定 DPDK App 使用的大页内存

建议使用 --socket-mem 选项指定 DPDK App 使用的大页内存与预留的 hugepage 内存一致。例如:–socket-mem=0,512 指定在 Socket0(一般就是 NUMA0)上预留 512MB 内存(从 Socket1 上预留的大页内存中分配)。

如果没有指定,则由 DPDK App 在启动时自动完成确定。如果指定的内存大小超出了预留值,则 DPDK App 启动失败。如果指定的内存大小小于预留值,也可能会导致 DPDK App 启动失败,尤其是在使用 -m(不建议使用)选项的时候,这里需要注意。

隔离 DPDK App 使用 lcore

虽然 DPDK App 已经是绑定核心的,但 Linux 调度程序仍然会使用这些 lcore 来运行其他的任务,所以为了防止在这些核上运行额外的工作负载,可以使用 isolcpus Linux 内核参数来将其与通用的 Linux 调度程序隔离开来。

isolcpus=2,4,6

使用基于 Intel VT-d 的 Linux IOMMU Pass-Through 来运行 DPDK App

要在 Linux 内核中启用 Intel VT-d 硬件辅助的 IO 技术,必须配置一系列内核选项,包括:

  • IOMMU_SUPPORT
  • IOMMU_API
  • INTEL_IOMMU

要使用 Intel VT-d 来运行 DPDK App,在使用 igb_uio 驱动时,Grub 参数必须携带 iommu=pt 参数。 这使得主机可以直接通过 DMA 重映射查找网卡的存储空间。另外,如果内核中没有设置 INTEL_IOMMU_DEFAULT_ON 参数,那么还必须要使用到 intel_iommu=on 参数。这可以确保 Intel IOMMU 被正确初始化。而在使用 vfio-pci 驱动程序时,则直接同时使用 iommu=pt intel_iommu=on

TestPMD

TestPMD 的本质是一个使用 DPDK 库实现的 DPDK Application,作用是在以太网端口之间转发数据包。通过 TestPMD 运行时的命令行,我们可用于配置端口(Port)之间的数据包转发和网卡(Network Interface)支持的其他功能。此外,我们还可以用 TestPMD 来尝试一些不同的驱动程序的功能,例如:RSS、过滤器和 Intel Ethernet Flow Director(以太网流量控制器)。

TestPMD 支持以下 3 种不同的转发模式:

  • 输入/输出模式(Input/Output mode):通常也被称为 IO 模式,是最常用的转发模式,也是 TestPMD 启动时的默认模式。在该模式下,CPU 从一个端口接收数据包(Rx),并将其发送到另一个端口(Tx)。如果需要的话,一个端口可同时用于接收和发送。
  • 收包模式(Rx-only mode):在此模式下,TestPMD 会轮询 Rx 端口的数据包,然后直接释放而不发送,以这种方式充当数据包接收器。
  • 发包模式(Tx-only mode):在此模式下,TestPMD 生成 64Byte 的 IP 数据包,并从 Tx 端口发送出去。不接收数据包,仅作为数据包的发送源。

注:后两种模式在单独检查收包或者发包的场景中非常有用。

TestPMD 支持两种配置场景:

  1. TestPMD 把两个以太网端口连接到外部的流量发生器。
    在这里插入图片描述
  2. TestPMD 把两个以太网端口连成环回模式,这样就可以在没有外部流量发生器的情况下检查网络设备的接收和传输功能。
    在这里插入图片描述

测试 testpmd 是否可用:

$ cd ${RTE_SDK}/${RTE_TARGET}/build/app/test-pmd
$  ./testpmd
EAL: Detected 6 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-1048576kB
EAL: Probing VFIO support...
EAL: VFIO support initialized
EAL: WARNING: cpu flags constant_tsc=yes nonstop_tsc=no -> using unreliable clock cycles !
EAL: PCI device 0000:00:03.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 1af4:1000 net_virtio
EAL: PCI device 0000:00:05.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 15b3:1018 net_mlx5
EAL: PCI device 0000:00:06.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 15b3:1018 net_mlx5
EAL: PCI device 0000:00:07.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 15b3:1018 net_mlx5
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=187456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc


Warning! port-topology=paired and odd forward ports number, the last port will pair with itself.


Configuring Port 0 (socket 0)
Port 0: FA:16:3E:FF:38:D2
Configuring Port 1 (socket 0)
Port 1: FA:16:3E:CD:4A:1D
Configuring Port 2 (socket 0)
Port 2: FA:16:3E:FE:FB:FA
Checking link statuses...
Done
No commandline core given, start packet forwarding
io packet forwarding - ports=3 - cores=1 - streams=3 - NUMA support enabled, MP over anonymous pages disabled
Logical Core 1 (socket 0) forwards packets on 3 streams:
  RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
  RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00
  RX P=2/Q=0 (socket 0) -> TX P=2/Q=0 (socket 0) peer=02:00:00:00:00:02


  io packet forwarding packets/burst=32
  nb forwarding cores=1 - nb forwarding ports=3
  port 0: RX queue number: 1 Tx queue number: 1
    Rx offloads=0x1000 Tx offloads=0x0
    RX queue: 0
      RX desc=0 - RX free threshold=0
      RX threshold registers: pthresh=0 hthresh=0  wthresh=0
      RX Offloads=0x0
    TX queue: 0
      TX desc=0 - TX free threshold=0
      TX threshold registers: pthresh=0 hthresh=0  wthresh=0
      TX offloads=0x0 - TX RS bit threshold=0
  port 1: RX queue number: 1 Tx queue number: 1
    Rx offloads=0x1000 Tx offloads=0x0
    RX queue: 0
      RX desc=0 - RX free threshold=0
      RX threshold registers: pthresh=0 hthresh=0  wthresh=0
      RX Offloads=0x0
    TX queue: 0
      TX desc=0 - TX free threshold=0
      TX threshold registers: pthresh=0 hthresh=0  wthresh=0
      TX offloads=0x0 - TX RS bit threshold=0
  port 2: RX queue number: 1 Tx queue number: 1
    Rx offloads=0x1000 Tx offloads=0x0
    RX queue: 0
      RX desc=0 - RX free threshold=0
      RX threshold registers: pthresh=0 hthresh=0  wthresh=0
      RX Offloads=0x0
    TX queue: 0
      TX desc=0 - TX free threshold=0
      TX threshold registers: pthresh=0 hthresh=0  wthresh=0
      TX offloads=0x0 - TX RS bit threshold=0
Press enter to exit

进入 testpmd 交互环境:

$  ./testpmd -l 1,2,3 --socket-mem 1024 -n 4 --log-level=8 -- -i
EAL: Detected 6 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-1048576kB
EAL: Probing VFIO support...
EAL: VFIO support initialized
EAL: WARNING: cpu flags constant_tsc=yes nonstop_tsc=no -> using unreliable clock cycles !
EAL: PCI device 0000:00:03.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 1af4:1000 net_virtio
EAL: PCI device 0000:00:05.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 15b3:1018 net_mlx5
EAL: PCI device 0000:00:06.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 15b3:1018 net_mlx5
EAL: PCI device 0000:00:07.0 on NUMA socket -1
EAL:   Invalid NUMA socket, default to 0
EAL:   probe driver: 15b3:1018 net_mlx5
Interactive-mode selected
testpmd: create a new mbuf pool <mbuf_pool_socket_0>: n=163456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc


Warning! port-topology=paired and odd forward ports number, the last port will pair with itself.


Configuring Port 0 (socket 0)
Port 0: FA:16:3E:FF:38:D2
Configuring Port 1 (socket 0)
Port 1: FA:16:3E:CD:4A:1D
Configuring Port 2 (socket 0)
Port 2: FA:16:3E:FE:FB:FA
Checking link statuses...
Done
testpmd> 
  • -l:指定运行 TestPMD 的 lcore,Core 1 用于管理命令行,Core 2、3 用于转发数据包。
  • -n:指定系统的内存通道数。
  • –:用于分开 EAL 参数和应用程序参数。

检查转发配置:

testpmd> show config fwd
io packet forwarding - ports=3 - cores=1 - streams=3 - NUMA support enabled, MP over anonymous pages disabled
Logical Core 2 (socket 0) forwards packets on 3 streams:
  RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
  RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00
  RX P=2/Q=0 (socket 0) -> TX P=2/Q=0 (socket 0) peer=02:00:00:00:00:02

这表明 TestPMD 正使用默认的 IO 转发模式,同时也表明 lcore 2(第二个启用的 Core)将用于轮询 Port 0 上的数据包并转发到 Port 1,反之亦然。 lcore 1 用于处理运实时命令行本身。

要开始转发,并检查端口之间是否有包正在转发:

testpmd> start
io packet forwarding - ports=3 - cores=1 - streams=3 - NUMA support enabled, MP over anonymous pages disabled
Logical Core 2 (socket 0) forwards packets on 3 streams:
  RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
  RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00
  RX P=2/Q=0 (socket 0) -> TX P=2/Q=0 (socket 0) peer=02:00:00:00:00:02


  io packet forwarding packets/burst=32
  nb forwarding cores=1 - nb forwarding ports=3
  port 0: RX queue number: 1 Tx queue number: 1
    Rx offloads=0x1000 Tx offloads=0x0
    RX queue: 0
      RX desc=0 - RX free threshold=0
      RX threshold registers: pthresh=0 hthresh=0  wthresh=0
      RX Offloads=0x0
    TX queue: 0
      TX desc=0 - TX free threshold=0
      TX threshold registers: pthresh=0 hthresh=0  wthresh=0
      TX offloads=0x0 - TX RS bit threshold=0
  port 1: RX queue number: 1 Tx queue number: 1
    Rx offloads=0x1000 Tx offloads=0x0
    RX queue: 0
      RX desc=0 - RX free threshold=0
      RX threshold registers: pthresh=0 hthresh=0  wthresh=0
      RX Offloads=0x0
    TX queue: 0
      TX desc=0 - TX free threshold=0
      TX threshold registers: pthresh=0 hthresh=0  wthresh=0
      TX offloads=0x0 - TX RS bit threshold=0
  port 2: RX queue number: 1 Tx queue number: 1
    Rx offloads=0x1000 Tx offloads=0x0
    RX queue: 0
      RX desc=0 - RX free threshold=0
      RX threshold registers: pthresh=0 hthresh=0  wthresh=0
      RX Offloads=0x0
    TX queue: 0
      TX desc=0 - TX free threshold=0
      TX threshold registers: pthresh=0 hthresh=0  wthresh=0
      TX offloads=0x0 - TX RS bit threshold=0

testpmd> show port stats all


  ######################## NIC statistics for port 0  ########################
  RX-packets: 0          RX-missed: 0          RX-bytes:  0
  RX-errors: 0
  RX-nombuf:  0
  TX-packets: 0          TX-errors: 0          TX-bytes:  0


  Throughput (since last show)
  Rx-pps:            0
  Tx-pps:            0
  ############################################################################


  ######################## NIC statistics for port 1  ########################
  RX-packets: 0          RX-missed: 0          RX-bytes:  0
  RX-errors: 0
  RX-nombuf:  0
  TX-packets: 0          TX-errors: 0          TX-bytes:  0


  Throughput (since last show)
  Rx-pps:            0
  Tx-pps:            0
  ############################################################################


  ######################## NIC statistics for port 2  ########################
  RX-packets: 0          RX-missed: 0          RX-bytes:  0
  RX-errors: 0
  RX-nombuf:  0
  TX-packets: 0          TX-errors: 0          TX-bytes:  0


  Throughput (since last show)
  Rx-pps:            0
  Tx-pps:            0
  ############################################################################

此输出显示了 TestPMD 开始转发后的所有数据包总数,包含有这两个端口接收和发送的数据包数。吞吐率是以数据包每秒来显示的。在这个例子中,所有端口上都没有接收到包,是因为 Port 1、2、3 都没有连接到网络环境中。

若要停止转发,只需输入 stop,这会停止转发并显示两个端口的累计统计数字以及一个概要:

testpmd> stop
Telling cores to stop...
Waiting for lcores to finish...


  ---------------------- Forward statistics for port 0  ----------------------
  RX-packets: 0              RX-dropped: 0             RX-total: 0
  TX-packets: 0              TX-dropped: 0             TX-total: 0
  ----------------------------------------------------------------------------


  ---------------------- Forward statistics for port 1  ----------------------
  RX-packets: 0              RX-dropped: 0             RX-total: 0
  TX-packets: 0              TX-dropped: 0             TX-total: 0
  ----------------------------------------------------------------------------


  ---------------------- Forward statistics for port 2  ----------------------
  RX-packets: 0              RX-dropped: 0             RX-total: 0
  TX-packets: 0              TX-dropped: 0             TX-total: 0
  ----------------------------------------------------------------------------


  +++++++++++++++ Accumulated forward statistics for all ports+++++++++++++++
  RX-packets: 0              RX-dropped: 0             RX-total: 0
  TX-packets: 0              TX-dropped: 0             TX-total: 0
  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Done.

退出:

testpmd> quit


Shutting down port 0...
Stopping ports...
Done
Closing ports...
Done


Shutting down port 1...
Stopping ports...
Done
Closing ports...
Done


Shutting down port 2...
Stopping ports...
Done
Closing ports...
Done


Bye...


Shutting down port 0...
Stopping ports...
Done
Closing ports...
Port 0 is already closed
Done


Shutting down port 1...
Stopping ports...
Done
Closing ports...
Port 1 is already closed
Done


Shutting down port 2...
Stopping ports...
Done
Closing ports...
Port 2 is already closed
Done


Bye...

使用多核

对于一个核不足以转发所有收到的包的场景中,多核可以用于处理来自不同端口的数据包。在前面的例子中,Core 2、3 都可用于转发数据包,但默认情况下只有 Core 2 被用到了。要启用另一个核,我们可以使用以下命令:

testpmd> set nbcore 2
Number of forwarding cores set to 2

testpmd> show config fwd
txonly packet forwarding - ports=3 - cores=2 - streams=3 - NUMA support enabled, MP over anonymous pages disabled
Logical Core 2 (socket 0) forwards packets on 1 streams:
  RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
Logical Core 3 (socket 0) forwards packets on 2 streams:
  RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00
  RX P=2/Q=0 (socket 0) -> TX P=2/Q=0 (socket 0) peer=02:00:00:00:00:02

这样 Core2 将从 Port 0 接收数据包并转发到 Port 1 发送数据包,而 Core3 将接收来自 Port 1 的数据包,并从 Port 0 上发送。

切换模式

如上所述,TestPMD 具有不同的转发模式。若要将转发模式更改为发包模式,我们可以使用 set fwd 命令:

testpmd> set fwd txonly
Set txonly packet forwarding mode
testpmd> start
txonly packet forwarding - ports=3 - cores=1 - streams=3 - NUMA support enabled, MP over anonymous pages disabled
Logical Core 2 (socket 0) forwards packets on 3 streams:
  RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
  RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00
  RX P=2/Q=0 (socket 0) -> TX P=2/Q=0 (socket 0) peer=02:00:00:00:00:02

  txonly packet forwarding packets/burst=32
  packet len=64 - nb packet segments=1
  nb forwarding cores=1 - nb forwarding ports=3
  port 0: RX queue number: 1 Tx queue number: 1
    Rx offloads=0x1000 Tx offloads=0x0
    RX queue: 0
      RX desc=0 - RX free threshold=0
      RX threshold registers: pthresh=0 hthresh=0  wthresh=0
      RX Offloads=0x0
    TX queue: 0
      TX desc=0 - TX free threshold=0
      TX threshold registers: pthresh=0 hthresh=0  wthresh=0
      TX offloads=0x0 - TX RS bit threshold=0
  port 1: RX queue number: 1 Tx queue number: 1
    Rx offloads=0x1000 Tx offloads=0x0
    RX queue: 0
      RX desc=0 - RX free threshold=0
      RX threshold registers: pthresh=0 hthresh=0  wthresh=0
      RX Offloads=0x0
    TX queue: 0
      TX desc=0 - TX free threshold=0
      TX threshold registers: pthresh=0 hthresh=0  wthresh=0
      TX offloads=0x0 - TX RS bit threshold=0
  port 2: RX queue number: 1 Tx queue number: 1
    Rx offloads=0x1000 Tx offloads=0x0
    RX queue: 0
      RX desc=0 - RX free threshold=0
      RX threshold registers: pthresh=0 hthresh=0  wthresh=0
      RX Offloads=0x0
    TX queue: 0
      TX desc=0 - TX free threshold=0
      TX threshold registers: pthresh=0 hthresh=0  wthresh=0
      TX offloads=0x0 - TX RS bit threshold=0
testpmd> show port stats all

  ######################## NIC statistics for port 0  ########################
  RX-packets: 0          RX-missed: 0          RX-bytes:  0
  RX-errors: 0
  RX-nombuf:  0
  TX-packets: 12099712   TX-errors: 0          TX-bytes:  774381568

  Throughput (since last show)
  Rx-pps:            0
  Tx-pps:       561119
  ############################################################################

  ######################## NIC statistics for port 1  ########################
  RX-packets: 0          RX-missed: 0          RX-bytes:  0
  RX-errors: 0
  RX-nombuf:  0
  TX-packets: 12084672   TX-errors: 0          TX-bytes:  773419008

  Throughput (since last show)
  Rx-pps:            0
  Tx-pps:       560421
  ############################################################################

  ######################## NIC statistics for port 2  ########################
  RX-packets: 0          RX-missed: 0          RX-bytes:  0
  RX-errors: 0
  RX-nombuf:  0
  TX-packets: 12086720   TX-errors: 0          TX-bytes:  773550080

  Throughput (since last show)
  Rx-pps:            0
  Tx-pps:       560514
  ############################################################################
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章