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 #. Go to the example directory:
42 .. code-block:: console
44 export RTE_SDK=/path/to/rte_sdk
45 cd ${RTE_SDK}/examples/helloworld
47 #. Set the target (a default target is used if not specified). For example:
49 .. code-block:: console
51 export RTE_TARGET=x86_64-native-linuxapp-gcc
53 See the *DPDK Getting Started* Guide for possible RTE_TARGET values.
55 #. Build the application:
57 .. code-block:: console
61 Running the Application
62 -----------------------
64 To run the example in a linuxapp environment:
66 .. code-block:: console
68 $ ./build/helloworld -l 0-3 -n 4
70 Refer to *DPDK Getting Started Guide* for general information on running applications
71 and the Environment Abstraction Layer (EAL) options.
76 The following sections provide some explanation of code.
81 The first task is to initialize the Environment Abstraction Layer (EAL).
82 This is done in the main() function using the following code:
88 main(int argc, char **argv)
91 ret = rte_eal_init(argc, argv);
93 rte_panic("Cannot init EAL\n");
95 This call finishes the initialization process that was started before main() is called (in case of a Linuxapp environment).
96 The argc and argv arguments are provided to the rte_eal_init() function.
97 The value returned is the number of parsed arguments.
99 Starting Application Unit Lcores
100 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
102 Once the EAL is initialized, the application is ready to launch a function on an lcore.
103 In this example, lcore_hello() is called on every available lcore.
104 The following is the definition of the function:
109 lcore_hello( attribute ((unused)) void *arg)
113 lcore_id = rte_lcore_id();
114 printf("hello from core %u\n", lcore_id);
118 The code that launches the function on each lcore is as follows:
122 /* call lcore_hello() on every slave lcore */
124 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
125 rte_eal_remote_launch(lcore_hello, NULL, lcore_id);
128 /* call it on master lcore too */
132 The following code is equivalent and simpler:
136 rte_eal_mp_remote_launch(lcore_hello, NULL, CALL_MASTER);
138 Refer to the *DPDK API Reference* for detailed information on the rte_eal_mp_remote_launch() function.