From patchwork Tue Nov 24 12:32:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ibtisam Tariq X-Patchwork-Id: 84508 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 B5572A04B1; Tue, 24 Nov 2020 13:34:50 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1373DC954; Tue, 24 Nov 2020 13:33:47 +0100 (CET) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by dpdk.org (Postfix) with ESMTP id CBEB9C938 for ; Tue, 24 Nov 2020 13:33:44 +0100 (CET) Received: by mail-wr1-f65.google.com with SMTP id l1so22124397wrb.9 for ; Tue, 24 Nov 2020 04:33:44 -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=0rOssm3c5g1ESEh+V5TagxsSV+gyRmy/iN8Y9DJxTzc=; b=oPINEokY9SDRmzWrwNl9HmFNJPz9JPJLhtbLhdUow+qQhx+UBIt/cMoMWHto/lbUPe pkcRTy2pnhK69IvjKmh1+pm62SalmVddbGyBpP/l0pD15v84U4G9aPSFyrgInrKacOz3 yf6ux3eBvBF6UkCBkRYsrrq+0MRheEPn3UnsArxmz7/DLSPYBcVI9Ie1DvuV8uVcEGHZ R/8i3JDa9YKZq4lFqEy2so1t02cv7M0qUhKOgMmwYxsWtAvpmpq38WU2KRonMpFB/zqb csCBuZJPmbu4jppD/onpzW9FKageOzlmJaqZ2RCVwShJkNsBVuukfUCnpId1s5NttgWR HFgw== 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=0rOssm3c5g1ESEh+V5TagxsSV+gyRmy/iN8Y9DJxTzc=; b=T2Grg2eSfl84n1c+VPmZVAX14XNgy+wL6mlUM/Ba0TJBcRdUK/EycehnZlFxNk1bkb eZXUYDxGeF6GaSBqA2iS2cizOAQhei3EN7TVpCYTzd2HYojVSSqITyP2J8WzxzzkcMtf pRRyBEIVN11O5WH4fThibpgv4zIJA9B8Tj/1nvPiIezbHGqz1ROEyYGCzqPf10cZeagn 7EZnP9HykKRv+/WixDNp9tUzdCh6SusBUM0ofYbW7iBRC+ZAPmSq4kW439KucIY3WlrV 57z6aB2mvThmoolDsOl87NTxMMXPXHqhyHFrTNHZV3LMpG/J2GC2dzp0FrcWT8vx2hwV J5oQ== X-Gm-Message-State: AOAM531I+ivkwBA38vPGLpQQvKv3RB0fKzh4bv9zZ9hlmaqjjto2ooqJ Y4yNR4oV+C7vvj+pXqeiBNUABA== X-Google-Smtp-Source: ABdhPJx/YxN6rG8JCoW2qgBlfRWqSqoiKbV7CsVRYf2Eu8UV/quep4cc8CeDNVfVggMwqFLyggaxFg== X-Received: by 2002:adf:9b85:: with SMTP id d5mr5149972wrc.9.1606221224540; Tue, 24 Nov 2020 04:33:44 -0800 (PST) Received: from localhost.localdomain ([39.33.169.238]) by smtp.gmail.com with ESMTPSA id w3sm5409034wma.3.2020.11.24.04.33.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Nov 2020 04:33:44 -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: Tue, 24 Nov 2020 12:32:47 +0000 Message-Id: <20201124123249.14451-5-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201124123249.14451-1-ibtisam.tariq@emumba.com> References: <20201124123249.14451-1-ibtisam.tariq@emumba.com> Subject: [dpdk-dev] [PATCH 5/7] examples/qos_sched: 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. 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 --- 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;