【dpdk】Getting Started Guide for Linux DPDK

本文详细介绍了如何在Linux系统中使用DPDK,包括设置hugepages、配置vfio-pci和UIO驱动、管理虚拟函数以及运行示例应用。特别关注了如何预留和管理hugepages,以及使用vfio-pci创建虚拟功能和处理可能出现的故障排查方法。
摘要由CSDN通过智能技术生成

Getting Started Guide for Linux — Data Plane Development Kit 23.11.0 documentation (dpdk.org)

DPDK官网

1.dpdk build with isa-l

ISA-L Compression Poll Mode Driver

2.System Requirements

System Requirements

1.启用iommu

ubuntu
cat /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash, intel_iommu=on"

grub-mkconfig --output=/boot/grub/grub.cfg

3.Running DPDK Applications

The reservation of hugepages can be performed at run time. This is done by echoing the number of hugepages required to a nr_hugepages file in the /sys/kernel/ directory corresponding to a specific page size (in Kilobytes). For a single-node system, the command to use is as follows (assuming that 1024 of 2MB pages are required):

echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages

On a NUMA machine, the above command will usually divide the number of hugepages equally across all NUMA nodes (assuming there is enough memory on all NUMA nodes). However, pages can also be reserved explicitly on individual NUMA nodes using a nr_hugepages file in the /sys/devices/ directory:

echo 1024 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
echo 1024 > /sys/devices/system/node/node1/hugepages/hugepages-2048kB/nr_hugepages

The tool dpdk-hugepages.py can be used to manage hugepages.

3.1. dpdk-hugepages Application

The dpdk-hugepages tool is a Data Plane Development Kit (DPDK) utility that helps in reserving hugepages. As well as checking for current settings.

3.1.1. Running the Application

The tool has a number of command line options:

dpdk-hugepages [options]
3.1.2. Options
  • -h, --help

    Display usage information and quit

  • -s, --show

    Print the current huge page configuration

  • -c driver, --clear

    Clear existing huge page reservation

  • -m, --mount

    Mount the huge page filesystem

  • -u, --unmount

    Unmount the huge page filesystem

  • -n NODE, --node=NODE

    Set NUMA node to reserve pages on

  • -p SIZE, --pagesize=SIZE

    • Select hugepage size to use.

      If not specified the default system huge page size is used.

  • -r SIZE, --reserve=SIZE

    • Reserve huge pages.

      Size is in bytes with K, M or G suffix.

  • --setup SIZE

    Short cut to clear, unmount, reserve and mount.

Warning

While any user can run the dpdk-hugepages.py script to view the status of huge pages, modifying the setup requires root privileges.

3.1.3. Examples

To display current huge page settings:

dpdk-hugepages.py -s

To a complete setup of with 2 Gigabyte of 1G huge pages:

dpdk-hugepages.py -p 1G --setup 2G

4.Linux Drivers

Different PMDs may require different kernel drivers in order to work properly. Depending on the PMD being used, a corresponding kernel driver should be loaded, and network ports should be bound to that driver.

This section is for PMDs which use the UIO or VFIO drivers.

It is recommended that vfio-pci be used as the kernel module for DPDK-bound ports in all cases. If an IOMMU is unavailable, the vfio-pci can be used in no-iommu mode. If, for some reason, vfio is unavailable, then UIO-based modules, igb_uio and uio_pci_generic may be used. See section UIO for details.

Most devices require that the hardware to be used by DPDK be unbound from the kernel driver it uses, and instead be bound to the vfio-pci kernel module before the application is run. For such PMDs, any network ports or other hardware under Linux* control will be ignored and cannot be used by the application.

To bind ports to the vfio-pci module for DPDK use, or to return ports to Linux control, a utility script called dpdk-devbind.py is provided in the usertools subdirectory. This utility can be used to provide a view of the current state of the network ports on the system, and to bind and unbind those ports from the different kernel modules, including the VFIO and UIO modules. The following are some examples of how the script can be used. A full description of the script and its parameters can be obtained by calling the script with the --help or --usage options. Note that the UIO or VFIO kernel modules to be used, should be loaded into the kernel before running the dpdk-devbind.py script.

Note:

Due to the way VFIO works, there are certain limitations to which devices can be used with VFIO. Mainly it comes down to how IOMMU groups work. Any Virtual Function device can usually be used with VFIO on its own, but physical devices may require either all ports bound to VFIO, or some of them bound to VFIO while others not being bound to anything at all.

If your device is behind a PCI-to-PCI bridge, the bridge will then be part of the IOMMU group in which your device is in. Therefore, the bridge driver should also be unbound from the bridge PCI device for VFIO to work with devices behind the bridge.

While any user can run the dpdk-devbind.py script to view the status of the network ports, binding or unbinding network ports requires root privileges.

To see the status of all network ports on the system:

./usertools/dpdk-devbind.py --status

Network devices using DPDK-compatible driver
============================================
0000:82:00.0 '82599EB 10-GbE NIC' drv=vfio-pci unused=ixgbe
0000:82:00.1 '82599EB 10-GbE NIC' drv=vfio-pci unused=ixgbe

Network devices using kernel driver
===================================
0000:04:00.0 'I350 1-GbE NIC' if=em0  drv=igb unused=vfio-pci *Active*
0000:04:00.1 'I350 1-GbE NIC' if=eth1 drv=igb unused=vfio-pci
0000:04:00.2 'I350 1-GbE NIC' if=eth2 drv=igb unused=vfio-pci
0000:04:00.3 'I350 1-GbE NIC' if=eth3 drv=igb unused=vfio-pci

Other network devices
=====================
<none>

To bind device eth1,04:00.1, to the vfio-pci driver:

./usertools/dpdk-devbind.py --bind=vfio-pci 04:00.1

or, alternatively,

./usertools/dpdk-devbind.py --bind=vfio-pci eth1

When specifying device ids, wildcards can be used for the final part of the address. To restore device 82:00.0 and 82:00.1 to their original kernel binding:

./usertools/dpdk-devbind.py --bind=ixgbe 82:00.*

5.VFIO

Turn on VT-d if you wants to use VFIO in BIOS

VFIO is a robust and secure driver that relies on IOMMU protection. To make use of VFIO, the vfio-pci module must be loaded:

sudo modprobe vfio-pci

VFIO kernel is usually present by default in all distributions, however please consult your distributions documentation to make sure that is the case.

To make use of full VFIO functionality, both kernel and BIOS must support and be configured to use IO virtualization (such as Intel® VT-d).

Note

In most cases, specifying “iommu=on” as kernel parameter should be enough to configure the Linux kernel to use IOMMU.

For proper operation of VFIO when running DPDK applications as a non-privileged user, correct permissions should also be set up. For more information, please refer to Running DPDK Applications Without Root Privileges.

5.1 Creating Virtual Functions using vfio-pci

Since Linux version 5.7, the vfio-pci module supports the creation of virtual functions. After the PF is bound to vfio-pci module, the user can create the VFs using the sysfs interface, and these VFs will be bound to vfio-pci module automatically.

When the PF is bound to vfio-pci, by default it will have a randomly generated VF token. For security reasons, this token is write only, so the user cannot read it from the kernel directly. To access the VFs, the user needs to create a new token, and use it to initialize both VF and PF devices. The tokens are in UUID format, so any UUID generation tool can be used to create a new token.

This VF token can be passed to DPDK by using EAL parameter --vfio-vf-token. The token will be used for all PF and VF ports within the application.

  1. Generate the VF token by uuid command

    14d63f20-8445-11ea-8900-1f9ce7d5650d
    
  2. Load the vfio-pci module with enable_sriov parameter set

    sudo modprobe vfio-pci enable_sriov=1
    

    Alternatively, pass the enable_sriov parameter through the sysfs if the module is already loaded or is built-in:

    echo 1 | sudo tee /sys/module/vfio_pci/parameters/enable_sriov
    
  3. Bind the PCI devices to vfio-pci driver

    ./usertools/dpdk-devbind.py -b vfio-pci 0000:86:00.0
    
  4. Create the desired number of VF devices

    echo 2 > /sys/bus/pci/devices/0000:86:00.0/sriov_numvfs
    
  5. Start the DPDK application that will manage the PF device

    <build_dir>/app/dpdk-testpmd -l 22-25 -n 4 -a 86:00.0 \
    --vfio-vf-token=14d63f20-8445-11ea-8900-1f9ce7d5650d --file-prefix=pf -- -i
    
  6. Start the DPDK application that will manage the VF device

    <build_dir>/app/dpdk-testpmd -l 26-29 -n 4 -a 86:02.0 \
    --vfio-vf-token=14d63f20-8445-11ea-8900-1f9ce7d5650d --file-prefix=vf0 -- -i
    

Note

Linux versions earlier than version 5.7 do not support the creation of virtual functions within the VFIO framework.

5.2Troubleshooting VFIO

In certain situations, using dpdk-devbind.py script to bind a device to VFIO driver may fail. The first place to check is the kernel messages:

dmesg | tail
...
[ 1297.875090] vfio-pci: probe of 0000:31:00.0 failed with error -22
...

In most cases, the error -22 indicates that the VFIO subsystem could not be enabled because there is no IOMMU support.

To check whether the kernel has been booted with correct parameters, one can check the kernel command-line:

cat /proc/cmdline

Please refer to earlier sections on how to configure kernel parameters correctly for your system.

If the kernel is configured correctly, one also has to make sure that the BIOS configuration has virtualization features (such as Intel® VT-d). There is no standard way to check if the platform is configured correctly, so please check with your platform documentation to see if it has such features, and how to enable them.

In certain distributions, default kernel configuration is such that the no-IOMMU mode is disabled altogether at compile time. This can be checked in the boot configuration of your system:

cat /boot/config-$(uname -r) | grep NOIOMMU
# CONFIG_VFIO_NOIOMMU is not set

If CONFIG_VFIO_NOIOMMU is not enabled in the kernel configuration, VFIO driver will not support the no-IOMMU mode, and other alternatives (such as UIO drivers) will have to be used.

6.UIO

Warning

Using UIO drivers is inherently unsafe due to this method lacking IOMMU protection, and can only be done by root user.

In situations where using VFIO is not an option, there are alternative drivers one can use. In many cases, the standard uio_pci_generic module included in the Linux kernel can be used as a substitute for VFIO. This module can be loaded using the command:

sudo modprobe uio_pci_generic

Note

uio_pci_generic module doesn’t support the creation of virtual functions.

As an alternative to the uio_pci_generic, there is the igb_uio module which can be found in the repository dpdk-kmods. It can be loaded as shown below:

sudo modprobe uio
sudo insmod igb_uio.ko

Note

For some devices which lack support for legacy interrupts, e.g. virtual function (VF) devices, the igb_uio module may be needed in place of uio_pci_generic.

Note

If UEFI secure boot is enabled, the Linux kernel may disallow the use of UIO on the system. Therefore, devices for use by DPDK should be bound to the vfio-pci kernel module rather than any UIO-based module. For more details see Binding and Unbinding Network Ports to/from the Kernel Modules below.

Note

If the devices used for DPDK are bound to a UIO-based kernel module, please make sure that the IOMMU is disabled or is in passthrough mode. One can add intel_iommu=off or amd_iommu=off or intel_iommu=on iommu=pt in GRUB command line on x86_64 systems, or add iommu.passthrough=1 on aarch64 systems.

7.Running Sample Applications

Running Sample Applications — Data Plane Development Kit 23.11.0 documentation (dpdk.org)

  • 18
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值