From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1413CA04B5; Thu, 29 Oct 2020 13:56:59 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7F06ECDB2; Thu, 29 Oct 2020 13:54:16 +0100 (CET) Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by dpdk.org (Postfix) with ESMTP id 54F54CD45 for ; Thu, 29 Oct 2020 13:54:14 +0100 (CET) Received: by mail-ed1-f67.google.com with SMTP id w25so2949753edx.2 for ; Thu, 29 Oct 2020 05:54:14 -0700 (PDT) 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=7TLpnV0i2RdCBqHiVAFELll23TafIhKVlHVsgadQudE=; b=mmoaflowPEyQ9sqxXNwNcX4K4udBM7e5mSlm31F4eRulFCFsyx9UQwdFzH0VyoLQU1 lGnD4jZCHx0Nhjsd9q3e4W0kJ+4IDhF3dMNPvhMZW1ryN9eTYFW+HwfoWDxEwv4wX2TS ago4INWu0Uq9Nw1r2JRx04sGnUbN6uXyKZyToEdB+QDJkqdS/bOQOOvBW/O5fnoTOSjW TkjC4yig6lNJxD5tTF1CUV0JQmdubsbeNpSNXsygaYPPHRbDb16BxH/pdebdWn0FaFmw 29PwtiSFf+CK3KvndrzK7bjb5ul1ZpRLZGhiN/9CwtP62ucj05kLu5AtgrL7afj+p0od hvmQ== 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=7TLpnV0i2RdCBqHiVAFELll23TafIhKVlHVsgadQudE=; b=CEccIQO3A9e5lsvBsglBMplo2xPiIUMIpCMmtNj5T7/tQcJcwn46Fze8r2U6aH85Wb /A6oISQoExDcJwGSgOStr57D3ALKeqBrEy3xW3/L9C44tmDLbbXFm6shI1pFhocg47kJ CC+VYIQlQCqyPOnDCWW0PgVShRnWVqtyskYxGmIY4HcxN90BClzZprIAxNRh4l1hqdaJ zc9xLeyC0zLWmNl6t4+Jowfym8hpq2dMWtGVi9xd2fxmVTiTXS8DGYa446h0CHfboRBu PANdQReqmscIiiqas4snG7J2R3f6i36xC6T2JbIF4j4PvnH2kphiHl+u/p3blK9oyttb DX8Q== X-Gm-Message-State: AOAM532gdBawJsvOPbiIMEzkdCgzWWWPRz654x2JY3RrbXwTRbrcjjvH L9ywZu+nYawRqx4GyNHFCWmwUw== X-Google-Smtp-Source: ABdhPJyYJSD4y6TP9CQwovLRpA065vL0R4XuywdOdqNW9bRNR0+nSlmoSUbgTSxt/RD0e7eCpRQHww== X-Received: by 2002:a05:6402:289:: with SMTP id l9mr3882983edv.294.1603976053050; Thu, 29 Oct 2020 05:54:13 -0700 (PDT) Received: from localhost.localdomain ([39.33.228.207]) by smtp.gmail.com with ESMTPSA id q19sm1487951ejz.90.2020.10.29.05.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 05:54:12 -0700 (PDT) From: Ibtisam Tariq 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 , stephen@networkplumber.org Date: Thu, 29 Oct 2020 12:53:36 +0000 Message-Id: <20201029125339.30916-5-ibtisam.tariq@emumba.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201029125339.30916-1-ibtisam.tariq@emumba.com> References: <20201029125339.30916-1-ibtisam.tariq@emumba.com> Subject: [dpdk-dev] [PATCH 5/8] 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. Bugzilla ID: 238 Fixes: de3cfa2c98 ("sched: initial import") Fixes: cb056611a8 ("eal: rename lcore master and slave") Cc: stephen@networkplumber.org Reported-by: David Marchand Signed-off-by: Ibtisam Tariq --- examples/qos_sched/args.c | 161 +++++++++++++++++++++++--------------- 1 file changed, 99 insertions(+), 62 deletions(-) diff --git a/examples/qos_sched/args.c b/examples/qos_sched/args.c index c62719623..8411a87b5 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 CMD_LINE_OPT_PFC "pfc" + CMD_LINE_OPT_PFC_NUM = 256, +#define CMD_LINE_OPT_MNC "mnc" + CMD_LINE_OPT_MNC_NUM, +#define CMD_LINE_OPT_RSZ "rsz" + CMD_LINE_OPT_RSZ_NUM, +#define CMD_LINE_OPT_BSZ "bsz" + CMD_LINE_OPT_BSZ_NUM, +#define CMD_LINE_OPT_MSZ "msz" + CMD_LINE_OPT_MSZ_NUM, +#define CMD_LINE_OPT_RTH "rth" + CMD_LINE_OPT_RTH_NUM, +#define CMD_LINE_OPT_TTH "tth" + CMD_LINE_OPT_TTH_NUM, +#define CMD_LINE_OPT_CFG "cfg" + CMD_LINE_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,19 +325,26 @@ 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 }, + { CMD_LINE_OPT_PFC, 1, + NULL, CMD_LINE_OPT_PFC_NUM }, + { CMD_LINE_OPT_MNC, 1, + NULL, CMD_LINE_OPT_MNC_NUM}, + { CMD_LINE_OPT_RSZ, 1, + NULL, CMD_LINE_OPT_RSZ_NUM}, + { CMD_LINE_OPT_BSZ, 1, + NULL, CMD_LINE_OPT_BSZ_NUM}, + { CMD_LINE_OPT_MSZ, 1, + NULL, CMD_LINE_OPT_MSZ_NUM}, + { CMD_LINE_OPT_RTH, 1, + NULL, CMD_LINE_OPT_RTH_NUM}, + { CMD_LINE_OPT_TTH, 1, + NULL, CMD_LINE_OPT_TTH_NUM}, + { CMD_LINE_OPT_CFG, 1, + NULL, CMD_LINE_OPT_CFG_NUM}, { NULL, 0, 0, 0 } }; @@ -342,66 +368,77 @@ 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 CMD_LINE_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 CMD_LINE_OPT_MNC_NUM: + { + app_main_core = (uint32_t)atoi(optarg); + break; + } + case CMD_LINE_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 CMD_LINE_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 CMD_LINE_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 CMD_LINE_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 CMD_LINE_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 CMD_LINE_OPT_CFG_NUM: + { + cfg_profile = optarg; + break; + } default: app_usage(prgname); return -1; -- 2.17.1