15630257fSFerruh Yigit.. SPDX-License-Identifier: BSD-3-Clause 25630257fSFerruh Yigit Copyright(c) 2010-2014 Intel Corporation. 31ab07743SBernard Iremonger 41ab07743SBernard IremongerCompiling and Running Sample Applications 51ab07743SBernard Iremonger========================================= 61ab07743SBernard Iremonger 72e486e26SSiobhan ButlerThe chapter describes how to compile and run applications in an DPDK environment. 81ab07743SBernard IremongerIt also provides a pointer to where sample applications are stored. 91ab07743SBernard Iremonger 101ab07743SBernard Iremonger.. note:: 111ab07743SBernard Iremonger 1229c67340SJohn McNamara Parts of this process can also be done using the setup script described the 1329c67340SJohn McNamara :ref:`linux_setup_script` section of this document. 141ab07743SBernard Iremonger 151ab07743SBernard IremongerCompiling a Sample Application 161ab07743SBernard Iremonger------------------------------ 171ab07743SBernard Iremonger 18*3cc6ecfdSCiara PowerPlease refer to :ref:`building_app_using_installed_dpdk` for detail on compiling sample apps. 191ab07743SBernard Iremonger 201ab07743SBernard IremongerRunning a Sample Application 211ab07743SBernard Iremonger---------------------------- 221ab07743SBernard Iremonger 231ab07743SBernard Iremonger.. warning:: 241ab07743SBernard Iremonger 251ee5af82SShahaf Shuler Before running the application make sure: 261ab07743SBernard Iremonger 271ee5af82SShahaf Shuler - Hugepages setup is done. 281ee5af82SShahaf Shuler - Any kernel driver being used is loaded. 291ee5af82SShahaf Shuler - In case needed, ports being used by the application should be 301ee5af82SShahaf Shuler bound to the corresponding kernel driver. 311ab07743SBernard Iremonger 321ee5af82SShahaf Shuler refer to :ref:`linux_gsg_linux_drivers` for more details. 331ab07743SBernard Iremonger 342e486e26SSiobhan ButlerThe application is linked with the DPDK target environment's Environmental Abstraction Layer (EAL) library, 352e486e26SSiobhan Butlerwhich provides some options that are generic to every DPDK application. 361ab07743SBernard Iremonger 371ab07743SBernard IremongerThe following is the list of options that can be given to the EAL: 381ab07743SBernard Iremonger 391ab07743SBernard Iremonger.. code-block:: console 401ab07743SBernard Iremonger 4135b09d76SKeith Wiles ./rte-app [-c COREMASK | -l CORELIST] [-n NUM] [-b <domain:bus:devid.func>] \ 42fe2497f9SReshma Pattan [--socket-mem=MB,...] [-d LIB.so|DIR] [-m MB] [-r NUM] [-v] [--file-prefix] \ 43f26ab687SJianfeng Tan [--proc-type <primary|secondary|auto>] 441ab07743SBernard Iremonger 451ab07743SBernard IremongerThe EAL options are as follows: 461ab07743SBernard Iremonger 4735b09d76SKeith Wiles* ``-c COREMASK`` or ``-l CORELIST``: 4829c67340SJohn McNamara An hexadecimal bit mask of the cores to run on. Note that core numbering can 4935b09d76SKeith Wiles change between platforms and should be determined beforehand. The corelist is 5035b09d76SKeith Wiles a set of core numbers instead of a bitmap core mask. 511ab07743SBernard Iremonger 5229c67340SJohn McNamara* ``-n NUM``: 5329c67340SJohn McNamara Number of memory channels per processor socket. 541ab07743SBernard Iremonger 5529c67340SJohn McNamara* ``-b <domain:bus:devid.func>``: 5629c67340SJohn McNamara Blacklisting of ports; prevent EAL from using specified PCI device 5729c67340SJohn McNamara (multiple ``-b`` options are allowed). 581ab07743SBernard Iremonger 5929c67340SJohn McNamara* ``--use-device``: 6029c67340SJohn McNamara use the specified Ethernet device(s) only. Use comma-separate 6129c67340SJohn McNamara ``[domain:]bus:devid.func`` values. Cannot be used with ``-b`` option. 621ab07743SBernard Iremonger 6329c67340SJohn McNamara* ``--socket-mem``: 64b3173932SAnatoly Burakov Memory to allocate from hugepages on specific sockets. In dynamic memory mode, 65b3173932SAnatoly Burakov this memory will also be pinned (i.e. not released back to the system until 66b3173932SAnatoly Burakov application closes). 671ab07743SBernard Iremonger 68e4348122SAnatoly Burakov* ``--socket-limit``: 69e4348122SAnatoly Burakov Limit maximum memory available for allocation on each socket. Does not support 70e4348122SAnatoly Burakov legacy memory mode. 71e4348122SAnatoly Burakov 72fe2497f9SReshma Pattan* ``-d``: 73fe2497f9SReshma Pattan Add a driver or driver directory to be loaded. 74fe2497f9SReshma Pattan The application should use this option to load the pmd drivers 75fe2497f9SReshma Pattan that are built as shared libraries. 76fe2497f9SReshma Pattan 7729c67340SJohn McNamara* ``-m MB``: 7829c67340SJohn McNamara Memory to allocate from hugepages, regardless of processor socket. It is 7929c67340SJohn McNamara recommended that ``--socket-mem`` be used instead of this option. 801ab07743SBernard Iremonger 8129c67340SJohn McNamara* ``-r NUM``: 8229c67340SJohn McNamara Number of memory ranks. 831ab07743SBernard Iremonger 8429c67340SJohn McNamara* ``-v``: 8529c67340SJohn McNamara Display version information on startup. 861ab07743SBernard Iremonger 8729c67340SJohn McNamara* ``--huge-dir``: 8829c67340SJohn McNamara The directory where hugetlbfs is mounted. 891ab07743SBernard Iremonger 90a103a97eSSantosh Shukla* ``mbuf-pool-ops-name``: 91a103a97eSSantosh Shukla Pool ops name for mbuf to use. 92a103a97eSSantosh Shukla 9329c67340SJohn McNamara* ``--file-prefix``: 9429c67340SJohn McNamara The prefix text used for hugepage filenames. 951ab07743SBernard Iremonger 9629c67340SJohn McNamara* ``--proc-type``: 9729c67340SJohn McNamara The type of process instance. 981ab07743SBernard Iremonger 9929c67340SJohn McNamara* ``--vmware-tsc-map``: 10029c67340SJohn McNamara Use VMware TSC map instead of native RDTSC. 1011ab07743SBernard Iremonger 10229c67340SJohn McNamara* ``--base-virtaddr``: 10329c67340SJohn McNamara Specify base virtual address. 1041ab07743SBernard Iremonger 10529c67340SJohn McNamara* ``--vfio-intr``: 10629c67340SJohn McNamara Specify interrupt type to be used by VFIO (has no effect if VFIO is not used). 1071ab07743SBernard Iremonger 108b3173932SAnatoly Burakov* ``--legacy-mem``: 109b3173932SAnatoly Burakov Run DPDK in legacy memory mode (disable memory reserve/unreserve at runtime, 110b3173932SAnatoly Burakov but provide more IOVA-contiguous memory). 111b3173932SAnatoly Burakov 112b3173932SAnatoly Burakov* ``--single-file-segments``: 113b3173932SAnatoly Burakov Store memory segments in fewer files (dynamic memory mode only - does not 114b3173932SAnatoly Burakov affect legacy memory mode). 115b3173932SAnatoly Burakov 11635b09d76SKeith WilesThe ``-c`` or ``-l`` and option is mandatory; the others are optional. 1171ab07743SBernard Iremonger 1182e486e26SSiobhan ButlerCopy the DPDK application binary to your target, then run the application as follows 1191ab07743SBernard Iremonger(assuming the platform has four memory channels per processor socket, 12029c67340SJohn McNamaraand that cores 0-3 are present and are to be used for running the application):: 1211ab07743SBernard Iremonger 12235b09d76SKeith Wiles ./helloworld -l 0-3 -n 4 1231ab07743SBernard Iremonger 1241ab07743SBernard Iremonger.. note:: 1251ab07743SBernard Iremonger 12629c67340SJohn McNamara The ``--proc-type`` and ``--file-prefix`` EAL options are used for running 12729c67340SJohn McNamara multiple DPDK processes. See the "Multi-process Sample Application" 12829c67340SJohn McNamara chapter in the *DPDK Sample Applications User Guide* and the *DPDK 12929c67340SJohn McNamara Programmers Guide* for more details. 1301ab07743SBernard Iremonger 1311ab07743SBernard IremongerLogical Core Use by Applications 1321ab07743SBernard Iremonger~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1331ab07743SBernard Iremonger 13435b09d76SKeith WilesThe coremask (-c 0x0f) or corelist (-l 0-3) parameter is always mandatory for DPDK applications. 13535b09d76SKeith 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. 1361ab07743SBernard IremongerSince these logical core numbers, and their mapping to specific cores on specific NUMA sockets, can vary from platform to platform, 13735b09d76SKeith Wilesit is recommended that the core layout for each platform be considered when choosing the coremask/corelist to use in each case. 1381ab07743SBernard Iremonger 1392e486e26SSiobhan ButlerOn initialization of the EAL layer by an DPDK application, the logical cores to be used and their socket location are displayed. 14029c67340SJohn 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``. 1411ab07743SBernard IremongerThe physical id attribute listed for each processor indicates the CPU socket to which it belongs. 1421ab07743SBernard IremongerThis can be useful when using other processors to understand the mapping of the logical cores to the sockets. 1431ab07743SBernard Iremonger 1441ab07743SBernard Iremonger.. note:: 1451ab07743SBernard Iremonger 14629c67340SJohn McNamara A more graphical view of the logical core layout may be obtained using the ``lstopo`` Linux utility. 14729c67340SJohn McNamara On Fedora Linux, this may be installed and run using the following command:: 1481ab07743SBernard Iremonger 1491ab07743SBernard Iremonger sudo yum install hwloc 1501ab07743SBernard Iremonger ./lstopo 1511ab07743SBernard Iremonger 1521ab07743SBernard Iremonger.. warning:: 1531ab07743SBernard Iremonger 15435b09d76SKeith Wiles The logical core layout can change between different board layouts and should be checked before selecting an application coremask/corelist. 1551ab07743SBernard Iremonger 1561ab07743SBernard IremongerHugepage Memory Use by Applications 1571ab07743SBernard Iremonger~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1581ab07743SBernard Iremonger 1591ab07743SBernard IremongerWhen running an application, it is recommended to use the same amount of memory as that allocated for hugepages. 1602e486e26SSiobhan ButlerThis is done automatically by the DPDK application at startup, 16129c67340SJohn McNamaraif no ``-m`` or ``--socket-mem`` parameter is passed to it when run. 1621ab07743SBernard Iremonger 16329c67340SJohn McNamaraIf more memory is requested by explicitly passing a ``-m`` or ``--socket-mem`` value, the application fails. 16429c67340SJohn 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. 1651ab07743SBernard IremongerThe reason is as follows. 1661ab07743SBernard IremongerSuppose the system has 1024 reserved 2 MB pages in socket 0 and 1024 in socket 1. 1671ab07743SBernard IremongerIf the user requests 128 MB of memory, the 64 pages may not match the constraints: 1681ab07743SBernard Iremonger 1691ab07743SBernard Iremonger* The hugepage memory by be given to the application by the kernel in socket 1 only. 1701ab07743SBernard Iremonger In this case, if the application attempts to create an object, such as a ring or memory pool in socket 0, it fails. 17129c67340SJohn McNamara To avoid this issue, it is recommended that the ``--socket-mem`` option be used instead of the ``-m`` option. 1721ab07743SBernard Iremonger 1732e486e26SSiobhan Butler* These pages can be located anywhere in physical memory, and, although the DPDK EAL will attempt to allocate memory in contiguous blocks, 1741ab07743SBernard Iremonger it is possible that the pages will not be contiguous. In this case, the application is not able to allocate big memory pools. 1751ab07743SBernard Iremonger 1761ab07743SBernard IremongerThe socket-mem option can be used to request specific amounts of memory for specific sockets. 17729c67340SJohn McNamaraThis is accomplished by supplying the ``--socket-mem`` flag followed by amounts of memory requested on each socket, 17829c67340SJohn McNamarafor example, supply ``--socket-mem=0,512`` to try and reserve 512 MB for socket 1 only. 17929c67340SJohn 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. 1801ab07743SBernard IremongerNo memory will be reserved on any CPU socket that is not explicitly referenced, for example, socket 3 in this case. 1812e486e26SSiobhan ButlerIf the DPDK cannot allocate enough memory on each socket, the EAL initialization fails. 1821ab07743SBernard Iremonger 1831ab07743SBernard IremongerAdditional Sample Applications 1841ab07743SBernard Iremonger------------------------------ 1851ab07743SBernard Iremonger 1861ab07743SBernard IremongerAdditional sample applications are included in the ${RTE_SDK}/examples directory. 1871ab07743SBernard IremongerThese sample applications may be built and run in a manner similar to that described in earlier sections in this manual. 1882e486e26SSiobhan ButlerIn addition, see the *DPDK Sample Applications User Guide* for a description of the application, 1891ab07743SBernard Iremongerspecific instructions on compilation and execution and some explanation of the code. 1901ab07743SBernard Iremonger 1911ab07743SBernard IremongerAdditional Test Applications 1921ab07743SBernard Iremonger---------------------------- 1931ab07743SBernard Iremonger 1941ab07743SBernard IremongerIn addition, there are two other applications that are built when the libraries are created. 1951ab07743SBernard IremongerThe source files for these are in the DPDK/app directory and are called test and testpmd. 1961ab07743SBernard IremongerOnce the libraries are created, they can be found in the build/app directory. 1971ab07743SBernard Iremonger 1982e486e26SSiobhan Butler* The test application provides a variety of specific tests for the various functions in the DPDK. 1991ab07743SBernard Iremonger 2001ab07743SBernard Iremonger* The testpmd application provides a number of different packet throughput tests and 2011ab07743SBernard Iremonger examples of features such as how to use the Flow Director found in the Intel® 82599 10 Gigabit Ethernet Controller. 202