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_atomic.h>
18 #include <rte_branch_prediction.h>
19 #include <rte_launch.h>
21 #include <rte_per_lcore.h>
22 #include <rte_lcore.h>
24 #include <rte_debug.h>
25 #include <rte_mempool.h>
26 #include <rte_string_fns.h>
28 #include <cmdline_rdline.h>
29 #include <cmdline_parse.h>
30 #include <cmdline_parse_string.h>
31 #include <cmdline_socket.h>
33 #include "mp_commands.h"
35 /**********************************************************/
37 struct cmd_send_result
{
38 cmdline_fixed_string_t action
;
39 cmdline_fixed_string_t message
;
42 static void cmd_send_parsed(void *parsed_result
,
43 __attribute__((unused
)) struct cmdline
*cl
,
44 __attribute__((unused
)) void *data
)
47 struct cmd_send_result
*res
= parsed_result
;
49 if (rte_mempool_get(message_pool
, &msg
) < 0)
50 rte_panic("Failed to get message buffer\n");
51 strlcpy((char *)msg
, res
->message
, STR_TOKEN_SIZE
);
52 if (rte_ring_enqueue(send_ring
, msg
) < 0) {
53 printf("Failed to send message - message discarded\n");
54 rte_mempool_put(message_pool
, msg
);
58 cmdline_parse_token_string_t cmd_send_action
=
59 TOKEN_STRING_INITIALIZER(struct cmd_send_result
, action
, "send");
60 cmdline_parse_token_string_t cmd_send_message
=
61 TOKEN_STRING_INITIALIZER(struct cmd_send_result
, message
, NULL
);
63 cmdline_parse_inst_t cmd_send
= {
64 .f
= cmd_send_parsed
, /* function to call */
65 .data
= NULL
, /* 2nd arg of func */
66 .help_str
= "send a string to another process",
67 .tokens
= { /* token list, NULL terminated */
68 (void *)&cmd_send_action
,
69 (void *)&cmd_send_message
,
74 /**********************************************************/
76 struct cmd_quit_result
{
77 cmdline_fixed_string_t quit
;
80 static void cmd_quit_parsed(__attribute__((unused
)) void *parsed_result
,
82 __attribute__((unused
)) void *data
)
88 cmdline_parse_token_string_t cmd_quit_quit
=
89 TOKEN_STRING_INITIALIZER(struct cmd_quit_result
, quit
, "quit");
91 cmdline_parse_inst_t cmd_quit
= {
92 .f
= cmd_quit_parsed
, /* function to call */
93 .data
= NULL
, /* 2nd arg of func */
94 .help_str
= "close the application",
95 .tokens
= { /* token list, NULL terminated */
96 (void *)&cmd_quit_quit
,
101 /**********************************************************/
103 struct cmd_help_result
{
104 cmdline_fixed_string_t help
;
107 static void cmd_help_parsed(__attribute__((unused
)) void *parsed_result
,
109 __attribute__((unused
)) void *data
)
111 cmdline_printf(cl
, "Simple demo example of multi-process in RTE\n\n"
112 "This is a readline-like interface that can be used to\n"
113 "send commands to the simple app. Commands supported are:\n\n"
114 "- send [string]\n" "- help\n" "- quit\n\n");
117 cmdline_parse_token_string_t cmd_help_help
=
118 TOKEN_STRING_INITIALIZER(struct cmd_help_result
, help
, "help");
120 cmdline_parse_inst_t cmd_help
= {
121 .f
= cmd_help_parsed
, /* function to call */
122 .data
= NULL
, /* 2nd arg of func */
123 .help_str
= "show help",
124 .tokens
= { /* token list, NULL terminated */
125 (void *)&cmd_help_help
,
130 /****** CONTEXT (list of instruction) */
131 cmdline_parse_ctx_t simple_mp_ctx
[] = {
132 (cmdline_parse_inst_t
*)&cmd_send
,
133 (cmdline_parse_inst_t
*)&cmd_quit
,
134 (cmdline_parse_inst_t
*)&cmd_help
,