1c0a775a1SBruce Richardson.. SPDX-License-Identifier: BSD-3-Clause 2c0a775a1SBruce Richardson Copyright(c) 2018 Intel Corporation. 3c0a775a1SBruce Richardson 4adbeba36SHari Kumar VemulaInstalling DPDK Using the meson build system 5adbeba36SHari Kumar Vemula============================================ 6adbeba36SHari Kumar Vemula 7adbeba36SHari Kumar VemulaSummary 8adbeba36SHari Kumar Vemula-------- 9adbeba36SHari Kumar VemulaFor many platforms, compiling and installing DPDK should work using the 10adbeba36SHari Kumar Vemulafollowing set of commands:: 11adbeba36SHari Kumar Vemula 12e24b8ad4SStephen Hemminger meson setup build 13adbeba36SHari Kumar Vemula cd build 14adbeba36SHari Kumar Vemula ninja 159599c59bSBruce Richardson meson install 16adbeba36SHari Kumar Vemula 17adbeba36SHari Kumar VemulaThis will compile DPDK in the ``build`` subdirectory, and then install the 18adbeba36SHari Kumar Vemularesulting libraries, drivers and header files onto the system - generally 19adbeba36SHari Kumar Vemulain /usr/local. A package-config file, ``libdpdk.pc``, for DPDK will also 20adbeba36SHari Kumar Vemulabe installed to allow ease of compiling and linking with applications. 21adbeba36SHari Kumar Vemula 22adbeba36SHari Kumar VemulaAfter installation, to use DPDK, the necessary CFLAG and LDFLAG variables 23adbeba36SHari Kumar Vemulacan be got from pkg-config:: 24adbeba36SHari Kumar Vemula 25adbeba36SHari Kumar Vemula pkg-config --cflags libdpdk 26adbeba36SHari Kumar Vemula pkg-config --libs libdpdk 27adbeba36SHari Kumar Vemula 28adbeba36SHari Kumar VemulaMore detail on each of these steps can be got from the following sections. 29adbeba36SHari Kumar Vemula 30adbeba36SHari Kumar Vemula 31adbeba36SHari Kumar VemulaGetting the Tools 32adbeba36SHari Kumar Vemula------------------ 33adbeba36SHari Kumar Vemula 34adbeba36SHari Kumar VemulaThe ``meson`` tool is used to configure a DPDK build. On most Linux 35adbeba36SHari Kumar Vemuladistributions this can be got using the local package management system, 36adbeba36SHari Kumar Vemulae.g. ``dnf install meson`` or ``apt-get install meson``. If meson is not 37adbeba36SHari Kumar Vemulaavailable as a suitable package, it can also be installed using the Python 38*6f3dbd30SBruce Richardson3 ``pip`` tool, e.g. ``pip3 install meson``. Version 0.57 or later of meson is 39adbeba36SHari Kumar Vemularequired - if the version packaged is too old, the latest version is 40adbeba36SHari Kumar Vemulagenerally available from "pip". 41adbeba36SHari Kumar Vemula 42adbeba36SHari Kumar VemulaThe other dependency for building is the ``ninja`` tool, which acts similar 43adbeba36SHari Kumar Vemulato make and performs the actual build using information provided by meson. 44adbeba36SHari Kumar VemulaInstalling meson will, in many cases, also install ninja, but, if not 45adbeba36SHari Kumar Vemulaalready installed, it too is generally packaged by most Linux distributions. 46adbeba36SHari Kumar VemulaIf not available as a package, it can be downloaded as source or binary from 47adbeba36SHari Kumar Vemulahttps://ninja-build.org/ 48adbeba36SHari Kumar Vemula 49d1355fccSAsaf PensoIt is best advised to go over the following links for the complete dependencies: 50d1355fccSAsaf Penso 51d1355fccSAsaf Penso* :doc:`Linux <../linux_gsg/sys_reqs>` 52d1355fccSAsaf Penso* :doc:`FreeBSD <../freebsd_gsg/build_dpdk>` 53d1355fccSAsaf Penso* :doc:`Windows <../windows_gsg/build_dpdk>` 54d1355fccSAsaf Penso 55adbeba36SHari Kumar Vemula 56adbeba36SHari Kumar VemulaConfiguring the Build 57adbeba36SHari Kumar Vemula---------------------- 58adbeba36SHari Kumar Vemula 59adbeba36SHari Kumar VemulaTo configure a build, run the meson tool, passing the path to the directory 60e24b8ad4SStephen Hemmingerto be used for the build e.g. ``meson setup build``, as shown above. If calling 61adbeba36SHari Kumar Vemulameson from somewhere other than the root directory of the DPDK project the 62adbeba36SHari Kumar Vemulapath to the root directory should be passed as the first parameter, and the 63adbeba36SHari Kumar Vemulabuild path as the second. For example, to build DPDK in /tmp/dpdk-build:: 64adbeba36SHari Kumar Vemula 65e24b8ad4SStephen Hemminger user@host:/tmp$ meson setup ~user/dpdk dpdk-build 66adbeba36SHari Kumar Vemula 67adbeba36SHari Kumar VemulaMeson will then configure the build based on settings in the project's 68adbeba36SHari Kumar Vemulameson.build files, and by checking the build environment for e.g. compiler 69adbeba36SHari Kumar Vemulaproperties or the presence of dependencies, such as libpcap, or openssl 70adbeba36SHari Kumar Vemulalibcrypto libraries. Once done, meson writes a ``build.ninja`` file in the 71adbeba36SHari Kumar Vemulabuild directory to be used to do the build itself when ninja is called. 72adbeba36SHari Kumar Vemula 73adbeba36SHari Kumar VemulaTuning of the build is possible, both as part of the original meson call, 74adbeba36SHari Kumar Vemulaor subsequently using ``meson configure`` command (``mesonconf`` in some 75adbeba36SHari Kumar Vemulaolder versions). Some options, such as ``buildtype``, or ``werror`` are 76adbeba36SHari Kumar Vemulabuilt into meson, while others, such as ``max_lcores``, or the list of 77adbeba36SHari Kumar Vemulaexamples to build, are DPDK-specific. To have a list of all options 78adbeba36SHari Kumar Vemulaavailable run ``meson configure`` in the build directory. 79adbeba36SHari Kumar Vemula 80adbeba36SHari Kumar VemulaExamples of adjusting the defaults when doing initial meson configuration. 81adbeba36SHari Kumar VemulaProject-specific options are passed used -Doption=value:: 82adbeba36SHari Kumar Vemula 83e24b8ad4SStephen Hemminger # build with warnings as errors 84e24b8ad4SStephen Hemminger meson setup --werror werrorbuild 85adbeba36SHari Kumar Vemula 86e24b8ad4SStephen Hemminger # build for debugging 87e24b8ad4SStephen Hemminger meson setup --buildtype=debug debugbuild 88adbeba36SHari Kumar Vemula 89e24b8ad4SStephen Hemminger # build some examples as part of the normal DPDK build 90e24b8ad4SStephen Hemminger meson setup -Dexamples=l3fwd,l2fwd fwdbuild 91adbeba36SHari Kumar Vemula 92e24b8ad4SStephen Hemminger # scale build for smaller systems 93e24b8ad4SStephen Hemminger meson setup -Dmax_lcores=8 smallbuild 94adbeba36SHari Kumar Vemula 95e24b8ad4SStephen Hemminger # build and install docs 96e24b8ad4SStephen Hemminger meson setup -Denable_docs=true fullbuild 97adbeba36SHari Kumar Vemula 98e24b8ad4SStephen Hemminger # use builder-independent baseline -march 99e24b8ad4SStephen Hemminger meson setup -Dcpu_instruction_set=generic 100adbeba36SHari Kumar Vemula 101e24b8ad4SStephen Hemminger # disable tap driver and all eventdev PMDs for a smaller build 102e24b8ad4SStephen Hemminger meson setup -Ddisable_drivers=event/*,net/tap 103adbeba36SHari Kumar Vemula 104e24b8ad4SStephen Hemminger # build with fast path traces enabled 105e24b8ad4SStephen Hemminger meson setup -Denable_trace_fp=true tracebuild 10627db82c7SJerin Jacob 107adbeba36SHari Kumar VemulaExamples of setting some of the same options using meson configure:: 108adbeba36SHari Kumar Vemula 109adbeba36SHari Kumar Vemula meson configure -Dwerror=true 110adbeba36SHari Kumar Vemula 111adbeba36SHari Kumar Vemula meson configure -Dbuildtype=debug 112adbeba36SHari Kumar Vemula 113adbeba36SHari Kumar Vemula meson configure -Dexamples=l3fwd,l2fwd 114adbeba36SHari Kumar Vemula 115adbeba36SHari Kumar Vemula meson configure -Dmax_lcores=8 116adbeba36SHari Kumar Vemula 11727db82c7SJerin Jacob meson configure -Denable_trace_fp=true 11827db82c7SJerin Jacob 1191509ef93SBruce Richardson.. note:: 1201509ef93SBruce Richardson 1211509ef93SBruce Richardson once meson has been run to configure a build in a directory, it 122adbeba36SHari Kumar Vemula cannot be run again on the same directory. Instead ``meson configure`` 123adbeba36SHari Kumar Vemula should be used to change the build settings within the directory, and when 124adbeba36SHari Kumar Vemula ``ninja`` is called to do the build itself, it will trigger the necessary 125adbeba36SHari Kumar Vemula re-scan from meson. 126adbeba36SHari Kumar Vemula 1271509ef93SBruce Richardson.. note:: 1289cd9c570SJuraj Linkeš 1299cd9c570SJuraj Linkeš cpu_instruction_set=generic uses an instruction set that works on 1309cd9c570SJuraj Linkeš all supported architectures regardless of the capabilities of the machine 1319cd9c570SJuraj Linkeš where the build is happening. 1329cd9c570SJuraj Linkeš 1339cd9c570SJuraj Linkeš.. note:: 1349cd9c570SJuraj Linkeš 1359cd9c570SJuraj Linkeš cpu_instruction_set is not used in Arm builds, as setting the instruction set 1369cd9c570SJuraj Linkeš without other parameters leads to inferior builds. 1379cd9c570SJuraj Linkeš The way to tailor Arm builds is to build for a SoC using -Dplatform=<SoC>. 138adbeba36SHari Kumar Vemula 139adbeba36SHari Kumar VemulaAs well as those settings taken from ``meson configure``, other options 140adbeba36SHari Kumar Vemulasuch as the compiler to use can be passed via environment variables. For 141adbeba36SHari Kumar Vemulaexample:: 142adbeba36SHari Kumar Vemula 143e24b8ad4SStephen Hemminger CC=clang meson setup clang-build 144adbeba36SHari Kumar Vemula 1451509ef93SBruce Richardson.. note:: 1461509ef93SBruce Richardson 1471509ef93SBruce Richardson for more comprehensive overriding of compilers or other environment 148adbeba36SHari Kumar Vemula settings, the tools for cross-compilation may be considered. However, for 149adbeba36SHari Kumar Vemula basic overriding of the compiler etc., the above form works as expected. 150adbeba36SHari Kumar Vemula 151adbeba36SHari Kumar Vemula 152adbeba36SHari Kumar VemulaPerforming the Build 153adbeba36SHari Kumar Vemula--------------------- 154adbeba36SHari Kumar Vemula 155adbeba36SHari Kumar VemulaUse ``ninja`` to perform the actual build inside the build folder 156adbeba36SHari Kumar Vemulapreviously configured. In most cases no arguments are necessary. 157adbeba36SHari Kumar Vemula 158adbeba36SHari Kumar VemulaNinja accepts a number of flags which are similar to make. For example, to 159adbeba36SHari Kumar Vemulacall ninja from outside the build folder, you can use ``ninja -C build``. 160adbeba36SHari Kumar VemulaNinja also runs parallel builds by default, but you can limit this using 161adbeba36SHari Kumar Vemulathe ``-j`` flag, e.g. ``ninja -j1 -v`` to do the build one step at a time, 162adbeba36SHari Kumar Vemulaprinting each command on a new line as it runs. 163adbeba36SHari Kumar Vemula 164adbeba36SHari Kumar Vemula 165adbeba36SHari Kumar VemulaInstalling the Compiled Files 166adbeba36SHari Kumar Vemula------------------------------ 167adbeba36SHari Kumar Vemula 1689599c59bSBruce RichardsonUse ``meson install`` to install the required DPDK files onto the system. 169adbeba36SHari Kumar VemulaThe install prefix defaults to ``/usr/local`` but can be used as with other 170adbeba36SHari Kumar Vemulaoptions above. The environment variable ``DESTDIR`` can be used to adjust 171adbeba36SHari Kumar Vemulathe root directory for the install, for example when packaging. 172adbeba36SHari Kumar Vemula 173adbeba36SHari Kumar VemulaWith the base install directory, the individual directories for libraries 174adbeba36SHari Kumar Vemulaand headers are configurable. By default, the following will be the 175adbeba36SHari Kumar Vemulainstalled layout:: 176adbeba36SHari Kumar Vemula 177adbeba36SHari Kumar Vemula headers -> /usr/local/include 178adbeba36SHari Kumar Vemula libraries -> /usr/local/lib64 179adbeba36SHari Kumar Vemula drivers -> /usr/local/lib64/dpdk/drivers 180adbeba36SHari Kumar Vemula libdpdk.pc -> /usr/local/lib64/pkgconfig 181adbeba36SHari Kumar Vemula 182adbeba36SHari Kumar VemulaFor the drivers, these will also be symbolically linked into the library 183adbeba36SHari Kumar Vemulainstall directory, so that ld.so can find them in cases where one driver may 184adbeba36SHari Kumar Vemuladepend on another, e.g. a NIC PMD depending upon the PCI bus driver. Within 185adbeba36SHari Kumar Vemulathe EAL, the default search path for drivers will be set to the configured 186adbeba36SHari Kumar Vemuladriver install path, so dynamically-linked applications can be run without 187adbeba36SHari Kumar Vemulahaving to pass in ``-d /path/to/driver`` options for standard drivers. 188adbeba36SHari Kumar Vemula 189adbeba36SHari Kumar Vemula 190adbeba36SHari Kumar VemulaCross Compiling DPDK 191adbeba36SHari Kumar Vemula-------------------- 192adbeba36SHari Kumar Vemula 193adbeba36SHari Kumar VemulaTo cross-compile DPDK on a desired target machine we can use the following 194adbeba36SHari Kumar Vemulacommand:: 195adbeba36SHari Kumar Vemula 196e24b8ad4SStephen Hemminger meson setup cross-build --cross-file <target_machine_configuration> 197adbeba36SHari Kumar Vemula 198adbeba36SHari Kumar VemulaFor example if the target machine is arm64 we can use the following 199adbeba36SHari Kumar Vemulacommand:: 200adbeba36SHari Kumar Vemula 201e24b8ad4SStephen Hemminger meson setup arm-build --cross-file config/arm/arm64_armv8_linux_gcc 202adbeba36SHari Kumar Vemula 203adbeba36SHari Kumar Vemulawhere config/arm/arm64_armv8_linux_gcc contains settings for the compilers 204adbeba36SHari Kumar Vemulaand other build tools to be used, as well as characteristics of the target 205adbeba36SHari Kumar Vemulamachine. 206adbeba36SHari Kumar Vemula 207adbeba36SHari Kumar VemulaUsing the DPDK within an Application 208adbeba36SHari Kumar Vemula------------------------------------- 209adbeba36SHari Kumar Vemula 210adbeba36SHari Kumar VemulaTo compile and link against DPDK within an application, pkg-config should 211adbeba36SHari Kumar Vemulabe used to query the correct parameters. Examples of this are given in the 212adbeba36SHari Kumar Vemulamakefiles for the example applications included with DPDK. They demonstrate 213adbeba36SHari Kumar Vemulahow to link either against the DPDK shared libraries, or against the static 214adbeba36SHari Kumar Vemulaversions of the same. 215adbeba36SHari Kumar Vemula 216adbeba36SHari Kumar VemulaFrom examples/helloworld/Makefile:: 217adbeba36SHari Kumar Vemula 218adbeba36SHari Kumar Vemula PC_FILE := $(shell pkg-config --path libdpdk) 219adbeba36SHari Kumar Vemula CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) 220adbeba36SHari Kumar Vemula LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) 2218549295dSBruce Richardson LDFLAGS_STATIC = $(shell pkg-config --static --libs libdpdk) 222adbeba36SHari Kumar Vemula 223adbeba36SHari Kumar Vemula build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build 224adbeba36SHari Kumar Vemula $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED) 225adbeba36SHari Kumar Vemula 226adbeba36SHari Kumar Vemula build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build 227adbeba36SHari Kumar Vemula $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC) 228adbeba36SHari Kumar Vemula 229adbeba36SHari Kumar Vemula build: 230adbeba36SHari Kumar Vemula @mkdir -p $@ 231