15630257fSFerruh Yigit.. SPDX-License-Identifier: BSD-3-Clause 25630257fSFerruh Yigit Copyright(c) 2010-2014 Intel Corporation. 3dacdbfa4SBernard Iremonger 43e7b87ddSBruce Richardson.. _building_from_source: 53e7b87ddSBruce Richardson 69c587847SSiobhan ButlerCompiling the DPDK Target from Source 79c587847SSiobhan Butler===================================== 8dacdbfa4SBernard Iremonger 9add61c79SBruce RichardsonPrerequisites 10add61c79SBruce Richardson------------- 113e7b87ddSBruce Richardson 12add61c79SBruce RichardsonThe following FreeBSD packages are required to build DPDK: 133e7b87ddSBruce Richardson 14add61c79SBruce Richardson* meson 15add61c79SBruce Richardson* ninja 16add61c79SBruce Richardson* pkgconf 173e7b87ddSBruce Richardson 18add61c79SBruce RichardsonThese can be installed using (as root):: 193e7b87ddSBruce Richardson 20add61c79SBruce Richardson pkg install meson pkgconf 213e7b87ddSBruce Richardson 22add61c79SBruce RichardsonTo compile the required kernel modules for memory management and working 23add61c79SBruce Richardsonwith physical NIC devices, the kernel sources for FreeBSD also 24add61c79SBruce Richardsonneed to be installed. If not already present on the system, these can be 25add61c79SBruce Richardsoninstalled via commands like the following, for FreeBSD 12.1 on x86_64:: 263e7b87ddSBruce Richardson 27add61c79SBruce Richardson fetch http://ftp.freebsd.org/pub/FreeBSD/releases/amd64/12.1-RELEASE/src.txz 28add61c79SBruce Richardson tar -C / -xJvf src.txz 293e7b87ddSBruce Richardson 30add61c79SBruce RichardsonTo enable the telemetry library in DPDK, the jansson library also needs to 31add61c79SBruce Richardsonbe installed, and can be installed via:: 323e7b87ddSBruce Richardson 33add61c79SBruce Richardson pkg install jansson 343e7b87ddSBruce Richardson 35add61c79SBruce RichardsonIndividual drivers may have additional requirements. Consult the relevant 36add61c79SBruce Richardsondriver guide for any driver-specific requirements of interest. 373e7b87ddSBruce Richardson 38add61c79SBruce RichardsonBuilding DPDK 39add61c79SBruce Richardson------------- 403e7b87ddSBruce Richardson 41add61c79SBruce RichardsonThe following commands can be used to build and install DPDK on a system. 42add61c79SBruce RichardsonThe final, install, step generally needs to be run as root:: 433e7b87ddSBruce Richardson 44add61c79SBruce Richardson meson build 45add61c79SBruce Richardson cd build 46add61c79SBruce Richardson ninja 47add61c79SBruce Richardson ninja install 483e7b87ddSBruce Richardson 49add61c79SBruce RichardsonThis will install the DPDK libraries and drivers to `/usr/local/lib` with a 50add61c79SBruce Richardsonpkg-config file `libdpdk.pc` installed to `/usr/local/lib/pkgconfig`. The 51add61c79SBruce RichardsonDPDK test applications, such as `dpdk-testpmd` are installed to 52add61c79SBruce Richardson`/usr/local/bin`. To use these applications, it is recommended that the 53add61c79SBruce Richardson`contigmem` and `nic_uio` kernel modules be loaded first, as described in 54add61c79SBruce Richardsonthe next section. 553e7b87ddSBruce Richardson 563e7b87ddSBruce Richardson.. note:: 573e7b87ddSBruce Richardson 58add61c79SBruce Richardson It is recommended that pkg-config be used to query information 59add61c79SBruce Richardson about the compiler and linker flags needed to build applications 60add61c79SBruce Richardson against DPDK. In some cases, the path `/usr/local/lib/pkgconfig` 61add61c79SBruce Richardson may not be in the default search paths for `.pc` files, which means 62add61c79SBruce Richardson that queries for DPDK information may fail. This can be fixed by 63add61c79SBruce Richardson setting the appropriate path in `PKG_CONFIG_PATH` environment 64add61c79SBruce Richardson variable. 653e7b87ddSBruce Richardson 663e7b87ddSBruce Richardson 673e7b87ddSBruce Richardson.. _loading_contigmem: 683e7b87ddSBruce Richardson 699c587847SSiobhan ButlerLoading the DPDK contigmem Module 709c587847SSiobhan Butler--------------------------------- 71dacdbfa4SBernard Iremonger 729c587847SSiobhan ButlerTo run a DPDK application, physically contiguous memory is required. 733e7b87ddSBruce RichardsonIn the absence of non-transparent superpages, the included sources for the 743e7b87ddSBruce Richardsoncontigmem kernel module provides the ability to present contiguous blocks of 759c587847SSiobhan Butlermemory for the DPDK to use. The contigmem module must be loaded into the 76d0cc4116SBruce Richardsonrunning kernel before any DPDK is run. Once DPDK is installed on the 77d0cc4116SBruce Richardsonsystem, the module can be found in the `/boot/modules` directory. 783e7b87ddSBruce Richardson 793e7b87ddSBruce RichardsonThe amount of physically contiguous memory along with the number of physically 803e7b87ddSBruce Richardsoncontiguous blocks to be reserved by the module can be set at runtime prior to 81d0cc4116SBruce Richardsonmodule loading using:: 823e7b87ddSBruce Richardson 83728c9e54SJohn McNamara kenv hw.contigmem.num_buffers=n 84728c9e54SJohn McNamara kenv hw.contigmem.buffer_size=m 853e7b87ddSBruce Richardson 863e7b87ddSBruce RichardsonThe kernel environment variables can also be specified during boot by placing the 87d0cc4116SBruce Richardsonfollowing in ``/boot/loader.conf``: 883e7b87ddSBruce Richardson 89d0cc4116SBruce Richardson.. code-block:: shell 903e7b87ddSBruce Richardson 91d0cc4116SBruce Richardson hw.contigmem.num_buffers=n 92d0cc4116SBruce Richardson hw.contigmem.buffer_size=m 933e7b87ddSBruce Richardson 94d0cc4116SBruce RichardsonThe variables can be inspected using the following command:: 953e7b87ddSBruce Richardson 96728c9e54SJohn McNamara sysctl -a hw.contigmem 973e7b87ddSBruce Richardson 983e7b87ddSBruce RichardsonWhere n is the number of blocks and m is the size in bytes of each area of 993e7b87ddSBruce Richardsoncontiguous memory. A default of two buffers of size 1073741824 bytes (1 Gigabyte) 1003e7b87ddSBruce Richardsoneach is set during module load if they are not specified in the environment. 1013e7b87ddSBruce Richardson 102d0cc4116SBruce RichardsonThe module can then be loaded using kldload:: 103dacdbfa4SBernard Iremonger 104d0cc4116SBruce Richardson kldload contigmem 105dacdbfa4SBernard Iremonger 106f9e2411aSBruce RichardsonIt is advisable to include the loading of the contigmem module during the boot 107f9e2411aSBruce Richardsonprocess to avoid issues with potential memory fragmentation during later system 108d0cc4116SBruce Richardsonup time. This can be achieved by placing lines similar to the following into 109d0cc4116SBruce Richardson``/boot/loader.conf``: 110dacdbfa4SBernard Iremonger 111d0cc4116SBruce Richardson.. code-block:: shell 112d0cc4116SBruce Richardson 113d0cc4116SBruce Richardson hw.contigmem.num_buffers=1 114d0cc4116SBruce Richardson hw.contigmem.buffer_size=1073741824 115dacdbfa4SBernard Iremonger contigmem_load="YES" 116dacdbfa4SBernard Iremonger 117dacdbfa4SBernard Iremonger.. note:: 118dacdbfa4SBernard Iremonger 119f9e2411aSBruce Richardson The contigmem_load directive should be placed after any definitions of 120728c9e54SJohn McNamara ``hw.contigmem.num_buffers`` and ``hw.contigmem.buffer_size`` if the default values 121f9e2411aSBruce Richardson are not to be used. 122dacdbfa4SBernard Iremonger 123d0cc4116SBruce RichardsonAn error such as:: 1243e7b87ddSBruce Richardson 125*6a74b08aSCiara Power kldload: can't load <build_dir>/kernel/freebsd/contigmem.ko: 126728c9e54SJohn McNamara Exec format error 1273e7b87ddSBruce Richardson 1283e7b87ddSBruce Richardsonis generally attributed to not having enough contiguous memory 129d0cc4116SBruce Richardsonavailable and can be verified via dmesg or ``/var/log/messages``:: 130dacdbfa4SBernard Iremonger 131dacdbfa4SBernard Iremonger kernel: contigmalloc failed for buffer <n> 132dacdbfa4SBernard Iremonger 133dacdbfa4SBernard IremongerTo avoid this error, reduce the number of buffers or the buffer size. 134dacdbfa4SBernard Iremonger 1353e7b87ddSBruce Richardson.. _loading_nic_uio: 1363e7b87ddSBruce Richardson 1379c587847SSiobhan ButlerLoading the DPDK nic_uio Module 1389c587847SSiobhan Butler------------------------------- 139dacdbfa4SBernard Iremonger 140af82892dSPablo de LaraAfter loading the contigmem module, the ``nic_uio`` module must also be loaded into the 141d0cc4116SBruce Richardsonrunning kernel prior to running any DPDK application, e.g. using:: 142dacdbfa4SBernard Iremonger 143d0cc4116SBruce Richardson kldload nic_uio 144dacdbfa4SBernard Iremonger 145dacdbfa4SBernard Iremonger.. note:: 146dacdbfa4SBernard Iremonger 1473e7b87ddSBruce Richardson If the ports to be used are currently bound to a existing kernel driver 148728c9e54SJohn McNamara then the ``hw.nic_uio.bdfs sysctl`` value will need to be set before loading the 1493e7b87ddSBruce Richardson module. Setting this value is described in the next section below. 150dacdbfa4SBernard Iremonger 151728c9e54SJohn McNamaraCurrently loaded modules can be seen by using the ``kldstat`` command and a module 152728c9e54SJohn McNamaracan be removed from the running kernel by using ``kldunload <module_name>``. 1533e7b87ddSBruce Richardson 154d0cc4116SBruce RichardsonTo load the module during boot place the following into ``/boot/loader.conf``: 155d0cc4116SBruce Richardson 156d0cc4116SBruce Richardson.. code-block:: shell 157dacdbfa4SBernard Iremonger 158dacdbfa4SBernard Iremonger nic_uio_load="YES" 159dacdbfa4SBernard Iremonger 160dacdbfa4SBernard Iremonger.. note:: 161dacdbfa4SBernard Iremonger 162728c9e54SJohn McNamara ``nic_uio_load="YES"`` must appear after the contigmem_load directive, if it exists. 163dacdbfa4SBernard Iremonger 164728c9e54SJohn McNamaraBy default, the ``nic_uio`` module will take ownership of network ports if they are 1659c587847SSiobhan Butlerrecognized DPDK devices and are not owned by another module. However, since 1663e7b87ddSBruce Richardsonthe FreeBSD kernel includes support, either built-in, or via a separate driver 1673e7b87ddSBruce Richardsonmodule, for most network card devices, it is likely that the ports to be used are 168728c9e54SJohn McNamaraalready bound to a driver other than ``nic_uio``. The following sub-section describe 1693e7b87ddSBruce Richardsonhow to query and modify the device ownership of the ports to be used by 1709c587847SSiobhan ButlerDPDK applications. 171dacdbfa4SBernard Iremonger 1723e7b87ddSBruce Richardson.. _binding_network_ports: 173dacdbfa4SBernard Iremonger 1743e7b87ddSBruce RichardsonBinding Network Ports to the nic_uio Module 1753e7b87ddSBruce Richardson~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1763e7b87ddSBruce Richardson 1773e7b87ddSBruce RichardsonDevice ownership can be viewed using the pciconf -l command. The example below shows 178728c9e54SJohn McNamarafour Intel® 82599 network ports under ``if_ixgbe`` module ownership. 179dacdbfa4SBernard Iremonger 180d0cc4116SBruce Richardson.. code-block:: none 181dacdbfa4SBernard Iremonger 182728c9e54SJohn McNamara pciconf -l 183dacdbfa4SBernard Iremonger ix0@pci0:1:0:0: class=0x020000 card=0x00038086 chip=0x10fb8086 rev=0x01 hdr=0x00 184dacdbfa4SBernard Iremonger ix1@pci0:1:0:1: class=0x020000 card=0x00038086 chip=0x10fb8086 rev=0x01 hdr=0x00 185dacdbfa4SBernard Iremonger ix2@pci0:2:0:0: class=0x020000 card=0x00038086 chip=0x10fb8086 rev=0x01 hdr=0x00 186dacdbfa4SBernard Iremonger ix3@pci0:2:0:1: class=0x020000 card=0x00038086 chip=0x10fb8086 rev=0x01 hdr=0x00 187dacdbfa4SBernard Iremonger 188dacdbfa4SBernard IremongerThe first column constitutes three components: 189dacdbfa4SBernard Iremonger 190728c9e54SJohn McNamara#. Device name: ``ixN`` 191dacdbfa4SBernard Iremonger 192728c9e54SJohn McNamara#. Unit name: ``pci0`` 193dacdbfa4SBernard Iremonger 194728c9e54SJohn McNamara#. Selector (Bus:Device:Function): ``1:0:0`` 195dacdbfa4SBernard Iremonger 196728c9e54SJohn McNamaraWhere no driver is associated with a device, the device name will be ``none``. 197dacdbfa4SBernard Iremonger 198728c9e54SJohn McNamaraBy default, the FreeBSD kernel will include built-in drivers for the most common 199f9e2411aSBruce Richardsondevices; a kernel rebuild would normally be required to either remove the drivers 200f9e2411aSBruce Richardsonor configure them as loadable modules. 201dacdbfa4SBernard Iremonger 202728c9e54SJohn McNamaraTo avoid building a custom kernel, the ``nic_uio`` module can detach a network port 203728c9e54SJohn McNamarafrom its current device driver. This is achieved by setting the ``hw.nic_uio.bdfs`` 204728c9e54SJohn McNamarakernel environment variable prior to loading ``nic_uio``, as follows:: 205dacdbfa4SBernard Iremonger 206d0cc4116SBruce Richardson kenv hw.nic_uio.bdfs="b:d:f,b:d:f,..." 207dacdbfa4SBernard Iremonger 208f9e2411aSBruce RichardsonWhere a comma separated list of selectors is set, the list must not contain any 209f9e2411aSBruce Richardsonwhitespace. 210dacdbfa4SBernard Iremonger 211728c9e54SJohn McNamaraFor example to re-bind ``ix2@pci0:2:0:0`` and ``ix3@pci0:2:0:1`` to the ``nic_uio`` module 212728c9e54SJohn McNamaraupon loading, use the following command:: 213dacdbfa4SBernard Iremonger 214dacdbfa4SBernard Iremonger kenv hw.nic_uio.bdfs="2:0:0,2:0:1" 215dacdbfa4SBernard Iremonger 216f9e2411aSBruce RichardsonThe variable can also be specified during boot by placing the following into 217728c9e54SJohn McNamara``/boot/loader.conf``, before the previously-described ``nic_uio_load`` line - as 218d0cc4116SBruce Richardsonshown: 219d0cc4116SBruce Richardson 220d0cc4116SBruce Richardson.. code-block:: shell 221dacdbfa4SBernard Iremonger 222dacdbfa4SBernard Iremonger hw.nic_uio.bdfs="2:0:0,2:0:1" 2233e7b87ddSBruce Richardson nic_uio_load="YES" 224dacdbfa4SBernard Iremonger 2253e7b87ddSBruce RichardsonBinding Network Ports Back to their Original Kernel Driver 2263e7b87ddSBruce Richardson~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 227dacdbfa4SBernard Iremonger 2283e7b87ddSBruce RichardsonIf the original driver for a network port has been compiled into the kernel, 229728c9e54SJohn McNamarait is necessary to reboot FreeBSD to restore the original device binding. Before 230728c9e54SJohn McNamaradoing so, update or remove the ``hw.nic_uio.bdfs`` in ``/boot/loader.conf``. 231dacdbfa4SBernard Iremonger 232f9e2411aSBruce RichardsonIf rebinding to a driver that is a loadable module, the network port binding can 2333e7b87ddSBruce Richardsonbe reset without rebooting. To do so, unload both the target kernel module and the 234728c9e54SJohn McNamara``nic_uio`` module, modify or clear the ``hw.nic_uio.bdfs`` kernel environment (kenv) 2353e7b87ddSBruce Richardsonvalue, and reload the two drivers - first the original kernel driver, and then 236728c9e54SJohn McNamarathe ``nic_uio driver``. Note: the latter does not need to be reloaded unless there are 237728c9e54SJohn McNamaraports that are still to be bound to it. 238dacdbfa4SBernard Iremonger 239d0cc4116SBruce RichardsonExample commands to perform these steps are shown below:: 240dacdbfa4SBernard Iremonger 241dacdbfa4SBernard Iremonger kldunload nic_uio 242dacdbfa4SBernard Iremonger kldunload <original_driver> 243dacdbfa4SBernard Iremonger 244728c9e54SJohn McNamara # To clear the value completely: 245728c9e54SJohn McNamara kenv -u hw.nic_uio.bdfs 246dacdbfa4SBernard Iremonger 247728c9e54SJohn McNamara # To update the list of ports to bind: 248728c9e54SJohn McNamara kenv hw.nic_uio.bdfs="b:d:f,b:d:f,..." 249dacdbfa4SBernard Iremonger 250dacdbfa4SBernard Iremonger kldload <original_driver> 251dacdbfa4SBernard Iremonger 2523e7b87ddSBruce Richardson kldload nic_uio # optional 253