2 Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the
15 * Neither the name of Intel Corporation nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 Hello World Sample Application
32 ==============================
34 The Hello World sample application is an example of the simplest DPDK application that can be written.
35 The application simply prints an "helloworld" message on every enabled lcore.
37 Compiling the Application
38 -------------------------
40 To compile the sample application see :doc:`compiling`.
42 The application is located in the ``helloworld`` sub-directory.
44 Running the Application
45 -----------------------
47 To run the example in a linuxapp environment:
49 .. code-block:: console
51 $ ./build/helloworld -l 0-3 -n 4
53 Refer to *DPDK Getting Started Guide* for general information on running applications
54 and the Environment Abstraction Layer (EAL) options.
59 The following sections provide some explanation of code.
64 The first task is to initialize the Environment Abstraction Layer (EAL).
65 This is done in the main() function using the following code:
71 main(int argc, char **argv)
74 ret = rte_eal_init(argc, argv);
76 rte_panic("Cannot init EAL\n");
78 This call finishes the initialization process that was started before main() is called (in case of a Linuxapp environment).
79 The argc and argv arguments are provided to the rte_eal_init() function.
80 The value returned is the number of parsed arguments.
82 Starting Application Unit Lcores
83 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85 Once the EAL is initialized, the application is ready to launch a function on an lcore.
86 In this example, lcore_hello() is called on every available lcore.
87 The following is the definition of the function:
92 lcore_hello( attribute ((unused)) void *arg)
96 lcore_id = rte_lcore_id();
97 printf("hello from core %u\n", lcore_id);
101 The code that launches the function on each lcore is as follows:
105 /* call lcore_hello() on every slave lcore */
107 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
108 rte_eal_remote_launch(lcore_hello, NULL, lcore_id);
111 /* call it on master lcore too */
115 The following code is equivalent and simpler:
119 rte_eal_mp_remote_launch(lcore_hello, NULL, CALL_MASTER);
121 Refer to the *DPDK API Reference* for detailed information on the rte_eal_mp_remote_launch() function.