15630257fSFerruh Yigit.. SPDX-License-Identifier: BSD-3-Clause 25630257fSFerruh Yigit Copyright(c) 2010-2015 Intel Corporation. 31ab07743SBernard Iremonger 43b60ce8cSJohn McNamara.. _linux_gsg_compiling_dpdk: 53b60ce8cSJohn McNamara 62e486e26SSiobhan ButlerCompiling the DPDK Target from Source 72e486e26SSiobhan Butler===================================== 81ab07743SBernard Iremonger 91ab07743SBernard Iremonger.. note:: 101ab07743SBernard Iremonger 1129c67340SJohn McNamara Parts of this process can also be done using the setup script described in 1229c67340SJohn McNamara the :ref:`linux_setup_script` section of this document. 131ab07743SBernard Iremonger 14*63fc2479SBruce RichardsonUncompress DPDK and Browse Sources 15*63fc2479SBruce Richardson---------------------------------- 161ab07743SBernard Iremonger 172e486e26SSiobhan ButlerFirst, uncompress the archive and move to the uncompressed DPDK source directory: 181ab07743SBernard Iremonger 191ab07743SBernard Iremonger.. code-block:: console 201ab07743SBernard Iremonger 21d1c34b5bSBaruch Siach tar xJf dpdk-<version>.tar.xz 22d1c34b5bSBaruch Siach cd dpdk-<version> 2329c67340SJohn McNamara 242e486e26SSiobhan ButlerThe DPDK is composed of several directories: 251ab07743SBernard Iremonger 262e486e26SSiobhan Butler* lib: Source code of DPDK libraries 271ab07743SBernard Iremonger 28980ed498SBruce Richardson* drivers: Source code of DPDK poll-mode drivers 29980ed498SBruce Richardson 302e486e26SSiobhan Butler* app: Source code of DPDK applications (automatic tests) 311ab07743SBernard Iremonger 322e486e26SSiobhan Butler* examples: Source code of DPDK application examples 331ab07743SBernard Iremonger 34c6dab2a8SThomas Monjalon* config, buildtools, mk: Framework-related makefiles, scripts and configuration 351ab07743SBernard Iremonger 36*63fc2479SBruce RichardsonCompiling and Installing DPDK System-wide 37*63fc2479SBruce Richardson----------------------------------------- 38*63fc2479SBruce Richardson 39*63fc2479SBruce RichardsonDPDK can be configured, built and installed on your system using the tools 40*63fc2479SBruce Richardson``meson`` and ``ninja``. 41*63fc2479SBruce Richardson 42*63fc2479SBruce Richardson.. note:: 43*63fc2479SBruce Richardson 44*63fc2479SBruce Richardson The older makefile-based build system used in older DPDK releases is 45*63fc2479SBruce Richardson still present and its use is described in section 46*63fc2479SBruce Richardson `Installation of DPDK Target Environment using Make`_. 47*63fc2479SBruce Richardson 48*63fc2479SBruce RichardsonDPDK Configuration 49*63fc2479SBruce Richardson~~~~~~~~~~~~~~~~~~ 50*63fc2479SBruce Richardson 51*63fc2479SBruce RichardsonTo configure a DPDK build use: 52*63fc2479SBruce Richardson 53*63fc2479SBruce Richardson.. code-block:: console 54*63fc2479SBruce Richardson 55*63fc2479SBruce Richardson meson <options> build 56*63fc2479SBruce Richardson 57*63fc2479SBruce Richardsonwhere "build" is the desired output build directory, and "<options>" can be 58*63fc2479SBruce Richardsonempty or one of a number of meson or DPDK-specific build options, described 59*63fc2479SBruce Richardsonlater in this section. The configuration process will finish with a summary 60*63fc2479SBruce Richardsonof what DPDK libraries and drivers are to be built and installed, and for 61*63fc2479SBruce Richardsoneach item disabled, a reason why that is the case. This information can be 62*63fc2479SBruce Richardsonused, for example, to identify any missing required packages for a driver. 63*63fc2479SBruce Richardson 64*63fc2479SBruce RichardsonOnce configured, to build and then install DPDK system-wide use: 65*63fc2479SBruce Richardson 66*63fc2479SBruce Richardson.. code-block:: console 67*63fc2479SBruce Richardson 68*63fc2479SBruce Richardson cd build 69*63fc2479SBruce Richardson ninja 70*63fc2479SBruce Richardson ninja install 71*63fc2479SBruce Richardson ldconfig 72*63fc2479SBruce Richardson 73*63fc2479SBruce RichardsonThe last two commands above generally need to be run as root, 74*63fc2479SBruce Richardsonwith the `ninja install` step copying the built objects to their final system-wide locations, 75*63fc2479SBruce Richardsonand the last step causing the dynamic loader `ld.so` to update its cache to take account of the new objects. 76*63fc2479SBruce Richardson 77*63fc2479SBruce Richardson.. note:: 78*63fc2479SBruce Richardson 79*63fc2479SBruce Richardson On some linux distributions, such as Fedora or Redhat, paths in `/usr/local` are 80*63fc2479SBruce Richardson not in the default paths for the loader. Therefore, on these 81*63fc2479SBruce Richardson distributions, `/usr/local/lib` and `/usr/local/lib64` should be added 82*63fc2479SBruce Richardson to a file in `/etc/ld.so.conf.d/` before running `ldconfig`. 83*63fc2479SBruce Richardson 84*63fc2479SBruce Richardson 85*63fc2479SBruce RichardsonAdjusting Build Options 86*63fc2479SBruce Richardson~~~~~~~~~~~~~~~~~~~~~~~ 87*63fc2479SBruce Richardson 88*63fc2479SBruce RichardsonDPDK has a number of options that can be adjusted as part of the build configuration process. 89*63fc2479SBruce RichardsonThese options can be listed by running ``meson configure`` inside a configured build folder. 90*63fc2479SBruce RichardsonMany of these options come from the "meson" tool itself and can be seen documented on the 91*63fc2479SBruce Richardson`Meson Website <https://mesonbuild.com/Builtin-options.html>`_. 92*63fc2479SBruce Richardson 93*63fc2479SBruce RichardsonFor example, to change the build-type from the default, "debugoptimized", 94*63fc2479SBruce Richardsonto a regular "debug" build, you can either: 95*63fc2479SBruce Richardson 96*63fc2479SBruce Richardson* pass ``-Dbuildtype=debug`` or ``--buildtype=debug`` to meson when configuring the build folder initially 97*63fc2479SBruce Richardson 98*63fc2479SBruce Richardson* run ``meson configure -Dbuildtype=debug`` inside the build folder after the initial meson run. 99*63fc2479SBruce Richardson 100*63fc2479SBruce RichardsonOther options are specific to the DPDK project but can be adjusted similarly. 101*63fc2479SBruce RichardsonTo set the "max_lcores" value to 256, for example, you can either: 102*63fc2479SBruce Richardson 103*63fc2479SBruce Richardson* pass ``-Dmax_lcores=256`` to meson when configuring the build folder initially 104*63fc2479SBruce Richardson 105*63fc2479SBruce Richardson* run ``meson configure -Dmax_lcores=256`` inside the build folder after the initial meson run. 106*63fc2479SBruce Richardson 107*63fc2479SBruce RichardsonSome of the DPDK sample applications in the `examples` directory can be 108*63fc2479SBruce Richardsonautomatically built as part of a meson build too. 109*63fc2479SBruce RichardsonTo do so, pass a comma-separated list of the examples to build to the 110*63fc2479SBruce Richardson`-Dexamples` meson option as below:: 111*63fc2479SBruce Richardson 112*63fc2479SBruce Richardson meson -Dexamples=l2fwd,l3fwd build 113*63fc2479SBruce Richardson 114*63fc2479SBruce RichardsonAs with other meson options, this can also be set post-initial-config using `meson configure` in the build directory. 115*63fc2479SBruce RichardsonThere is also a special value "all" to request that all example applications whose 116*63fc2479SBruce Richardsondependencies are met on the current system are built. 117*63fc2479SBruce RichardsonWhen `-Dexamples=all` is set as a meson option, meson will check each example application to see if it can be built, 118*63fc2479SBruce Richardsonand add all which can be built to the list of tasks in the ninja build configuration file. 119*63fc2479SBruce Richardson 120*63fc2479SBruce RichardsonBuilding Applications Using Installed DPDK 121*63fc2479SBruce Richardson~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 122*63fc2479SBruce Richardson 123*63fc2479SBruce RichardsonWhen installed system-wide, DPDK provides a pkg-config file ``libdpdk.pc`` for applications to query as part of their build. 124*63fc2479SBruce RichardsonIt's recommended that the pkg-config file be used, rather than hard-coding the parameters (cflags/ldflags) 125*63fc2479SBruce Richardsonfor DPDK into the application build process. 126*63fc2479SBruce Richardson 127*63fc2479SBruce RichardsonAn example of how to query and use the pkg-config file can be found in the ``Makefile`` of each of the example applications included with DPDK. 128*63fc2479SBruce RichardsonA simplified example snippet is shown below, where the target binary name has been stored in the variable ``$(APP)`` 129*63fc2479SBruce Richardsonand the sources for that build are stored in ``$(SRCS-y)``. 130*63fc2479SBruce Richardson 131*63fc2479SBruce Richardson.. code-block:: makefile 132*63fc2479SBruce Richardson 133*63fc2479SBruce Richardson PKGCONF = pkg-config 134*63fc2479SBruce Richardson 135*63fc2479SBruce Richardson CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk) 136*63fc2479SBruce Richardson LDFLAGS += $(shell $(PKGCONF) --libs libdpdk) 137*63fc2479SBruce Richardson 138*63fc2479SBruce Richardson $(APP): $(SRCS-y) Makefile 139*63fc2479SBruce Richardson $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) 140*63fc2479SBruce Richardson 141*63fc2479SBruce Richardson.. note:: 142*63fc2479SBruce Richardson 143*63fc2479SBruce Richardson Unlike with the older make build system, the meson system is not 144*63fc2479SBruce Richardson designed to be used directly from a build directory. Instead it is 145*63fc2479SBruce Richardson recommended that it be installed either system-wide or to a known 146*63fc2479SBruce Richardson location in the user's home directory. The install location can be set 147*63fc2479SBruce Richardson using the `--prefix` meson option (default: `/usr/local`). 148*63fc2479SBruce Richardson 149*63fc2479SBruce Richardsonan equivalent build recipe for a simple DPDK application using meson as a 150*63fc2479SBruce Richardsonbuild system is shown below: 151*63fc2479SBruce Richardson 152*63fc2479SBruce Richardson.. code-block:: python 153*63fc2479SBruce Richardson 154*63fc2479SBruce Richardson project('dpdk-app', 'c') 155*63fc2479SBruce Richardson 156*63fc2479SBruce Richardson dpdk = dependency('libdpdk') 157*63fc2479SBruce Richardson sources = files('main.c') 158*63fc2479SBruce Richardson executable('dpdk-app', sources, dependencies: dpdk) 159*63fc2479SBruce Richardson 160*63fc2479SBruce Richardson 161*63fc2479SBruce RichardsonInstallation of DPDK Target Environment using Make 162*63fc2479SBruce Richardson-------------------------------------------------- 163*63fc2479SBruce Richardson 164*63fc2479SBruce Richardson.. note:: 165*63fc2479SBruce Richardson 166*63fc2479SBruce Richardson The building of DPDK using make will be deprecated in a future release. It 167*63fc2479SBruce Richardson is therefore recommended that DPDK installation is done using meson and 168*63fc2479SBruce Richardson ninja as described above. 1691ab07743SBernard Iremonger 17029c67340SJohn McNamaraThe format of a DPDK target is:: 1711ab07743SBernard Iremonger 1721ab07743SBernard Iremonger ARCH-MACHINE-EXECENV-TOOLCHAIN 1731ab07743SBernard Iremonger 1741ab07743SBernard Iremongerwhere: 1751ab07743SBernard Iremonger 176f8277965SBrian Brooks* ``ARCH`` can be: ``i686``, ``x86_64``, ``ppc_64``, ``arm64`` 1771ab07743SBernard Iremonger 178f8277965SBrian Brooks* ``MACHINE`` can be: ``native``, ``power8``, ``armv8a`` 1791ab07743SBernard Iremonger 180218c4e68SBruce Richardson* ``EXECENV`` can be: ``linux``, ``freebsd`` 1811ab07743SBernard Iremonger 18229c67340SJohn McNamara* ``TOOLCHAIN`` can be: ``gcc``, ``icc`` 1831ab07743SBernard Iremonger 1841ab07743SBernard IremongerThe targets to be installed depend on the 32-bit and/or 64-bit packages and compilers installed on the host. 1851ab07743SBernard IremongerAvailable targets can be found in the DPDK/config directory. 1861ab07743SBernard IremongerThe defconfig\_ prefix should not be used. 1871ab07743SBernard Iremonger 1881ab07743SBernard Iremonger.. note:: 1891ab07743SBernard Iremonger 19029c67340SJohn McNamara Configuration files are provided with the ``RTE_MACHINE`` optimization level set. 19129c67340SJohn McNamara Within the configuration files, the ``RTE_MACHINE`` configuration value is set to native, 1921ab07743SBernard Iremonger which means that the compiled software is tuned for the platform on which it is built. 1932e486e26SSiobhan Butler For more information on this setting, and its possible values, see the *DPDK Programmers Guide*. 1941ab07743SBernard Iremonger 1951ab07743SBernard IremongerWhen using the Intel® C++ Compiler (icc), one of the following commands should be invoked for 64-bit or 32-bit use respectively. 19629c67340SJohn McNamaraNotice that the shell scripts update the ``$PATH`` variable and therefore should not be performed in the same session. 1971ab07743SBernard IremongerAlso, verify the compiler's installation directory since the path may be different: 1981ab07743SBernard Iremonger 1991ab07743SBernard Iremonger.. code-block:: console 2001ab07743SBernard Iremonger 2011ab07743SBernard Iremonger source /opt/intel/bin/iccvars.sh intel64 2021ab07743SBernard Iremonger source /opt/intel/bin/iccvars.sh ia32 2031ab07743SBernard Iremonger 20429c67340SJohn McNamaraTo install and make targets, use the ``make install T=<target>`` command in the top-level DPDK directory. 2051ab07743SBernard Iremonger 2061ab07743SBernard IremongerFor example, to compile a 64-bit target using icc, run: 2071ab07743SBernard Iremonger 2081ab07743SBernard Iremonger.. code-block:: console 2091ab07743SBernard Iremonger 210218c4e68SBruce Richardson make install T=x86_64-native-linux-icc 2111ab07743SBernard Iremonger 2121ab07743SBernard IremongerTo compile a 32-bit build using gcc, the make command should be: 2131ab07743SBernard Iremonger 2141ab07743SBernard Iremonger.. code-block:: console 2151ab07743SBernard Iremonger 216218c4e68SBruce Richardson make install T=i686-native-linux-gcc 2171ab07743SBernard Iremonger 2181ab07743SBernard IremongerTo prepare a target without building it, for example, if the configuration changes need to be made before compilation, 21929c67340SJohn McNamarause the ``make config T=<target>`` command: 2201ab07743SBernard Iremonger 2211ab07743SBernard Iremonger.. code-block:: console 2221ab07743SBernard Iremonger 223218c4e68SBruce Richardson make config T=x86_64-native-linux-gcc 2241ab07743SBernard Iremonger 2251ab07743SBernard Iremonger.. warning:: 2261ab07743SBernard Iremonger 22729c67340SJohn McNamara Any kernel modules to be used, e.g. ``igb_uio``, ``kni``, must be compiled with the 228974438fbSBruce Richardson same kernel as the one running on the target. 2292e486e26SSiobhan Butler If the DPDK is not being built on the target machine, 23029c67340SJohn McNamara 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. 2311ab07743SBernard Iremonger 2321ab07743SBernard IremongerOnce the target environment is created, the user may move to the target environment directory and continue to make code changes and re-compile. 2332e486e26SSiobhan ButlerThe user may also make modifications to the compile-time DPDK configuration by editing the .config file in the build directory. 2341ab07743SBernard Iremonger(This is a build-local copy of the defconfig file from the top- level config directory). 2351ab07743SBernard Iremonger 2361ab07743SBernard Iremonger.. code-block:: console 2371ab07743SBernard Iremonger 238218c4e68SBruce Richardson cd x86_64-native-linux-gcc 2391ab07743SBernard Iremonger vi .config 2401ab07743SBernard Iremonger make 2411ab07743SBernard Iremonger 2421ab07743SBernard IremongerIn addition, the make clean command can be used to remove any existing compiled files for a subsequent full, clean rebuild of the code. 2431ab07743SBernard Iremonger 2442e486e26SSiobhan ButlerBrowsing the Installed DPDK Environment Target 2452e486e26SSiobhan Butler---------------------------------------------- 2461ab07743SBernard Iremonger 247980ed498SBruce RichardsonOnce a target is created it contains all libraries, including poll-mode drivers, and header files for the DPDK environment that are required to build customer applications. 2481ab07743SBernard IremongerIn addition, the test and testpmd applications are built under the build/app directory, which may be used for testing. 249980ed498SBruce RichardsonA kmod directory is also present that contains kernel modules which may be loaded if needed. 250