From patchwork Thu Oct 29 12:53:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ibtisam Tariq X-Patchwork-Id: 82771 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id F1FD5A04B5; Thu, 29 Oct 2020 13:56:39 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 06116CD0C; Thu, 29 Oct 2020 13:54:10 +0100 (CET) Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by dpdk.org (Postfix) with ESMTP id 3B9D9CB77 for ; Thu, 29 Oct 2020 13:54:09 +0100 (CET) Received: by mail-ed1-f65.google.com with SMTP id x1so2944984eds.1 for ; Thu, 29 Oct 2020 05:54:09 -0700 (PDT) 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=hh3g5WzqD5S+zUs5HGu2JK9e4iFTPeM4q2faRMtwklA=; b=BQz0M5JFK2EEOKs76fAcNRgIsg9sLom6Aj3kOLjqmJiwVuPSukHkHFRNxDtbFkRyvr njRLq7Z4bXat4KLXUUYH/DBCgaN8H0kMwEsWx+9qMSKApNK/IjSNWI1KRMWq5x8maSd4 RXr0070equr56Wkbs72MfMm3WJqPANb6zEvGzkt5nDQm7QeK6VQKyWNJm+V/GQM4LosP YD1+Jrk5VDIdIm2nzyF7XIm1QFYXjvFnqFAJLIIQ6GCdvB1+3tgxLopNkGGRv8yedIim KmdjfkJ/CTuMAECBuWGpsEIrQFTuocbVi01MB8UaQpSL8XClq4fJfqJuBd/STa0YsYZ3 6zFA== 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=hh3g5WzqD5S+zUs5HGu2JK9e4iFTPeM4q2faRMtwklA=; b=TDKoVN/loHcGYRdfy4wvq7b31pt4KXQOW7ZQzuua8zvRWoas8/l0JjnU8WZlUZFlmN 2YpGNw2o4DOmHekYlQZV7OdRfdnSeSBwxsimo6l7L84rGqZliA0TTDoEFmCCqQ+JmjKm UQnyE/pp8cr7RPFBmPMikcZW3yuJOG/rmYOMk7VCzYetkvRLAUwomt0PFpRi+qamChcQ TzfzB15BeovVetxShSj2hvRAjT4oSy/169WM6tkataslB/n9HBCmBGeF5X7BJw16RBKn Wf1vumXE+nMUlfJlzrDx3Tb32s8KYxzdjCj3tQCZkWKytTfbpkAFwKjsLFA93efplXbo 2NuQ== X-Gm-Message-State: AOAM530+Wp2ACYvUKjKa1AP+O4rrmptahPoAMa+ceBwW5GL4wRkRZT+u 4kO7iEqFAAr9/EuDvSxYIzmEXA== X-Google-Smtp-Source: ABdhPJwW6kjYNd7Y5RveKANt2gpt9xsRAG0GjzgVvhgZHKPVYdSUPb6em3FzIS8bWlWYdOc8GqP6qw== X-Received: by 2002:a05:6402:1d13:: with SMTP id dg19mr3887268edb.217.1603976047923; Thu, 29 Oct 2020 05:54:07 -0700 (PDT) Received: from localhost.localdomain ([39.33.228.207]) by smtp.gmail.com with ESMTPSA id q19sm1487951ejz.90.2020.10.29.05.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 05:54:07 -0700 (PDT) From: Ibtisam Tariq To: marko.kovacevic@intel.com, konstantin.ananyev@intel.com, reshma.pattan@intel.com, john.mcnamara@intel.com, cristian.dumitrescu@intel.com, jasvinder.singh@intel.com, chenbo.xia@intel.com, maxime.coquelin@redhat.com, xiaoyun.li@intel.com Cc: dev@dpdk.org, Ibtisam Tariq , ian.betts@intel.com Date: Thu, 29 Oct 2020 12:53:35 +0000 Message-Id: <20201029125339.30916-4-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201029125339.30916-1-ibtisam.tariq@emumba.com> References: <20201029125339.30916-1-ibtisam.tariq@emumba.com> Subject: [dpdk-dev] [PATCH 4/8] examples/performance-thread/l3fwd-thread: enhance getopt_long usage X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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. Bugzilla ID: 238 Fixes: d48415e1fe ("examples/performance-thread: add l3fwd-thread app") Cc: ian.betts@intel.com Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- .../performance-thread/l3fwd-thread/main.c | 221 ++++++++++-------- 1 file changed, 121 insertions(+), 100 deletions(-) diff --git a/examples/performance-thread/l3fwd-thread/main.c b/examples/performance-thread/l3fwd-thread/main.c index e96076f29..3de33438f 100644 --- a/examples/performance-thread/l3fwd-thread/main.c +++ b/examples/performance-thread/l3fwd-thread/main.c @@ -2858,18 +2858,28 @@ parse_eth_dest(const char *optarg) dest[c] = peer_addr[c]; *(uint64_t *)(val_eth + portid) = dest_eth_addr[portid]; } - +enum { #define CMD_LINE_OPT_RX_CONFIG "rx" + CMD_LINE_OPT_RX_CONFIG_NUM = 256, #define CMD_LINE_OPT_TX_CONFIG "tx" + CMD_LINE_OPT_TX_CONFIG_NUM, #define CMD_LINE_OPT_STAT_LCORE "stat-lcore" + CMD_LINE_OPT_STAT_LCORE_NUM, #define CMD_LINE_OPT_ETH_DEST "eth-dest" + CMD_LINE_OPT_ETH_DEST_NUM, #define CMD_LINE_OPT_NO_NUMA "no-numa" + CMD_LINE_OPT_NO_NUMA_NUM, #define CMD_LINE_OPT_IPV6 "ipv6" + CMD_LINE_OPT_IPV6_NUM, #define CMD_LINE_OPT_ENABLE_JUMBO "enable-jumbo" + CMD_LINE_OPT_ENABLE_JUMBO_NUM, #define CMD_LINE_OPT_HASH_ENTRY_NUM "hash-entry-num" + CMD_LINE_OPT_HASH_ENTRY_NUM_NUM, #define CMD_LINE_OPT_NO_LTHREADS "no-lthreads" + CMD_LINE_OPT_NO_LTHREADS_NUM, #define CMD_LINE_OPT_PARSE_PTYPE "parse-ptype" - + CMD_LINE_OPT_PARSE_PTYPE_NUM, +}; /* Parse the argument given in the command line of the application */ static int parse_args(int argc, char **argv) @@ -2879,16 +2889,26 @@ 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}, + {CMD_LINE_OPT_RX_CONFIG, 1, + NULL, CMD_LINE_OPT_RX_CONFIG_NUM}, + {CMD_LINE_OPT_TX_CONFIG, 1, + NULL, CMD_LINE_OPT_TX_CONFIG_NUM}, + {CMD_LINE_OPT_STAT_LCORE, 1, + NULL, CMD_LINE_OPT_STAT_LCORE_NUM}, + {CMD_LINE_OPT_ETH_DEST, 1, + NULL, CMD_LINE_OPT_ETH_DEST_NUM}, + {CMD_LINE_OPT_NO_NUMA, 0, + NULL, CMD_LINE_OPT_NO_NUMA_NUM}, + {CMD_LINE_OPT_IPV6, 0, + NULL, CMD_LINE_OPT_IPV6_NUM}, + {CMD_LINE_OPT_ENABLE_JUMBO, 0, + NULL, CMD_LINE_OPT_ENABLE_JUMBO_NUM}, + {CMD_LINE_OPT_HASH_ENTRY_NUM, 1, + NULL, CMD_LINE_OPT_HASH_ENTRY_NUM_NUM}, + {CMD_LINE_OPT_NO_LTHREADS, 0, + NULL, CMD_LINE_OPT_NO_LTHREADS_NUM}, + {CMD_LINE_OPT_PARSE_PTYPE, 0, + NULL, CMD_LINE_OPT_PARSE_PTYPE_NUM}, {NULL, 0, 0, 0} }; @@ -2913,107 +2933,108 @@ parse_args(int argc, char **argv) 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 CMD_LINE_OPT_RX_CONFIG_NUM: + { + ret = parse_rx_config(optarg); + if (ret) { + printf("invalid rx-config\n"); + print_usage(prgname); + return -1; } - - 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; - } + break; + } + case CMD_LINE_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 CMD_LINE_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); - - 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 CMD_LINE_OPT_ETH_DEST_NUM: + { + parse_eth_dest(optarg); + break; + } + case CMD_LINE_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 CMD_LINE_OPT_IPV6_NUM: + { + printf("ipv6 is specified\n"); + ipv6 = 1; + break; + } #endif + case CMD_LINE_OPT_NO_LTHREADS_NUM: + { + printf("l-threads model is disabled\n"); + lthreads_on = 0; + break; + } + case CMD_LINE_OPT_PARSE_PTYPE_NUM: + { + printf("software packet type parsing enabled\n"); + parse_ptype_on = 1; + break; + } + case CMD_LINE_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)) { - 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; - } - - 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; - } - - 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"); + 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 CMD_LINE_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); return -1;