DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ibtisam Tariq <ibtisam.tariq@emumba.com>
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 <ibtisam.tariq@emumba.com>,
	stephen@networkplumber.org
Subject: [dpdk-dev] [PATCH 5/7] examples/qos_sched: enhance getopt_long usage
Date: Wed, 11 Nov 2020 08:15:05 +0000
Message-ID: <20201111081507.19913-5-ibtisam.tariq@emumba.com> (raw)
In-Reply-To: <20201111081507.19913-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. This is to improve readability and consistency in
all examples.

Bugzilla ID: 238
Cc: stephen@networkplumber.org

Reported-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Ibtisam Tariq <ibtisam.tariq@emumba.com>
---
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
---
 examples/qos_sched/args.c | 145 ++++++++++++++++++++++----------------
 1 file changed, 83 insertions(+), 62 deletions(-)

diff --git a/examples/qos_sched/args.c b/examples/qos_sched/args.c
index c62719623..15bedae13 100644
--- a/examples/qos_sched/args.c
+++ b/examples/qos_sched/args.c
@@ -297,6 +297,25 @@ app_parse_burst_conf(const char *conf_str)
 	return 0;
 }
 
+enum {
+#define OPT_PFC "pfc"
+	OPT_PFC_NUM = 256,
+#define OPT_MNC "mnc"
+	OPT_MNC_NUM,
+#define OPT_RSZ "rsz"
+	OPT_RSZ_NUM,
+#define OPT_BSZ "bsz"
+	OPT_BSZ_NUM,
+#define OPT_MSZ "msz"
+	OPT_MSZ_NUM,
+#define OPT_RTH "rth"
+	OPT_RTH_NUM,
+#define OPT_TTH "tth"
+	OPT_TTH_NUM,
+#define OPT_CFG "cfg"
+	OPT_CFG_NUM,
+};
+
 /*
  * Parses the argument given in the command line of the application,
  * calculates mask for used cores and initializes EAL with calculated core mask
@@ -306,20 +325,19 @@ app_parse_args(int argc, char **argv)
 {
 	int opt, ret;
 	int option_index;
-	const char *optname;
 	char *prgname = argv[0];
 	uint32_t i, nb_lcores;
 
 	static struct option lgopts[] = {
-		{ "pfc", 1, 0, 0 },
-		{ "mnc", 1, 0, 0 },
-		{ "rsz", 1, 0, 0 },
-		{ "bsz", 1, 0, 0 },
-		{ "msz", 1, 0, 0 },
-		{ "rth", 1, 0, 0 },
-		{ "tth", 1, 0, 0 },
-		{ "cfg", 1, 0, 0 },
-		{ NULL,  0, 0, 0 }
+		{OPT_PFC, 1, NULL, OPT_PFC_NUM},
+		{OPT_MNC, 1, NULL, OPT_MNC_NUM},
+		{OPT_RSZ, 1, NULL, OPT_RSZ_NUM},
+		{OPT_BSZ, 1, NULL, OPT_BSZ_NUM},
+		{OPT_MSZ, 1, NULL, OPT_MSZ_NUM},
+		{OPT_RTH, 1, NULL, OPT_RTH_NUM},
+		{OPT_TTH, 1, NULL, OPT_TTH_NUM},
+		{OPT_CFG, 1, NULL, OPT_CFG_NUM},
+		{NULL,    0, 0,    0          }
 	};
 
 	/* initialize EAL first */
@@ -342,66 +360,69 @@ app_parse_args(int argc, char **argv)
 				interactive = 1;
 				break;
 			/* long options */
-			case 0:
-				optname = lgopts[option_index].name;
-				if (str_is(optname, "pfc")) {
-					ret = app_parse_flow_conf(optarg);
-					if (ret) {
-						RTE_LOG(ERR, APP, "Invalid pipe configuration %s\n", optarg);
-						return -1;
-					}
-					break;
-				}
-				if (str_is(optname, "mnc")) {
-					app_main_core = (uint32_t)atoi(optarg);
-					break;
-				}
-				if (str_is(optname, "rsz")) {
-					ret = app_parse_ring_conf(optarg);
-					if (ret) {
-						RTE_LOG(ERR, APP, "Invalid ring configuration %s\n", optarg);
-						return -1;
-					}
-					break;
+
+			case OPT_PFC_NUM:
+				ret = app_parse_flow_conf(optarg);
+				if (ret) {
+					RTE_LOG(ERR, APP, "Invalid pipe configuration %s\n",
+							optarg);
+					return -1;
 				}
-				if (str_is(optname, "bsz")) {
-					ret = app_parse_burst_conf(optarg);
-					if (ret) {
-						RTE_LOG(ERR, APP, "Invalid burst configuration %s\n", optarg);
-						return -1;
-					}
-					break;
+				break;
+
+			case OPT_MNC_NUM:
+				app_main_core = (uint32_t)atoi(optarg);
+				break;
+
+			case OPT_RSZ_NUM:
+				ret = app_parse_ring_conf(optarg);
+				if (ret) {
+					RTE_LOG(ERR, APP, "Invalid ring configuration %s\n",
+							optarg);
+					return -1;
 				}
-				if (str_is(optname, "msz")) {
-					mp_size = atoi(optarg);
-					if (mp_size <= 0) {
-						RTE_LOG(ERR, APP, "Invalid mempool size %s\n", optarg);
-						return -1;
-					}
-					break;
+				break;
+
+			case OPT_BSZ_NUM:
+				ret = app_parse_burst_conf(optarg);
+				if (ret) {
+					RTE_LOG(ERR, APP, "Invalid burst configuration %s\n",
+							optarg);
+					return -1;
 				}
-				if (str_is(optname, "rth")) {
-					ret = app_parse_rth_conf(optarg);
-					if (ret) {
-						RTE_LOG(ERR, APP, "Invalid RX threshold configuration %s\n", optarg);
-						return -1;
-					}
-					break;
+				break;
+
+			case OPT_MSZ_NUM:
+				mp_size = atoi(optarg);
+				if (mp_size <= 0) {
+					RTE_LOG(ERR, APP, "Invalid mempool size %s\n",
+							optarg);
+					return -1;
 				}
-				if (str_is(optname, "tth")) {
-					ret = app_parse_tth_conf(optarg);
-					if (ret) {
-						RTE_LOG(ERR, APP, "Invalid TX threshold configuration %s\n", optarg);
-						return -1;
-					}
-					break;
+				break;
+
+			case OPT_RTH_NUM:
+				ret = app_parse_rth_conf(optarg);
+				if (ret) {
+					RTE_LOG(ERR, APP, "Invalid RX threshold configuration %s\n",
+							optarg);
+					return -1;
 				}
-				if (str_is(optname, "cfg")) {
-					cfg_profile = optarg;
-					break;
+				break;
+
+			case OPT_TTH_NUM:
+				ret = app_parse_tth_conf(optarg);
+				if (ret) {
+					RTE_LOG(ERR, APP, "Invalid TX threshold configuration %s\n",
+							optarg);
+					return -1;
 				}
 				break;
 
+			case OPT_CFG_NUM:
+				cfg_profile = optarg;
+				break;
+
 			default:
 				app_usage(prgname);
 				return -1;
-- 
2.17.1


  parent reply	other threads:[~2020-11-11  8:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-11  8:15 [dpdk-dev] [PATCH 1/7] examples/fips_validation: " Ibtisam Tariq
2020-11-11  8:15 ` [dpdk-dev] [PATCH 2/7] examples/l3fwd-acl: " Ibtisam Tariq
2020-11-13 12:26   ` Ananyev, Konstantin
2020-11-17  7:52     ` Ibtisam Tariq
2020-11-11  8:15 ` [dpdk-dev] [PATCH 3/7] examples/packet_ordering: " Ibtisam Tariq
2020-11-11  8:15 ` [dpdk-dev] [PATCH 4/7] examples/performance-thread/l3fwd-thread: " Ibtisam Tariq
2020-11-11  8:15 ` Ibtisam Tariq [this message]
2020-11-14 11:12   ` [dpdk-dev] [PATCH 5/7] examples/qos_sched: " David Marchand
2020-11-17  7:42     ` Ibtisam Tariq
2020-11-11  8:15 ` [dpdk-dev] [PATCH 6/7] examples/vhost: " Ibtisam Tariq
2020-11-11  8:15 ` [dpdk-dev] [PATCH 7/7] examples/vhost_crypto: " Ibtisam Tariq
2020-11-24 12:32 [dpdk-dev] [PATCH 1/7] examples/fips_validation: " Ibtisam Tariq
2020-11-24 12:32 ` [dpdk-dev] [PATCH 5/7] examples/qos_sched: " 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=20201111081507.19913-5-ibtisam.tariq@emumba.com \
    --to=ibtisam.tariq@emumba.com \
    --cc=chenbo.xia@intel.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    --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=stephen@networkplumber.org \
    /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

DPDK patches and discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \
		dev@dpdk.org
	public-inbox-index dev

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git