15630257fSFerruh Yigit.. SPDX-License-Identifier: BSD-3-Clause 25630257fSFerruh Yigit Copyright(c) 2010-2014 Intel Corporation. 3dacdbfa4SBernard Iremonger 49e6f75e2SBruce Richardson.. include:: <isonum.txt> 59e6f75e2SBruce Richardson 63e7b87ddSBruce Richardson.. _building_from_source: 73e7b87ddSBruce Richardson 89c587847SSiobhan ButlerCompiling the DPDK Target from Source 99c587847SSiobhan Butler===================================== 10dacdbfa4SBernard Iremonger 11add61c79SBruce RichardsonPrerequisites 12add61c79SBruce Richardson------------- 133e7b87ddSBruce Richardson 14add61c79SBruce RichardsonThe following FreeBSD packages are required to build DPDK: 153e7b87ddSBruce Richardson 16add61c79SBruce Richardson* meson 17add61c79SBruce Richardson* ninja 18add61c79SBruce Richardson* pkgconf 199e6f75e2SBruce Richardson* py38-pyelftools 209e6f75e2SBruce Richardson 219e6f75e2SBruce Richardson.. note: 229e6f75e2SBruce Richardson 239e6f75e2SBruce Richardson The specific package for pyelftools is dependent on the version of python in use, 249e6f75e2SBruce Richardson Python 3.8 being the version at type of writing, hence the ``py38`` prefix. 253e7b87ddSBruce Richardson 26add61c79SBruce RichardsonThese can be installed using (as root):: 273e7b87ddSBruce Richardson 289e6f75e2SBruce Richardson pkg install meson pkgconf py38-pyelftools 293e7b87ddSBruce Richardson 30add61c79SBruce RichardsonTo compile the required kernel modules for memory management and working 31add61c79SBruce Richardsonwith physical NIC devices, the kernel sources for FreeBSD also 32add61c79SBruce Richardsonneed to be installed. If not already present on the system, these can be 33add61c79SBruce Richardsoninstalled via commands like the following, for FreeBSD 12.1 on x86_64:: 343e7b87ddSBruce Richardson 35add61c79SBruce Richardson fetch http://ftp.freebsd.org/pub/FreeBSD/releases/amd64/12.1-RELEASE/src.txz 36add61c79SBruce Richardson tar -C / -xJvf src.txz 373e7b87ddSBruce Richardson 38add61c79SBruce RichardsonIndividual drivers may have additional requirements. Consult the relevant 39add61c79SBruce Richardsondriver guide for any driver-specific requirements of interest. 403e7b87ddSBruce Richardson 41add61c79SBruce RichardsonBuilding DPDK 42add61c79SBruce Richardson------------- 433e7b87ddSBruce Richardson 44add61c79SBruce RichardsonThe following commands can be used to build and install DPDK on a system. 45add61c79SBruce RichardsonThe final, install, step generally needs to be run as root:: 463e7b87ddSBruce Richardson 47e24b8ad4SStephen Hemminger meson setup build 48add61c79SBruce Richardson cd build 49add61c79SBruce Richardson ninja 509599c59bSBruce Richardson meson install 513e7b87ddSBruce Richardson 52add61c79SBruce RichardsonThis will install the DPDK libraries and drivers to `/usr/local/lib` with a 53add61c79SBruce Richardsonpkg-config file `libdpdk.pc` installed to `/usr/local/lib/pkgconfig`. The 54add61c79SBruce RichardsonDPDK test applications, such as `dpdk-testpmd` are installed to 55add61c79SBruce Richardson`/usr/local/bin`. To use these applications, it is recommended that the 56add61c79SBruce Richardson`contigmem` and `nic_uio` kernel modules be loaded first, as described in 57add61c79SBruce Richardsonthe next section. 583e7b87ddSBruce Richardson 593e7b87ddSBruce Richardson.. note:: 603e7b87ddSBruce Richardson 61add61c79SBruce Richardson It is recommended that pkg-config be used to query information 62add61c79SBruce Richardson about the compiler and linker flags needed to build applications 63add61c79SBruce Richardson against DPDK. In some cases, the path `/usr/local/lib/pkgconfig` 64add61c79SBruce Richardson may not be in the default search paths for `.pc` files, which means 65add61c79SBruce Richardson that queries for DPDK information may fail. This can be fixed by 66add61c79SBruce Richardson setting the appropriate path in `PKG_CONFIG_PATH` environment 67add61c79SBruce Richardson variable. 683e7b87ddSBruce Richardson 693e7b87ddSBruce Richardson 703e7b87ddSBruce Richardson.. _loading_contigmem: 713e7b87ddSBruce Richardson 729c587847SSiobhan ButlerLoading the DPDK contigmem Module 739c587847SSiobhan Butler--------------------------------- 74dacdbfa4SBernard Iremonger 759c587847SSiobhan ButlerTo run a DPDK application, physically contiguous memory is required. 763e7b87ddSBruce RichardsonIn the absence of non-transparent superpages, the included sources for the 773e7b87ddSBruce Richardsoncontigmem kernel module provides the ability to present contiguous blocks of 789c587847SSiobhan Butlermemory for the DPDK to use. The contigmem module must be loaded into the 79d0cc4116SBruce Richardsonrunning kernel before any DPDK is run. Once DPDK is installed on the 80d0cc4116SBruce Richardsonsystem, the module can be found in the `/boot/modules` directory. 813e7b87ddSBruce Richardson 823e7b87ddSBruce RichardsonThe amount of physically contiguous memory along with the number of physically 833e7b87ddSBruce Richardsoncontiguous blocks to be reserved by the module can be set at runtime prior to 84d0cc4116SBruce Richardsonmodule loading using:: 853e7b87ddSBruce Richardson 86728c9e54SJohn McNamara kenv hw.contigmem.num_buffers=n 87728c9e54SJohn McNamara kenv hw.contigmem.buffer_size=m 883e7b87ddSBruce Richardson 89*cbe57f35SDmitry KozlyukWhere n is the number of blocks and m is the size in bytes of each area of contiguous memory. 90*cbe57f35SDmitry KozlyukA default of two buffers of size 1073741824 bytes (1 Gigabyte) each 91*cbe57f35SDmitry Kozlyukis set during module load if they are not specified in the environment. 92*cbe57f35SDmitry Kozlyuk 93*cbe57f35SDmitry KozlyukBuffers are excluded from core dump by default. 94*cbe57f35SDmitry KozlyukMapped buffers can be included in core dump using the following tunable:: 95*cbe57f35SDmitry Kozlyuk 96*cbe57f35SDmitry Kozlyuk hw.contigmem.coredump_enable=1 97*cbe57f35SDmitry Kozlyuk 98*cbe57f35SDmitry Kozlyuk.. note:: 99*cbe57f35SDmitry Kozlyuk 100*cbe57f35SDmitry Kozlyuk Including contigmem buffers in core dump file increases its size, 101*cbe57f35SDmitry Kozlyuk which may fill the storage or overload the transport. 102*cbe57f35SDmitry Kozlyuk Buffers typically hold data processed by the application, 103*cbe57f35SDmitry Kozlyuk like network packets, which may contain sensitive information. 104*cbe57f35SDmitry Kozlyuk 1053e7b87ddSBruce RichardsonThe kernel environment variables can also be specified during boot by placing the 106d0cc4116SBruce Richardsonfollowing in ``/boot/loader.conf``: 1073e7b87ddSBruce Richardson 108d0cc4116SBruce Richardson.. code-block:: shell 1093e7b87ddSBruce Richardson 110d0cc4116SBruce Richardson hw.contigmem.num_buffers=n 111d0cc4116SBruce Richardson hw.contigmem.buffer_size=m 112*cbe57f35SDmitry Kozlyuk hw.contigmem.coredump_enable=1 1133e7b87ddSBruce Richardson 114d0cc4116SBruce RichardsonThe variables can be inspected using the following command:: 1153e7b87ddSBruce Richardson 116728c9e54SJohn McNamara sysctl -a hw.contigmem 1173e7b87ddSBruce Richardson 118d0cc4116SBruce RichardsonThe module can then be loaded using kldload:: 119dacdbfa4SBernard Iremonger 120d0cc4116SBruce Richardson kldload contigmem 121dacdbfa4SBernard Iremonger 122f9e2411aSBruce RichardsonIt is advisable to include the loading of the contigmem module during the boot 123f9e2411aSBruce Richardsonprocess to avoid issues with potential memory fragmentation during later system 124d0cc4116SBruce Richardsonup time. This can be achieved by placing lines similar to the following into 125d0cc4116SBruce Richardson``/boot/loader.conf``: 126dacdbfa4SBernard Iremonger 127d0cc4116SBruce Richardson.. code-block:: shell 128d0cc4116SBruce Richardson 129d0cc4116SBruce Richardson hw.contigmem.num_buffers=1 130d0cc4116SBruce Richardson hw.contigmem.buffer_size=1073741824 131*cbe57f35SDmitry Kozlyuk hw.contigmem.coredump_enable=1 132dacdbfa4SBernard Iremonger contigmem_load="YES" 133dacdbfa4SBernard Iremonger 134dacdbfa4SBernard Iremonger.. note:: 135dacdbfa4SBernard Iremonger 136*cbe57f35SDmitry Kozlyuk The ``contigmem_load`` directive should be placed after any definitions 137*cbe57f35SDmitry Kozlyuk of ``hw.contigmem.*`` if the default values are not to be used. 138dacdbfa4SBernard Iremonger 139d0cc4116SBruce RichardsonAn error such as:: 1403e7b87ddSBruce Richardson 1416a74b08aSCiara Power kldload: can't load <build_dir>/kernel/freebsd/contigmem.ko: 142728c9e54SJohn McNamara Exec format error 1433e7b87ddSBruce Richardson 1443e7b87ddSBruce Richardsonis generally attributed to not having enough contiguous memory 145d0cc4116SBruce Richardsonavailable and can be verified via dmesg or ``/var/log/messages``:: 146dacdbfa4SBernard Iremonger 147dacdbfa4SBernard Iremonger kernel: contigmalloc failed for buffer <n> 148dacdbfa4SBernard Iremonger 149dacdbfa4SBernard IremongerTo avoid this error, reduce the number of buffers or the buffer size. 150dacdbfa4SBernard Iremonger 1513e7b87ddSBruce Richardson.. _loading_nic_uio: 1523e7b87ddSBruce Richardson 1539c587847SSiobhan ButlerLoading the DPDK nic_uio Module 1549c587847SSiobhan Butler------------------------------- 155dacdbfa4SBernard Iremonger 156af82892dSPablo de LaraAfter loading the contigmem module, the ``nic_uio`` module must also be loaded into the 157d0cc4116SBruce Richardsonrunning kernel prior to running any DPDK application, e.g. using:: 158dacdbfa4SBernard Iremonger 159d0cc4116SBruce Richardson kldload nic_uio 160dacdbfa4SBernard Iremonger 161dacdbfa4SBernard Iremonger.. note:: 162dacdbfa4SBernard Iremonger 1633e7b87ddSBruce Richardson If the ports to be used are currently bound to a existing kernel driver 164728c9e54SJohn McNamara then the ``hw.nic_uio.bdfs sysctl`` value will need to be set before loading the 1653e7b87ddSBruce Richardson module. Setting this value is described in the next section below. 166dacdbfa4SBernard Iremonger 167728c9e54SJohn McNamaraCurrently loaded modules can be seen by using the ``kldstat`` command and a module 168728c9e54SJohn McNamaracan be removed from the running kernel by using ``kldunload <module_name>``. 1693e7b87ddSBruce Richardson 170d0cc4116SBruce RichardsonTo load the module during boot place the following into ``/boot/loader.conf``: 171d0cc4116SBruce Richardson 172d0cc4116SBruce Richardson.. code-block:: shell 173dacdbfa4SBernard Iremonger 174dacdbfa4SBernard Iremonger nic_uio_load="YES" 175dacdbfa4SBernard Iremonger 176dacdbfa4SBernard Iremonger.. note:: 177dacdbfa4SBernard Iremonger 178728c9e54SJohn McNamara ``nic_uio_load="YES"`` must appear after the contigmem_load directive, if it exists. 179dacdbfa4SBernard Iremonger 180728c9e54SJohn McNamaraBy default, the ``nic_uio`` module will take ownership of network ports if they are 1819c587847SSiobhan Butlerrecognized DPDK devices and are not owned by another module. However, since 1823e7b87ddSBruce Richardsonthe FreeBSD kernel includes support, either built-in, or via a separate driver 1833e7b87ddSBruce Richardsonmodule, for most network card devices, it is likely that the ports to be used are 184728c9e54SJohn McNamaraalready bound to a driver other than ``nic_uio``. The following sub-section describe 1853e7b87ddSBruce Richardsonhow to query and modify the device ownership of the ports to be used by 1869c587847SSiobhan ButlerDPDK applications. 187dacdbfa4SBernard Iremonger 1883e7b87ddSBruce Richardson.. _binding_network_ports: 189dacdbfa4SBernard Iremonger 1903e7b87ddSBruce RichardsonBinding Network Ports to the nic_uio Module 1913e7b87ddSBruce Richardson~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1923e7b87ddSBruce Richardson 1933e7b87ddSBruce RichardsonDevice ownership can be viewed using the pciconf -l command. The example below shows 1949e6f75e2SBruce Richardsonfour Intel\ |reg| 82599 network ports under ``if_ixgbe`` module ownership. 195dacdbfa4SBernard Iremonger 196d0cc4116SBruce Richardson.. code-block:: none 197dacdbfa4SBernard Iremonger 198728c9e54SJohn McNamara pciconf -l 199dacdbfa4SBernard Iremonger ix0@pci0:1:0:0: class=0x020000 card=0x00038086 chip=0x10fb8086 rev=0x01 hdr=0x00 200dacdbfa4SBernard Iremonger ix1@pci0:1:0:1: class=0x020000 card=0x00038086 chip=0x10fb8086 rev=0x01 hdr=0x00 201dacdbfa4SBernard Iremonger ix2@pci0:2:0:0: class=0x020000 card=0x00038086 chip=0x10fb8086 rev=0x01 hdr=0x00 202dacdbfa4SBernard Iremonger ix3@pci0:2:0:1: class=0x020000 card=0x00038086 chip=0x10fb8086 rev=0x01 hdr=0x00 203dacdbfa4SBernard Iremonger 204dacdbfa4SBernard IremongerThe first column constitutes three components: 205dacdbfa4SBernard Iremonger 206728c9e54SJohn McNamara#. Device name: ``ixN`` 207dacdbfa4SBernard Iremonger 208728c9e54SJohn McNamara#. Unit name: ``pci0`` 209dacdbfa4SBernard Iremonger 210728c9e54SJohn McNamara#. Selector (Bus:Device:Function): ``1:0:0`` 211dacdbfa4SBernard Iremonger 212728c9e54SJohn McNamaraWhere no driver is associated with a device, the device name will be ``none``. 213dacdbfa4SBernard Iremonger 214728c9e54SJohn McNamaraBy default, the FreeBSD kernel will include built-in drivers for the most common 215f9e2411aSBruce Richardsondevices; a kernel rebuild would normally be required to either remove the drivers 216f9e2411aSBruce Richardsonor configure them as loadable modules. 217dacdbfa4SBernard Iremonger 218728c9e54SJohn McNamaraTo avoid building a custom kernel, the ``nic_uio`` module can detach a network port 219728c9e54SJohn McNamarafrom its current device driver. This is achieved by setting the ``hw.nic_uio.bdfs`` 220728c9e54SJohn McNamarakernel environment variable prior to loading ``nic_uio``, as follows:: 221dacdbfa4SBernard Iremonger 222d0cc4116SBruce Richardson kenv hw.nic_uio.bdfs="b:d:f,b:d:f,..." 223dacdbfa4SBernard Iremonger 224f9e2411aSBruce RichardsonWhere a comma separated list of selectors is set, the list must not contain any 225f9e2411aSBruce Richardsonwhitespace. 226dacdbfa4SBernard Iremonger 227728c9e54SJohn McNamaraFor example to re-bind ``ix2@pci0:2:0:0`` and ``ix3@pci0:2:0:1`` to the ``nic_uio`` module 228728c9e54SJohn McNamaraupon loading, use the following command:: 229dacdbfa4SBernard Iremonger 230dacdbfa4SBernard Iremonger kenv hw.nic_uio.bdfs="2:0:0,2:0:1" 231dacdbfa4SBernard Iremonger 232f9e2411aSBruce RichardsonThe variable can also be specified during boot by placing the following into 233728c9e54SJohn McNamara``/boot/loader.conf``, before the previously-described ``nic_uio_load`` line - as 234d0cc4116SBruce Richardsonshown: 235d0cc4116SBruce Richardson 236d0cc4116SBruce Richardson.. code-block:: shell 237dacdbfa4SBernard Iremonger 238dacdbfa4SBernard Iremonger hw.nic_uio.bdfs="2:0:0,2:0:1" 2393e7b87ddSBruce Richardson nic_uio_load="YES" 240dacdbfa4SBernard Iremonger 2413e7b87ddSBruce RichardsonBinding Network Ports Back to their Original Kernel Driver 2423e7b87ddSBruce Richardson~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 243dacdbfa4SBernard Iremonger 2443e7b87ddSBruce RichardsonIf the original driver for a network port has been compiled into the kernel, 245728c9e54SJohn McNamarait is necessary to reboot FreeBSD to restore the original device binding. Before 246728c9e54SJohn McNamaradoing so, update or remove the ``hw.nic_uio.bdfs`` in ``/boot/loader.conf``. 247dacdbfa4SBernard Iremonger 248f9e2411aSBruce RichardsonIf rebinding to a driver that is a loadable module, the network port binding can 2493e7b87ddSBruce Richardsonbe reset without rebooting. To do so, unload both the target kernel module and the 250728c9e54SJohn McNamara``nic_uio`` module, modify or clear the ``hw.nic_uio.bdfs`` kernel environment (kenv) 2513e7b87ddSBruce Richardsonvalue, and reload the two drivers - first the original kernel driver, and then 252728c9e54SJohn McNamarathe ``nic_uio driver``. Note: the latter does not need to be reloaded unless there are 253728c9e54SJohn McNamaraports that are still to be bound to it. 254dacdbfa4SBernard Iremonger 255d0cc4116SBruce RichardsonExample commands to perform these steps are shown below:: 256dacdbfa4SBernard Iremonger 257dacdbfa4SBernard Iremonger kldunload nic_uio 258dacdbfa4SBernard Iremonger kldunload <original_driver> 259dacdbfa4SBernard Iremonger 260728c9e54SJohn McNamara # To clear the value completely: 261728c9e54SJohn McNamara kenv -u hw.nic_uio.bdfs 262dacdbfa4SBernard Iremonger 263728c9e54SJohn McNamara # To update the list of ports to bind: 264728c9e54SJohn McNamara kenv hw.nic_uio.bdfs="b:d:f,b:d:f,..." 265dacdbfa4SBernard Iremonger 266dacdbfa4SBernard Iremonger kldload <original_driver> 267dacdbfa4SBernard Iremonger 2683e7b87ddSBruce Richardson kldload nic_uio # optional 269