1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
6 * This sample application is a simple multi-process application which
7 * demostrates sharing of queues and memory pools between processes, and
8 * using those queues/pools for communication between the processes.
10 * Application is designed to run with two processes, a primary and a
11 * secondary, and each accepts commands on the commandline, the most
12 * important of which is "send", which just sends a string to the other
24 #include <sys/queue.h>
26 #include <rte_common.h>
27 #include <rte_memory.h>
28 #include <rte_launch.h>
30 #include <rte_per_lcore.h>
31 #include <rte_lcore.h>
32 #include <rte_debug.h>
33 #include <rte_atomic.h>
34 #include <rte_branch_prediction.h>
37 #include <rte_mempool.h>
38 #include <cmdline_rdline.h>
39 #include <cmdline_parse.h>
40 #include <cmdline_parse_string.h>
41 #include <cmdline_socket.h>
43 #include "mp_commands.h"
45 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
47 static const char *_MSG_POOL = "MSG_POOL";
48 static const char *_SEC_2_PRI = "SEC_2_PRI";
49 static const char *_PRI_2_SEC = "PRI_2_SEC";
51 struct rte_ring *send_ring, *recv_ring;
52 struct rte_mempool *message_pool;
53 volatile int quit = 0;
56 lcore_recv(__rte_unused void *arg)
58 unsigned lcore_id = rte_lcore_id();
60 printf("Starting core %u\n", lcore_id);
63 if (rte_ring_dequeue(recv_ring, &msg) < 0){
67 printf("core %u: Received '%s'\n", lcore_id, (char *)msg);
68 rte_mempool_put(message_pool, msg);
75 main(int argc, char **argv)
77 const unsigned flags = 0;
78 const unsigned ring_size = 64;
79 const unsigned pool_size = 1024;
80 const unsigned pool_cache = 32;
81 const unsigned priv_data_sz = 0;
86 ret = rte_eal_init(argc, argv);
88 rte_exit(EXIT_FAILURE, "Cannot init EAL\n");
90 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
91 send_ring = rte_ring_create(_PRI_2_SEC, ring_size, rte_socket_id(), flags);
92 recv_ring = rte_ring_create(_SEC_2_PRI, ring_size, rte_socket_id(), flags);
93 message_pool = rte_mempool_create(_MSG_POOL, pool_size,
94 STR_TOKEN_SIZE, pool_cache, priv_data_sz,
95 NULL, NULL, NULL, NULL,
96 rte_socket_id(), flags);
98 recv_ring = rte_ring_lookup(_PRI_2_SEC);
99 send_ring = rte_ring_lookup(_SEC_2_PRI);
100 message_pool = rte_mempool_lookup(_MSG_POOL);
102 if (send_ring == NULL)
103 rte_exit(EXIT_FAILURE, "Problem getting sending ring\n");
104 if (recv_ring == NULL)
105 rte_exit(EXIT_FAILURE, "Problem getting receiving ring\n");
106 if (message_pool == NULL)
107 rte_exit(EXIT_FAILURE, "Problem getting message pool\n");
109 RTE_LOG(INFO, APP, "Finished Process Init.\n");
111 /* call lcore_recv() on every slave lcore */
112 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
113 rte_eal_remote_launch(lcore_recv, NULL, lcore_id);
116 /* call cmd prompt on master lcore */
117 struct cmdline *cl = cmdline_stdin_new(simple_mp_ctx, "\nsimple_mp > ");
119 rte_exit(EXIT_FAILURE, "Cannot create cmdline instance\n");
120 cmdline_interact(cl);
121 cmdline_stdin_exit(cl);
123 rte_eal_mp_wait_lcore();