xref: /dpdk/examples/helloworld/main.c (revision 9a212dc06c7aaf09b146d9c3dcfd584d741634c1)
13998e2a0SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
23998e2a0SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
3af75078fSIntel  */
4af75078fSIntel 
5af75078fSIntel #include <stdio.h>
6af75078fSIntel #include <string.h>
7af75078fSIntel #include <stdint.h>
8af75078fSIntel #include <errno.h>
9af75078fSIntel #include <sys/queue.h>
10af75078fSIntel 
11af75078fSIntel #include <rte_memory.h>
12af75078fSIntel #include <rte_launch.h>
13af75078fSIntel #include <rte_eal.h>
14af75078fSIntel #include <rte_per_lcore.h>
15af75078fSIntel #include <rte_lcore.h>
16af75078fSIntel #include <rte_debug.h>
17af75078fSIntel 
18*9a212dc0SConor Fogarty /* Launch a function on lcore. 8< */
19af75078fSIntel static int
lcore_hello(__rte_unused void * arg)20f2fc83b4SThomas Monjalon lcore_hello(__rte_unused void *arg)
21af75078fSIntel {
22af75078fSIntel 	unsigned lcore_id;
23af75078fSIntel 	lcore_id = rte_lcore_id();
24af75078fSIntel 	printf("hello from core %u\n", lcore_id);
25af75078fSIntel 	return 0;
26af75078fSIntel }
27*9a212dc0SConor Fogarty /* >8 End of launching function on lcore. */
28af75078fSIntel 
29*9a212dc0SConor Fogarty /* Initialization of Environment Abstraction Layer (EAL). 8< */
30af75078fSIntel int
main(int argc,char ** argv)3198a16481SDavid Marchand main(int argc, char **argv)
32af75078fSIntel {
33af75078fSIntel 	int ret;
34af75078fSIntel 	unsigned lcore_id;
35af75078fSIntel 
36af75078fSIntel 	ret = rte_eal_init(argc, argv);
37af75078fSIntel 	if (ret < 0)
38af75078fSIntel 		rte_panic("Cannot init EAL\n");
39*9a212dc0SConor Fogarty 	/* >8 End of initialization of Environment Abstraction Layer */
40af75078fSIntel 
41*9a212dc0SConor Fogarty 	/* Launches the function on each lcore. 8< */
42cb056611SStephen Hemminger 	RTE_LCORE_FOREACH_WORKER(lcore_id) {
43*9a212dc0SConor Fogarty 		/* Simpler equivalent. 8< */
44af75078fSIntel 		rte_eal_remote_launch(lcore_hello, NULL, lcore_id);
45*9a212dc0SConor Fogarty 		/* >8 End of simpler equivalent. */
46af75078fSIntel 	}
47af75078fSIntel 
48cb056611SStephen Hemminger 	/* call it on main lcore too */
49af75078fSIntel 	lcore_hello(NULL);
50*9a212dc0SConor Fogarty 	/* >8 End of launching the function on each lcore. */
51af75078fSIntel 
52af75078fSIntel 	rte_eal_mp_wait_lcore();
5310aa3757SChengchang Tang 
5410aa3757SChengchang Tang 	/* clean up the EAL */
5510aa3757SChengchang Tang 	rte_eal_cleanup();
5610aa3757SChengchang Tang 
57af75078fSIntel 	return 0;
58af75078fSIntel }
59