1 .. SPDX-License-Identifier: BSD-3-Clause
2 Copyright(c) 2010-2014 Intel Corporation.
4 .. _compiling_sample_apps:
6 Compiling and Running Sample Applications
7 =========================================
9 The chapter describes how to compile and run applications in a DPDK
10 environment. It also provides a pointer to where sample applications are stored.
12 Compiling a Sample Application
13 ------------------------------
15 Once a DPDK target environment directory has been created (such as
16 ``x86_64-native-bsdapp-clang``), it contains all libraries and header files required
17 to build an application.
19 When compiling an application in the FreeBSD environment on the DPDK,
20 the following variables must be exported:
22 * ``RTE_SDK`` - Points to the DPDK installation directory.
24 * ``RTE_TARGET`` - Points to the DPDK target environment directory.
25 For FreeBSD, this is the ``x86_64-native-bsdapp-clang`` or
26 ``x86_64-native-bsdapp-gcc`` directory.
28 The following is an example of creating the ``helloworld`` application, which runs
29 in the DPDK FreeBSD environment. While the example demonstrates compiling
30 using gcc version 4.9, compiling with clang will be similar, except that the ``CC=``
31 parameter can probably be omitted. The ``helloworld`` example may be found in the
32 ``${RTE_SDK}/examples`` directory.
34 The directory contains the ``main.c`` file. This file, when combined with the
35 libraries in the DPDK target environment, calls the various functions to
36 initialize the DPDK environment, then launches an entry point (dispatch
37 application) for each core to be utilized. By default, the binary is generated
38 in the build directory.
40 .. code-block:: console
42 setenv RTE_SDK /home/user/DPDK
44 cd examples/helloworld/
45 setenv RTE_SDK $HOME/DPDK
46 setenv RTE_TARGET x86_64-native-bsdapp-gcc
51 INSTALL-APP helloworld
52 INSTALL-MAP helloworld.map
55 helloworld helloworld.map
59 In the above example, ``helloworld`` was in the directory structure of the
60 DPDK. However, it could have been located outside the directory
61 structure to keep the DPDK structure intact. In the following case,
62 the ``helloworld`` application is copied to a new directory as a new starting
65 .. code-block:: console
67 setenv RTE_SDK /home/user/DPDK
68 cp -r $(RTE_SDK)/examples/helloworld my_rte_app
70 setenv RTE_TARGET x86_64-native-bsdapp-gcc
75 INSTALL-APP helloworld
76 INSTALL-MAP helloworld.map
78 .. _running_sample_app:
80 Running a Sample Application
81 ----------------------------
83 #. The ``contigmem`` and ``nic_uio`` modules must be set up prior to running an application.
85 #. Any ports to be used by the application must be already bound to the ``nic_uio`` module,
86 as described in section :ref:`binding_network_ports`, prior to running the application.
87 The application is linked with the DPDK target environment's Environment
88 Abstraction Layer (EAL) library, which provides some options that are generic
89 to every DPDK application.
91 The following is the list of options that can be given to the EAL:
93 .. code-block:: console
95 ./rte-app -l CORELIST [-n NUM] [-b <domain:bus:devid.func>] \
96 [-r NUM] [-v] [--proc-type <primary|secondary|auto>]
100 EAL has a common interface between all operating systems and is based on the
101 Linux notation for PCI devices. For example, a FreeBSD device selector of
102 ``pci0:2:0:1`` is referred to as ``02:00.1`` in EAL.
104 The EAL options for FreeBSD are as follows:
106 * ``-c COREMASK`` or ``-l CORELIST``:
107 A hexadecimal bit mask of the cores to run on. Note that core numbering
108 can change between platforms and should be determined beforehand. The corelist
109 is a list of cores to use instead of a core mask.
112 Number of memory channels per processor socket.
114 * ``-b <domain:bus:devid.func>``:
115 Blacklisting of ports; prevent EAL from using specified PCI device
116 (multiple ``-b`` options are allowed).
119 Use the specified Ethernet device(s) only. Use comma-separate
120 ``[domain:]bus:devid.func`` values. Cannot be used with ``-b`` option.
123 Number of memory ranks.
126 Display version information on startup.
129 The type of process instance.
132 Memory to allocate from hugepages, regardless of processor socket.
134 Other options, specific to Linux and are not supported under FreeBSD are as follows:
137 Memory to allocate from hugepages on specific sockets.
140 The directory where hugetlbfs is mounted.
142 * ``mbuf-pool-ops-name``:
143 Pool ops name for mbuf to use.
146 The prefix text used for hugepage filenames.
148 The ``-c`` or ``-l`` option is mandatory; the others are optional.
150 Copy the DPDK application binary to your target, then run the application
151 as follows (assuming the platform has four memory channels, and that cores 0-3
152 are present and are to be used for running the application)::
154 ./helloworld -l 0-3 -n 4
158 The ``--proc-type`` and ``--file-prefix`` EAL options are used for running multiple
159 DPDK processes. See the "Multi-process Sample Application" chapter
160 in the *DPDK Sample Applications User Guide and the DPDK
161 Programmers Guide* for more details.
163 .. _running_non_root:
165 Running DPDK Applications Without Root Privileges
166 -------------------------------------------------
168 Although applications using the DPDK use network ports and other hardware
169 resources directly, with a number of small permission adjustments, it is possible
170 to run these applications as a user other than "root". To do so, the ownership,
171 or permissions, on the following file system objects should be adjusted to ensure
172 that the user account being used to run the DPDK application has access
175 * The userspace-io device files in ``/dev``, for example, ``/dev/uio0``, ``/dev/uio1``, and so on
177 * The userspace contiguous memory device: ``/dev/contigmem``
181 Please refer to the DPDK Release Notes for supported applications.