4 * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * This sample application is a simple multi-process application which
37 * demostrates sharing of queues and memory pools between processes, and
38 * using those queues/pools for communication between the processes.
40 * Application is designed to run with two processes, a primary and a
41 * secondary, and each accepts commands on the commandline, the most
42 * important of which is "send", which just sends a string to the other
54 #include <sys/queue.h>
56 #include <rte_common.h>
57 #include <rte_memory.h>
58 #include <rte_memzone.h>
59 #include <rte_launch.h>
60 #include <rte_tailq.h>
62 #include <rte_per_lcore.h>
63 #include <rte_lcore.h>
64 #include <rte_debug.h>
65 #include <rte_atomic.h>
66 #include <rte_branch_prediction.h>
69 #include <rte_mempool.h>
70 #include <cmdline_rdline.h>
71 #include <cmdline_parse.h>
72 #include <cmdline_socket.h>
74 #include "mp_commands.h"
76 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1
78 static const char *_MSG_POOL = "MSG_POOL";
79 static const char *_SEC_2_PRI = "SEC_2_PRI";
80 static const char *_PRI_2_SEC = "PRI_2_SEC";
81 const unsigned string_size = 64;
83 struct rte_ring *send_ring, *recv_ring;
84 struct rte_mempool *message_pool;
85 volatile int quit = 0;
88 lcore_recv(__attribute__((unused)) void *arg)
90 unsigned lcore_id = rte_lcore_id();
92 printf("Starting core %u\n", lcore_id);
95 if (rte_ring_dequeue(recv_ring, &msg) < 0){
99 printf("core %u: Received '%s'\n", lcore_id, (char *)msg);
100 rte_mempool_put(message_pool, msg);
107 main(int argc, char **argv)
109 const unsigned flags = 0;
110 const unsigned ring_size = 64;
111 const unsigned pool_size = 1024;
112 const unsigned pool_cache = 32;
113 const unsigned priv_data_sz = 0;
118 ret = rte_eal_init(argc, argv);
120 rte_exit(EXIT_FAILURE, "Cannot init EAL\n");
122 if (rte_eal_process_type() == RTE_PROC_PRIMARY){
123 send_ring = rte_ring_create(_PRI_2_SEC, ring_size, rte_socket_id(), flags);
124 recv_ring = rte_ring_create(_SEC_2_PRI, ring_size, rte_socket_id(), flags);
125 message_pool = rte_mempool_create(_MSG_POOL, pool_size,
126 string_size, pool_cache, priv_data_sz,
127 NULL, NULL, NULL, NULL,
128 rte_socket_id(), flags);
130 recv_ring = rte_ring_lookup(_PRI_2_SEC);
131 send_ring = rte_ring_lookup(_SEC_2_PRI);
132 message_pool = rte_mempool_lookup(_MSG_POOL);
134 if (send_ring == NULL)
135 rte_exit(EXIT_FAILURE, "Problem getting sending ring\n");
136 if (recv_ring == NULL)
137 rte_exit(EXIT_FAILURE, "Problem getting receiving ring\n");
138 if (message_pool == NULL)
139 rte_exit(EXIT_FAILURE, "Problem getting message pool\n");
141 RTE_LOG(INFO, APP, "Finished Process Init.\n");
143 /* call lcore_recv() on every slave lcore */
144 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
145 rte_eal_remote_launch(lcore_recv, NULL, lcore_id);
148 /* call cmd prompt on master lcore */
149 struct cmdline *cl = cmdline_stdin_new(simple_mp_ctx, "\nsimple_mp > ");
151 rte_exit(EXIT_FAILURE, "Cannot create cmdline instance\n");
152 cmdline_interact(cl);
153 cmdline_stdin_exit(cl);
155 rte_eal_mp_wait_lcore();