xref: /dpdk/doc/guides/linux_gsg/build_dpdk.rst (revision fea1d908d39989a27890b29b5c0ec94c85c8257b)
11ab07743SBernard Iremonger..  BSD LICENSE
21ab07743SBernard Iremonger    Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
31ab07743SBernard Iremonger    All rights reserved.
41ab07743SBernard Iremonger
51ab07743SBernard Iremonger    Redistribution and use in source and binary forms, with or without
61ab07743SBernard Iremonger    modification, are permitted provided that the following conditions
71ab07743SBernard Iremonger    are met:
81ab07743SBernard Iremonger
91ab07743SBernard Iremonger    * Redistributions of source code must retain the above copyright
101ab07743SBernard Iremonger    notice, this list of conditions and the following disclaimer.
111ab07743SBernard Iremonger    * Redistributions in binary form must reproduce the above copyright
121ab07743SBernard Iremonger    notice, this list of conditions and the following disclaimer in
131ab07743SBernard Iremonger    the documentation and/or other materials provided with the
141ab07743SBernard Iremonger    distribution.
151ab07743SBernard Iremonger    * Neither the name of Intel Corporation nor the names of its
161ab07743SBernard Iremonger    contributors may be used to endorse or promote products derived
171ab07743SBernard Iremonger    from this software without specific prior written permission.
181ab07743SBernard Iremonger
191ab07743SBernard Iremonger    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
201ab07743SBernard Iremonger    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
211ab07743SBernard Iremonger    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
221ab07743SBernard Iremonger    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
231ab07743SBernard Iremonger    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
241ab07743SBernard Iremonger    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
251ab07743SBernard Iremonger    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
261ab07743SBernard Iremonger    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
271ab07743SBernard Iremonger    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
281ab07743SBernard Iremonger    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
291ab07743SBernard Iremonger    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
301ab07743SBernard Iremonger
312e486e26SSiobhan ButlerCompiling the DPDK Target from Source
322e486e26SSiobhan Butler=====================================
331ab07743SBernard Iremonger
341ab07743SBernard Iremonger.. note::
351ab07743SBernard Iremonger
361ab07743SBernard Iremonger    Parts of this process can also be done using the setup script described in Chapter 6 of this document.
371ab07743SBernard Iremonger
382e486e26SSiobhan ButlerInstall the DPDK and Browse Sources
392e486e26SSiobhan Butler-----------------------------------
401ab07743SBernard Iremonger
412e486e26SSiobhan ButlerFirst, uncompress the archive and move to the uncompressed DPDK source directory:
421ab07743SBernard Iremonger
431ab07743SBernard Iremonger.. code-block:: console
441ab07743SBernard Iremonger
451ab07743SBernard Iremonger   user@host:~$ unzip DPDK-<version>.zip
461ab07743SBernard Iremonger   user@host:~$ cd DPDK-<version>
471ab07743SBernard Iremonger   user@host:~/DPDK-<version>$ ls
481ab07743SBernard Iremonger   app/   config/   examples/   lib/   LICENSE.GPL   LICENSE.LGPL   Makefile   mk/   scripts/   tools/
491ab07743SBernard Iremonger
502e486e26SSiobhan ButlerThe DPDK is composed of several directories:
511ab07743SBernard Iremonger
522e486e26SSiobhan Butler*   lib: Source code of DPDK libraries
531ab07743SBernard Iremonger
542e486e26SSiobhan Butler*   app: Source code of DPDK applications (automatic tests)
551ab07743SBernard Iremonger
562e486e26SSiobhan Butler*   examples: Source code of DPDK application examples
571ab07743SBernard Iremonger
581ab07743SBernard Iremonger*   config, tools, scripts, mk: Framework-related makefiles, scripts and configuration
591ab07743SBernard Iremonger
602e486e26SSiobhan ButlerInstallation of DPDK Target Environments
612e486e26SSiobhan Butler----------------------------------------
621ab07743SBernard Iremonger
632e486e26SSiobhan ButlerThe format of a DPDK target is:
641ab07743SBernard Iremonger
651ab07743SBernard Iremonger    ARCH-MACHINE-EXECENV-TOOLCHAIN
661ab07743SBernard Iremonger
671ab07743SBernard Iremongerwhere:
681ab07743SBernard Iremonger
69df6aaab3SChao Zhu*   ARCH can be:  i686, x86_64, ppc_64
701ab07743SBernard Iremonger
71df6aaab3SChao Zhu*   MACHINE can be:  native, ivshmem, power8
721ab07743SBernard Iremonger
731ab07743SBernard Iremonger*   EXECENV can be:  linuxapp,  bsdapp
741ab07743SBernard Iremonger
751ab07743SBernard Iremonger*   TOOLCHAIN can be:  gcc,  icc
761ab07743SBernard Iremonger
771ab07743SBernard IremongerThe targets to be installed depend on the 32-bit and/or 64-bit packages and compilers installed on the host.
781ab07743SBernard IremongerAvailable targets can be found in the DPDK/config directory.
791ab07743SBernard IremongerThe defconfig\_ prefix should not be used.
801ab07743SBernard Iremonger
811ab07743SBernard Iremonger.. note::
821ab07743SBernard Iremonger
831ab07743SBernard Iremonger    Configuration files are provided with the RTE_MACHINE optimization level set.
841ab07743SBernard Iremonger    Within the configuration files, the RTE_MACHINE configuration value is set to native,
851ab07743SBernard Iremonger    which means that the compiled software is tuned for the platform on which it is built.
862e486e26SSiobhan Butler    For more information on this setting, and its possible values, see the *DPDK Programmers Guide*.
871ab07743SBernard Iremonger
881ab07743SBernard IremongerWhen using the Intel® C++ Compiler (icc), one of the following commands should be invoked for 64-bit or 32-bit use respectively.
891ab07743SBernard IremongerNotice that the shell scripts update the $PATH variable and therefore should not be performed in the same session.
901ab07743SBernard IremongerAlso, verify the compiler's installation directory since the path may be different:
911ab07743SBernard Iremonger
921ab07743SBernard Iremonger.. code-block:: console
931ab07743SBernard Iremonger
941ab07743SBernard Iremonger    source /opt/intel/bin/iccvars.sh intel64
951ab07743SBernard Iremonger    source /opt/intel/bin/iccvars.sh ia32
961ab07743SBernard Iremonger
972e486e26SSiobhan ButlerTo install and make targets, use the make install T=<target> command in the top-level DPDK directory.
981ab07743SBernard Iremonger
991ab07743SBernard IremongerFor example, to compile a 64-bit target using icc, run:
1001ab07743SBernard Iremonger
1011ab07743SBernard Iremonger.. code-block:: console
1021ab07743SBernard Iremonger
1031ab07743SBernard Iremonger    make install T=x86_64-native-linuxapp-icc
1041ab07743SBernard Iremonger
1051ab07743SBernard IremongerTo compile a 32-bit build using gcc, the make command should be:
1061ab07743SBernard Iremonger
1071ab07743SBernard Iremonger.. code-block:: console
1081ab07743SBernard Iremonger
1091ab07743SBernard Iremonger    make install T=i686-native-linuxapp-gcc
1101ab07743SBernard Iremonger
1111ab07743SBernard IremongerTo compile all 64-bit targets using gcc, use:
1121ab07743SBernard Iremonger
1131ab07743SBernard Iremonger.. code-block:: console
1141ab07743SBernard Iremonger
1151ab07743SBernard Iremonger    make install T=x86_64*gcc
1161ab07743SBernard Iremonger
1171ab07743SBernard IremongerTo compile all 64-bit targets using both gcc and icc, use:
1181ab07743SBernard Iremonger
1191ab07743SBernard Iremonger.. code-block:: console
1201ab07743SBernard Iremonger
1211ab07743SBernard Iremonger    make install T=x86_64-*
1221ab07743SBernard Iremonger
1231ab07743SBernard Iremonger.. note::
1241ab07743SBernard Iremonger
1251ab07743SBernard Iremonger    The wildcard operator (*) can be used to create multiple targets at the same time.
1261ab07743SBernard Iremonger
1271ab07743SBernard IremongerTo prepare a target without building it, for example, if the configuration changes need to be made before compilation,
1281ab07743SBernard Iremongeruse the make config T=<target> command:
1291ab07743SBernard Iremonger
1301ab07743SBernard Iremonger.. code-block:: console
1311ab07743SBernard Iremonger
1321ab07743SBernard Iremonger    make config T=x86_64-native-linuxapp-gcc
1331ab07743SBernard Iremonger
1341ab07743SBernard Iremonger.. warning::
1351ab07743SBernard Iremonger
136974438fbSBruce Richardson    Any kernel modules to be used, e.g. igb_uio, kni, must be compiled with the
137974438fbSBruce Richardson    same kernel as the one running on the target.
1382e486e26SSiobhan Butler    If the DPDK is not being built on the target machine,
1391ab07743SBernard Iremonger    the RTE_KERNELDIR environment variable should be used to point the compilation at a copy of the kernel version to be used on the target machine.
1401ab07743SBernard Iremonger
1411ab07743SBernard IremongerOnce the target environment is created, the user may move to the target environment directory and continue to make code changes and re-compile.
1422e486e26SSiobhan ButlerThe user may also make modifications to the compile-time DPDK configuration by editing the .config file in the build directory.
1431ab07743SBernard Iremonger(This is a build-local copy of the defconfig file from the top- level config directory).
1441ab07743SBernard Iremonger
1451ab07743SBernard Iremonger.. code-block:: console
1461ab07743SBernard Iremonger
1471ab07743SBernard Iremonger    cd x86_64-native-linuxapp-gcc
1481ab07743SBernard Iremonger    vi .config
1491ab07743SBernard Iremonger    make
1501ab07743SBernard Iremonger
1511ab07743SBernard IremongerIn addition, the make clean command can be used to remove any existing compiled files for a subsequent full, clean rebuild of the code.
1521ab07743SBernard Iremonger
1532e486e26SSiobhan ButlerBrowsing the Installed DPDK Environment Target
1542e486e26SSiobhan Butler----------------------------------------------
1551ab07743SBernard Iremonger
1562e486e26SSiobhan ButlerOnce a target is created it contains all libraries and header files for the DPDK environment that are required to build customer applications.
1571ab07743SBernard IremongerIn addition, the test and testpmd applications are built under the build/app directory, which may be used for testing.
158974438fbSBruce RichardsonA kmod  directory is also present that contains kernel modules which may be loaded if needed:
1591ab07743SBernard Iremonger
1601ab07743SBernard Iremonger.. code-block:: console
1611ab07743SBernard Iremonger
1621ab07743SBernard Iremonger    $ ls x86_64-native-linuxapp-gcc
1631ab07743SBernard Iremonger    app build hostapp include kmod lib Makefile
1641ab07743SBernard Iremonger
165974438fbSBruce RichardsonLoading Modules to Enable Userspace IO for DPDK
166974438fbSBruce Richardson-----------------------------------------------
1671ab07743SBernard Iremonger
168974438fbSBruce RichardsonTo run any DPDK application, a suitable uio module can be loaded into the running kernel.
169*fea1d908SJohn McNamaraIn many cases, the standard uio_pci_generic module included in the Linux kernel
170974438fbSBruce Richardsoncan provide the uio capability. This module can be loaded using the command
1711ab07743SBernard Iremonger
1721ab07743SBernard Iremonger.. code-block:: console
1731ab07743SBernard Iremonger
174974438fbSBruce Richardson    sudo modprobe uio_pci_generic
1751ab07743SBernard Iremonger
176974438fbSBruce RichardsonAs an alternative to the uio_pci_generic, the DPDK also includes the igb_uio
1775af3be00SBruce Richardsonmodule which can be found in the kmod subdirectory referred to above. It can
1785af3be00SBruce Richardsonbe loaded as shown below:
1795af3be00SBruce Richardson
1805af3be00SBruce Richardson.. code-block:: console
1815af3be00SBruce Richardson
1825af3be00SBruce Richardson    sudo modprobe uio
1835af3be00SBruce Richardson    sudo insmod kmod/igb_uio.ko
1845af3be00SBruce Richardson
1855af3be00SBruce Richardson.. note::
1865af3be00SBruce Richardson
1875af3be00SBruce Richardson    For some devices which lack support for legacy interrupts, e.g. virtual function
1885af3be00SBruce Richardson    (VF) devices, the igb_uio module may be needed in place of uio_pci_generic.
189974438fbSBruce Richardson
190974438fbSBruce RichardsonSince DPDK release 1.7 onward provides VFIO support, use of UIO is optional
191974438fbSBruce Richardsonfor platforms that support using VFIO.
1921ab07743SBernard Iremonger
1931ab07743SBernard IremongerLoading VFIO Module
1941ab07743SBernard Iremonger-------------------
1951ab07743SBernard Iremonger
1962e486e26SSiobhan ButlerTo run an DPDK application and make use of VFIO, the vfio-pci module must be loaded:
1971ab07743SBernard Iremonger
1981ab07743SBernard Iremonger.. code-block:: console
1991ab07743SBernard Iremonger
2001ab07743SBernard Iremonger    sudo modprobe vfio-pci
2011ab07743SBernard Iremonger
2021ab07743SBernard IremongerNote that in order to use VFIO, your kernel must support it.
2031ab07743SBernard IremongerVFIO kernel modules have been included in the Linux kernel since version 3.6.0 and are usually present by default,
2041ab07743SBernard Iremongerhowever please consult your distributions documentation to make sure that is the case.
2051ab07743SBernard Iremonger
2061ab07743SBernard IremongerAlso, to use VFIO, both kernel and BIOS must support and be configured to use IO virtualization (such as Intel® VT-d).
2071ab07743SBernard Iremonger
2082e486e26SSiobhan ButlerFor proper operation of VFIO when running DPDK applications as a non-privileged user, correct permissions should also be set up.
2092e486e26SSiobhan ButlerThis can be done by using the DPDK setup script (called setup.sh and located in the tools directory).
2101ab07743SBernard Iremonger
211974438fbSBruce RichardsonBinding and Unbinding Network Ports to/from the Kernel Modules
2121ab07743SBernard Iremonger----------------------------------------------------------------------
2131ab07743SBernard Iremonger
2142e486e26SSiobhan ButlerAs of release 1.4, DPDK applications no longer automatically unbind all supported network ports from the kernel driver in use.
215974438fbSBruce RichardsonInstead, all ports that are to be used by an DPDK application must be bound to the
216974438fbSBruce Richardsonuio_pci_generic, igb_uio or vfio-pci module before the application is run.
2172e486e26SSiobhan ButlerAny network ports under Linux* control will be ignored by the DPDK poll-mode drivers and cannot be used by the application.
2181ab07743SBernard Iremonger
2191ab07743SBernard Iremonger.. warning::
2201ab07743SBernard Iremonger
2212e486e26SSiobhan Butler    The DPDK will, by default, no longer automatically unbind network ports from the kernel driver at startup.
222974438fbSBruce Richardson    Any ports to be used by an DPDK application must be unbound from Linux* control and
223974438fbSBruce Richardson    bound to the uio_pci_generic, igb_uio or vfio-pci module before the application is run.
2241ab07743SBernard Iremonger
225974438fbSBruce RichardsonTo bind ports to the uio_pci_generic, igb_uio or vfio-pci module for DPDK use,
226974438fbSBruce Richardsonand then subsequently return ports to Linux* control,
2271ab07743SBernard Iremongera utility script called dpdk_nic _bind.py is provided in the tools subdirectory.
2281ab07743SBernard IremongerThis utility can be used to provide a view of the current state of the network ports on the system,
229974438fbSBruce Richardsonand to bind and unbind those ports from the different kernel modules, including the uio and vfio modules.
2301ab07743SBernard IremongerThe following are some examples of how the script can be used.
2311ab07743SBernard IremongerA full description of the script and its parameters can be obtained by calling the script with the --help or --usage options.
232974438fbSBruce RichardsonNote that the uio or vfio kernel modules to be used, should be loaded into the kernel before
233974438fbSBruce Richardsonrunning the dpdk_nic_bind.py script.
2341ab07743SBernard Iremonger
2351ab07743SBernard Iremonger.. warning::
2361ab07743SBernard Iremonger
2371ab07743SBernard Iremonger    Due to the way VFIO works, there are certain limitations to which devices can be used with VFIO.
2381ab07743SBernard Iremonger    Mainly it comes down to how IOMMU groups work.
2391ab07743SBernard Iremonger    Any Virtual Function device can be used with VFIO on its own, but physical devices will require either all ports bound to VFIO,
2401ab07743SBernard Iremonger    or some of them bound to VFIO while others not being bound to anything at all.
2411ab07743SBernard Iremonger
2421ab07743SBernard Iremonger    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.
2431ab07743SBernard Iremonger    Therefore, the bridge driver should also be unbound from the bridge PCI device for VFIO to work with devices behind the bridge.
2441ab07743SBernard Iremonger
2451ab07743SBernard Iremonger.. warning::
2461ab07743SBernard Iremonger
2471ab07743SBernard Iremonger    While any user can run the dpdk_nic_bind.py script to view the status of the network ports,
2481ab07743SBernard Iremonger    binding or unbinding network ports requires root privileges.
2491ab07743SBernard Iremonger
2501ab07743SBernard IremongerTo see the status of all network ports on the system:
2511ab07743SBernard Iremonger
2521ab07743SBernard Iremonger.. code-block:: console
2531ab07743SBernard Iremonger
2541ab07743SBernard Iremonger    root@host:DPDK# ./tools/dpdk_nic_bind.py --status
2551ab07743SBernard Iremonger
256974438fbSBruce Richardson    Network devices using DPDK-compatible driver
257974438fbSBruce Richardson    ============================================
258974438fbSBruce Richardson    0000:82:00.0 '82599EB 10-Gigabit SFI/SFP+ Network Connection' drv=uio_pci_generic unused=ixgbe
259974438fbSBruce Richardson    0000:82:00.1 '82599EB 10-Gigabit SFI/SFP+ Network Connection' drv=uio_pci_generic unused=ixgbe
2601ab07743SBernard Iremonger
2611ab07743SBernard Iremonger    Network devices using kernel driver
2621ab07743SBernard Iremonger    ===================================
263974438fbSBruce Richardson    0000:04:00.0 'I350 Gigabit Network Connection' if=em0 drv=igb unused=uio_pci_generic *Active*
264974438fbSBruce Richardson    0000:04:00.1 'I350 Gigabit Network Connection' if=eth1 drv=igb unused=uio_pci_generic
265974438fbSBruce Richardson    0000:04:00.2 'I350 Gigabit Network Connection' if=eth2 drv=igb unused=uio_pci_generic
266974438fbSBruce Richardson    0000:04:00.3 'I350 Gigabit Network Connection' if=eth3 drv=igb unused=uio_pci_generic
2671ab07743SBernard Iremonger
2681ab07743SBernard Iremonger    Other network devices
2691ab07743SBernard Iremonger    =====================
2701ab07743SBernard Iremonger    <none>
2711ab07743SBernard Iremonger
272974438fbSBruce RichardsonTo bind device eth1, 04:00.1, to the uio_pci_generic driver:
2731ab07743SBernard Iremonger
2741ab07743SBernard Iremonger.. code-block:: console
2751ab07743SBernard Iremonger
276974438fbSBruce Richardson    root@host:DPDK# ./tools/dpdk_nic_bind.py --bind=uio_pci_generic 04:00.1
2771ab07743SBernard Iremonger
2781ab07743SBernard Iremongeror, alternatively,
2791ab07743SBernard Iremonger
2801ab07743SBernard Iremonger.. code-block:: console
2811ab07743SBernard Iremonger
282974438fbSBruce Richardson    root@host:DPDK# ./tools/dpdk_nic_bind.py --bind=uio_pci_generic eth1
2831ab07743SBernard Iremonger
2841ab07743SBernard IremongerTo restore device 82:00.0 to its original kernel binding:
2851ab07743SBernard Iremonger
2861ab07743SBernard Iremonger.. code-block:: console
2871ab07743SBernard Iremonger
2881ab07743SBernard Iremonger    root@host:DPDK# ./tools/dpdk_nic_bind.py --bind=ixgbe 82:00.0
289