[PATCH 12/12] examples/dma: replace getopt with argparse

Thomas Monjalon thomas at monjalon.net
Wed Jan 24 14:26:41 CET 2024


22/01/2024 04:58, Chengwen Feng:
> -#define CMD_LINE_OPT_MAC_UPDATING "mac-updating"
> -#define CMD_LINE_OPT_NO_MAC_UPDATING "no-mac-updating"
> -#define CMD_LINE_OPT_PORTMASK "portmask"
> -#define CMD_LINE_OPT_NB_QUEUE "nb-queue"
> -#define CMD_LINE_OPT_COPY_TYPE "copy-type"
> -#define CMD_LINE_OPT_RING_SIZE "ring-size"
> -#define CMD_LINE_OPT_BATCH_SIZE "dma-batch-size"
> -#define CMD_LINE_OPT_FRAME_SIZE "max-frame-size"
> -#define CMD_LINE_OPT_FORCE_COPY_SIZE "force-min-copy-size"
> -#define CMD_LINE_OPT_STATS_INTERVAL "stats-interval"
> +#define CMD_LINE_OPT_MAC_UPDATING "--mac-updating"
> +#define CMD_LINE_OPT_NO_MAC_UPDATING "--no-mac-updating"
> +#define CMD_LINE_OPT_PORTMASK "--portmask"
> +#define CMD_LINE_OPT_PORTMASK_INDEX 1
> +#define CMD_LINE_OPT_NB_QUEUE "--nb-queue"
> +#define CMD_LINE_OPT_COPY_TYPE "--copy-type"
> +#define CMD_LINE_OPT_COPY_TYPE_INDEX 2
> +#define CMD_LINE_OPT_RING_SIZE "--ring-size"
> +#define CMD_LINE_OPT_BATCH_SIZE "--dma-batch-size"
> +#define CMD_LINE_OPT_FRAME_SIZE "--max-frame-size"
> +#define CMD_LINE_OPT_FORCE_COPY_SIZE "--force-min-copy-size"
> +#define CMD_LINE_OPT_STATS_INTERVAL "--stats-interval"

I would completely drop these defines.
It would be easier to read the string directly in .args below:

[...]
> +		.args = {
> +			{ CMD_LINE_OPT_MAC_UPDATING, NULL, "Enable MAC addresses updating",
> +			  &mac_updating, (void *)1,
> +			  RTE_ARGPARSE_ARG_NO_VALUE | RTE_ARGPARSE_ARG_VALUE_INT,
> +			},
> +			{ CMD_LINE_OPT_NO_MAC_UPDATING, NULL, "Disable MAC addresses updating",
> +			  &mac_updating, (void *)0,
> +			  RTE_ARGPARSE_ARG_NO_VALUE | RTE_ARGPARSE_ARG_VALUE_INT,
> +			},
> +			{ CMD_LINE_OPT_PORTMASK, "-p", "hexadecimal bitmask of ports to configure",
> +			  NULL, (void *)CMD_LINE_OPT_PORTMASK_INDEX,
> +			  RTE_ARGPARSE_ARG_REQUIRED_VALUE,
> +			},
> +			{ CMD_LINE_OPT_NB_QUEUE, "-q", "number of RX queues per port (default is 1)",
> +			  &nb_queues, NULL,
> +			  RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_U16,
> +			},
> +			{ CMD_LINE_OPT_COPY_TYPE, "-c", "type of copy: sw|hw",
> +			  NULL, (void *)CMD_LINE_OPT_COPY_TYPE_INDEX,
> +			  RTE_ARGPARSE_ARG_REQUIRED_VALUE,
> +			},
> +			{ CMD_LINE_OPT_RING_SIZE, "-s", "size of dmadev descriptor ring for hardware copy mode or rte_ring for software copy mode",
> +			  &ring_size, NULL,
> +			  RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_U16,
> +			},
> +			{ CMD_LINE_OPT_BATCH_SIZE, "-b", "number of requests per DMA batch",
> +			  &dma_batch_sz, NULL,
> +			  RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_U32,
> +			},
> +			{ CMD_LINE_OPT_FRAME_SIZE, "-f", "max frame size",
> +			  &max_frame_size, NULL,
> +			  RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_U32,
> +			},
> +			{ CMD_LINE_OPT_FORCE_COPY_SIZE, "-m", "force a minimum copy length, even for smaller packets",
> +			  &force_min_copy_size, NULL,
> +			  RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_U32,
> +			},
> +			{ CMD_LINE_OPT_STATS_INTERVAL, "-i", "interval, in seconds, between stats prints (default is 1)",
> +			  &stats_interval, NULL,
> +			  RTE_ARGPARSE_ARG_REQUIRED_VALUE | RTE_ARGPARSE_ARG_VALUE_U16,
> +			},
> +			ARGPARSE_ARG_END(),





More information about the dev mailing list