4 * Copyright(c) 2010-2014 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.
41 #include <sys/queue.h>
43 #include <rte_common.h>
44 #include <rte_memory.h>
45 #include <rte_memzone.h>
47 #include <rte_atomic.h>
48 #include <rte_branch_prediction.h>
49 #include <rte_launch.h>
51 #include <rte_per_lcore.h>
52 #include <rte_lcore.h>
54 #include <rte_debug.h>
55 #include <rte_mempool.h>
56 #include <rte_string_fns.h>
58 #include <cmdline_rdline.h>
59 #include <cmdline_parse.h>
60 #include <cmdline_parse_string.h>
61 #include <cmdline_socket.h>
63 #include "mp_commands.h"
65 /**********************************************************/
67 struct cmd_send_result {
68 cmdline_fixed_string_t action;
69 cmdline_fixed_string_t message;
72 static void cmd_send_parsed(void *parsed_result,
73 __attribute__((unused)) struct cmdline *cl,
74 __attribute__((unused)) void *data)
77 struct cmd_send_result *res = parsed_result;
79 if (rte_mempool_get(message_pool, &msg) < 0)
80 rte_panic("Failed to get message buffer\n");
81 snprintf((char *)msg, string_size, "%s", res->message);
82 if (rte_ring_enqueue(send_ring, msg) < 0) {
83 printf("Failed to send message - message discarded\n");
84 rte_mempool_put(message_pool, msg);
88 cmdline_parse_token_string_t cmd_send_action =
89 TOKEN_STRING_INITIALIZER(struct cmd_send_result, action, "send");
90 cmdline_parse_token_string_t cmd_send_message =
91 TOKEN_STRING_INITIALIZER(struct cmd_send_result, message, NULL);
93 cmdline_parse_inst_t cmd_send = {
94 .f = cmd_send_parsed, /* function to call */
95 .data = NULL, /* 2nd arg of func */
96 .help_str = "send a string to another process",
97 .tokens = { /* token list, NULL terminated */
98 (void *)&cmd_send_action,
99 (void *)&cmd_send_message,
104 /**********************************************************/
106 struct cmd_quit_result {
107 cmdline_fixed_string_t quit;
110 static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
112 __attribute__((unused)) void *data)
118 cmdline_parse_token_string_t cmd_quit_quit =
119 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
121 cmdline_parse_inst_t cmd_quit = {
122 .f = cmd_quit_parsed, /* function to call */
123 .data = NULL, /* 2nd arg of func */
124 .help_str = "close the application",
125 .tokens = { /* token list, NULL terminated */
126 (void *)&cmd_quit_quit,
131 /**********************************************************/
133 struct cmd_help_result {
134 cmdline_fixed_string_t help;
137 static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
139 __attribute__((unused)) void *data)
141 cmdline_printf(cl, "Simple demo example of multi-process in RTE\n\n"
142 "This is a readline-like interface that can be used to\n"
143 "send commands to the simple app. Commands supported are:\n\n"
144 "- send [string]\n" "- help\n" "- quit\n\n");
147 cmdline_parse_token_string_t cmd_help_help =
148 TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
150 cmdline_parse_inst_t cmd_help = {
151 .f = cmd_help_parsed, /* function to call */
152 .data = NULL, /* 2nd arg of func */
153 .help_str = "show help",
154 .tokens = { /* token list, NULL terminated */
155 (void *)&cmd_help_help,
160 /****** CONTEXT (list of instruction) */
161 cmdline_parse_ctx_t simple_mp_ctx[] = {
162 (cmdline_parse_inst_t *)&cmd_send,
163 (cmdline_parse_inst_t *)&cmd_quit,
164 (cmdline_parse_inst_t *)&cmd_help,