]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/dpdk/examples/multi_process/simple_mp/mp_commands.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / dpdk / examples / multi_process / simple_mp / mp_commands.c
CommitLineData
11fdf7f2
TL
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
7c673cae
FG
3 */
4#include <stdint.h>
5#include <string.h>
6#include <stdlib.h>
7#include <stdarg.h>
8#include <inttypes.h>
9#include <stdio.h>
10#include <termios.h>
11#include <errno.h>
12#include <sys/queue.h>
13
14#include <rte_common.h>
15#include <rte_memory.h>
7c673cae
FG
16#include <rte_eal.h>
17#include <rte_atomic.h>
18#include <rte_branch_prediction.h>
19#include <rte_launch.h>
20#include <rte_log.h>
21#include <rte_per_lcore.h>
22#include <rte_lcore.h>
23#include <rte_ring.h>
24#include <rte_debug.h>
25#include <rte_mempool.h>
26#include <rte_string_fns.h>
27
28#include <cmdline_rdline.h>
29#include <cmdline_parse.h>
30#include <cmdline_parse_string.h>
31#include <cmdline_socket.h>
32#include <cmdline.h>
33#include "mp_commands.h"
34
35/**********************************************************/
36
37struct cmd_send_result {
38 cmdline_fixed_string_t action;
39 cmdline_fixed_string_t message;
40};
41
42static void cmd_send_parsed(void *parsed_result,
43 __attribute__((unused)) struct cmdline *cl,
44 __attribute__((unused)) void *data)
45{
46 void *msg = NULL;
47 struct cmd_send_result *res = parsed_result;
48
49 if (rte_mempool_get(message_pool, &msg) < 0)
50 rte_panic("Failed to get message buffer\n");
9f95a23c 51 strlcpy((char *)msg, res->message, STR_TOKEN_SIZE);
7c673cae
FG
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);
55 }
56}
57
58cmdline_parse_token_string_t cmd_send_action =
59 TOKEN_STRING_INITIALIZER(struct cmd_send_result, action, "send");
60cmdline_parse_token_string_t cmd_send_message =
61 TOKEN_STRING_INITIALIZER(struct cmd_send_result, message, NULL);
62
63cmdline_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,
70 NULL,
71 },
72};
73
74/**********************************************************/
75
76struct cmd_quit_result {
77 cmdline_fixed_string_t quit;
78};
79
80static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result,
81 struct cmdline *cl,
82 __attribute__((unused)) void *data)
83{
84 quit = 1;
85 cmdline_quit(cl);
86}
87
88cmdline_parse_token_string_t cmd_quit_quit =
89 TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit");
90
91cmdline_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,
97 NULL,
98 },
99};
100
101/**********************************************************/
102
103struct cmd_help_result {
104 cmdline_fixed_string_t help;
105};
106
107static void cmd_help_parsed(__attribute__((unused)) void *parsed_result,
108 struct cmdline *cl,
109 __attribute__((unused)) void *data)
110{
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");
115}
116
117cmdline_parse_token_string_t cmd_help_help =
118 TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help");
119
120cmdline_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,
126 NULL,
127 },
128};
129
130/****** CONTEXT (list of instruction) */
131cmdline_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,
135 NULL,
136};