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 EC172A0A0E; Thu, 4 Feb 2021 08:35:07 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6CCC72405A6; Thu, 4 Feb 2021 08:34:55 +0100 (CET) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by mails.dpdk.org (Postfix) with ESMTP id 71BC224058B for ; Thu, 4 Feb 2021 08:34:54 +0100 (CET) Received: by mail-wm1-f44.google.com with SMTP id m1so2093467wml.2 for ; Wed, 03 Feb 2021 23:34:54 -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=NnSV00WerX9kYlnNqdk35XhWEJrzuwHatqcmgZ5qOYA=; b=TvhQDqx9FOdH5UY/vILWRLDz/cAa/NMXNQ/QAplX8PFJG2hcXE5fPcJMVNNGzgJvYZ letgoXLBZCMyR/BsOHOSz1zpGG8Qd05Ud10z98L2gq+FmzukMfwFfk0dyfwpxAZ2ozYu E2WmbI1iPKZVVm1UY7cU38BJ8KwIn7W8xja1NGtDx9vecXh0gH5webfOABpCKwcdyyEB kWmbDhh3rOPJZml3se+c6ChkG8gOQlTambpIzEkjddhGC73GK2D3W8YmERwmMa4umflw 0p4kcdIKgKDvRcW5XQhxy7SNZViTk9vHPPHHsP4rpyw+/RYGLlPiEjguyMGYHUFJxuKK CZIQ== 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=NnSV00WerX9kYlnNqdk35XhWEJrzuwHatqcmgZ5qOYA=; b=LtjVYJfQOXLjT/eoBFr4CXOvxFXzxd/QNFQ7u8DpL9qDcJLsbPxCDcnTLaspDPi98X AYZiARbeq8TcDx8qYcBu31Shm9stx37WAzU/cFcQtFPgciv+9qUo7qJUIf5A4RhBTqz4 TSOMc8aMhwVX4zqOunImpa+w5IcxqnsHh+gBDaj5d2wRweeHoX1Tnrqr7dlOXoH3hGVQ RNUY7e6xPJx+OfjtE4HHzCS6J6DIF6ZuuUBDSLJ2HrkDzvSBg26kNNjAU0jA7DrkSn10 2KLhM+2Du9m2UwBOQoaM9aX0mpYSxv/WidV2FXWFvdWSVoVYGtNklrMIB101gaoTUV/p /qcQ== X-Gm-Message-State: AOAM531kGPf1bVSayE7Qgifq619o3vkfrVqMLq0CFVf8EHRGTxGVlS8n l1GPofvt5OMmsm1whEgRArA6zHfSu9LEj6WP X-Google-Smtp-Source: ABdhPJxX/nLWX6hPleogueKC4jeEH6xxDNa7L+0RQFtmZ8EhxsydGTR21ABG337uTpnM1KlaHlsBSQ== X-Received: by 2002:a1c:25c2:: with SMTP id l185mr6126020wml.62.1612424094234; Wed, 03 Feb 2021 23:34:54 -0800 (PST) Received: from localhost.localdomain ([39.33.143.135]) by smtp.gmail.com with ESMTPSA id j11sm7082604wrt.26.2021.02.03.23.34.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Feb 2021 23:34:53 -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 , stephen@networkplumber.org Date: Thu, 4 Feb 2021 07:34:18 +0000 Message-Id: <20210204073420.2421-5-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 5/7] examples/qos_sched: 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: stephen@networkplumber.org Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- v4: * None. v3: * Remove str_is function. 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 | 149 +++++++++++++++++++++----------------- 1 file changed, 83 insertions(+), 66 deletions(-) diff --git a/examples/qos_sched/args.c b/examples/qos_sched/args.c index c369ba9b4..10ca7bea6 100644 --- a/examples/qos_sched/args.c +++ b/examples/qos_sched/args.c @@ -81,10 +81,6 @@ app_usage(const char *prgname) ); } -static inline int str_is(const char *str, const char *is) -{ - return strcmp(str, is) == 0; -} /* returns core mask used by DPDK */ static uint64_t @@ -297,6 +293,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 +321,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 +356,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