DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ibtisam Tariq <ibtisam.tariq@emumba.com>
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 <ibtisam.tariq@emumba.com>,
	ian.betts@intel.com
Subject: [dpdk-dev] [PATCH 4/8] examples/performance-thread/l3fwd-thread: enhance getopt_long usage
Date: Thu, 29 Oct 2020 12:53:35 +0000	[thread overview]
Message-ID: <20201029125339.30916-4-ibtisam.tariq@emumba.com> (raw)
In-Reply-To: <20201029125339.30916-1-ibtisam.tariq@emumba.com>

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 <david.marchand@redhat.com>
Signed-off-by: Ibtisam Tariq <ibtisam.tariq@emumba.com>
---
 .../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;
-- 
2.17.1


  parent reply	other threads:[~2020-10-29 12:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29 12:53 [dpdk-dev] [PATCH 1/8] examples/fips_validation: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 2/8] examples/l3fwd-acl: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 3/8] examples/packet_ordering: " Ibtisam Tariq
2020-10-29 12:53 ` Ibtisam Tariq [this message]
2020-10-29 12:53 ` [dpdk-dev] [PATCH 5/8] examples/qos_sched: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 6/8] examples/vhost: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 7/8] examples/vhost_crypto: " Ibtisam Tariq
2020-10-29 12:53 ` [dpdk-dev] [PATCH 8/8] examples/tep_termination: " Ibtisam Tariq
2020-10-29 13:16   ` David Marchand
2020-11-02  8:18     ` Ibtisam Tariq
2020-10-29 22:07 ` [dpdk-dev] [PATCH 1/8] examples/fips_validation: " David Marchand
2020-11-02  8:32   ` Ibtisam Tariq
2020-11-04 10:00     ` Ibtisam Tariq
2020-11-05  8:59       ` David Marchand
2020-11-10  6:10         ` Ibtisam Tariq
2020-11-10  8:23           ` David Marchand
2020-11-10  9:03             ` Ibtisam Tariq

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201029125339.30916-4-ibtisam.tariq@emumba.com \
    --to=ibtisam.tariq@emumba.com \
    --cc=chenbo.xia@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --cc=ian.betts@intel.com \
    --cc=jasvinder.singh@intel.com \
    --cc=john.mcnamara@intel.com \
    --cc=konstantin.ananyev@intel.com \
    --cc=marko.kovacevic@intel.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=reshma.pattan@intel.com \
    --cc=xiaoyun.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).