13998e2a0SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 23998e2a0SBruce Richardson * Copyright(c) 2010-2014 Intel Corporation 3af75078fSIntel */ 4af75078fSIntel #include <stdint.h> 5af75078fSIntel #include <string.h> 6af75078fSIntel #include <stdlib.h> 7af75078fSIntel #include <stdarg.h> 8af75078fSIntel #include <inttypes.h> 9af75078fSIntel #include <stdio.h> 10af75078fSIntel #include <termios.h> 11af75078fSIntel #include <errno.h> 12af75078fSIntel #include <sys/queue.h> 13af75078fSIntel 14af75078fSIntel #include <rte_common.h> 15af75078fSIntel #include <rte_memory.h> 16af75078fSIntel #include <rte_eal.h> 17af75078fSIntel #include <rte_atomic.h> 18af75078fSIntel #include <rte_branch_prediction.h> 19af75078fSIntel #include <rte_launch.h> 20af75078fSIntel #include <rte_log.h> 21af75078fSIntel #include <rte_per_lcore.h> 22af75078fSIntel #include <rte_lcore.h> 23af75078fSIntel #include <rte_ring.h> 24af75078fSIntel #include <rte_debug.h> 25af75078fSIntel #include <rte_mempool.h> 26af75078fSIntel #include <rte_string_fns.h> 27af75078fSIntel 28af75078fSIntel #include <cmdline_rdline.h> 29af75078fSIntel #include <cmdline_parse.h> 30af75078fSIntel #include <cmdline_parse_string.h> 31af75078fSIntel #include <cmdline_socket.h> 32af75078fSIntel #include <cmdline.h> 33af75078fSIntel #include "mp_commands.h" 34af75078fSIntel 35af75078fSIntel /**********************************************************/ 36af75078fSIntel 37af75078fSIntel struct cmd_send_result { 38af75078fSIntel cmdline_fixed_string_t action; 39af75078fSIntel cmdline_fixed_string_t message; 40af75078fSIntel }; 41af75078fSIntel 42af75078fSIntel static void cmd_send_parsed(void *parsed_result, 43af75078fSIntel __attribute__((unused)) struct cmdline *cl, 44af75078fSIntel __attribute__((unused)) void *data) 45af75078fSIntel { 46a974564bSIntel void *msg = NULL; 47af75078fSIntel struct cmd_send_result *res = parsed_result; 48af75078fSIntel 49af75078fSIntel if (rte_mempool_get(message_pool, &msg) < 0) 50af75078fSIntel rte_panic("Failed to get message buffer\n"); 51*f9acaf84SBruce Richardson strlcpy((char *)msg, res->message, STR_TOKEN_SIZE); 52af75078fSIntel if (rte_ring_enqueue(send_ring, msg) < 0) { 53af75078fSIntel printf("Failed to send message - message discarded\n"); 54af75078fSIntel rte_mempool_put(message_pool, msg); 55af75078fSIntel } 56af75078fSIntel } 57af75078fSIntel 58af75078fSIntel cmdline_parse_token_string_t cmd_send_action = 59af75078fSIntel TOKEN_STRING_INITIALIZER(struct cmd_send_result, action, "send"); 60af75078fSIntel cmdline_parse_token_string_t cmd_send_message = 61af75078fSIntel TOKEN_STRING_INITIALIZER(struct cmd_send_result, message, NULL); 62af75078fSIntel 63af75078fSIntel cmdline_parse_inst_t cmd_send = { 64af75078fSIntel .f = cmd_send_parsed, /* function to call */ 65af75078fSIntel .data = NULL, /* 2nd arg of func */ 66af75078fSIntel .help_str = "send a string to another process", 67af75078fSIntel .tokens = { /* token list, NULL terminated */ 68af75078fSIntel (void *)&cmd_send_action, 69af75078fSIntel (void *)&cmd_send_message, 70af75078fSIntel NULL, 71af75078fSIntel }, 72af75078fSIntel }; 73af75078fSIntel 74af75078fSIntel /**********************************************************/ 75af75078fSIntel 76af75078fSIntel struct cmd_quit_result { 77af75078fSIntel cmdline_fixed_string_t quit; 78af75078fSIntel }; 79af75078fSIntel 80af75078fSIntel static void cmd_quit_parsed(__attribute__((unused)) void *parsed_result, 81af75078fSIntel struct cmdline *cl, 82af75078fSIntel __attribute__((unused)) void *data) 83af75078fSIntel { 84af75078fSIntel quit = 1; 85af75078fSIntel cmdline_quit(cl); 86af75078fSIntel } 87af75078fSIntel 88af75078fSIntel cmdline_parse_token_string_t cmd_quit_quit = 89af75078fSIntel TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); 90af75078fSIntel 91af75078fSIntel cmdline_parse_inst_t cmd_quit = { 92af75078fSIntel .f = cmd_quit_parsed, /* function to call */ 93af75078fSIntel .data = NULL, /* 2nd arg of func */ 94af75078fSIntel .help_str = "close the application", 95af75078fSIntel .tokens = { /* token list, NULL terminated */ 96af75078fSIntel (void *)&cmd_quit_quit, 97af75078fSIntel NULL, 98af75078fSIntel }, 99af75078fSIntel }; 100af75078fSIntel 101af75078fSIntel /**********************************************************/ 102af75078fSIntel 103af75078fSIntel struct cmd_help_result { 104af75078fSIntel cmdline_fixed_string_t help; 105af75078fSIntel }; 106af75078fSIntel 107af75078fSIntel static void cmd_help_parsed(__attribute__((unused)) void *parsed_result, 108af75078fSIntel struct cmdline *cl, 109af75078fSIntel __attribute__((unused)) void *data) 110af75078fSIntel { 111af75078fSIntel cmdline_printf(cl, "Simple demo example of multi-process in RTE\n\n" 112af75078fSIntel "This is a readline-like interface that can be used to\n" 113af75078fSIntel "send commands to the simple app. Commands supported are:\n\n" 114af75078fSIntel "- send [string]\n" "- help\n" "- quit\n\n"); 115af75078fSIntel } 116af75078fSIntel 117af75078fSIntel cmdline_parse_token_string_t cmd_help_help = 118af75078fSIntel TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help"); 119af75078fSIntel 120af75078fSIntel cmdline_parse_inst_t cmd_help = { 121af75078fSIntel .f = cmd_help_parsed, /* function to call */ 122af75078fSIntel .data = NULL, /* 2nd arg of func */ 123af75078fSIntel .help_str = "show help", 124af75078fSIntel .tokens = { /* token list, NULL terminated */ 125af75078fSIntel (void *)&cmd_help_help, 126af75078fSIntel NULL, 127af75078fSIntel }, 128af75078fSIntel }; 129af75078fSIntel 130af75078fSIntel /****** CONTEXT (list of instruction) */ 131af75078fSIntel cmdline_parse_ctx_t simple_mp_ctx[] = { 132af75078fSIntel (cmdline_parse_inst_t *)&cmd_send, 133af75078fSIntel (cmdline_parse_inst_t *)&cmd_quit, 134af75078fSIntel (cmdline_parse_inst_t *)&cmd_help, 135af75078fSIntel NULL, 136af75078fSIntel }; 137