xref: /dpdk/doc/guides/sample_app_ug/hello_world.rst (revision 8750576fb2a9a067ffbcce4bab6481f3bfa47097)
1..  SPDX-License-Identifier: BSD-3-Clause
2    Copyright(c) 2010-2014 Intel Corporation.
3
4Hello World Sample Application
5==============================
6
7
8Overview
9--------
10
11The Hello World sample application is an example of the simplest DPDK application that can be written.
12The application simply prints an "helloworld" message on every enabled lcore.
13
14Compiling the Application
15-------------------------
16
17To compile the sample application see :doc:`compiling`.
18
19The application is located in the ``helloworld`` sub-directory.
20
21Running the Application
22-----------------------
23
24To run the example in a linux environment:
25
26.. code-block:: console
27
28    $ ./<build_dir>/examples/dpdk-helloworld -l 0-3 -n 4
29
30Refer to *DPDK Getting Started Guide* for general information on running applications
31and the Environment Abstraction Layer (EAL) options.
32
33Explanation
34-----------
35
36The following sections provide an explanation of the code.
37
38EAL Initialization
39~~~~~~~~~~~~~~~~~~
40
41The first task is to initialize the Environment Abstraction Layer (EAL).
42This is done in the main() function using the following code:
43
44.. literalinclude:: ../../../examples/helloworld/main.c
45    :language: c
46    :start-after: Initialization of Environment Abstraction Layer (EAL). 8<
47    :end-before: >8 End of initialization of Environment Abstraction Layer
48
49This call finishes the initialization process that was started before main() is called (in case of a Linux environment).
50The argc and argv arguments are provided to the rte_eal_init() function.
51The value returned is the number of parsed arguments.
52
53Starting Application Unit Lcores
54~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55
56Once the EAL is initialized, the application is ready to launch a function on an lcore.
57In this example, lcore_hello() is called on every available lcore.
58The following is the definition of the function:
59
60.. literalinclude:: ../../../examples/helloworld/main.c
61    :language: c
62    :start-after: Launch a function on lcore. 8<
63    :end-before: >8 End of launching function on lcore.
64
65The code that launches the function on each lcore is as follows:
66
67.. literalinclude:: ../../../examples/helloworld/main.c
68    :language: c
69    :start-after: Launches the function on each lcore. 8<
70    :end-before: >8 End of launching the function on each lcore.
71    :dedent: 1
72
73The following code is equivalent and simpler:
74
75.. literalinclude:: ../../../examples/helloworld/main.c
76    :language: c
77    :start-after: Simpler equivalent. 8<
78    :end-before: >8 End of simpler equivalent.
79    :dedent: 2
80
81Refer to the *DPDK API Reference* for detailed information on the rte_eal_mp_remote_launch() function.
82