136fc5710SXiaolong Ye.. SPDX-License-Identifier: BSD-3-Clause 236fc5710SXiaolong Ye Copyright(c) 2019 Intel Corporation. 336fc5710SXiaolong Ye 436fc5710SXiaolong YeEnable DPDK on OpenWrt 536fc5710SXiaolong Ye====================== 636fc5710SXiaolong Ye 736fc5710SXiaolong YeThis document describes how to enable Data Plane Development Kit (DPDK) on 836fc5710SXiaolong YeOpenWrt in both a virtual and physical x86 environment. 936fc5710SXiaolong Ye 1036fc5710SXiaolong YeIntroduction 1136fc5710SXiaolong Ye------------ 1236fc5710SXiaolong Ye 1336fc5710SXiaolong YeThe OpenWrt project is a well-known source-based router OS which provides a 1436fc5710SXiaolong Yefully writable filesystem with package management. 1536fc5710SXiaolong Ye 1636fc5710SXiaolong YeBuild OpenWrt 1736fc5710SXiaolong Ye------------- 1836fc5710SXiaolong Ye 1936fc5710SXiaolong YeYou can obtain OpenWrt image through https://downloads.openwrt.org/releases. 2036fc5710SXiaolong YeTo fully customize your own OpenWrt, it is highly recommended to build it from 2136fc5710SXiaolong Yethe source code. You can clone the OpenWrt source code as follows: 2236fc5710SXiaolong Ye 2336fc5710SXiaolong Ye.. code-block:: console 2436fc5710SXiaolong Ye 2536fc5710SXiaolong Ye git clone https://git.openwrt.org/openwrt/openwrt.git 2636fc5710SXiaolong Ye 2736fc5710SXiaolong YeOpenWrt configuration 2836fc5710SXiaolong Ye~~~~~~~~~~~~~~~~~~~~~ 2936fc5710SXiaolong Ye 3036fc5710SXiaolong Ye* Select ``x86`` in ``Target System`` 3136fc5710SXiaolong Ye* Select ``x86_64`` in ``Subtarget`` 3236fc5710SXiaolong Ye* Select ``Build the OpenWrt SDK`` for cross-compilation environment 3336fc5710SXiaolong Ye* Select ``Use glibc`` in ``Advanced configuration options (for developers)`` 3436fc5710SXiaolong Ye then ``ToolChain Options`` and ``C Library implementation`` 3536fc5710SXiaolong Ye 3636fc5710SXiaolong YeKernel configuration 3736fc5710SXiaolong Ye~~~~~~~~~~~~~~~~~~~~ 3836fc5710SXiaolong Ye 3936fc5710SXiaolong YeThe following configurations should be enabled: 4036fc5710SXiaolong Ye 4136fc5710SXiaolong Ye* ``CONFIG_VFIO_IOMMU_TYPE1=y`` 4236fc5710SXiaolong Ye* ``CONFIG_VFIO_VIRQFD=y`` 4336fc5710SXiaolong Ye* ``CONFIG_VFIO=y`` 4436fc5710SXiaolong Ye* ``CONFIG_VFIO_NOIOMMU=y`` 4536fc5710SXiaolong Ye* ``CONFIG_VFIO_PCI=y`` 4636fc5710SXiaolong Ye* ``CONFIG_VFIO_PCI_MMAP=y`` 4736fc5710SXiaolong Ye* ``CONFIG_HUGETLBFS=y`` 4836fc5710SXiaolong Ye* ``CONFIG_HUGETLB_PAGE=y`` 4936fc5710SXiaolong Ye* ``CONFIG_PROC_PAGE_MONITOR=y`` 5036fc5710SXiaolong Ye 5136fc5710SXiaolong YeBuild steps 5236fc5710SXiaolong Ye~~~~~~~~~~~ 5336fc5710SXiaolong Ye 5436fc5710SXiaolong YeFor detailed OpenWrt build steps and prerequisites, please refer to the 5536fc5710SXiaolong Ye`OpenWrt build guide 5636fc5710SXiaolong Ye<https://openwrt.org/docs/guide-developer/build-system/use-buildsystem>`_. 5736fc5710SXiaolong Ye 5836fc5710SXiaolong YeAfter the build is completed, you can find the images and SDK in 5936fc5710SXiaolong Ye``<OpenWrt Root>/bin/targets/x86/64-glibc/``. 6036fc5710SXiaolong Ye 6136fc5710SXiaolong Ye 6236fc5710SXiaolong YeDPDK Cross Compilation for OpenWrt 6336fc5710SXiaolong Ye---------------------------------- 6436fc5710SXiaolong Ye 6536fc5710SXiaolong YePre-requisites 6636fc5710SXiaolong Ye~~~~~~~~~~~~~~ 6736fc5710SXiaolong Ye 6836fc5710SXiaolong YeNUMA is required to run DPDK in x86. 6936fc5710SXiaolong Ye 7036fc5710SXiaolong Ye.. note:: 7136fc5710SXiaolong Ye 7236fc5710SXiaolong Ye For compiling the NUMA lib, run ``libtool --version`` to ensure the libtool 7336fc5710SXiaolong Ye version >= 2.2, otherwise the compilation will fail with errors. 7436fc5710SXiaolong Ye 7536fc5710SXiaolong Ye.. code-block:: console 7636fc5710SXiaolong Ye 7736fc5710SXiaolong Ye git clone https://github.com/numactl/numactl.git 7836fc5710SXiaolong Ye cd numactl 7936fc5710SXiaolong Ye git checkout v2.0.13 -b v2.0.13 8036fc5710SXiaolong Ye ./autogen.sh 8136fc5710SXiaolong Ye autoconf -i 8236fc5710SXiaolong Ye export PATH=<OpenWrt SDK>/glibc/openwrt-sdk-x86-64_gcc-8.3.0_glibc.Linux-x86_64/staging_dir/toolchain-x86_64_gcc-8.3.0_glibc/bin/:$PATH 8336fc5710SXiaolong Ye ./configure CC=x86_64-openwrt-linux-gnu-gcc --prefix=<OpenWrt SDK toolchain dir> 8436fc5710SXiaolong Ye make install 8536fc5710SXiaolong Ye 8636fc5710SXiaolong YeThe numa header files and lib file is generated in the include and lib folder 8736fc5710SXiaolong Yerespectively under <OpenWrt SDK toolchain dir>. 8836fc5710SXiaolong Ye 8936fc5710SXiaolong YeBuild DPDK 9036fc5710SXiaolong Ye~~~~~~~~~~ 9136fc5710SXiaolong Ye 9236fc5710SXiaolong YeTo cross compile with meson build, you need to write a customized cross file 9336fc5710SXiaolong Yefirst. 9436fc5710SXiaolong Ye 9536fc5710SXiaolong Ye.. code-block:: console 9636fc5710SXiaolong Ye 9736fc5710SXiaolong Ye [binaries] 9836fc5710SXiaolong Ye c = 'x86_64-openwrt-linux-gcc' 9936fc5710SXiaolong Ye cpp = 'x86_64-openwrt-linux-cpp' 10036fc5710SXiaolong Ye ar = 'x86_64-openwrt-linux-ar' 10136fc5710SXiaolong Ye strip = 'x86_64-openwrt-linux-strip' 10236fc5710SXiaolong Ye 103*e24b8ad4SStephen Hemminger meson setup builddir --cross-file openwrt-cross 10436fc5710SXiaolong Ye ninja -C builddir 10536fc5710SXiaolong Ye 10636fc5710SXiaolong YeRunning DPDK application on OpenWrt 10736fc5710SXiaolong Ye----------------------------------- 10836fc5710SXiaolong Ye 10936fc5710SXiaolong YeVirtual machine 11036fc5710SXiaolong Ye~~~~~~~~~~~~~~~ 11136fc5710SXiaolong Ye 11236fc5710SXiaolong Ye* Extract the boot image 11336fc5710SXiaolong Ye 11436fc5710SXiaolong Ye.. code-block:: console 11536fc5710SXiaolong Ye 11636fc5710SXiaolong Ye gzip -d openwrt-x86-64-combined-ext4.img.gz 11736fc5710SXiaolong Ye 11836fc5710SXiaolong Ye* Launch Qemu 11936fc5710SXiaolong Ye 12036fc5710SXiaolong Ye.. code-block:: console 12136fc5710SXiaolong Ye 12236fc5710SXiaolong Ye qemu-system-x86_64 \ 12336fc5710SXiaolong Ye -cpu host \ 12436fc5710SXiaolong Ye -smp 8 \ 12536fc5710SXiaolong Ye -enable-kvm \ 12636fc5710SXiaolong Ye -M q35 \ 12736fc5710SXiaolong Ye -m 2048M \ 12836fc5710SXiaolong Ye -object memory-backend-file,id=mem,size=2048M,mem-path=/tmp/hugepages,share=on \ 12936fc5710SXiaolong Ye -drive file=<Your OpenWrt images folder>/openwrt-x86-64-combined-ext4.img,id=d0,if=none,bus=0,unit=0 \ 13036fc5710SXiaolong Ye -device ide-hd,drive=d0,bus=ide.0 \ 13136fc5710SXiaolong Ye -net nic,vlan=0 \ 13236fc5710SXiaolong Ye -net nic,vlan=1 \ 13336fc5710SXiaolong Ye -net user,vlan=1 \ 13436fc5710SXiaolong Ye -display none \ 13536fc5710SXiaolong Ye 13636fc5710SXiaolong Ye 13736fc5710SXiaolong YePhysical machine 13836fc5710SXiaolong Ye~~~~~~~~~~~~~~~~ 13936fc5710SXiaolong Ye 14036fc5710SXiaolong YeYou can use the ``dd`` tool to write the OpenWrt image to the drive you 14136fc5710SXiaolong Yewant to write the image on. 14236fc5710SXiaolong Ye 14336fc5710SXiaolong Ye.. code-block:: console 14436fc5710SXiaolong Ye 14536fc5710SXiaolong Ye dd if=openwrt-18.06.1-x86-64-combined-squashfs.img of=/dev/sdX 14636fc5710SXiaolong Ye 14736fc5710SXiaolong YeWhere sdX is name of the drive. (You can find it though ``fdisk -l``) 14836fc5710SXiaolong Ye 14936fc5710SXiaolong YeRunning DPDK 15036fc5710SXiaolong Ye~~~~~~~~~~~~ 15136fc5710SXiaolong Ye 15236fc5710SXiaolong YeMore detailed info about how to run a DPDK application please refer to 15336fc5710SXiaolong Ye``Running DPDK Applications`` section of :ref:`the DPDK documentation <linux_gsg>`. 15436fc5710SXiaolong Ye 15536fc5710SXiaolong Ye.. note:: 15636fc5710SXiaolong Ye 15736fc5710SXiaolong Ye You need to install pre-built NUMA libraries (including soft link) 15836fc5710SXiaolong Ye to /usr/lib64 in OpenWrt. 159