From patchwork Fri Oct 27 11:01:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 133501 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 844DD43215; Fri, 27 Oct 2023 13:02:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6D07042E27; Fri, 27 Oct 2023 13:01:47 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mails.dpdk.org (Postfix) with ESMTP id 964CB42E10 for ; Fri, 27 Oct 2023 13:01:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698404505; x=1729940505; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XcIW41mdP/aND+hYsOeIRwGJJMHt9INJPO52QPeCgiA=; b=fZg+WrE9DIqeJnjxY0QRHnwL9un8QKcbGX4qKAjGMJ2eLyxumDU/51X8 gbTCV7KwqMOVQG26zMNrM0lnJaPuhiz+qh9NMMImJl+NndQ2Tzvhb8w3t Zc0L6AYU4E97Z6TyLTiqMGDRkJ6Cs4tuK4aGXHztG4ufkxEftvAr+WqNX xtO+lI821xop3OiQYR0jsMcBc8Q3nVQ+6HJXxTMMOBIWm7WtU8dv2CA2n evZ+saE62u3nXx8wT1r7YRbcCxfHmSPCIJN1+6rW8CjbWQVtrEWDkr12Y ZvGKp+XIcSGAdZmIcZh780qYvtwqS/5oqeS0kAE4CkWfANBMYkpINAQF4 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10875"; a="546720" X-IronPort-AV: E=Sophos;i="6.03,256,1694761200"; d="scan'208";a="546720" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2023 04:01:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10875"; a="883157879" X-IronPort-AV: E=Sophos;i="6.03,256,1694761200"; d="scan'208";a="883157879" Received: from silpixa00401385.ir.intel.com ([10.237.214.154]) by orsmga004.jf.intel.com with ESMTP; 27 Oct 2023 04:01:42 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: david.marchand@redhat.com, rjarry@redhat.com, Bruce Richardson Subject: [PATCH v7 9/9] examples/ntb: auto-generate cmdline boilerplate Date: Fri, 27 Oct 2023 12:01:17 +0100 Message-Id: <20231027110117.70995-10-bruce.richardson@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231027110117.70995-1-bruce.richardson@intel.com> References: <20230802170052.955323-1-bruce.richardson@intel.com> <20231027110117.70995-1-bruce.richardson@intel.com> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Use the dpdk-cmdline-gen script to autogenerate all the boilerplate structs and defines for the commandline part of the app. Signed-off-by: Bruce Richardson --- examples/ntb/Makefile | 12 ++- examples/ntb/commands.list | 11 ++ examples/ntb/meson.build | 7 ++ examples/ntb/ntb_fwd.c | 200 ++++--------------------------------- 4 files changed, 47 insertions(+), 183 deletions(-) create mode 100644 examples/ntb/commands.list diff --git a/examples/ntb/Makefile b/examples/ntb/Makefile index d9b6e53090..f5b3405c47 100644 --- a/examples/ntb/Makefile +++ b/examples/ntb/Makefile @@ -6,6 +6,7 @@ APP = ntb_fwd # all source are stored in SRCS-y SRCS-y := ntb_fwd.c +SRC-DEPS := build/commands.h PKGCONF ?= pkg-config @@ -25,10 +26,13 @@ CFLAGS += -D_FILE_OFFSET_BITS=64 LDFLAGS += -pthread PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null) -CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk) +CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk) -I build/ LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk) LDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk) +build/commands.h: commands.list Makefile + dpdk-cmdline-gen.py -o $@ --context-name=main_ctx $< + ifeq ($(MAKECMDGOALS),static) # check for broken pkg-config ifeq ($(shell echo $(LDFLAGS_STATIC) | grep 'whole-archive.*l:lib.*no-whole-archive'),) @@ -39,10 +43,10 @@ endif CFLAGS += -DALLOW_EXPERIMENTAL_API -build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build +build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build $(SRC-DEPS) $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED) -build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build +build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build $(SRC-DEPS) $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC) build: @@ -50,5 +54,5 @@ build: .PHONY: clean clean: - rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared + rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared build/*.h test -d build && rmdir -p build || true diff --git a/examples/ntb/commands.list b/examples/ntb/commands.list new file mode 100644 index 0000000000..a26b8acfa3 --- /dev/null +++ b/examples/ntb/commands.list @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2023 Intel Corporation +# +help # show help +quit # exit application +send filepath # send +start # start pkt fwd between ntb and ethdev +stop # stop packet forwarding +show port stats # show statistics for all ports +clear port stats # clear all port statistics +set fwd <(file-trans,iofwd,txonly,rxonly)>mode # set forwarding mode as file-trans|rxonly|txonly|iofwd diff --git a/examples/ntb/meson.build b/examples/ntb/meson.build index 18eaffdf21..6c23081c41 100644 --- a/examples/ntb/meson.build +++ b/examples/ntb/meson.build @@ -17,3 +17,10 @@ cflags += ['-D_FILE_OFFSET_BITS=64'] sources = files( 'ntb_fwd.c', ) +cmd_h = custom_target('commands_hdr', + output: 'commands.h', + input: files('commands.list'), + capture: true, + command: [cmdline_gen_cmd, '--context-name=main_ctx', '@INPUT@'] +) +sources += cmd_h diff --git a/examples/ntb/ntb_fwd.c b/examples/ntb/ntb_fwd.c index 585aad9d70..95a6148c82 100644 --- a/examples/ntb/ntb_fwd.c +++ b/examples/ntb/ntb_fwd.c @@ -21,6 +21,7 @@ #include #include #include +#include "commands.h" /* Per-port statistics struct */ struct ntb_port_statistics { @@ -103,12 +104,7 @@ static struct rte_eth_conf eth_port_conf = { }, }; -/* *** Help command with introduction. *** */ -struct cmd_help_result { - cmdline_fixed_string_t help; -}; - -static void +void cmd_help_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) @@ -134,26 +130,7 @@ cmd_help_parsed(__rte_unused void *parsed_result, ); } - -cmdline_parse_token_string_t cmd_help_help = - TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, "help"); - -cmdline_parse_inst_t cmd_help = { - .f = cmd_help_parsed, - .data = NULL, - .help_str = "show help", - .tokens = { - (void *)&cmd_help_help, - NULL, - }, -}; - -/* *** QUIT *** */ -struct cmd_quit_result { - cmdline_fixed_string_t quit; -}; - -static void +void cmd_quit_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) @@ -188,31 +165,12 @@ cmd_quit_parsed(__rte_unused void *parsed_result, cmdline_quit(cl); } -cmdline_parse_token_string_t cmd_quit_quit = - TOKEN_STRING_INITIALIZER(struct cmd_quit_result, quit, "quit"); - -cmdline_parse_inst_t cmd_quit = { - .f = cmd_quit_parsed, - .data = NULL, - .help_str = "exit application", - .tokens = { - (void *)&cmd_quit_quit, - NULL, - }, -}; - -/* *** SEND FILE PARAMETERS *** */ -struct cmd_sendfile_result { - cmdline_fixed_string_t send_string; - char filepath[]; -}; - -static void -cmd_sendfile_parsed(void *parsed_result, +void +cmd_send_parsed(void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data) { - struct cmd_sendfile_result *res = parsed_result; + struct cmd_send_result *res = parsed_result; struct rte_rawdev_buf *pkts_send[NTB_MAX_PKT_BURST]; struct rte_mbuf *mbuf_send[NTB_MAX_PKT_BURST]; uint64_t size, count, i, j, nb_burst; @@ -327,24 +285,6 @@ cmd_sendfile_parsed(void *parsed_result, fclose(file); } -cmdline_parse_token_string_t cmd_send_file_send = - TOKEN_STRING_INITIALIZER(struct cmd_sendfile_result, send_string, - "send"); -cmdline_parse_token_string_t cmd_send_file_filepath = - TOKEN_STRING_INITIALIZER(struct cmd_sendfile_result, filepath, NULL); - - -cmdline_parse_inst_t cmd_send_file = { - .f = cmd_sendfile_parsed, - .data = NULL, - .help_str = "send ", - .tokens = { - (void *)&cmd_send_file_send, - (void *)&cmd_send_file_filepath, - NULL, - }, -}; - #define RECV_FILE_LEN 30 static int start_polling_recv_file(void *param) @@ -788,12 +728,7 @@ start_pkt_fwd(void) } } -/* *** START FWD PARAMETERS *** */ -struct cmd_start_result { - cmdline_fixed_string_t start; -}; - -static void +void cmd_start_parsed(__rte_unused void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data) @@ -801,25 +736,7 @@ cmd_start_parsed(__rte_unused void *parsed_result, start_pkt_fwd(); } -cmdline_parse_token_string_t cmd_start_start = - TOKEN_STRING_INITIALIZER(struct cmd_start_result, start, "start"); - -cmdline_parse_inst_t cmd_start = { - .f = cmd_start_parsed, - .data = NULL, - .help_str = "start pkt fwd between ntb and ethdev", - .tokens = { - (void *)&cmd_start_start, - NULL, - }, -}; - -/* *** STOP *** */ -struct cmd_stop_result { - cmdline_fixed_string_t stop; -}; - -static void +void cmd_stop_parsed(__rte_unused void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data) @@ -844,19 +761,6 @@ cmd_stop_parsed(__rte_unused void *parsed_result, printf("\nDone.\n"); } -cmdline_parse_token_string_t cmd_stop_stop = - TOKEN_STRING_INITIALIZER(struct cmd_stop_result, stop, "stop"); - -cmdline_parse_inst_t cmd_stop = { - .f = cmd_stop_parsed, - .data = NULL, - .help_str = "stop: Stop packet forwarding", - .tokens = { - (void *)&cmd_stop_stop, - NULL, - }, -}; - static void ntb_stats_clear(void) { @@ -975,58 +879,28 @@ ntb_stats_display(void) free(ids); } -/* *** SHOW/CLEAR PORT STATS *** */ -struct cmd_stats_result { - cmdline_fixed_string_t show; - cmdline_fixed_string_t port; - cmdline_fixed_string_t stats; -}; - -static void -cmd_stats_parsed(void *parsed_result, +void +cmd_show_port_stats_parsed(__rte_unused void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data) { - struct cmd_stats_result *res = parsed_result; - if (!strcmp(res->show, "clear")) - ntb_stats_clear(); - else - ntb_stats_display(); + ntb_stats_display(); } -cmdline_parse_token_string_t cmd_stats_show = - TOKEN_STRING_INITIALIZER(struct cmd_stats_result, show, "show#clear"); -cmdline_parse_token_string_t cmd_stats_port = - TOKEN_STRING_INITIALIZER(struct cmd_stats_result, port, "port"); -cmdline_parse_token_string_t cmd_stats_stats = - TOKEN_STRING_INITIALIZER(struct cmd_stats_result, stats, "stats"); - - -cmdline_parse_inst_t cmd_stats = { - .f = cmd_stats_parsed, - .data = NULL, - .help_str = "show|clear port stats", - .tokens = { - (void *)&cmd_stats_show, - (void *)&cmd_stats_port, - (void *)&cmd_stats_stats, - NULL, - }, -}; - -/* *** SET FORWARDING MODE *** */ -struct cmd_set_fwd_mode_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t fwd; - cmdline_fixed_string_t mode; -}; +void +cmd_clear_port_stats_parsed(__rte_unused void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + ntb_stats_clear(); +} -static void -cmd_set_fwd_mode_parsed(__rte_unused void *parsed_result, +void +cmd_set_fwd_parsed(void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data) { - struct cmd_set_fwd_mode_result *res = parsed_result; + struct cmd_set_fwd_result *res = parsed_result; int i; if (in_test) { @@ -1043,38 +917,6 @@ cmd_set_fwd_mode_parsed(__rte_unused void *parsed_result, printf("Invalid %s packet forwarding mode.\n", res->mode); } -cmdline_parse_token_string_t cmd_setfwd_set = - TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, set, "set"); -cmdline_parse_token_string_t cmd_setfwd_fwd = - TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, fwd, "fwd"); -cmdline_parse_token_string_t cmd_setfwd_mode = - TOKEN_STRING_INITIALIZER(struct cmd_set_fwd_mode_result, mode, - "file-trans#iofwd#txonly#rxonly"); - -cmdline_parse_inst_t cmd_set_fwd_mode = { - .f = cmd_set_fwd_mode_parsed, - .data = NULL, - .help_str = "set forwarding mode as file-trans|rxonly|txonly|iofwd", - .tokens = { - (void *)&cmd_setfwd_set, - (void *)&cmd_setfwd_fwd, - (void *)&cmd_setfwd_mode, - NULL, - }, -}; - -/* list of instructions */ -cmdline_parse_ctx_t main_ctx[] = { - (cmdline_parse_inst_t *)&cmd_help, - (cmdline_parse_inst_t *)&cmd_send_file, - (cmdline_parse_inst_t *)&cmd_start, - (cmdline_parse_inst_t *)&cmd_stop, - (cmdline_parse_inst_t *)&cmd_stats, - (cmdline_parse_inst_t *)&cmd_set_fwd_mode, - (cmdline_parse_inst_t *)&cmd_quit, - NULL, -}; - /* prompt function, called from main on MAIN lcore */ static void prompt(void)