From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9817843215; Fri, 27 Oct 2023 13:02:32 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7D8B642E0A; Fri, 27 Oct 2023 13:01:44 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mails.dpdk.org (Postfix) with ESMTP id 4D40142DDA for ; Fri, 27 Oct 2023 13:01:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698404502; x=1729940502; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eHJRZHmN4kFqKeivEFmViSHUGQL6TI2gSbwpJ0KbhFQ=; b=BK9lf3L4L+MM/CUmYyhhlrbZ88Kl9KbgmEBKbqZ+9hfoIlYsbne1pAs8 8RRTqe3D02I08i4rGmlKh8tFbchN8CZ1uv2dXcxkLh3x6+nZqyHMQL0El jb12wl2OXs8JYyeZ9yjTURmaM4e4CfIOHT9K+91ZAXm4eyWZ7PfbGHAie 93w1ZVKT4a5ItpIpA1wsd9WYL0sE0qZiE8VsWT11pB/qy6jWzzbm5rGQj r95jxw/YWkp1BsKmNcwqbI+1qEMMh9485zA52e8DaBTpPx952OlcqZQDe fFIvWlF1RbDss8XNbaQ6Vr2YTLuZI3HaTfSh4KilFHfiIcuOmRwN7CFEn A==; X-IronPort-AV: E=McAfee;i="6600,9927,10875"; a="546710" X-IronPort-AV: E=Sophos;i="6.03,256,1694761200"; d="scan'208";a="546710" 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:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10875"; a="883157872" X-IronPort-AV: E=Sophos;i="6.03,256,1694761200"; d="scan'208";a="883157872" Received: from silpixa00401385.ir.intel.com ([10.237.214.154]) by orsmga004.jf.intel.com with ESMTP; 27 Oct 2023 04:01:39 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: david.marchand@redhat.com, rjarry@redhat.com, Bruce Richardson Subject: [PATCH v7 7/9] examples/vdpa: auto-generate cmdline boilerplate Date: Fri, 27 Oct 2023 12:01:15 +0100 Message-Id: <20231027110117.70995-8-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 Content-Transfer-Encoding: 8bit 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/vdpa/Makefile | 12 ++-- examples/vdpa/commands.list | 8 +++ examples/vdpa/main.c | 131 ++---------------------------------- examples/vdpa/meson.build | 7 ++ 4 files changed, 30 insertions(+), 128 deletions(-) create mode 100644 examples/vdpa/commands.list diff --git a/examples/vdpa/Makefile b/examples/vdpa/Makefile index d974db4f40..aa60a000cf 100644 --- a/examples/vdpa/Makefile +++ b/examples/vdpa/Makefile @@ -6,6 +6,7 @@ APP = vdpa # all source are stored in SRCS-y SRCS-y := main.c +SRC-DEPS := build/commands.h CFLAGS += -DALLOW_EXPERIMENTAL_API PKGCONF ?= pkg-config @@ -23,10 +24,13 @@ static: build/$(APP)-static ln -sf $(APP)-static build/$(APP) 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'),) @@ -35,10 +39,10 @@ $(error "Cannot generate statically-linked binaries with this version of pkg-con endif endif -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: @@ -46,5 +50,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/vdpa/commands.list b/examples/vdpa/commands.list new file mode 100644 index 0000000000..1eb8486c45 --- /dev/null +++ b/examples/vdpa/commands.list @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2023 Intel Corporation +# +help # show help +list # list all available vdpa devices +create socket_path bdf # create a new vdpa port +stats bdf qid # show device statistics +quit # exit application diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index 4d3203f3a7..289db26498 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -16,11 +16,8 @@ #include #include -#include #include -#include -#include -#include +#include "commands.h" /* auto-generated file from commands.list */ #include "vdpa_blk_compact.h" #define MAX_PATH_LEN 128 @@ -301,14 +298,9 @@ signal_handler(int signum) } } -/* interactive cmds */ +/* interactive cmd functions */ -/* *** Help command with introduction. *** */ -struct cmd_help_result { - cmdline_fixed_string_t help; -}; - -static void cmd_help_parsed(__rte_unused void *parsed_result, +void cmd_help_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) { @@ -325,25 +317,7 @@ static void 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, - }, -}; - -/* *** List all available vdpa devices *** */ -struct cmd_list_result { - cmdline_fixed_string_t action; -}; - -static void cmd_list_vdpa_devices_parsed( +void cmd_list_parsed( __rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) @@ -376,27 +350,7 @@ static void cmd_list_vdpa_devices_parsed( } } -cmdline_parse_token_string_t cmd_action_list = - TOKEN_STRING_INITIALIZER(struct cmd_list_result, action, "list"); - -cmdline_parse_inst_t cmd_list_vdpa_devices = { - .f = cmd_list_vdpa_devices_parsed, - .data = NULL, - .help_str = "list all available vdpa devices", - .tokens = { - (void *)&cmd_action_list, - NULL, - }, -}; - -/* *** Create new vdpa port *** */ -struct cmd_create_result { - cmdline_fixed_string_t action; - cmdline_fixed_string_t socket_path; - cmdline_fixed_string_t bdf; -}; - -static void cmd_create_vdpa_port_parsed(void *parsed_result, +void cmd_create_parsed(void *parsed_result, struct cmdline *cl, __rte_unused void *data) { @@ -417,33 +371,7 @@ static void cmd_create_vdpa_port_parsed(void *parsed_result, devcnt++; } -cmdline_parse_token_string_t cmd_action_create = - TOKEN_STRING_INITIALIZER(struct cmd_create_result, action, "create"); -cmdline_parse_token_string_t cmd_socket_path = - TOKEN_STRING_INITIALIZER(struct cmd_create_result, socket_path, NULL); -cmdline_parse_token_string_t cmd_bdf = - TOKEN_STRING_INITIALIZER(struct cmd_create_result, bdf, NULL); - -cmdline_parse_inst_t cmd_create_vdpa_port = { - .f = cmd_create_vdpa_port_parsed, - .data = NULL, - .help_str = "create a new vdpa port", - .tokens = { - (void *)&cmd_action_create, - (void *)&cmd_socket_path, - (void *)&cmd_bdf, - NULL, - }, -}; - -/* *** STATS *** */ -struct cmd_stats_result { - cmdline_fixed_string_t stats; - cmdline_fixed_string_t bdf; - uint16_t qid; -}; - -static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, +void cmd_stats_parsed(void *parsed_result, struct cmdline *cl, __rte_unused void *data) { struct cmd_stats_result *res = parsed_result; @@ -525,31 +453,7 @@ static void cmd_device_stats_parsed(void *parsed_result, struct cmdline *cl, } } -cmdline_parse_token_string_t cmd_device_stats_ = - TOKEN_STRING_INITIALIZER(struct cmd_stats_result, stats, "stats"); -cmdline_parse_token_string_t cmd_device_bdf = - TOKEN_STRING_INITIALIZER(struct cmd_stats_result, bdf, NULL); -cmdline_parse_token_num_t cmd_queue_id = - TOKEN_NUM_INITIALIZER(struct cmd_stats_result, qid, RTE_UINT32); - -cmdline_parse_inst_t cmd_device_stats = { - .f = cmd_device_stats_parsed, - .data = NULL, - .help_str = "stats: show device statistics", - .tokens = { - (void *)&cmd_device_stats_, - (void *)&cmd_device_bdf, - (void *)&cmd_queue_id, - NULL, - }, -}; - -/* *** QUIT *** */ -struct cmd_quit_result { - cmdline_fixed_string_t quit; -}; - -static void cmd_quit_parsed(__rte_unused void *parsed_result, +void cmd_quit_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) { @@ -557,27 +461,6 @@ static void 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 = "quit: exit application", - .tokens = { - (void *)&cmd_quit_quit, - NULL, - }, -}; -cmdline_parse_ctx_t main_ctx[] = { - (cmdline_parse_inst_t *)&cmd_help, - (cmdline_parse_inst_t *)&cmd_list_vdpa_devices, - (cmdline_parse_inst_t *)&cmd_create_vdpa_port, - (cmdline_parse_inst_t *)&cmd_device_stats, - (cmdline_parse_inst_t *)&cmd_quit, - NULL, -}; - int main(int argc, char *argv[]) { diff --git a/examples/vdpa/meson.build b/examples/vdpa/meson.build index bd086050dc..a48028da4d 100644 --- a/examples/vdpa/meson.build +++ b/examples/vdpa/meson.build @@ -16,3 +16,10 @@ allow_experimental_apis = true sources = files( 'main.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 -- 2.39.2