From patchwork Mon Sep 18 13:03:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 131570 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 6C7E5425D1; Mon, 18 Sep 2023 15:04:09 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D5BFE406B6; Mon, 18 Sep 2023 15:04:05 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id EDA69402E9 for ; Mon, 18 Sep 2023 15:04:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695042244; x=1726578244; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Q6X4+XrTZnGqehR8VOKiHBDU2cKd9vL1tM0DiwP18Fw=; b=eaJuG7IZfl4nO0Ev1DQI33YLImBL+BcuG57ShnOcxKpuwu8zSZYaOtMd ZV1WDnMVTBfPR1oUcDE6xiXVkc+lV+jLFSYmtxxdoUsOYxh8y6jauFCft zUsth+tRmLLCZ2licHEZaBxcSTAQcAiVyMlOS+A9/rNXOJyi0h9AXXZ2U hEZyrPopGN7bF7cfpJ4iF1rI/jazykE8ZjCwCUe/iv2wpHHt4lDRa9M+b uqJaLlANy2noUG/n0V6J4Aq0ikXj62XcL89XgJ2PDE3rn+oVU76Nv2HOi ju6sDbd1aLRc2Oad0QfXWCZ/BYFZ9YQg3vI5ClKMM0m2jstvnd8A3Zzce Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="369969378" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="369969378" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2023 06:04:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="739130631" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="739130631" Received: from silpixa00401385.ir.intel.com ([10.237.214.14]) by orsmga007.jf.intel.com with ESMTP; 18 Sep 2023 06:04:00 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Olivier Matz , Bruce Richardson Subject: [RFC PATCH v2 1/5] buildtools/dpdk-cmdline-gen: generate boilerplate for simple cmds Date: Mon, 18 Sep 2023 14:03:48 +0100 Message-Id: <20230918130352.379478-2-bruce.richardson@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918130352.379478-1-bruce.richardson@intel.com> References: <20230802170052.955323-1-bruce.richardson@intel.com> <20230918130352.379478-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 Provide a script for application developers to quickly generate the boilerplate code necessary for using the cmdline library. This initial version works only with commands using simple strings and numbers, but this is sufficient for many use-cases. Future extensions could, no doubt, expand support to expose more capabilities of the library. Example of use: The script takes an input file with a list of commands the user wants in the app, where the parameter variables are tagged with the type. For example: $ cat commands.list list add x y echo message add socket path quit When run through the script as "./dpdk-cmdline-gen.py commands.list", the output will be the contents of a header file with all the boilerplate necessary for a commandline instance with those commands. If the flag --stubs is passed, an output header filename must also be passed, in which case both a header file with the definitions and a C file with function stubs in it is written to disk. The separation is so that the header file can be rewritten at any future point to add more commands, while the C file can be kept as-is and extended by the user with any additional functions needed. Signed-off-by: Bruce Richardson --- buildtools/dpdk-cmdline-gen.py | 146 +++++++++++++++++++++++++++++++++ buildtools/meson.build | 7 ++ 2 files changed, 153 insertions(+) create mode 100755 buildtools/dpdk-cmdline-gen.py diff --git a/buildtools/dpdk-cmdline-gen.py b/buildtools/dpdk-cmdline-gen.py new file mode 100755 index 0000000000..1ddd8b6bbb --- /dev/null +++ b/buildtools/dpdk-cmdline-gen.py @@ -0,0 +1,146 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2023 Intel Corporation +# + +import sys +import os +import argparse + +PARSE_FN_PARAMS = "void *parsed_result, struct cmdline *cl, void *data" +PARSE_FN_BODY = """ + /* TODO: command action */ + RTE_SET_USED(parsed_result); + RTE_SET_USED(cl); + RTE_SET_USED(data); +""" + +def process_command(tokens, cfile): + name = [] + + if tokens[0].startswith('<'): + print("Error: each command must start with at least one literal string", + file=sys.stderr) + sys.exit(1) + for t in tokens: + if t.startswith('<'): + break; + name.append(t) + name = "_".join(name) + + result_struct = [] + initializers = [] + token_list = [] + for t in tokens: + if t.startswith('<'): + t_type, t_name = t[1:].split('>') + t_val = "NULL" + else: + t_type = "STRING" + t_name = t + t_val = f'"{t}"' + + if t_type == "STRING": + result_struct.append(f"\tcmdline_fixed_string_t {t_name};") + initializers.append(f"static cmdline_parse_token_string_t cmd_{name}_{t_name}_tok =\n" + + f"\tTOKEN_STRING_INITIALIZER(struct cmd_{name}_result, {t_name}, {t_val});") + elif t_type in ['UINT8', 'UINT16', 'UINT32', 'UINT64', + 'INT8', 'INT16', 'INT32', 'INT64']: + result_struct.append(f"\t{t_type.lower()}_t {t_name};") + initializers.append(f"static cmdline_parse_token_num_t cmd_{name}_{t_name}_tok =\n" + + f"\tTOKEN_NUM_INITIALIZER(struct cmd_{name}_result, {t_name}, RTE_{t_type});") + else: + print(f"Error: unknown token-type {t}", file=sys.stderr) + sys.exit(1) + token_list.append(f"cmd_{name}_{t_name}_tok") + + print(f"/* Auto-generated handling for command '{' '.join(tokens)}' */") + # output function prototype + func_sig = f"void\ncmd_{name}_parsed({PARSE_FN_PARAMS})" + print(f"extern {func_sig};\n") + # output function template if C file being written + if (cfile): + print(f"{func_sig}\n{{{PARSE_FN_BODY}}}\n", file=cfile) + # output result data structure + print(f"struct cmd_{name}_result {{\n" + + '\n'.join(result_struct) + + "\n};\n") + # output the initializer tokens + print("\n".join(initializers) + '\n') + # output the instance structure + print(f"static cmdline_parse_inst_t cmd_{name} = {{\n" + + f'\t.f = cmd_{name}_parsed,\n' + + f'\t.data = NULL,\n' + + f'\t.help_str = "",\n' + + f'\t.tokens = {{') + for t in token_list: + print(f"\t\t(void *)&{t},") + print("\t\tNULL\n" + + "\t}\n" + + "};\n") + + # return the instance structure name + return f"cmd_{name}" + +def process_commands(infile, hfile, cfile, ctxname): + instances = [] + + # redirect stdout to output the header, to save passing file= each print + old_sys_stdout = sys.stdout + sys.stdout = hfile + + print(f"/* File autogenerated by {sys.argv[0]} */") + print('#ifndef GENERATED_COMMANDS_H') + print('#define GENERATED_COMMANDS_H') + print("#include ") + print("#include ") + print("#include ") + print("#include ") + print("") + + for line in infile.readlines(): + if line.lstrip().startswith('#'): + continue + instances.append(process_command(line.strip().split(), cfile)) + + print(f'static __rte_used cmdline_parse_ctx_t {ctxname}[] = {{') + for inst in instances: + print(f'\t&{inst},') + print('\tNULL') + print('};\n') + print('#endif /* GENERATED_COMMANDS_H */') + + sys.stdout = old_sys_stdout + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--stubs", action="store_true", + help="Produce C file with empty function stubs for each command") + ap.add_argument("--output-file", "-o", default="-", + help="Output header filename [default to stdout]") + ap.add_argument("--context-name", default="ctx", + help="Name given to the cmdline context variable in the output header [default=ctx]") + ap.add_argument("infile", type=argparse.FileType('r'), + help="File with list of commands") + args = ap.parse_args() + + if not args.stubs: + if args.output_file == '-': + process_commands(args.infile, sys.stdout, None, args.context_name) + else: + with open(args.output_file, "w") as hfile: + process_commands(args.infile, hfile, None, args.context_name) + else: + if not args.output_file.endswith('.h'): + print("Error: output filename must end with '.h' extension when creating stubs", + file=sys.stderr) + sys.exit(1) + + cfilename = args.output_file[:-2] + '.c' + with open(args.output_file, "w") as hfile: + with open(cfilename, "w") as cfile: + print(f"#include \"{args.output_file}\"\n", file=cfile) + process_commands(args.infile, hfile, cfile, args.context_name) + +if __name__ == "__main__": + main() diff --git a/buildtools/meson.build b/buildtools/meson.build index 948ac17dd2..72447b60a0 100644 --- a/buildtools/meson.build +++ b/buildtools/meson.build @@ -19,6 +19,13 @@ get_cpu_count_cmd = py3 + files('get-cpu-count.py') get_numa_count_cmd = py3 + files('get-numa-count.py') get_test_suites_cmd = py3 + files('get-test-suites.py') has_hugepages_cmd = py3 + files('has-hugepages.py') +cmdline_gen_cmd = py3 + files('dpdk-cmdline-gen.py') + +# install any build tools that end-users might want also +install_data([ + 'dpdk-cmdline-gen.py', + ], + install_dir: 'bin') # select library and object file format pmdinfo = py3 + files('gen-pmdinfo-cfile.py') + [meson.current_build_dir()] From patchwork Mon Sep 18 13:03:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 131571 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 689B7425D1; Mon, 18 Sep 2023 15:04:21 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A8DEC40A7A; Mon, 18 Sep 2023 15:04:07 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id D6B4E402E9 for ; Mon, 18 Sep 2023 15:04:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695042245; x=1726578245; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dY2Y/5GGi/o0inJq+GzWxXcjoCKkpNfa/aSNHlTetdU=; b=QuCIhb36+DAfHG3QLwOcD1xSV1wnO3lrM3AtmE+WMuysginHWJztuI7B TI6mr+uymh4o5tT3a5mSJPG7K++5AHDACZ7Fr/wrBX9Q5sb/Xn8awERfk pukwa7mLIRxZi1F256CuRyTEIJh8Flx+Ieq2Eu0aDWjmEVjKyPZh4Ijp2 /stZtE8Z3lkAipmWzjYWf2Y82aJcqK2riY4ZOc86ahIWofUZfVZMFvyqc 3TxPo8q08kg22n7k6hvFoHIL5GOLhAOXkPV+udzANxf27hncrgUQsCHpp qy3x1aYWl74w2CO1SauiZ0MXzBlhuOkcfXuKQfumLV2fi4zI5j44PXx0B Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="369969382" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="369969382" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2023 06:04:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="739130635" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="739130635" Received: from silpixa00401385.ir.intel.com ([10.237.214.14]) by orsmga007.jf.intel.com with ESMTP; 18 Sep 2023 06:04:03 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Olivier Matz , Bruce Richardson Subject: [RFC PATCH v2 2/5] examples/simple_mp: auto-generate cmdline boilerplate Date: Mon, 18 Sep 2023 14:03:49 +0100 Message-Id: <20230918130352.379478-3-bruce.richardson@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918130352.379478-1-bruce.richardson@intel.com> References: <20230802170052.955323-1-bruce.richardson@intel.com> <20230918130352.379478-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/multi_process/simple_mp/Makefile | 10 +- examples/multi_process/simple_mp/meson.build | 9 ++ .../multi_process/simple_mp/mp_commands.c | 106 ++---------------- .../multi_process/simple_mp/mp_commands.h | 14 --- .../multi_process/simple_mp/mp_commands.list | 3 + 5 files changed, 29 insertions(+), 113 deletions(-) delete mode 100644 examples/multi_process/simple_mp/mp_commands.h create mode 100644 examples/multi_process/simple_mp/mp_commands.list -- 2.39.2 diff --git a/examples/multi_process/simple_mp/Makefile b/examples/multi_process/simple_mp/Makefile index 1d0a260e64..b460f53ece 100644 --- a/examples/multi_process/simple_mp/Makefile +++ b/examples/multi_process/simple_mp/Makefile @@ -6,6 +6,7 @@ APP = simple_mp # all source are stored in SRCS-y SRCS-y := main.c mp_commands.c +SRC-DEPS := build/mp_commands.h PKGCONF ?= pkg-config @@ -22,10 +23,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/mp_commands.h: mp_commands.list Makefile + dpdk-cmdline-gen.py -o $@ --context-name=simple_mp_ctx $< + ifeq ($(MAKECMDGOALS),static) # check for broken pkg-config ifeq ($(shell echo $(LDFLAGS_STATIC) | grep 'whole-archive.*l:lib.*no-whole-archive'),) @@ -36,10 +40,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: diff --git a/examples/multi_process/simple_mp/meson.build b/examples/multi_process/simple_mp/meson.build index 359af4384d..e99b7a3f6f 100644 --- a/examples/multi_process/simple_mp/meson.build +++ b/examples/multi_process/simple_mp/meson.build @@ -7,7 +7,16 @@ # DPDK instance, use 'make' allow_experimental_apis = true + +cmd_h = custom_target('commands_hdr', + output: 'mp_commands.h', + input: files('mp_commands.list'), + capture: true, + command: [cmdline_gen_cmd, '--context-name=simple_mp_ctx', '@INPUT@'] +) + sources = files( 'mp_commands.c', 'main.c', ) +sources += cmd_h diff --git a/examples/multi_process/simple_mp/mp_commands.c b/examples/multi_process/simple_mp/mp_commands.c index a5f91b00be..df9fa94208 100644 --- a/examples/multi_process/simple_mp/mp_commands.c +++ b/examples/multi_process/simple_mp/mp_commands.c @@ -1,44 +1,18 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2010-2014 Intel Corporation + * Copyright(c) 2010-2023 Intel Corporation */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include #include -#include #include #include -#include -#include -#include -#include -#include #include "mp_commands.h" -/**********************************************************/ - -struct cmd_send_result { - cmdline_fixed_string_t action; - cmdline_fixed_string_t message; -}; +extern struct rte_ring *send_ring, *recv_ring; +extern struct rte_mempool *message_pool; +extern volatile int quit; -static void cmd_send_parsed(void *parsed_result, +void +cmd_send_parsed(void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data) { @@ -54,29 +28,8 @@ static void cmd_send_parsed(void *parsed_result, } } -cmdline_parse_token_string_t cmd_send_action = - TOKEN_STRING_INITIALIZER(struct cmd_send_result, action, "send"); -cmdline_parse_token_string_t cmd_send_message = - TOKEN_STRING_INITIALIZER(struct cmd_send_result, message, NULL); - -cmdline_parse_inst_t cmd_send = { - .f = cmd_send_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "send a string to another process", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_send_action, - (void *)&cmd_send_message, - NULL, - }, -}; - -/**********************************************************/ - -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) { @@ -84,26 +37,8 @@ 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, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "close the application", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_quit_quit, - NULL, - }, -}; - -/**********************************************************/ - -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) { @@ -112,24 +47,3 @@ static void cmd_help_parsed(__rte_unused void *parsed_result, "send commands to the simple app. Commands supported are:\n\n" "- send [string]\n" "- help\n" "- quit\n\n"); } - -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, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "show help", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_help_help, - NULL, - }, -}; - -/****** CONTEXT (list of instruction) */ -cmdline_parse_ctx_t simple_mp_ctx[] = { - (cmdline_parse_inst_t *)&cmd_send, - (cmdline_parse_inst_t *)&cmd_quit, - (cmdline_parse_inst_t *)&cmd_help, - NULL, -}; diff --git a/examples/multi_process/simple_mp/mp_commands.h b/examples/multi_process/simple_mp/mp_commands.h deleted file mode 100644 index 5d67413e7c..0000000000 --- a/examples/multi_process/simple_mp/mp_commands.h +++ /dev/null @@ -1,14 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2010-2014 Intel Corporation - */ - -#ifndef _SIMPLE_MP_COMMANDS_H_ -#define _SIMPLE_MP_COMMANDS_H_ - -extern struct rte_ring *send_ring; -extern struct rte_mempool *message_pool; -extern volatile int quit; - -extern cmdline_parse_ctx_t simple_mp_ctx[]; - -#endif /* _SIMPLE_MP_COMMANDS_H_ */ diff --git a/examples/multi_process/simple_mp/mp_commands.list b/examples/multi_process/simple_mp/mp_commands.list new file mode 100644 index 0000000000..da452249a6 --- /dev/null +++ b/examples/multi_process/simple_mp/mp_commands.list @@ -0,0 +1,3 @@ +send message +help +quit \ No newline at end of file From patchwork Mon Sep 18 13:03:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 131572 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 8DA48425D1; Mon, 18 Sep 2023 15:04:31 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DDD1E40A84; Mon, 18 Sep 2023 15:04:08 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id C27E8409FA for ; Mon, 18 Sep 2023 15:04:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695042247; x=1726578247; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kXNOtVfgugGxE1ZJlf1z03ZiLUy8KLypWgjuRvJY/Jk=; b=ecV7uvKovIEHaBeCiTEEksQpKRBeMSVYdhz5Jpn/wAF4tcD6ObIFt66H 4e2GBAjKeBpRzkfWHws4Y1zM1X5jTlbWRFYHaEW5s6zlA6btPyLBZS6c+ Mxv1o/vCjKsEL/TctuuQbw4EgyomN7rZ0/bJRO4I3PBSUukOtvcuAUVow YkH2lZWatdb+z9zqSJko2YcpbfkIJYOjhWk6+iZ0ICD3GnmdKX+FQdYYj APTv3ZWaSJ5OdamVodyaneNMjEedVndbkSnP/aqvtpDS3kXw+IpN4rFSl yBlSQS6nW0VBLjxHQgTfKuqlUV8C4kM8/OwuANjaApxwavQ/sbUXL7rGA A==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="369969394" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="369969394" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2023 06:04:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="739130639" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="739130639" Received: from silpixa00401385.ir.intel.com ([10.237.214.14]) by orsmga007.jf.intel.com with ESMTP; 18 Sep 2023 06:04:04 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Olivier Matz , Bruce Richardson Subject: [RFC PATCH v2 3/5] examples/hotplug_mp: auto-generate cmdline boilerplate Date: Mon, 18 Sep 2023 14:03:50 +0100 Message-Id: <20230918130352.379478-4-bruce.richardson@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918130352.379478-1-bruce.richardson@intel.com> References: <20230802170052.955323-1-bruce.richardson@intel.com> <20230918130352.379478-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/multi_process/hotplug_mp/Makefile | 10 +- examples/multi_process/hotplug_mp/commands.c | 147 ++---------------- examples/multi_process/hotplug_mp/commands.h | 10 -- .../multi_process/hotplug_mp/commands.list | 5 + examples/multi_process/hotplug_mp/meson.build | 9 ++ 5 files changed, 34 insertions(+), 147 deletions(-) delete mode 100644 examples/multi_process/hotplug_mp/commands.h create mode 100644 examples/multi_process/hotplug_mp/commands.list diff --git a/examples/multi_process/hotplug_mp/Makefile b/examples/multi_process/hotplug_mp/Makefile index 6b20d6e49a..77e8fe2737 100644 --- a/examples/multi_process/hotplug_mp/Makefile +++ b/examples/multi_process/hotplug_mp/Makefile @@ -6,6 +6,7 @@ APP = hotplug_mp # all source are stored in SRCS-y SRCS-y := main.c commands.c +SRC-DEPS := build/commands.h PKGCONF ?= pkg-config @@ -22,10 +23,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'),) @@ -36,10 +40,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: diff --git a/examples/multi_process/hotplug_mp/commands.c b/examples/multi_process/hotplug_mp/commands.c index 88f44e00a0..900eb9f774 100644 --- a/examples/multi_process/hotplug_mp/commands.c +++ b/examples/multi_process/hotplug_mp/commands.c @@ -1,24 +1,12 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2018 Intel Corporation. + * Copyright(c) 2018-2023 Intel Corporation. */ -#include -#include -#include -#include -#include -#include - #include #include +#include "commands.h" -/**********************************************************/ - -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) { @@ -29,52 +17,16 @@ static void cmd_help_parsed(__rte_unused void *parsed_result, "- list\n\n"); } -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, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "show help", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_help_help, - NULL, - }, -}; - -/**********************************************************/ - -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) { 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, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "quit", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_quit_quit, - NULL, - }, -}; - -/**********************************************************/ - -struct cmd_list_result { - cmdline_fixed_string_t list; -}; - -static void cmd_list_parsed(__rte_unused void *parsed_result, +void +cmd_list_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) { @@ -92,31 +44,12 @@ static void cmd_list_parsed(__rte_unused void *parsed_result, } } -cmdline_parse_token_string_t cmd_list_list = - TOKEN_STRING_INITIALIZER(struct cmd_list_result, list, "list"); - -cmdline_parse_inst_t cmd_list = { - .f = cmd_list_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "list all devices", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_list_list, - NULL, - }, -}; - -/**********************************************************/ - -struct cmd_dev_attach_result { - cmdline_fixed_string_t attach; - cmdline_fixed_string_t devargs; -}; - -static void cmd_dev_attach_parsed(void *parsed_result, +void +cmd_attach_parsed(void *parsed_result, struct cmdline *cl, __rte_unused void *data) { - struct cmd_dev_attach_result *res = parsed_result; + struct cmd_attach_result *res = parsed_result; struct rte_devargs da; memset(&da, 0, sizeof(da)); @@ -134,35 +67,12 @@ static void cmd_dev_attach_parsed(void *parsed_result, rte_devargs_reset(&da); } -cmdline_parse_token_string_t cmd_dev_attach_attach = - TOKEN_STRING_INITIALIZER(struct cmd_dev_attach_result, attach, - "attach"); -cmdline_parse_token_string_t cmd_dev_attach_devargs = - TOKEN_STRING_INITIALIZER(struct cmd_dev_attach_result, devargs, NULL); - -cmdline_parse_inst_t cmd_attach_device = { - .f = cmd_dev_attach_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "attach a device", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_dev_attach_attach, - (void *)&cmd_dev_attach_devargs, - NULL, - }, -}; - -/**********************************************************/ - -struct cmd_dev_detach_result { - cmdline_fixed_string_t detach; - cmdline_fixed_string_t devargs; -}; - -static void cmd_dev_detach_parsed(void *parsed_result, +void +cmd_detach_parsed(void *parsed_result, struct cmdline *cl, __rte_unused void *data) { - struct cmd_dev_detach_result *res = parsed_result; + struct cmd_detach_result *res = parsed_result; struct rte_devargs da; memset(&da, 0, sizeof(da)); @@ -181,34 +91,3 @@ static void cmd_dev_detach_parsed(void *parsed_result, da.name); rte_devargs_reset(&da); } - -cmdline_parse_token_string_t cmd_dev_detach_detach = - TOKEN_STRING_INITIALIZER(struct cmd_dev_detach_result, detach, - "detach"); - -cmdline_parse_token_string_t cmd_dev_detach_devargs = - TOKEN_STRING_INITIALIZER(struct cmd_dev_detach_result, devargs, NULL); - -cmdline_parse_inst_t cmd_detach_device = { - .f = cmd_dev_detach_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "detach a device", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_dev_detach_detach, - (void *)&cmd_dev_detach_devargs, - NULL, - }, -}; - -/**********************************************************/ -/**********************************************************/ -/****** CONTEXT (list of instruction) */ - -cmdline_parse_ctx_t main_ctx[] = { - (cmdline_parse_inst_t *)&cmd_help, - (cmdline_parse_inst_t *)&cmd_quit, - (cmdline_parse_inst_t *)&cmd_list, - (cmdline_parse_inst_t *)&cmd_attach_device, - (cmdline_parse_inst_t *)&cmd_detach_device, - NULL, -}; diff --git a/examples/multi_process/hotplug_mp/commands.h b/examples/multi_process/hotplug_mp/commands.h deleted file mode 100644 index afcf177dba..0000000000 --- a/examples/multi_process/hotplug_mp/commands.h +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2018 Intel Corporation - */ - -#ifndef _COMMANDS_H_ -#define _COMMANDS_H_ - -extern cmdline_parse_ctx_t main_ctx[]; - -#endif /* _COMMANDS_H_ */ diff --git a/examples/multi_process/hotplug_mp/commands.list b/examples/multi_process/hotplug_mp/commands.list new file mode 100644 index 0000000000..683e53cb0e --- /dev/null +++ b/examples/multi_process/hotplug_mp/commands.list @@ -0,0 +1,5 @@ +help +quit +list +attach devargs +detach devargs \ No newline at end of file diff --git a/examples/multi_process/hotplug_mp/meson.build b/examples/multi_process/hotplug_mp/meson.build index a1ad98ca2e..7a0e9ca47a 100644 --- a/examples/multi_process/hotplug_mp/meson.build +++ b/examples/multi_process/hotplug_mp/meson.build @@ -7,7 +7,16 @@ # DPDK instance, use 'make' allow_experimental_apis = true + +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 = files( 'commands.c', 'main.c', ) +sources += cmd_h From patchwork Mon Sep 18 13:03:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 131573 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 E955B425D1; Mon, 18 Sep 2023 15:04:39 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 16B7740A8B; Mon, 18 Sep 2023 15:04:10 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 0676640A6E for ; Mon, 18 Sep 2023 15:04:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695042248; x=1726578248; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/LgBJRJsTvjFbK/Eeym9+ozhJFSN56v/DJZLnFfiznQ=; b=LMr4kj85BaaygFf4XXt2iOsoMZYNb6tjrls5nOj451QwSpvCHc5lm2QA xTFQ/FnyjWy0w7DUh7yHM559TV7GEc6pMXB0kytdydOlfWrPwSMGSvCcT e/eaX3/spAP0oCTB8zJJaCtIPF3J1W1bXxHAisCxjyjsm0Tqhec/quTbX ijVMjuBi/5caARM2cGOIdSQ9VGlqLkP+kBwugBaUJtx5Vpfu8nm02j3+v p7CzugW74GJuMp/sBWCcXaARSAOiCnTsGSCRB7E3WOaORSEY1dHp0CBxE CoDLXfNmEIfMoT6kF9Mi5JMslCUCb5WuX1Uy/K+wdC8Z1Y0yirSTL1dlD g==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="369969403" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="369969403" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2023 06:04:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="739130642" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="739130642" Received: from silpixa00401385.ir.intel.com ([10.237.214.14]) by orsmga007.jf.intel.com with ESMTP; 18 Sep 2023 06:04:06 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Olivier Matz , Bruce Richardson Subject: [RFC PATCH v2 4/5] buildtools/dpdk-cmdline-gen: add IP address support Date: Mon, 18 Sep 2023 14:03:51 +0100 Message-Id: <20230918130352.379478-5-bruce.richardson@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918130352.379478-1-bruce.richardson@intel.com> References: <20230802170052.955323-1-bruce.richardson@intel.com> <20230918130352.379478-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 Add support for apps to have IP addresses as command parameters Signed-off-by: Bruce Richardson --- buildtools/dpdk-cmdline-gen.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/buildtools/dpdk-cmdline-gen.py b/buildtools/dpdk-cmdline-gen.py index 1ddd8b6bbb..c1f8a6f1da 100755 --- a/buildtools/dpdk-cmdline-gen.py +++ b/buildtools/dpdk-cmdline-gen.py @@ -49,6 +49,10 @@ def process_command(tokens, cfile): result_struct.append(f"\t{t_type.lower()}_t {t_name};") initializers.append(f"static cmdline_parse_token_num_t cmd_{name}_{t_name}_tok =\n" + f"\tTOKEN_NUM_INITIALIZER(struct cmd_{name}_result, {t_name}, RTE_{t_type});") + elif t_type in ['IP', 'IP_ADDR', 'IPADDR']: + result_struct.append(f"\tcmdline_ipaddr_t {t_name};") + initializers.append(f"cmdline_parse_token_ipaddr_t cmd_{name}_{t_name}_tok =\n" + + f"\tTOKEN_IPV4_INITIALIZER(struct cmd_{name}_result, {t_name});") else: print(f"Error: unknown token-type {t}", file=sys.stderr) sys.exit(1) @@ -96,6 +100,7 @@ def process_commands(infile, hfile, cfile, ctxname): print("#include ") print("#include ") print("#include ") + print("#include ") print("") for line in infile.readlines(): From patchwork Mon Sep 18 13:03:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 131574 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 D49CC425D1; Mon, 18 Sep 2023 15:04:48 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 32EA140DC9; Mon, 18 Sep 2023 15:04:11 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id A1E7140A8A for ; Mon, 18 Sep 2023 15:04:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695042249; x=1726578249; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3emelectBIpbDMHMaNoUGWpCzzKxcxS4Kf7pjz1erAU=; b=VZtJnhjLbVMRc7pKRVxFQWQwRZmBMCLpoT3S6l06ex1eG46AHit3Wi/5 7q1mXvDJUHfu2e8XkiBbAPUttTQmm8ILMb6mYuvLnVef+MwAwrYuqdOX6 ulKtsbBQ3I7SqolIihmI8kvWmvI9fsO9H4uBKcXe4Xthela61jCtOjQaE QKVR6MthsyBS+9oFZrBYVyAsUI/cwfsFgX4LJc0lhlJRyeWoiHBgbFD44 /XRaOjwMYUeYhsZpd94WQKFjOkOkxJcnBT5hsh/pX9k3KWawrAI7l1Ce7 0/Q4BlIpcVGeGqFeE45SU1QAEiUvQPwL7YjfjTbCWzP8XqZm8KFd55aCg w==; X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="369969408" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="369969408" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Sep 2023 06:04:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10837"; a="739130645" X-IronPort-AV: E=Sophos;i="6.02,156,1688454000"; d="scan'208";a="739130645" Received: from silpixa00401385.ir.intel.com ([10.237.214.14]) by orsmga007.jf.intel.com with ESMTP; 18 Sep 2023 06:04:07 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Olivier Matz , Bruce Richardson Subject: [RFC PATCH v2 5/5] examples/bond: auto-generate cmdline boilerplate Date: Mon, 18 Sep 2023 14:03:52 +0100 Message-Id: <20230918130352.379478-6-bruce.richardson@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918130352.379478-1-bruce.richardson@intel.com> References: <20230802170052.955323-1-bruce.richardson@intel.com> <20230918130352.379478-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/bond/Makefile | 10 ++- examples/bond/commands.list | 6 ++ examples/bond/main.c | 161 ++++-------------------------------- examples/bond/main.h | 10 --- examples/bond/meson.build | 8 ++ 5 files changed, 36 insertions(+), 159 deletions(-) create mode 100644 examples/bond/commands.list delete mode 100644 examples/bond/main.h diff --git a/examples/bond/Makefile b/examples/bond/Makefile index ad711a5bee..0a559ad82b 100644 --- a/examples/bond/Makefile +++ b/examples/bond/Makefile @@ -6,6 +6,7 @@ APP = bond_app # all source are stored in SRCS-y SRCS-y := main.c +SRC-DEPS := build/commands.h PKGCONF ?= pkg-config @@ -24,10 +25,13 @@ static: build/$(APP)-static LDFLAGS += -lrte_net_bond 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'),) @@ -38,10 +42,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: diff --git a/examples/bond/commands.list b/examples/bond/commands.list new file mode 100644 index 0000000000..08e1a3fea8 --- /dev/null +++ b/examples/bond/commands.list @@ -0,0 +1,6 @@ +send ip +start +stop +show +help +quit \ No newline at end of file diff --git a/examples/bond/main.c b/examples/bond/main.c index 9b076bb39f..e893005701 100644 --- a/examples/bond/main.c +++ b/examples/bond/main.c @@ -45,16 +45,8 @@ #include #include -#include -#include -#include -#include -#include -#include #include -#include - -#include "main.h" +#include "commands.h" #define RTE_LOGTYPE_DCB RTE_LOGTYPE_USER1 @@ -462,11 +454,7 @@ static int lcore_main(__rte_unused void *arg1) return 0; } -struct cmd_obj_send_result { - cmdline_fixed_string_t action; - cmdline_ipaddr_t ip; -}; -static inline void get_string(struct cmd_obj_send_result *res, char *buf, uint8_t size) +static inline void get_string(struct cmd_send_result *res, char *buf, uint8_t size) { snprintf(buf, size, NIPQUAD_FMT, ((unsigned)((unsigned char *)&(res->ip.addr.ipv4))[0]), @@ -475,12 +463,11 @@ static inline void get_string(struct cmd_obj_send_result *res, char *buf, uint8_ ((unsigned)((unsigned char *)&(res->ip.addr.ipv4))[3]) ); } -static void cmd_obj_send_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) +void +cmd_send_parsed(void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data) { - struct cmd_obj_send_result *res = parsed_result; + struct cmd_send_result *res = parsed_result; char ip_str[INET6_ADDRSTRLEN]; struct rte_ether_addr bond_mac_addr; @@ -544,29 +531,8 @@ static void cmd_obj_send_parsed(void *parsed_result, cmdline_printf(cl, "\n"); } -cmdline_parse_token_string_t cmd_obj_action_send = - TOKEN_STRING_INITIALIZER(struct cmd_obj_send_result, action, "send"); -cmdline_parse_token_ipaddr_t cmd_obj_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_obj_send_result, ip); - -cmdline_parse_inst_t cmd_obj_send = { - .f = cmd_obj_send_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "send client_ip", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_obj_action_send, - (void *)&cmd_obj_ip, - NULL, - }, -}; - -struct cmd_start_result { - cmdline_fixed_string_t start; -}; - -static void cmd_start_parsed(__rte_unused void *parsed_result, - struct cmdline *cl, - __rte_unused void *data) +void +cmd_start_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) { int worker_core_id = rte_lcore_id(); @@ -605,26 +571,8 @@ static void cmd_start_parsed(__rte_unused void *parsed_result, ); } -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, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "starts listening if not started at startup", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_start_start, - NULL, - }, -}; - -struct cmd_help_result { - cmdline_fixed_string_t help; -}; - -static void cmd_help_parsed(__rte_unused void *parsed_result, - struct cmdline *cl, - __rte_unused void *data) +void +cmd_help_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) { cmdline_printf(cl, "ALB - link bonding mode 6 example\n" @@ -637,26 +585,8 @@ 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, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "show help", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_help_help, - NULL, - }, -}; - -struct cmd_stop_result { - cmdline_fixed_string_t stop; -}; - -static void cmd_stop_parsed(__rte_unused void *parsed_result, - struct cmdline *cl, - __rte_unused void *data) +void +cmd_stop_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) { rte_spinlock_lock(&global_flag_stru_p->lock); if (global_flag_stru_p->LcoreMainIsRunning == 0) { @@ -678,26 +608,8 @@ static void cmd_stop_parsed(__rte_unused void *parsed_result, rte_spinlock_unlock(&global_flag_stru_p->lock); } -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, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "this command do not handle any arguments", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_stop_stop, - NULL, - }, -}; - -struct cmd_quit_result { - cmdline_fixed_string_t quit; -}; - -static void cmd_quit_parsed(__rte_unused void *parsed_result, - struct cmdline *cl, - __rte_unused void *data) +void +cmd_quit_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) { rte_spinlock_lock(&global_flag_stru_p->lock); if (global_flag_stru_p->LcoreMainIsRunning == 0) { @@ -721,26 +633,8 @@ 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, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "this command do not handle any arguments", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_quit_quit, - NULL, - }, -}; - -struct cmd_show_result { - cmdline_fixed_string_t show; -}; - -static void cmd_show_parsed(__rte_unused void *parsed_result, - struct cmdline *cl, - __rte_unused void *data) +void +cmd_show_parsed(__rte_unused void *parsed_result, struct cmdline *cl, __rte_unused void *data) { uint16_t slaves[16] = {0}; uint8_t len = 16; @@ -772,31 +666,6 @@ static void cmd_show_parsed(__rte_unused void *parsed_result, rte_spinlock_unlock(&global_flag_stru_p->lock); } -cmdline_parse_token_string_t cmd_show_show = - TOKEN_STRING_INITIALIZER(struct cmd_show_result, show, "show"); - -cmdline_parse_inst_t cmd_show = { - .f = cmd_show_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = "this command do not handle any arguments", - .tokens = { /* token list, NULL terminated */ - (void *)&cmd_show_show, - NULL, - }, -}; - -/****** CONTEXT (list of instruction) */ - -cmdline_parse_ctx_t main_ctx[] = { - (cmdline_parse_inst_t *)&cmd_start, - (cmdline_parse_inst_t *)&cmd_obj_send, - (cmdline_parse_inst_t *)&cmd_stop, - (cmdline_parse_inst_t *)&cmd_show, - (cmdline_parse_inst_t *)&cmd_quit, - (cmdline_parse_inst_t *)&cmd_help, - NULL, -}; - /* prompt function, called from main on MAIN lcore */ static void prompt(__rte_unused void *arg1) { diff --git a/examples/bond/main.h b/examples/bond/main.h deleted file mode 100644 index f91ed9c885..0000000000 --- a/examples/bond/main.h +++ /dev/null @@ -1,10 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2010-2015 Intel Corporation - */ - -#ifndef _MAIN_H_ -#define _MAIN_H_ - -int main(int argc, char *argv[]); - -#endif /* ifndef _MAIN_H_ */ diff --git a/examples/bond/meson.build b/examples/bond/meson.build index ed22b7887d..bfbec04ecd 100644 --- a/examples/bond/meson.build +++ b/examples/bond/meson.build @@ -11,3 +11,11 @@ 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