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 5E428A0A0E; Thu, 4 Feb 2021 08:34:59 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 34903240596; Thu, 4 Feb 2021 08:34:49 +0100 (CET) Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by mails.dpdk.org (Postfix) with ESMTP id 313C7240596 for ; Thu, 4 Feb 2021 08:34:48 +0100 (CET) Received: by mail-wr1-f52.google.com with SMTP id q7so2199107wre.13 for ; Wed, 03 Feb 2021 23:34:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CJGk2Wn+nSLdWIWbjQrTbm1E7PYXh8Uju35NS1n34ho=; b=YgZZuAOV51Yp3D1Fb2H/Zpn51ZZSpRQL5nzfnLAtdDDOFJSOK1LfezKpx5c+LxlnmA 0ilEwZhuncD7Zm+LOUnpRq/709waphlStI4kgErr7Hb2NaRn73QTOFH8+EBjt4Idhhkb cHnjeu9xJbXfJyRFOmbodnKTYS7qTpuVyxwC6auLICJ0SerzQySXdHZFxun6VVvlaZgF hgEqPFiSE/ebEedxZOUTNOI2h3nw1Aata63sCEW/mhOWFatV3hTHOtwNJt/2QHOiBcDL kN8RpOOZJN9yHB9v8gHQGRD1yP49eD/9EyX5P+zegrWcJB3WLnhbLw2f/gT9hbUi7jW7 8tnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CJGk2Wn+nSLdWIWbjQrTbm1E7PYXh8Uju35NS1n34ho=; b=ZkWkglT5CNEv22LQEHOgyWew3ABanND8aZqvKwhJS0hTzHVKfRC6onxMmGqQVU47hG zAGqi5Efcf0mj5yksxBEOX6A/26bDowmynWvYyfjz6UjKyUBwqa2wtX/A68VBqlU73bt 0ojGezPrXJWoTY0chhqxP1femQ0bzVGxKJrqGzl7PQp0Lncn7AMq3iixZVCoywEAPp6e gktDp3bkdohjx2Fd3i4QbB2zlRnktaSj4sJI9+E1ViI+9zHFA170dsofbXHheD14FWeK 21XmD8b0HREG+rSuazXQY89QMqjNAwA65cGMSb8k0EsLTMZ37qUj9CpYEH8wcvHlmvCl xYfg== X-Gm-Message-State: AOAM5333BXDWu76UgVHSO/JO2Je+FfDeY7VvaeKEUOZTqbu2Ypx8Be3g RgIltpqV6Vp5mtuhTytVztb6lA== X-Google-Smtp-Source: ABdhPJwv6ufX+uL3loBa8aILTsq+mbx+xxiaJi02kqtR32mYmdh22j5Tl6XtRu2xd+goODJvgnbmmw== X-Received: by 2002:adf:fd52:: with SMTP id h18mr7705093wrs.295.1612424087921; Wed, 03 Feb 2021 23:34:47 -0800 (PST) Received: from localhost.localdomain ([39.33.143.135]) by smtp.gmail.com with ESMTPSA id j11sm7082604wrt.26.2021.02.03.23.34.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 23:34:47 -0800 (PST) From: Ibtisam Tariq To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, cristian.dumitrescu@intel.com, jasvinder.singh@intel.com, john.mcnamara@intel.com, reshma.pattan@intel.com, konstantin.ananyev@intel.com, marko.kovacevic@intel.com Cc: dev@dpdk.org, Ibtisam Tariq , ian.betts@intel.com Date: Thu, 4 Feb 2021 07:34:17 +0000 Message-Id: <20210204073420.2421-4-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210204073420.2421-1-ibtisam.tariq@emumba.com> References: <20210204073420.2421-1-ibtisam.tariq@emumba.com> Subject: [dpdk-dev] [PATCH v4 4/7] examples/performance-thread/l3fwd-thread: enhance getopt_long usage 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 Sender: "dev" Instead of using getopt_long return value, strcmp was used to compare the input parameters with the struct option array. This patch get rid of all those strcmp by directly binding each longopt with an int enum. This is to improve readability and consistency in all examples. Bugzilla ID: 238 Cc: ian.betts@intel.com Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- v4: * Set indentation of preprocessor directives. v3: * None. v2: * Remove extra indentations. * Remove extra block brackets in switch statement. * Change enum names to start with OPT_ and remove KEYWORD from enum names. v1: * enhance getopt_long usage. --- .../performance-thread/l3fwd-thread/main.c | 208 +++++++++--------- 1 file changed, 106 insertions(+), 102 deletions(-) diff --git a/examples/performance-thread/l3fwd-thread/main.c b/examples/performance-thread/l3fwd-thread/main.c index 4d82fb82e..65652f993 100644 --- a/examples/performance-thread/l3fwd-thread/main.c +++ b/examples/performance-thread/l3fwd-thread/main.c @@ -2864,16 +2864,28 @@ parse_eth_dest(const char *optarg) *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid]; } -#define CMD_LINE_OPT_RX_CONFIG "rx" -#define CMD_LINE_OPT_TX_CONFIG "tx" -#define CMD_LINE_OPT_STAT_LCORE "stat-lcore" -#define CMD_LINE_OPT_ETH_DEST "eth-dest" -#define CMD_LINE_OPT_NO_NUMA "no-numa" -#define CMD_LINE_OPT_IPV6 "ipv6" -#define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo" -#define CMD_LINE_OPT_HASH_ENTRY_NUM "hash-entry-num" -#define CMD_LINE_OPT_NO_LTHREADS "no-lthreads" -#define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype" +enum { +#define OPT_RX_CONFIG "rx" + OPT_RX_CONFIG_NUM = 256, +#define OPT_TX_CONFIG "tx" + OPT_TX_CONFIG_NUM, +#define OPT_STAT_LCORE "stat-lcore" + OPT_STAT_LCORE_NUM, +#define OPT_ETH_DEST "eth-dest" + OPT_ETH_DEST_NUM, +#define OPT_NO_NUMA "no-numa" + OPT_NO_NUMA_NUM, +#define OPT_IPV6 "ipv6" + OPT_IPV6_NUM, +#define OPT_ENABLE_JUMBO "enable-jumbo" + OPT_ENABLE_JUMBO_NUM, +#define OPT_HASH_ENTRY_NUM "hash-entry-num" + OPT_HASH_ENTRY_NUM_NUM, +#define OPT_NO_LTHREADS "no-lthreads" + OPT_NO_LTHREADS_NUM, +#define OPT_PARSE_PTYPE "parse-ptype" + OPT_PARSE_PTYPE_NUM, +}; /* Parse the argument given in the command line of the application */ static int @@ -2884,17 +2896,17 @@ parse_args(int argc, char **argv) int option_index; char *prgname = argv[0]; static struct option lgopts[] = { - {CMD_LINE_OPT_RX_CONFIG, 1, 0, 0}, - {CMD_LINE_OPT_TX_CONFIG, 1, 0, 0}, - {CMD_LINE_OPT_STAT_LCORE, 1, 0, 0}, - {CMD_LINE_OPT_ETH_DEST, 1, 0, 0}, - {CMD_LINE_OPT_NO_NUMA, 0, 0, 0}, - {CMD_LINE_OPT_IPV6, 0, 0, 0}, - {CMD_LINE_OPT_ENABLE_JUMBO, 0, 0, 0}, - {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, 0, 0}, - {CMD_LINE_OPT_NO_LTHREADS, 0, 0, 0}, - {CMD_LINE_OPT_PARSE_PTYPE, 0, 0, 0}, - {NULL, 0, 0, 0} + {OPT_RX_CONFIG, 1, NULL, OPT_RX_CONFIG_NUM }, + {OPT_TX_CONFIG, 1, NULL, OPT_TX_CONFIG_NUM }, + {OPT_STAT_LCORE, 1, NULL, OPT_STAT_LCORE_NUM }, + {OPT_ETH_DEST, 1, NULL, OPT_ETH_DEST_NUM }, + {OPT_NO_NUMA, 0, NULL, OPT_NO_NUMA_NUM }, + {OPT_IPV6, 0, NULL, OPT_IPV6_NUM }, + {OPT_ENABLE_JUMBO, 0, NULL, OPT_ENABLE_JUMBO_NUM }, + {OPT_HASH_ENTRY_NUM, 1, NULL, OPT_HASH_ENTRY_NUM_NUM }, + {OPT_NO_LTHREADS, 0, NULL, OPT_NO_LTHREADS_NUM }, + {OPT_PARSE_PTYPE, 0, NULL, OPT_PARSE_PTYPE_NUM }, + {NULL, 0, 0, 0 } }; argvopt = argv; @@ -2912,112 +2924,104 @@ parse_args(int argc, char **argv) return -1; } break; + case 'P': printf("Promiscuous mode selected\n"); promiscuous_on = 1; break; /* long options */ - case 0: - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_RX_CONFIG, - sizeof(CMD_LINE_OPT_RX_CONFIG))) { - ret = parse_rx_config(optarg); - if (ret) { - printf("invalid rx-config\n"); - print_usage(prgname); - return -1; - } + case OPT_RX_CONFIG_NUM: + ret = parse_rx_config(optarg); + if (ret) { + printf("invalid rx-config\n"); + print_usage(prgname); + return -1; } + break; - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_TX_CONFIG, - sizeof(CMD_LINE_OPT_TX_CONFIG))) { - ret = parse_tx_config(optarg); - if (ret) { - printf("invalid tx-config\n"); - print_usage(prgname); - return -1; - } + case OPT_TX_CONFIG_NUM: + ret = parse_tx_config(optarg); + if (ret) { + printf("invalid tx-config\n"); + print_usage(prgname); + return -1; } + break; #if (APP_CPU_LOAD > 0) - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_STAT_LCORE, - sizeof(CMD_LINE_OPT_STAT_LCORE))) { - cpu_load_lcore_id = parse_stat_lcore(optarg); - } + case OPT_STAT_LCORE_NUM: + cpu_load_lcore_id = parse_stat_lcore(optarg); + break; #endif - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_ETH_DEST, - sizeof(CMD_LINE_OPT_ETH_DEST))) - parse_eth_dest(optarg); + case OPT_ETH_DEST_NUM: + parse_eth_dest(optarg); + break; - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_NO_NUMA, - sizeof(CMD_LINE_OPT_NO_NUMA))) { - printf("numa is disabled\n"); - numa_on = 0; - } + case OPT_NO_NUMA_NUM: + printf("numa is disabled\n"); + numa_on = 0; + break; #if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_IPV6, - sizeof(CMD_LINE_OPT_IPV6))) { - printf("ipv6 is specified\n"); - ipv6 = 1; - } + case OPT_IPV6_NUM: + printf("ipv6 is specified\n"); + ipv6 = 1; + break; #endif - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_NO_LTHREADS, - sizeof(CMD_LINE_OPT_NO_LTHREADS))) { - printf("l-threads model is disabled\n"); - lthreads_on = 0; - } + case OPT_NO_LTHREADS_NUM: + printf("l-threads model is disabled\n"); + lthreads_on = 0; + break; - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_PARSE_PTYPE, - sizeof(CMD_LINE_OPT_PARSE_PTYPE))) { - printf("software packet type parsing enabled\n"); - parse_ptype_on = 1; - } + case OPT_PARSE_PTYPE_NUM: + printf("software packet type parsing enabled\n"); + parse_ptype_on = 1; + break; - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_ENABLE_JUMBO, - sizeof(CMD_LINE_OPT_ENABLE_JUMBO))) { - struct option lenopts = {"max-pkt-len", required_argument, 0, - 0}; - - printf("jumbo frame is enabled - disabling simple TX path\n"); - port_conf.rxmode.offloads |= - DEV_RX_OFFLOAD_JUMBO_FRAME; - port_conf.txmode.offloads |= - DEV_TX_OFFLOAD_MULTI_SEGS; - - /* if no max-pkt-len set, use the default value - * RTE_ETHER_MAX_LEN - */ - if (0 == getopt_long(argc, argvopt, "", &lenopts, - &option_index)) { - - ret = parse_max_pkt_len(optarg); - if ((ret < 64) || (ret > MAX_JUMBO_PKT_LEN)) { - printf("invalid packet length\n"); - print_usage(prgname); - return -1; - } - port_conf.rxmode.max_rx_pkt_len = ret; - } - printf("set jumbo frame max packet length to %u\n", - (unsigned int)port_conf.rxmode.max_rx_pkt_len); - } -#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) - if (!strncmp(lgopts[option_index].name, CMD_LINE_OPT_HASH_ENTRY_NUM, - sizeof(CMD_LINE_OPT_HASH_ENTRY_NUM))) { - ret = parse_hash_entry_number(optarg); - if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) { - hash_entry_number = ret; - } else { - printf("invalid hash entry number\n"); + case OPT_ENABLE_JUMBO_NUM: + { + struct option lenopts = {"max-pkt-len", + required_argument, 0, 0}; + + printf("jumbo frame is enabled - disabling simple TX path\n"); + port_conf.rxmode.offloads |= + DEV_RX_OFFLOAD_JUMBO_FRAME; + port_conf.txmode.offloads |= + DEV_TX_OFFLOAD_MULTI_SEGS; + + /* if no max-pkt-len set, use the default value + * RTE_ETHER_MAX_LEN + */ + if (0 == getopt_long(argc, argvopt, "", &lenopts, + &option_index)) { + + ret = parse_max_pkt_len(optarg); + if ((ret < 64) || (ret > MAX_JUMBO_PKT_LEN)) { + printf("invalid packet length\n"); print_usage(prgname); return -1; } + port_conf.rxmode.max_rx_pkt_len = ret; } -#endif + printf("set jumbo frame max packet length to %u\n", + (unsigned int)port_conf.rxmode.max_rx_pkt_len); break; + } +#if (APP_LOOKUP_METHOD == APP_LOOKUP_EXACT_MATCH) + case OPT_HASH_ENTRY_NUM_NUM: + ret = parse_hash_entry_number(optarg); + if ((ret > 0) && (ret <= L3FWD_HASH_ENTRIES)) { + hash_entry_number = ret; + } else { + printf("invalid hash entry number\n"); + print_usage(prgname); + return -1; + } + break; +#endif default: print_usage(prgname); -- 2.17.1