1 .. SPDX-License-Identifier: BSD-3-Clause
2 Copyright(c) 2010-2014 Intel Corporation.
4 Hello World Sample Application
5 ==============================
7 The Hello World sample application is an example of the simplest DPDK application that can be written.
8 The application simply prints an "helloworld" message on every enabled lcore.
10 Compiling the Application
11 -------------------------
13 To compile the sample application see :doc:`compiling`.
15 The application is located in the ``helloworld`` sub-directory.
17 Running the Application
18 -----------------------
20 To run the example in a linux environment:
22 .. code-block:: console
24 $ ./build/helloworld -l 0-3 -n 4
26 Refer to *DPDK Getting Started Guide* for general information on running applications
27 and the Environment Abstraction Layer (EAL) options.
32 The following sections provide some explanation of code.
37 The first task is to initialize the Environment Abstraction Layer (EAL).
38 This is done in the main() function using the following code:
44 main(int argc, char **argv)
47 ret = rte_eal_init(argc, argv);
49 rte_panic("Cannot init EAL\n");
51 This call finishes the initialization process that was started before main() is called (in case of a Linux environment).
52 The argc and argv arguments are provided to the rte_eal_init() function.
53 The value returned is the number of parsed arguments.
55 Starting Application Unit Lcores
56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58 Once the EAL is initialized, the application is ready to launch a function on an lcore.
59 In this example, lcore_hello() is called on every available lcore.
60 The following is the definition of the function:
65 lcore_hello( attribute ((unused)) void *arg)
69 lcore_id = rte_lcore_id();
70 printf("hello from core %u\n", lcore_id);
74 The code that launches the function on each lcore is as follows:
78 /* call lcore_hello() on every slave lcore */
80 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
81 rte_eal_remote_launch(lcore_hello, NULL, lcore_id);
84 /* call it on master lcore too */
88 The following code is equivalent and simpler:
92 rte_eal_mp_remote_launch(lcore_hello, NULL, CALL_MASTER);
94 Refer to the *DPDK API Reference* for detailed information on the rte_eal_mp_remote_launch() function.