From patchwork Wed Nov 11 08:15:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ibtisam Tariq X-Patchwork-Id: 83995 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 C37AFA09D2; Wed, 11 Nov 2020 09:16:55 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 933AF5958; Wed, 11 Nov 2020 09:15:57 +0100 (CET) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by dpdk.org (Postfix) with ESMTP id 40E2D5953 for ; Wed, 11 Nov 2020 09:15:55 +0100 (CET) Received: by mail-wr1-f66.google.com with SMTP id 23so1622829wrc.8 for ; Wed, 11 Nov 2020 00:15:55 -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=qdz8HBU8UqesCQRtU4Wdn1Dxa/kS1kAAVQUmbk5BqEU=; b=NECjrd3Z7IzdSNLtF6IwCSZqXdResUjk0JcFP9DuvWVBMX/gcZMYY6S5h/91lyIq4x R0FUwtWUXVJ0/s0Pq6kXdJv2PWg7lkwyoXK91oz2o1UhcRUSKpj2NxU/2Rk5WZpL2C1P M1x0AFYnbmlIKAjau2cEMel6BXdtGUa9+u7Uxa7t2QYy9C1UbUCDrbe1Xl315DOLjHsw 2l+Tx9tcWV2b8NZZ4Yf13F7sJ4f7QgXnE3MD72qZ3Pufjqy8AbM3kTF/v7mRAUeMQmh8 NKzh3PA6fx8ZFfB8b8MH/KQ84iraZeGj20GcMsrY4MUz+VIA6gXHc9c3/SJ1cfnUKFsc BDIw== 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=qdz8HBU8UqesCQRtU4Wdn1Dxa/kS1kAAVQUmbk5BqEU=; b=X0SJ7LMJFHmY8zDcc7u/Tx4ariCOc2BIE+A2OYIdt+gGmCbpiNOpxCOJfVFlaTlKPP /i0J7h4ALd/RPXJAEmBPLa25KMiAeYSbNngKc1bMNPiePN4yBEnXxAxnVA7Gf+4jDtmT CDC9vSjWJM81XKid84ksI+L9hFODLwb1cP4K6mWRBXaCw5XhbX0QzkKxSaCVtsZ9alyv WN44UqORuU1rfVxJLYFo3joAxN8kcPQ2vX7SlJ+Rx3S1SpXKk+b/QOVJzoko5/UwTGtX /rIsQGIlpcXzLbx6g45B7THI7XwdQ5Y8bUsid/9DyJ7ZTrmxjzX91+BE0ZQhyU7Cz61a rNxg== X-Gm-Message-State: AOAM530NjO9u6pQO+HZlPrAW/iKEv4gQQq9feLsAff1643qi7R14bu3W 2zvem/JTHas5hbgu5vBnU52f2slIzKnI6R8oecQ= X-Google-Smtp-Source: ABdhPJzY5Xv2YmRmGN+TkobYVINPl66XcPswaFg3IcNYiQ2FEUrb6Qs6fTrfv+9CBvmL/akZIEV0zQ== X-Received: by 2002:a5d:4349:: with SMTP id u9mr28009994wrr.319.1605082554975; Wed, 11 Nov 2020 00:15:54 -0800 (PST) Received: from localhost.localdomain ([39.33.227.210]) by smtp.gmail.com with ESMTPSA id z3sm909539wrw.87.2020.11.11.00.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 00:15:54 -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: Wed, 11 Nov 2020 08:15:05 +0000 Message-Id: <20201111081507.19913-5-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201111081507.19913-1-ibtisam.tariq@emumba.com> References: <20201111081507.19913-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 --- 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;