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 963fc2479SBruce RichardsonUncompress DPDK and Browse Sources 1063fc2479SBruce Richardson---------------------------------- 111ab07743SBernard Iremonger 122e486e26SSiobhan ButlerFirst, uncompress the archive and move to the uncompressed DPDK source directory: 131ab07743SBernard Iremonger 141ab07743SBernard Iremonger.. code-block:: console 151ab07743SBernard Iremonger 16d1c34b5bSBaruch Siach tar xJf dpdk-<version>.tar.xz 17d1c34b5bSBaruch Siach cd dpdk-<version> 1829c67340SJohn McNamara 19e2075e0dSBruce RichardsonThe DPDK is composed of several directories, including: 20e2075e0dSBruce Richardson 21e2075e0dSBruce Richardson* doc: DPDK Documentation 22e2075e0dSBruce Richardson 23e2075e0dSBruce Richardson* license: DPDK license information 241ab07743SBernard Iremonger 252e486e26SSiobhan Butler* lib: Source code of DPDK libraries 261ab07743SBernard Iremonger 27980ed498SBruce Richardson* drivers: Source code of DPDK poll-mode drivers 28980ed498SBruce Richardson 292e486e26SSiobhan Butler* app: Source code of DPDK applications (automatic tests) 301ab07743SBernard Iremonger 312e486e26SSiobhan Butler* examples: Source code of DPDK application examples 321ab07743SBernard Iremonger 333cc6ecfdSCiara Power* config, buildtools: Framework-related scripts and configuration 341ab07743SBernard Iremonger 35e2075e0dSBruce Richardson* usertools: Utility scripts for end-users of DPDK applications 36e2075e0dSBruce Richardson 37e2075e0dSBruce Richardson* devtools: Scripts for use by DPDK developers 38e2075e0dSBruce Richardson 39e2075e0dSBruce Richardson* kernel: Kernel modules needed for some operating systems 40e2075e0dSBruce Richardson 41e2075e0dSBruce Richardson 4263fc2479SBruce RichardsonCompiling and Installing DPDK System-wide 4363fc2479SBruce Richardson----------------------------------------- 4463fc2479SBruce Richardson 4563fc2479SBruce RichardsonDPDK can be configured, built and installed on your system using the tools 4663fc2479SBruce Richardson``meson`` and ``ninja``. 4763fc2479SBruce Richardson 4863fc2479SBruce Richardson 4963fc2479SBruce RichardsonDPDK Configuration 5063fc2479SBruce Richardson~~~~~~~~~~~~~~~~~~ 5163fc2479SBruce Richardson 5263fc2479SBruce RichardsonTo configure a DPDK build use: 5363fc2479SBruce Richardson 5463fc2479SBruce Richardson.. code-block:: console 5563fc2479SBruce Richardson 56e24b8ad4SStephen Hemminger meson setup <options> build 5763fc2479SBruce Richardson 5863fc2479SBruce Richardsonwhere "build" is the desired output build directory, and "<options>" can be 5963fc2479SBruce Richardsonempty or one of a number of meson or DPDK-specific build options, described 6063fc2479SBruce Richardsonlater in this section. The configuration process will finish with a summary 6163fc2479SBruce Richardsonof what DPDK libraries and drivers are to be built and installed, and for 6263fc2479SBruce Richardsoneach item disabled, a reason why that is the case. This information can be 6363fc2479SBruce Richardsonused, for example, to identify any missing required packages for a driver. 6463fc2479SBruce Richardson 6563fc2479SBruce RichardsonOnce configured, to build and then install DPDK system-wide use: 6663fc2479SBruce Richardson 6763fc2479SBruce Richardson.. code-block:: console 6863fc2479SBruce Richardson 6963fc2479SBruce Richardson cd build 7063fc2479SBruce Richardson ninja 71*9599c59bSBruce Richardson meson install 7263fc2479SBruce Richardson ldconfig 7363fc2479SBruce Richardson 7463fc2479SBruce RichardsonThe last two commands above generally need to be run as root, 75*9599c59bSBruce Richardsonwith the `meson install` step copying the built objects to their final system-wide locations, 7663fc2479SBruce Richardsonand the last step causing the dynamic loader `ld.so` to update its cache to take account of the new objects. 7763fc2479SBruce Richardson 7863fc2479SBruce Richardson.. note:: 7963fc2479SBruce Richardson 8063fc2479SBruce Richardson On some linux distributions, such as Fedora or Redhat, paths in `/usr/local` are 8163fc2479SBruce Richardson not in the default paths for the loader. Therefore, on these 8263fc2479SBruce Richardson distributions, `/usr/local/lib` and `/usr/local/lib64` should be added 8363fc2479SBruce Richardson to a file in `/etc/ld.so.conf.d/` before running `ldconfig`. 8463fc2479SBruce Richardson 855c7cb088SCiara Power.. _adjusting_build_options: 8663fc2479SBruce Richardson 8763fc2479SBruce RichardsonAdjusting Build Options 8863fc2479SBruce Richardson~~~~~~~~~~~~~~~~~~~~~~~ 8963fc2479SBruce Richardson 9063fc2479SBruce RichardsonDPDK has a number of options that can be adjusted as part of the build configuration process. 9163fc2479SBruce RichardsonThese options can be listed by running ``meson configure`` inside a configured build folder. 9263fc2479SBruce RichardsonMany of these options come from the "meson" tool itself and can be seen documented on the 9363fc2479SBruce Richardson`Meson Website <https://mesonbuild.com/Builtin-options.html>`_. 9463fc2479SBruce Richardson 9563fc2479SBruce RichardsonFor example, to change the build-type from the default, "debugoptimized", 9663fc2479SBruce Richardsonto a regular "debug" build, you can either: 9763fc2479SBruce Richardson 9863fc2479SBruce Richardson* pass ``-Dbuildtype=debug`` or ``--buildtype=debug`` to meson when configuring the build folder initially 9963fc2479SBruce Richardson 10063fc2479SBruce Richardson* run ``meson configure -Dbuildtype=debug`` inside the build folder after the initial meson run. 10163fc2479SBruce Richardson 10263fc2479SBruce RichardsonOther options are specific to the DPDK project but can be adjusted similarly. 103bf66003bSJuraj LinkešThe "platform" option specifies a set a configuration parameters that will be used. 104bf66003bSJuraj LinkešThe valid values are: 105bf66003bSJuraj Linkeš 106bf66003bSJuraj Linkeš* ``-Dplatform=native`` will tailor the configuration to the build machine. 107bf66003bSJuraj Linkeš 108bf66003bSJuraj Linkeš* ``-Dplatform=generic`` will use configuration that works on all machines 109bf66003bSJuraj Linkeš of the same architecture as the build machine. 110bf66003bSJuraj Linkeš 111bf66003bSJuraj Linkeš* ``-Dplatform=<SoC>`` will use configuration optimized for a particular SoC. 112bf66003bSJuraj Linkeš Consult the "socs" dictionary in ``config/arm/meson.build`` to see which 113bf66003bSJuraj Linkeš SoCs are supported. 114bf66003bSJuraj Linkeš 115bf66003bSJuraj LinkešThe instruction set will be set automatically by default according to these rules: 116bf66003bSJuraj Linkeš 117bf66003bSJuraj Linkeš* ``-Dplatform=native`` sets ``cpu_instruction_set`` to ``native``, 118bf66003bSJuraj Linkeš which configures ``-march`` (x86_64), ``-mcpu`` (ppc), ``-mtune`` (ppc) to ``native``. 119bf66003bSJuraj Linkeš 120bf66003bSJuraj Linkeš* ``-Dplatform=generic`` sets ``cpu_instruction_set`` to ``generic``, 121bf66003bSJuraj Linkeš which configures ``-march`` (x86_64), ``-mcpu`` (ppc), ``-mtune`` (ppc) to 122bf66003bSJuraj Linkeš a common minimal baseline needed for DPDK. 123bf66003bSJuraj Linkeš 124bf66003bSJuraj LinkešTo override what instruction set will be used, set the ``cpu_instruction_set`` 125bf66003bSJuraj Linkešparameter to the instruction set of your choice (such as ``corei7``, ``power8``, etc.). 126bf66003bSJuraj Linkeš 127bf66003bSJuraj Linkeš``cpu_instruction_set`` is not used in Arm builds, as setting the instruction set 128bf66003bSJuraj Linkešwithout other parameters leads to inferior builds. The way to tailor Arm builds 129bf66003bSJuraj Linkešis to build for a SoC using ``-Dplatform=<SoC>`` mentioned above. 130bf66003bSJuraj Linkeš 131bf66003bSJuraj LinkešThe values determined by the ``platform`` parameter may be overwritten. 132bf66003bSJuraj LinkešFor example, to set the ``max_lcores`` value to 256, you can either: 13363fc2479SBruce Richardson 13463fc2479SBruce Richardson* pass ``-Dmax_lcores=256`` to meson when configuring the build folder initially 13563fc2479SBruce Richardson 13663fc2479SBruce Richardson* run ``meson configure -Dmax_lcores=256`` inside the build folder after the initial meson run. 13763fc2479SBruce Richardson 13863fc2479SBruce RichardsonSome of the DPDK sample applications in the `examples` directory can be 13963fc2479SBruce Richardsonautomatically built as part of a meson build too. 14063fc2479SBruce RichardsonTo do so, pass a comma-separated list of the examples to build to the 14163fc2479SBruce Richardson`-Dexamples` meson option as below:: 14263fc2479SBruce Richardson 143e24b8ad4SStephen Hemminger meson setup -Dexamples=l2fwd,l3fwd build 14463fc2479SBruce Richardson 14563fc2479SBruce RichardsonAs with other meson options, this can also be set post-initial-config using `meson configure` in the build directory. 14663fc2479SBruce RichardsonThere is also a special value "all" to request that all example applications whose 14763fc2479SBruce Richardsondependencies are met on the current system are built. 14863fc2479SBruce RichardsonWhen `-Dexamples=all` is set as a meson option, meson will check each example application to see if it can be built, 14963fc2479SBruce Richardsonand add all which can be built to the list of tasks in the ninja build configuration file. 15063fc2479SBruce Richardson 151a8adac0bSBruce Richardson 152a8adac0bSBruce RichardsonBuilding 32-bit DPDK on 64-bit Systems 153a8adac0bSBruce Richardson~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 154a8adac0bSBruce Richardson 155a8adac0bSBruce RichardsonTo build a 32-bit copy of DPDK on a 64-bit OS, 156a8adac0bSBruce Richardsonthe ``-m32`` flag should be passed to the compiler and linker 157a8adac0bSBruce Richardsonto force the generation of 32-bit objects and binaries. 158a8adac0bSBruce RichardsonThis can be done either by setting ``CFLAGS`` and ``LDFLAGS`` in the environment, 159a8adac0bSBruce Richardsonor by passing the value to meson using ``-Dc_args=-m32`` and ``-Dc_link_args=-m32``. 160a8adac0bSBruce RichardsonFor correctly identifying and using any dependency packages, 161a8adac0bSBruce Richardsonthe ``pkg-config`` tool must also be configured 162a8adac0bSBruce Richardsonto look in the appropriate directory for .pc files for 32-bit libraries. 163a8adac0bSBruce RichardsonThis is done by setting ``PKG_CONFIG_LIBDIR`` to the appropriate path. 164a8adac0bSBruce Richardson 165a8adac0bSBruce RichardsonThe following meson command can be used on RHEL/Fedora systems to configure a 32-bit build, 166a8adac0bSBruce Richardsonassuming the relevant 32-bit development packages, such as a 32-bit libc, are installed:: 167a8adac0bSBruce Richardson 168a8adac0bSBruce Richardson PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig \ 169e24b8ad4SStephen Hemminger meson setup -Dc_args='-m32' -Dc_link_args='-m32' build 170a8adac0bSBruce Richardson 171a8adac0bSBruce RichardsonFor Debian/Ubuntu systems, the equivalent command is:: 172a8adac0bSBruce Richardson 173a8adac0bSBruce Richardson PKG_CONFIG_LIBDIR=/usr/lib/i386-linux-gnu/pkgconfig \ 174e24b8ad4SStephen Hemminger meson setup -Dc_args='-m32' -Dc_link_args='-m32' build 175a8adac0bSBruce Richardson 176a8adac0bSBruce RichardsonOnce the build directory has been configured, 177a8adac0bSBruce RichardsonDPDK can be compiled using ``ninja`` as described above. 178a8adac0bSBruce Richardson 179a8adac0bSBruce Richardson 1805c7cb088SCiara Power.. _building_app_using_installed_dpdk: 1815c7cb088SCiara Power 18263fc2479SBruce RichardsonBuilding Applications Using Installed DPDK 18363fc2479SBruce Richardson~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 18463fc2479SBruce Richardson 18563fc2479SBruce RichardsonWhen installed system-wide, DPDK provides a pkg-config file ``libdpdk.pc`` for applications to query as part of their build. 18663fc2479SBruce RichardsonIt's recommended that the pkg-config file be used, rather than hard-coding the parameters (cflags/ldflags) 18763fc2479SBruce Richardsonfor DPDK into the application build process. 18863fc2479SBruce Richardson 18963fc2479SBruce 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. 19063fc2479SBruce RichardsonA simplified example snippet is shown below, where the target binary name has been stored in the variable ``$(APP)`` 19163fc2479SBruce Richardsonand the sources for that build are stored in ``$(SRCS-y)``. 19263fc2479SBruce Richardson 19363fc2479SBruce Richardson.. code-block:: makefile 19463fc2479SBruce Richardson 19563fc2479SBruce Richardson PKGCONF = pkg-config 19663fc2479SBruce Richardson 19763fc2479SBruce Richardson CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk) 19863fc2479SBruce Richardson LDFLAGS += $(shell $(PKGCONF) --libs libdpdk) 19963fc2479SBruce Richardson 20063fc2479SBruce Richardson $(APP): $(SRCS-y) Makefile 20163fc2479SBruce Richardson $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) 20263fc2479SBruce Richardson 20363fc2479SBruce Richardson.. note:: 20463fc2479SBruce Richardson 2055c7cb088SCiara Power Unlike with the make build system present in older DPDK releases, 2065c7cb088SCiara Power the meson system is not 20763fc2479SBruce Richardson designed to be used directly from a build directory. Instead it is 20863fc2479SBruce Richardson recommended that it be installed either system-wide or to a known 20963fc2479SBruce Richardson location in the user's home directory. The install location can be set 21063fc2479SBruce Richardson using the `--prefix` meson option (default: `/usr/local`). 21163fc2479SBruce Richardson 21263fc2479SBruce Richardsonan equivalent build recipe for a simple DPDK application using meson as a 21363fc2479SBruce Richardsonbuild system is shown below: 21463fc2479SBruce Richardson 21563fc2479SBruce Richardson.. code-block:: python 21663fc2479SBruce Richardson 21763fc2479SBruce Richardson project('dpdk-app', 'c') 21863fc2479SBruce Richardson 21963fc2479SBruce Richardson dpdk = dependency('libdpdk') 22063fc2479SBruce Richardson sources = files('main.c') 22163fc2479SBruce Richardson executable('dpdk-app', sources, dependencies: dpdk) 222