summaryrefslogtreecommitdiff
path: root/doc/guides/sample_app_ug/hello_world.rst
blob: c0e0a1549eb5f7d41f5a60fc448bb1843cd3c5f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
..  SPDX-License-Identifier: BSD-3-Clause
    Copyright(c) 2010-2014 Intel Corporation.

Hello World Sample Application
==============================

The Hello World sample application is an example of the simplest DPDK application that can be written.
The application simply prints an "helloworld" message on every enabled lcore.

Compiling the Application
-------------------------

To compile the sample application see :doc:`compiling`.

The application is located in the ``helloworld`` sub-directory.

Running the Application
-----------------------

To run the example in a linux environment:

.. code-block:: console

    $ ./build/helloworld -l 0-3 -n 4

Refer to *DPDK Getting Started Guide* for general information on running applications
and the Environment Abstraction Layer (EAL) options.

Explanation
-----------

The following sections provide some explanation of code.

EAL Initialization
~~~~~~~~~~~~~~~~~~

The first task is to initialize the Environment Abstraction Layer (EAL).
This is done in the main() function using the following code:

.. code-block:: c

    int

    main(int argc, char **argv)

    {
        ret = rte_eal_init(argc, argv);
        if (ret < 0)
            rte_panic("Cannot init EAL\n");

This call finishes the initialization process that was started before main() is called (in case of a Linux environment).
The argc and argv arguments are provided to the rte_eal_init() function.
The value returned is the number of parsed arguments.

Starting Application Unit Lcores
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Once the EAL is initialized, the application is ready to launch a function on an lcore.
In this example, lcore_hello() is called on every available lcore.
The following is the definition of the function:

.. code-block:: c

    static int
    lcore_hello( attribute ((unused)) void *arg)
    {
        unsigned lcore_id;

        lcore_id = rte_lcore_id();
        printf("hello from core %u\n", lcore_id);
        return 0;
    }

The code that launches the function on each lcore is as follows:

.. code-block:: c

    /* call lcore_hello() on every slave lcore */

    RTE_LCORE_FOREACH_SLAVE(lcore_id) {
       rte_eal_remote_launch(lcore_hello, NULL, lcore_id);
    }

    /* call it on master lcore too */

    lcore_hello(NULL);

The following code is equivalent and simpler:

.. code-block:: c

    rte_eal_mp_remote_launch(lcore_hello, NULL, CALL_MASTER);

Refer to the *DPDK API Reference* for detailed information on the rte_eal_mp_remote_launch() function.