xref: /dpdk/doc/guides/sample_app_ug/hello_world.rst (revision 8750576fb2a9a067ffbcce4bab6481f3bfa47097)
1f56a6ca4SKevin Traynor..  SPDX-License-Identifier: BSD-3-Clause
25630257fSFerruh Yigit    Copyright(c) 2010-2014 Intel Corporation.
3d0dff9baSBernard Iremonger
4d0dff9baSBernard IremongerHello World Sample Application
5d0dff9baSBernard Iremonger==============================
6d0dff9baSBernard Iremonger
7*8750576fSNandini Persad
8*8750576fSNandini PersadOverview
9*8750576fSNandini Persad--------
10*8750576fSNandini Persad
11e0c7c473SSiobhan ButlerThe Hello World sample application is an example of the simplest DPDK application that can be written.
12d0dff9baSBernard IremongerThe application simply prints an "helloworld" message on every enabled lcore.
13d0dff9baSBernard Iremonger
14d0dff9baSBernard IremongerCompiling the Application
15d0dff9baSBernard Iremonger-------------------------
16d0dff9baSBernard Iremonger
177cacb056SHerakliusz LipiecTo compile the sample application see :doc:`compiling`.
18d0dff9baSBernard Iremonger
197cacb056SHerakliusz LipiecThe application is located in the ``helloworld`` sub-directory.
20d0dff9baSBernard Iremonger
21d0dff9baSBernard IremongerRunning the Application
22d0dff9baSBernard Iremonger-----------------------
23d0dff9baSBernard Iremonger
24218c4e68SBruce RichardsonTo run the example in a linux environment:
25d0dff9baSBernard Iremonger
26d0dff9baSBernard Iremonger.. code-block:: console
27d0dff9baSBernard Iremonger
28e2a94f9aSCiara Power    $ ./<build_dir>/examples/dpdk-helloworld -l 0-3 -n 4
29d0dff9baSBernard Iremonger
30e0c7c473SSiobhan ButlerRefer to *DPDK Getting Started Guide* for general information on running applications
31d0dff9baSBernard Iremongerand the Environment Abstraction Layer (EAL) options.
32d0dff9baSBernard Iremonger
33d0dff9baSBernard IremongerExplanation
34d0dff9baSBernard Iremonger-----------
35d0dff9baSBernard Iremonger
36*8750576fSNandini PersadThe following sections provide an explanation of the code.
37d0dff9baSBernard Iremonger
38d0dff9baSBernard IremongerEAL Initialization
39d0dff9baSBernard Iremonger~~~~~~~~~~~~~~~~~~
40d0dff9baSBernard Iremonger
41d0dff9baSBernard IremongerThe first task is to initialize the Environment Abstraction Layer (EAL).
42d0dff9baSBernard IremongerThis is done in the main() function using the following code:
43d0dff9baSBernard Iremonger
449a212dc0SConor Fogarty.. literalinclude:: ../../../examples/helloworld/main.c
459a212dc0SConor Fogarty    :language: c
469a212dc0SConor Fogarty    :start-after: Initialization of Environment Abstraction Layer (EAL). 8<
479a212dc0SConor Fogarty    :end-before: >8 End of initialization of Environment Abstraction Layer
48d0dff9baSBernard Iremonger
49218c4e68SBruce RichardsonThis call finishes the initialization process that was started before main() is called (in case of a Linux environment).
50d0dff9baSBernard IremongerThe argc and argv arguments are provided to the rte_eal_init() function.
51d0dff9baSBernard IremongerThe value returned is the number of parsed arguments.
52d0dff9baSBernard Iremonger
53d0dff9baSBernard IremongerStarting Application Unit Lcores
54d0dff9baSBernard Iremonger~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55d0dff9baSBernard Iremonger
56d0dff9baSBernard IremongerOnce the EAL is initialized, the application is ready to launch a function on an lcore.
57d0dff9baSBernard IremongerIn this example, lcore_hello() is called on every available lcore.
58d0dff9baSBernard IremongerThe following is the definition of the function:
59d0dff9baSBernard Iremonger
609a212dc0SConor Fogarty.. literalinclude:: ../../../examples/helloworld/main.c
619a212dc0SConor Fogarty    :language: c
629a212dc0SConor Fogarty    :start-after: Launch a function on lcore. 8<
639a212dc0SConor Fogarty    :end-before: >8 End of launching function on lcore.
64d0dff9baSBernard Iremonger
65d0dff9baSBernard IremongerThe code that launches the function on each lcore is as follows:
66d0dff9baSBernard Iremonger
679a212dc0SConor Fogarty.. literalinclude:: ../../../examples/helloworld/main.c
689a212dc0SConor Fogarty    :language: c
699a212dc0SConor Fogarty    :start-after: Launches the function on each lcore. 8<
709a212dc0SConor Fogarty    :end-before: >8 End of launching the function on each lcore.
719a212dc0SConor Fogarty    :dedent: 1
72d0dff9baSBernard Iremonger
73d0dff9baSBernard IremongerThe following code is equivalent and simpler:
74d0dff9baSBernard Iremonger
759a212dc0SConor Fogarty.. literalinclude:: ../../../examples/helloworld/main.c
769a212dc0SConor Fogarty    :language: c
779a212dc0SConor Fogarty    :start-after: Simpler equivalent. 8<
789a212dc0SConor Fogarty    :end-before: >8 End of simpler equivalent.
799a212dc0SConor Fogarty    :dedent: 2
80d0dff9baSBernard Iremonger
81e0c7c473SSiobhan ButlerRefer to the *DPDK API Reference* for detailed information on the rte_eal_mp_remote_launch() function.
82