1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
12 #include <sys/queue.h>
14 #include <rte_common.h>
15 #include <rte_memory.h>
17 #include <rte_branch_prediction.h>
18 #include <rte_launch.h>
20 #include <rte_per_lcore.h>
21 #include <rte_lcore.h>
23 #include <rte_debug.h>
24 #include <rte_mempool.h>
25 #include <rte_string_fns.h>
27 #include <cmdline_rdline.h>
28 #include <cmdline_parse.h>
29 #include <cmdline_parse_string.h>
30 #include <cmdline_socket.h>
32 #include "mp_commands.h"
34 /**********************************************************/
36 struct cmd_send_result {
37 cmdline_fixed_string_t action;
38 cmdline_fixed_string_t message;
41 static void cmd_send_parsed(void *parsed_result,
42 __rte_unused struct cmdline *cl,
43 __rte_unused void *data)
46 struct cmd_send_result *res = parsed_result;
48 if (rte_mempool_get(message_pool, &msg) < 0)
49 rte_panic("Failed to get message buffer\n");
50 strlcpy((char *)msg, res->message, STR_TOKEN_SIZE);
51 if (rte_ring_enqueue(send_ring, msg) < 0) {
52 printf("Failed to send message - message discarded\n");
53 rte_mempool_put(message_pool, msg);
57 cmdline_parse_token_string_t cmd_send_action =
58 TOKEN_STRING_INITIALIZER(struct cmd_send_result, action, "send");
59 cmdline_parse_token_string_t cmd_send_message =
60 TOKEN_STRING_INITIALIZER(struct cmd_send_result, message, NULL);
62 cmdline_parse_inst_t cmd_send = {
63 .f = cmd_send_parsed, /* function to call */
64 .data = NULL, /* 2nd arg of func */
65 .help_str = "send a string to another process",
66 .tokens = { /* token list, NULL terminated */
67 (void *)&cmd_send_action,
68 (void *)&cmd_send_message,
73 /**********************************************************/
75 struct cmd_quit_result {
76 cmdline_fixed_string_t quit;
79 static void cmd_quit_parsed(__rte_unused void *parsed_result,
81 __rte_unused void *data)
87 cmdline_parse_token_string_t cmd_quit_quit =
88 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
90 cmdline_parse_inst_t cmd_quit = {
91 .f = cmd_quit_parsed, /* function to call */
92 .data = NULL, /* 2nd arg of func */
93 .help_str = "close the application",
94 .tokens = { /* token list, NULL terminated */
95 (void *)&cmd_quit_quit,
100 /**********************************************************/
102 struct cmd_help_result {
103 cmdline_fixed_string_t help;
106 static void cmd_help_parsed(__rte_unused void *parsed_result,
108 __rte_unused void *data)
110 cmdline_printf(cl, "Simple demo example of multi-process in RTE\n\n"
111 "This is a readline-like interface that can be used to\n"
112 "send commands to the simple app. Commands supported are:\n\n"
113 "- send [string]\n" "- help\n" "- quit\n\n");
116 cmdline_parse_token_string_t cmd_help_help =
117 TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
119 cmdline_parse_inst_t cmd_help = {
120 .f = cmd_help_parsed, /* function to call */
121 .data = NULL, /* 2nd arg of func */
122 .help_str = "show help",
123 .tokens = { /* token list, NULL terminated */
124 (void *)&cmd_help_help,
129 /****** CONTEXT (list of instruction) */
130 cmdline_parse_ctx_t simple_mp_ctx[] = {
131 (cmdline_parse_inst_t *)&cmd_send,
132 (cmdline_parse_inst_t *)&cmd_quit,
133 (cmdline_parse_inst_t *)&cmd_help,