11ab07743SBernard Iremonger.. BSD LICENSE 21ab07743SBernard Iremonger Copyright(c) 2010-2014 Intel Corporation. All rights reserved. 31ab07743SBernard Iremonger All rights reserved. 41ab07743SBernard Iremonger 51ab07743SBernard Iremonger Redistribution and use in source and binary forms, with or without 61ab07743SBernard Iremonger modification, are permitted provided that the following conditions 71ab07743SBernard Iremonger are met: 81ab07743SBernard Iremonger 91ab07743SBernard Iremonger * Redistributions of source code must retain the above copyright 101ab07743SBernard Iremonger notice, this list of conditions and the following disclaimer. 111ab07743SBernard Iremonger * Redistributions in binary form must reproduce the above copyright 121ab07743SBernard Iremonger notice, this list of conditions and the following disclaimer in 131ab07743SBernard Iremonger the documentation and/or other materials provided with the 141ab07743SBernard Iremonger distribution. 151ab07743SBernard Iremonger * Neither the name of Intel Corporation nor the names of its 161ab07743SBernard Iremonger contributors may be used to endorse or promote products derived 171ab07743SBernard Iremonger from this software without specific prior written permission. 181ab07743SBernard Iremonger 191ab07743SBernard Iremonger THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 201ab07743SBernard Iremonger "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 211ab07743SBernard Iremonger LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 221ab07743SBernard Iremonger A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 231ab07743SBernard Iremonger OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 241ab07743SBernard Iremonger SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 251ab07743SBernard Iremonger LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 261ab07743SBernard Iremonger DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 271ab07743SBernard Iremonger THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 281ab07743SBernard Iremonger (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 291ab07743SBernard Iremonger OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 301ab07743SBernard Iremonger 311ab07743SBernard IremongerCompiling and Running Sample Applications 321ab07743SBernard Iremonger========================================= 331ab07743SBernard Iremonger 342e486e26SSiobhan ButlerThe chapter describes how to compile and run applications in an DPDK environment. 351ab07743SBernard IremongerIt also provides a pointer to where sample applications are stored. 361ab07743SBernard Iremonger 371ab07743SBernard Iremonger.. note:: 381ab07743SBernard Iremonger 3929c67340SJohn McNamara Parts of this process can also be done using the setup script described the 4029c67340SJohn McNamara :ref:`linux_setup_script` section of this document. 411ab07743SBernard Iremonger 421ab07743SBernard IremongerCompiling a Sample Application 431ab07743SBernard Iremonger------------------------------ 441ab07743SBernard Iremonger 4529c67340SJohn McNamaraOnce an DPDK target environment directory has been created (such as ``x86_64-native-linuxapp-gcc``), 461ab07743SBernard Iremongerit contains all libraries and header files required to build an application. 471ab07743SBernard Iremonger 482e486e26SSiobhan ButlerWhen compiling an application in the Linux* environment on the DPDK, the following variables must be exported: 491ab07743SBernard Iremonger 5029c67340SJohn McNamara* ``RTE_SDK`` - Points to the DPDK installation directory. 511ab07743SBernard Iremonger 5229c67340SJohn McNamara* ``RTE_TARGET`` - Points to the DPDK target environment directory. 531ab07743SBernard Iremonger 5429c67340SJohn McNamaraThe following is an example of creating the ``helloworld`` application, which runs in the DPDK Linux environment. 5529c67340SJohn McNamaraThis example may be found in the ``${RTE_SDK}/examples`` directory. 561ab07743SBernard Iremonger 5729c67340SJohn McNamaraThe directory contains the ``main.c`` file. This file, when combined with the libraries in the DPDK target environment, 582e486e26SSiobhan Butlercalls the various functions to initialize the DPDK environment, 591ab07743SBernard Iremongerthen launches an entry point (dispatch application) for each core to be utilized. 601ab07743SBernard IremongerBy default, the binary is generated in the build directory. 611ab07743SBernard Iremonger 621ab07743SBernard Iremonger.. code-block:: console 631ab07743SBernard Iremonger 6429c67340SJohn McNamara cd examples/helloworld/ 6529c67340SJohn McNamara export RTE_SDK=$HOME/DPDK 6629c67340SJohn McNamara export RTE_TARGET=x86_64-native-linuxapp-gcc 6729c67340SJohn McNamara 6829c67340SJohn McNamara make 691ab07743SBernard Iremonger CC main.o 701ab07743SBernard Iremonger LD helloworld 711ab07743SBernard Iremonger INSTALL-APP helloworld 721ab07743SBernard Iremonger INSTALL-MAP helloworld.map 731ab07743SBernard Iremonger 7429c67340SJohn McNamara ls build/app 751ab07743SBernard Iremonger helloworld helloworld.map 761ab07743SBernard Iremonger 771ab07743SBernard Iremonger.. note:: 781ab07743SBernard Iremonger 7929c67340SJohn McNamara In the above example, ``helloworld`` was in the directory structure of the DPDK. 802e486e26SSiobhan Butler However, it could have been located outside the directory structure to keep the DPDK structure intact. 8129c67340SJohn McNamara In the following case, the ``helloworld`` application is copied to a new directory as a new starting point. 821ab07743SBernard Iremonger 831ab07743SBernard Iremonger .. code-block:: console 841ab07743SBernard Iremonger 8529c67340SJohn McNamara export RTE_SDK=/home/user/DPDK 8629c67340SJohn McNamara cp -r $(RTE_SDK)/examples/helloworld my_rte_app 8729c67340SJohn McNamara cd my_rte_app/ 8829c67340SJohn McNamara export RTE_TARGET=x86_64-native-linuxapp-gcc 8929c67340SJohn McNamara 9029c67340SJohn McNamara make 911ab07743SBernard Iremonger CC main.o 921ab07743SBernard Iremonger LD helloworld 931ab07743SBernard Iremonger INSTALL-APP helloworld 941ab07743SBernard Iremonger INSTALL-MAP helloworld.map 951ab07743SBernard Iremonger 961ab07743SBernard IremongerRunning a Sample Application 971ab07743SBernard Iremonger---------------------------- 981ab07743SBernard Iremonger 991ab07743SBernard Iremonger.. warning:: 1001ab07743SBernard Iremonger 1011ee5af82SShahaf Shuler Before running the application make sure: 1021ab07743SBernard Iremonger 1031ee5af82SShahaf Shuler - Hugepages setup is done. 1041ee5af82SShahaf Shuler - Any kernel driver being used is loaded. 1051ee5af82SShahaf Shuler - In case needed, ports being used by the application should be 1061ee5af82SShahaf Shuler bound to the corresponding kernel driver. 1071ab07743SBernard Iremonger 1081ee5af82SShahaf Shuler refer to :ref:`linux_gsg_linux_drivers` for more details. 1091ab07743SBernard Iremonger 1102e486e26SSiobhan ButlerThe application is linked with the DPDK target environment's Environmental Abstraction Layer (EAL) library, 1112e486e26SSiobhan Butlerwhich provides some options that are generic to every DPDK application. 1121ab07743SBernard Iremonger 1131ab07743SBernard IremongerThe following is the list of options that can be given to the EAL: 1141ab07743SBernard Iremonger 1151ab07743SBernard Iremonger.. code-block:: console 1161ab07743SBernard Iremonger 11735b09d76SKeith Wiles ./rte-app [-c COREMASK | -l CORELIST] [-n NUM] [-b <domain:bus:devid.func>] \ 118fe2497f9SReshma Pattan [--socket-mem=MB,...] [-d LIB.so|DIR] [-m MB] [-r NUM] [-v] [--file-prefix] \ 11929c67340SJohn McNamara [--proc-type <primary|secondary|auto>] [-- xen-dom0] 1201ab07743SBernard Iremonger 1211ab07743SBernard IremongerThe EAL options are as follows: 1221ab07743SBernard Iremonger 12335b09d76SKeith Wiles* ``-c COREMASK`` or ``-l CORELIST``: 12429c67340SJohn McNamara An hexadecimal bit mask of the cores to run on. Note that core numbering can 12535b09d76SKeith Wiles change between platforms and should be determined beforehand. The corelist is 12635b09d76SKeith Wiles a set of core numbers instead of a bitmap core mask. 1271ab07743SBernard Iremonger 12829c67340SJohn McNamara* ``-n NUM``: 12929c67340SJohn McNamara Number of memory channels per processor socket. 1301ab07743SBernard Iremonger 13129c67340SJohn McNamara* ``-b <domain:bus:devid.func>``: 13229c67340SJohn McNamara Blacklisting of ports; prevent EAL from using specified PCI device 13329c67340SJohn McNamara (multiple ``-b`` options are allowed). 1341ab07743SBernard Iremonger 13529c67340SJohn McNamara* ``--use-device``: 13629c67340SJohn McNamara use the specified Ethernet device(s) only. Use comma-separate 13729c67340SJohn McNamara ``[domain:]bus:devid.func`` values. Cannot be used with ``-b`` option. 1381ab07743SBernard Iremonger 13929c67340SJohn McNamara* ``--socket-mem``: 14029c67340SJohn McNamara Memory to allocate from hugepages on specific sockets. 1411ab07743SBernard Iremonger 142fe2497f9SReshma Pattan* ``-d``: 143fe2497f9SReshma Pattan Add a driver or driver directory to be loaded. 144fe2497f9SReshma Pattan The application should use this option to load the pmd drivers 145fe2497f9SReshma Pattan that are built as shared libraries. 146fe2497f9SReshma Pattan 14729c67340SJohn McNamara* ``-m MB``: 14829c67340SJohn McNamara Memory to allocate from hugepages, regardless of processor socket. It is 14929c67340SJohn McNamara recommended that ``--socket-mem`` be used instead of this option. 1501ab07743SBernard Iremonger 15129c67340SJohn McNamara* ``-r NUM``: 15229c67340SJohn McNamara Number of memory ranks. 1531ab07743SBernard Iremonger 15429c67340SJohn McNamara* ``-v``: 15529c67340SJohn McNamara Display version information on startup. 1561ab07743SBernard Iremonger 15729c67340SJohn McNamara* ``--huge-dir``: 15829c67340SJohn McNamara The directory where hugetlbfs is mounted. 1591ab07743SBernard Iremonger 160*a103a97eSSantosh Shukla* ``mbuf-pool-ops-name``: 161*a103a97eSSantosh Shukla Pool ops name for mbuf to use. 162*a103a97eSSantosh Shukla 16329c67340SJohn McNamara* ``--file-prefix``: 16429c67340SJohn McNamara The prefix text used for hugepage filenames. 1651ab07743SBernard Iremonger 16629c67340SJohn McNamara* ``--proc-type``: 16729c67340SJohn McNamara The type of process instance. 1681ab07743SBernard Iremonger 16929c67340SJohn McNamara* ``--xen-dom0``: 17029c67340SJohn McNamara Support application running on Xen Domain0 without hugetlbfs. 1711ab07743SBernard Iremonger 17229c67340SJohn McNamara* ``--vmware-tsc-map``: 17329c67340SJohn McNamara Use VMware TSC map instead of native RDTSC. 1741ab07743SBernard Iremonger 17529c67340SJohn McNamara* ``--base-virtaddr``: 17629c67340SJohn McNamara Specify base virtual address. 1771ab07743SBernard Iremonger 17829c67340SJohn McNamara* ``--vfio-intr``: 17929c67340SJohn McNamara Specify interrupt type to be used by VFIO (has no effect if VFIO is not used). 1801ab07743SBernard Iremonger 18135b09d76SKeith WilesThe ``-c`` or ``-l`` and option is mandatory; the others are optional. 1821ab07743SBernard Iremonger 1832e486e26SSiobhan ButlerCopy the DPDK application binary to your target, then run the application as follows 1841ab07743SBernard Iremonger(assuming the platform has four memory channels per processor socket, 18529c67340SJohn McNamaraand that cores 0-3 are present and are to be used for running the application):: 1861ab07743SBernard Iremonger 18735b09d76SKeith Wiles ./helloworld -l 0-3 -n 4 1881ab07743SBernard Iremonger 1891ab07743SBernard Iremonger.. note:: 1901ab07743SBernard Iremonger 19129c67340SJohn McNamara The ``--proc-type`` and ``--file-prefix`` EAL options are used for running 19229c67340SJohn McNamara multiple DPDK processes. See the "Multi-process Sample Application" 19329c67340SJohn McNamara chapter in the *DPDK Sample Applications User Guide* and the *DPDK 19429c67340SJohn McNamara Programmers Guide* for more details. 1951ab07743SBernard Iremonger 1961ab07743SBernard IremongerLogical Core Use by Applications 1971ab07743SBernard Iremonger~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1981ab07743SBernard Iremonger 19935b09d76SKeith WilesThe coremask (-c 0x0f) or corelist (-l 0-3) parameter is always mandatory for DPDK applications. 20035b09d76SKeith WilesEach bit of the mask corresponds to the equivalent logical core number as reported by Linux. The preferred corelist option is a cleaner method to define cores to be used. 2011ab07743SBernard IremongerSince these logical core numbers, and their mapping to specific cores on specific NUMA sockets, can vary from platform to platform, 20235b09d76SKeith Wilesit is recommended that the core layout for each platform be considered when choosing the coremask/corelist to use in each case. 2031ab07743SBernard Iremonger 2042e486e26SSiobhan ButlerOn initialization of the EAL layer by an DPDK application, the logical cores to be used and their socket location are displayed. 20529c67340SJohn McNamaraThis information can also be determined for all cores on the system by examining the ``/proc/cpuinfo`` file, for example, by running cat ``/proc/cpuinfo``. 2061ab07743SBernard IremongerThe physical id attribute listed for each processor indicates the CPU socket to which it belongs. 2071ab07743SBernard IremongerThis can be useful when using other processors to understand the mapping of the logical cores to the sockets. 2081ab07743SBernard Iremonger 2091ab07743SBernard Iremonger.. note:: 2101ab07743SBernard Iremonger 21129c67340SJohn McNamara A more graphical view of the logical core layout may be obtained using the ``lstopo`` Linux utility. 21229c67340SJohn McNamara On Fedora Linux, this may be installed and run using the following command:: 2131ab07743SBernard Iremonger 2141ab07743SBernard Iremonger sudo yum install hwloc 2151ab07743SBernard Iremonger ./lstopo 2161ab07743SBernard Iremonger 2171ab07743SBernard Iremonger.. warning:: 2181ab07743SBernard Iremonger 21935b09d76SKeith Wiles The logical core layout can change between different board layouts and should be checked before selecting an application coremask/corelist. 2201ab07743SBernard Iremonger 2211ab07743SBernard IremongerHugepage Memory Use by Applications 2221ab07743SBernard Iremonger~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2231ab07743SBernard Iremonger 2241ab07743SBernard IremongerWhen running an application, it is recommended to use the same amount of memory as that allocated for hugepages. 2252e486e26SSiobhan ButlerThis is done automatically by the DPDK application at startup, 22629c67340SJohn McNamaraif no ``-m`` or ``--socket-mem`` parameter is passed to it when run. 2271ab07743SBernard Iremonger 22829c67340SJohn McNamaraIf more memory is requested by explicitly passing a ``-m`` or ``--socket-mem`` value, the application fails. 22929c67340SJohn McNamaraHowever, the application itself can also fail if the user requests less memory than the reserved amount of hugepage-memory, particularly if using the ``-m`` option. 2301ab07743SBernard IremongerThe reason is as follows. 2311ab07743SBernard IremongerSuppose the system has 1024 reserved 2 MB pages in socket 0 and 1024 in socket 1. 2321ab07743SBernard IremongerIf the user requests 128 MB of memory, the 64 pages may not match the constraints: 2331ab07743SBernard Iremonger 2341ab07743SBernard Iremonger* The hugepage memory by be given to the application by the kernel in socket 1 only. 2351ab07743SBernard Iremonger In this case, if the application attempts to create an object, such as a ring or memory pool in socket 0, it fails. 23629c67340SJohn McNamara To avoid this issue, it is recommended that the ``--socket-mem`` option be used instead of the ``-m`` option. 2371ab07743SBernard Iremonger 2382e486e26SSiobhan Butler* These pages can be located anywhere in physical memory, and, although the DPDK EAL will attempt to allocate memory in contiguous blocks, 2391ab07743SBernard Iremonger it is possible that the pages will not be contiguous. In this case, the application is not able to allocate big memory pools. 2401ab07743SBernard Iremonger 2411ab07743SBernard IremongerThe socket-mem option can be used to request specific amounts of memory for specific sockets. 24229c67340SJohn McNamaraThis is accomplished by supplying the ``--socket-mem`` flag followed by amounts of memory requested on each socket, 24329c67340SJohn McNamarafor example, supply ``--socket-mem=0,512`` to try and reserve 512 MB for socket 1 only. 24429c67340SJohn McNamaraSimilarly, on a four socket system, to allocate 1 GB memory on each of sockets 0 and 2 only, the parameter ``--socket-mem=1024,0,1024`` can be used. 2451ab07743SBernard IremongerNo memory will be reserved on any CPU socket that is not explicitly referenced, for example, socket 3 in this case. 2462e486e26SSiobhan ButlerIf the DPDK cannot allocate enough memory on each socket, the EAL initialization fails. 2471ab07743SBernard Iremonger 2481ab07743SBernard IremongerAdditional Sample Applications 2491ab07743SBernard Iremonger------------------------------ 2501ab07743SBernard Iremonger 2511ab07743SBernard IremongerAdditional sample applications are included in the ${RTE_SDK}/examples directory. 2521ab07743SBernard IremongerThese sample applications may be built and run in a manner similar to that described in earlier sections in this manual. 2532e486e26SSiobhan ButlerIn addition, see the *DPDK Sample Applications User Guide* for a description of the application, 2541ab07743SBernard Iremongerspecific instructions on compilation and execution and some explanation of the code. 2551ab07743SBernard Iremonger 2561ab07743SBernard IremongerAdditional Test Applications 2571ab07743SBernard Iremonger---------------------------- 2581ab07743SBernard Iremonger 2591ab07743SBernard IremongerIn addition, there are two other applications that are built when the libraries are created. 2601ab07743SBernard IremongerThe source files for these are in the DPDK/app directory and are called test and testpmd. 2611ab07743SBernard IremongerOnce the libraries are created, they can be found in the build/app directory. 2621ab07743SBernard Iremonger 2632e486e26SSiobhan Butler* The test application provides a variety of specific tests for the various functions in the DPDK. 2641ab07743SBernard Iremonger 2651ab07743SBernard Iremonger* The testpmd application provides a number of different packet throughput tests and 2661ab07743SBernard Iremonger examples of features such as how to use the Flow Director found in the Intel® 82599 10 Gigabit Ethernet Controller. 267