From patchwork Mon Oct 16 14:06:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 132634 X-Patchwork-Delegate: thomas@monjalon.net 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 B8DEC4317F; Mon, 16 Oct 2023 16:07:24 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E8FB640E40; Mon, 16 Oct 2023 16:06:45 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 8F80240DFB for ; Mon, 16 Oct 2023 16:06:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697465203; x=1729001203; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DyaNgX/ULFPRYUlIAZvxPvUU763vDYCK/fkGChLAJN0=; b=F2MME8PWlYcT7PhK3xf7EdnHYQUYImX90TFWy7BPVqXdUKQEW8YA6l+v iXKlCnlIE9/2ONIKUyltfqLVa761rhc6Ki+90EpH2moUCWTuHg/k2rYvO nkntGD8+h4NHHE5mWRA+4FTNZ+M9nubQwZnV0W9bh2U32Hrrhc0StQLxD wrkDeCEmor2OQGeaW9yvyMOenzVyGWkN7KNJMrhPJPN6Ff0vXYIBJzO4G 2Gy9pyVCLQGMUO311uQFZJb2k+F1JywUmZp6sqjOKuXmIOTBdW23J2ATj J2e4n2yHrF71dogKyvzm4wcpUw5j3V0zFEADZ+KP3HTXT2wp+e8tCRC2K Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="385370341" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="385370341" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 07:06:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="821584042" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="821584042" Received: from silpixa00401385.ir.intel.com ([10.237.214.154]) by fmsmga008.fm.intel.com with ESMTP; 16 Oct 2023 07:06:40 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: david.marchand@redhat.com, rjarry@redhat.com, Bruce Richardson , Maxime Coquelin , Chenbo Xia Subject: [PATCH v4 7/7] examples/vdpa: auto-generate cmdline boilerplate Date: Mon, 16 Oct 2023 15:06:12 +0100 Message-Id: <20231016140612.664853-8-bruce.richardson@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231016140612.664853-1-bruce.richardson@intel.com> References: <20230802170052.955323-1-bruce.richardson@intel.com> <20231016140612.664853-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/vdpa/Makefile | 12 ++-- examples/vdpa/commands.list | 5 ++ examples/vdpa/main.c | 131 ++---------------------------------- examples/vdpa/meson.build | 7 ++ 4 files changed, 27 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..0d83b7c0e9 --- /dev/null +++ b/examples/vdpa/commands.list @@ -0,0 +1,5 @@ +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