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 12adbeba36SHari Kumar Vemula meson build 13adbeba36SHari Kumar Vemula cd build 14adbeba36SHari Kumar Vemula ninja 15adbeba36SHari Kumar Vemula ninja 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 388c105308SGabriel Ganne3 ``pip`` tool, e.g. ``pip3 install meson``. Version 0.49.2 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 49*d1355fccSAsaf PensoIt is best advised to go over the following links for the complete dependencies: 50*d1355fccSAsaf Penso 51*d1355fccSAsaf Penso* :doc:`Linux <../linux_gsg/sys_reqs>` 52*d1355fccSAsaf Penso* :doc:`FreeBSD <../freebsd_gsg/build_dpdk>` 53*d1355fccSAsaf Penso* :doc:`Windows <../windows_gsg/build_dpdk>` 54*d1355fccSAsaf 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 60adbeba36SHari Kumar Vemulato be used for the build e.g. ``meson 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 65adbeba36SHari Kumar Vemula user@host:/tmp$ meson ~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 83adbeba36SHari Kumar Vemula meson --werror werrorbuild # build with warnings as errors 84adbeba36SHari Kumar Vemula 85adbeba36SHari Kumar Vemula meson --buildtype=debug debugbuild # build for debugging 86adbeba36SHari Kumar Vemula 87adbeba36SHari Kumar Vemula meson -Dexamples=l3fwd,l2fwd fwdbuild # build some examples as 88adbeba36SHari Kumar Vemula # part of the normal DPDK build 89adbeba36SHari Kumar Vemula 90adbeba36SHari Kumar Vemula meson -Dmax_lcores=8 smallbuild # scale build for smaller systems 91adbeba36SHari Kumar Vemula 92adbeba36SHari Kumar Vemula meson -Denable_docs=true fullbuild # build and install docs 93adbeba36SHari Kumar Vemula 945b3a6ca6SJuraj Linkeš meson -Dmachine=generic # use builder-independent baseline -march 95adbeba36SHari Kumar Vemula 96adbeba36SHari Kumar Vemula meson -Ddisable_drivers=event/*,net/tap # disable tap driver and all 97adbeba36SHari Kumar Vemula # eventdev PMDs for a smaller build 98adbeba36SHari Kumar Vemula 9927db82c7SJerin Jacob meson -Denable_trace_fp=true tracebuild # build with fast path traces 10027db82c7SJerin Jacob # enabled 10127db82c7SJerin Jacob 102adbeba36SHari Kumar VemulaExamples of setting some of the same options using meson configure:: 103adbeba36SHari Kumar Vemula 104adbeba36SHari Kumar Vemula meson configure -Dwerror=true 105adbeba36SHari Kumar Vemula 106adbeba36SHari Kumar Vemula meson configure -Dbuildtype=debug 107adbeba36SHari Kumar Vemula 108adbeba36SHari Kumar Vemula meson configure -Dexamples=l3fwd,l2fwd 109adbeba36SHari Kumar Vemula 110adbeba36SHari Kumar Vemula meson configure -Dmax_lcores=8 111adbeba36SHari Kumar Vemula 11227db82c7SJerin Jacob meson configure -Denable_trace_fp=true 11327db82c7SJerin Jacob 1141509ef93SBruce Richardson.. note:: 1151509ef93SBruce Richardson 1161509ef93SBruce Richardson once meson has been run to configure a build in a directory, it 117adbeba36SHari Kumar Vemula cannot be run again on the same directory. Instead ``meson configure`` 118adbeba36SHari Kumar Vemula should be used to change the build settings within the directory, and when 119adbeba36SHari Kumar Vemula ``ninja`` is called to do the build itself, it will trigger the necessary 120adbeba36SHari Kumar Vemula re-scan from meson. 121adbeba36SHari Kumar Vemula 1221509ef93SBruce Richardson.. note:: 1235b3a6ca6SJuraj Linkeš machine=generic uses a config that works on all supported architectures 124adbeba36SHari Kumar Vemula regardless of the capabilities of the machine where the build is happening. 125adbeba36SHari Kumar Vemula 126adbeba36SHari Kumar VemulaAs well as those settings taken from ``meson configure``, other options 127adbeba36SHari Kumar Vemulasuch as the compiler to use can be passed via environment variables. For 128adbeba36SHari Kumar Vemulaexample:: 129adbeba36SHari Kumar Vemula 130adbeba36SHari Kumar Vemula CC=clang meson clang-build 131adbeba36SHari Kumar Vemula 1321509ef93SBruce Richardson.. note:: 1331509ef93SBruce Richardson 1341509ef93SBruce Richardson for more comprehensive overriding of compilers or other environment 135adbeba36SHari Kumar Vemula settings, the tools for cross-compilation may be considered. However, for 136adbeba36SHari Kumar Vemula basic overriding of the compiler etc., the above form works as expected. 137adbeba36SHari Kumar Vemula 138adbeba36SHari Kumar Vemula 139adbeba36SHari Kumar VemulaPerforming the Build 140adbeba36SHari Kumar Vemula--------------------- 141adbeba36SHari Kumar Vemula 142adbeba36SHari Kumar VemulaUse ``ninja`` to perform the actual build inside the build folder 143adbeba36SHari Kumar Vemulapreviously configured. In most cases no arguments are necessary. 144adbeba36SHari Kumar Vemula 145adbeba36SHari Kumar VemulaNinja accepts a number of flags which are similar to make. For example, to 146adbeba36SHari Kumar Vemulacall ninja from outside the build folder, you can use ``ninja -C build``. 147adbeba36SHari Kumar VemulaNinja also runs parallel builds by default, but you can limit this using 148adbeba36SHari Kumar Vemulathe ``-j`` flag, e.g. ``ninja -j1 -v`` to do the build one step at a time, 149adbeba36SHari Kumar Vemulaprinting each command on a new line as it runs. 150adbeba36SHari Kumar Vemula 151adbeba36SHari Kumar Vemula 152adbeba36SHari Kumar VemulaInstalling the Compiled Files 153adbeba36SHari Kumar Vemula------------------------------ 154adbeba36SHari Kumar Vemula 155adbeba36SHari Kumar VemulaUse ``ninja install`` to install the required DPDK files onto the system. 156adbeba36SHari Kumar VemulaThe install prefix defaults to ``/usr/local`` but can be used as with other 157adbeba36SHari Kumar Vemulaoptions above. The environment variable ``DESTDIR`` can be used to adjust 158adbeba36SHari Kumar Vemulathe root directory for the install, for example when packaging. 159adbeba36SHari Kumar Vemula 160adbeba36SHari Kumar VemulaWith the base install directory, the individual directories for libraries 161adbeba36SHari Kumar Vemulaand headers are configurable. By default, the following will be the 162adbeba36SHari Kumar Vemulainstalled layout:: 163adbeba36SHari Kumar Vemula 164adbeba36SHari Kumar Vemula headers -> /usr/local/include 165adbeba36SHari Kumar Vemula libraries -> /usr/local/lib64 166adbeba36SHari Kumar Vemula drivers -> /usr/local/lib64/dpdk/drivers 167adbeba36SHari Kumar Vemula libdpdk.pc -> /usr/local/lib64/pkgconfig 168adbeba36SHari Kumar Vemula 169adbeba36SHari Kumar VemulaFor the drivers, these will also be symbolically linked into the library 170adbeba36SHari Kumar Vemulainstall directory, so that ld.so can find them in cases where one driver may 171adbeba36SHari Kumar Vemuladepend on another, e.g. a NIC PMD depending upon the PCI bus driver. Within 172adbeba36SHari Kumar Vemulathe EAL, the default search path for drivers will be set to the configured 173adbeba36SHari Kumar Vemuladriver install path, so dynamically-linked applications can be run without 174adbeba36SHari Kumar Vemulahaving to pass in ``-d /path/to/driver`` options for standard drivers. 175adbeba36SHari Kumar Vemula 176adbeba36SHari Kumar Vemula 177adbeba36SHari Kumar VemulaCross Compiling DPDK 178adbeba36SHari Kumar Vemula-------------------- 179adbeba36SHari Kumar Vemula 180adbeba36SHari Kumar VemulaTo cross-compile DPDK on a desired target machine we can use the following 181adbeba36SHari Kumar Vemulacommand:: 182adbeba36SHari Kumar Vemula 183adbeba36SHari Kumar Vemula meson cross-build --cross-file <target_machine_configuration> 184adbeba36SHari Kumar Vemula 185adbeba36SHari Kumar VemulaFor example if the target machine is arm64 we can use the following 186adbeba36SHari Kumar Vemulacommand:: 187adbeba36SHari Kumar Vemula 188adbeba36SHari Kumar Vemula meson arm-build --cross-file config/arm/arm64_armv8_linux_gcc 189adbeba36SHari Kumar Vemula 190adbeba36SHari Kumar Vemulawhere config/arm/arm64_armv8_linux_gcc contains settings for the compilers 191adbeba36SHari Kumar Vemulaand other build tools to be used, as well as characteristics of the target 192adbeba36SHari Kumar Vemulamachine. 193adbeba36SHari Kumar Vemula 194adbeba36SHari Kumar VemulaUsing the DPDK within an Application 195adbeba36SHari Kumar Vemula------------------------------------- 196adbeba36SHari Kumar Vemula 197adbeba36SHari Kumar VemulaTo compile and link against DPDK within an application, pkg-config should 198adbeba36SHari Kumar Vemulabe used to query the correct parameters. Examples of this are given in the 199adbeba36SHari Kumar Vemulamakefiles for the example applications included with DPDK. They demonstrate 200adbeba36SHari Kumar Vemulahow to link either against the DPDK shared libraries, or against the static 201adbeba36SHari Kumar Vemulaversions of the same. 202adbeba36SHari Kumar Vemula 203adbeba36SHari Kumar VemulaFrom examples/helloworld/Makefile:: 204adbeba36SHari Kumar Vemula 205adbeba36SHari Kumar Vemula PC_FILE := $(shell pkg-config --path libdpdk) 206adbeba36SHari Kumar Vemula CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) 207adbeba36SHari Kumar Vemula LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) 2088549295dSBruce Richardson LDFLAGS_STATIC = $(shell pkg-config --static --libs libdpdk) 209adbeba36SHari Kumar Vemula 210adbeba36SHari Kumar Vemula build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build 211adbeba36SHari Kumar Vemula $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED) 212adbeba36SHari Kumar Vemula 213adbeba36SHari Kumar Vemula build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build 214adbeba36SHari Kumar Vemula $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC) 215adbeba36SHari Kumar Vemula 216adbeba36SHari Kumar Vemula build: 217adbeba36SHari Kumar Vemula @mkdir -p $@ 218