From patchwork Sat Nov 22 21:43:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 1455 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 641027FC4; Sat, 22 Nov 2014 22:33:48 +0100 (CET) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) by dpdk.org (Postfix) with ESMTP id AAA405910 for ; Sat, 22 Nov 2014 22:33:43 +0100 (CET) Received: by mail-wi0-f176.google.com with SMTP id ex7so2350237wid.15 for ; Sat, 22 Nov 2014 13:44:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=uQ18n7gtDct+Y0J5wqvYdtrkN3mkXP/jB/VmLDQ79bw=; b=CwOc/xnz6AxyM5OO4YFYyf4Kf/RDO0Masauf0u5tUvw9wcSxU2VBWE4q/v8n9jY2lv R3HmCGc6ucKKpOZiP4DK6mah9ZNTEkgPI4ilNVUrZFVVHO46asKrJoP3WzJV8RCmy3Y+ JbENDmZC1/UyD2QzA2AWPCemp2rUmrm2SmDuvEYwIB4FhwQKSrf7xSmIYwocwm4eGkkx ceJ2MrW4UuGelqcHVl0CV3VBD/ne3Ie2rbE6vSG6COlTVfuzKXkfrTl4Jq9q8231HG3N N1TFMQpFnrSubDybthyZbbb/+BfVzxdZBy8g4P3YJbZPWvdbZC1BuB4L272AXDrL4paj K+qw== X-Gm-Message-State: ALoCoQmsHvy4QGlDiNevmm+4W601X/25cHtBlQqsslRTmtNZ5JTM/faY5TqwYifaOYEBRbIRBkAX X-Received: by 10.180.101.104 with SMTP id ff8mr2098906wib.12.1416692664254; Sat, 22 Nov 2014 13:44:24 -0800 (PST) Received: from localhost.localdomain (136-92-190-109.dsl.ovh.fr. [109.190.92.136]) by mx.google.com with ESMTPSA id cz3sm13724087wjb.23.2014.11.22.13.44.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 22 Nov 2014 13:44:23 -0800 (PST) From: Thomas Monjalon To: dev@dpdk.org Date: Sat, 22 Nov 2014 22:43:37 +0100 Message-Id: <1416692622-28886-6-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1416692622-28886-1-git-send-email-thomas.monjalon@6wind.com> References: <1416692622-28886-1-git-send-email-thomas.monjalon@6wind.com> Subject: [dpdk-dev] [PATCH 05/10] eal: factorize options sanity check X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" No need to have duplicated check for common options. Some flags are set for options -c and -m in order to simplify the checks. Signed-off-by: Thomas Monjalon Acked-by: Bruce Richardson --- lib/librte_eal/bsdapp/eal/eal.c | 54 ++------------------------ lib/librte_eal/common/eal_common_options.c | 53 ++++++++++++++++++++++++++ lib/librte_eal/common/eal_options.h | 1 + lib/librte_eal/linuxapp/eal/eal.c | 61 ++++-------------------------- 4 files changed, 66 insertions(+), 103 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 391ce53..20a9c5f 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -316,7 +316,6 @@ eal_parse_args(int argc, char **argv) int opt, ret, i; char **argvopt; int option_index; - int coremask_ok = 0; char *prgname = argv[0]; argvopt = argv; @@ -339,13 +338,8 @@ eal_parse_args(int argc, char **argv) return -1; } /* common parser handled this option */ - if (ret == 0) { - /* special case, note that the common parser accepted - * the coremask option */ - if (opt == 'c') - coremask_ok = 1; + if (ret == 0) continue; - } switch (opt) { default: @@ -366,51 +360,11 @@ eal_parse_args(int argc, char **argv) } } - /* sanity checks */ - if (!coremask_ok) { - RTE_LOG(ERR, EAL, "coremask not specified\n"); - eal_usage(prgname); - return -1; - } - if (internal_config.process_type == RTE_PROC_AUTO){ + if (internal_config.process_type == RTE_PROC_AUTO) internal_config.process_type = eal_proc_type_detect(); - } - if (internal_config.process_type == RTE_PROC_INVALID){ - RTE_LOG(ERR, EAL, "Invalid process type specified\n"); - eal_usage(prgname); - return -1; - } - if (internal_config.process_type == RTE_PROC_PRIMARY && - internal_config.force_nchannel == 0) { - RTE_LOG(ERR, EAL, "Number of memory channels (-n) not specified\n"); - eal_usage(prgname); - return -1; - } - if (index(internal_config.hugefile_prefix,'%') != NULL){ - RTE_LOG(ERR, EAL, "Invalid char, '%%', in '"OPT_FILE_PREFIX"' option\n"); - eal_usage(prgname); - return -1; - } - if (internal_config.memory > 0 && internal_config.force_sockets == 1) { - RTE_LOG(ERR, EAL, "Options -m and --socket-mem cannot be specified " - "at the same time\n"); - eal_usage(prgname); - return -1; - } - /* --no-huge doesn't make sense with either -m or --socket-mem */ - if (internal_config.no_hugetlbfs && - (internal_config.memory > 0 || - internal_config.force_sockets == 1)) { - RTE_LOG(ERR, EAL, "Options -m or --socket-mem cannot be specified " - "together with --no-huge!\n"); - eal_usage(prgname); - return -1; - } - if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) != 0 && - rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_PCI) != 0) { - RTE_LOG(ERR, EAL, "Error: blacklist [-b] and whitelist " - "[-w] options cannot be used at the same time\n"); + /* sanity checks */ + if (eal_check_common_options(&internal_config) != 0) { eal_usage(prgname); return -1; } diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index ffc615a..630dfe0 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -85,6 +85,9 @@ eal_long_options[] = { {0, 0, 0, 0} }; +static int lcores_parsed; +static int mem_parsed; + void eal_reset_internal_config(struct internal_config *internal_cfg) { @@ -197,6 +200,7 @@ eal_parse_coremask(const char *coremask) return -1; /* Update the count of enabled logical cores of the EAL configuration */ cfg->lcore_count = count; + lcores_parsed = 1; return 0; } @@ -305,6 +309,7 @@ eal_parse_common_option(int opt, const char *optarg, conf->memory = atoi(optarg); conf->memory *= 1024ULL; conf->memory *= 1024ULL; + mem_parsed = 1; break; /* force number of channels */ case 'n': @@ -394,6 +399,54 @@ eal_parse_common_option(int opt, const char *optarg, return 0; } +int +eal_check_common_options(struct internal_config *internal_cfg) +{ + struct rte_config *cfg = rte_eal_get_configuration(); + + if (!lcores_parsed) { + RTE_LOG(ERR, EAL, "CPU cores must be enabled with option " + "-c\n"); + return -1; + } + + if (internal_cfg->process_type == RTE_PROC_INVALID) { + RTE_LOG(ERR, EAL, "Invalid process type specified\n"); + return -1; + } + if (internal_cfg->process_type == RTE_PROC_PRIMARY && + internal_cfg->force_nchannel == 0) { + RTE_LOG(ERR, EAL, "Number of memory channels (-n) not " + "specified\n"); + return -1; + } + if (index(internal_cfg->hugefile_prefix, '%') != NULL) { + RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" " + "option\n"); + return -1; + } + if (mem_parsed && internal_cfg->force_sockets == 1) { + RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot " + "be specified at the same time\n"); + return -1; + } + if (internal_cfg->no_hugetlbfs && + (mem_parsed || internal_cfg->force_sockets == 1)) { + RTE_LOG(ERR, EAL, "Options -m or --"OPT_SOCKET_MEM" cannot " + "be specified together with --"OPT_NO_HUGE"\n"); + return -1; + } + + if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) != 0 && + rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_PCI) != 0) { + RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) " + "cannot be used at the same time\n"); + return -1; + } + + return 0; +} + void eal_common_usage(void) { diff --git a/lib/librte_eal/common/eal_options.h b/lib/librte_eal/common/eal_options.h index 7a08507..75351c0 100644 --- a/lib/librte_eal/common/eal_options.h +++ b/lib/librte_eal/common/eal_options.h @@ -83,6 +83,7 @@ extern const struct option eal_long_options[]; int eal_parse_common_option(int opt, const char *argv, struct internal_config *conf); +int eal_check_common_options(struct internal_config *internal_cfg); void eal_common_usage(void); #endif /* EAL_OPTIONS_H */ diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index bb35669..f5de277 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -507,7 +507,6 @@ eal_parse_args(int argc, char **argv) int opt, ret, i; char **argvopt; int option_index; - int coremask_ok = 0; char *prgname = argv[0]; struct shared_driver *solib; @@ -531,13 +530,8 @@ eal_parse_args(int argc, char **argv) return -1; } /* common parser handled this option */ - if (ret == 0) { - /* special case, note that the common parser accepted - * the coremask option */ - if (opt == 'c') - coremask_ok = 1; + if (ret == 0) continue; - } switch (opt) { /* force loading of external driver */ @@ -622,58 +616,19 @@ eal_parse_args(int argc, char **argv) } } - /* sanity checks */ - if (!coremask_ok) { - RTE_LOG(ERR, EAL, "coremask not specified\n"); - eal_usage(prgname); - return -1; - } - if (internal_config.process_type == RTE_PROC_AUTO){ + if (internal_config.process_type == RTE_PROC_AUTO) internal_config.process_type = eal_proc_type_detect(); - } - if (internal_config.process_type == RTE_PROC_INVALID){ - RTE_LOG(ERR, EAL, "Invalid process type specified\n"); - eal_usage(prgname); - return -1; - } - if (internal_config.process_type == RTE_PROC_PRIMARY && - internal_config.force_nchannel == 0) { - RTE_LOG(ERR, EAL, "Number of memory channels (-n) not specified\n"); - eal_usage(prgname); - return -1; - } - if (index(internal_config.hugefile_prefix,'%') != NULL){ - RTE_LOG(ERR, EAL, "Invalid char, '%%', in '"OPT_FILE_PREFIX"' option\n"); - eal_usage(prgname); - return -1; - } - if (internal_config.memory > 0 && internal_config.force_sockets == 1) { - RTE_LOG(ERR, EAL, "Options -m and --socket-mem cannot be specified " - "at the same time\n"); - eal_usage(prgname); - return -1; - } - /* --no-huge doesn't make sense with either -m or --socket-mem */ - if (internal_config.no_hugetlbfs && - (internal_config.memory > 0 || - internal_config.force_sockets == 1)) { - RTE_LOG(ERR, EAL, "Options -m or --socket-mem cannot be specified " - "together with --no-huge!\n"); + + /* sanity checks */ + if (eal_check_common_options(&internal_config) != 0) { eal_usage(prgname); return -1; } + /* --xen-dom0 doesn't make sense with --socket-mem */ if (internal_config.xen_dom0_support && internal_config.force_sockets == 1) { - RTE_LOG(ERR, EAL, "Options --socket-mem cannot be specified " - "together with --xen_dom0!\n"); - eal_usage(prgname); - return -1; - } - - if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) != 0 && - rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_PCI) != 0) { - RTE_LOG(ERR, EAL, "Error: blacklist [-b] and whitelist " - "[-w] options cannot be used at the same time\n"); + RTE_LOG(ERR, EAL, "Options --"OPT_SOCKET_MEM" cannot be specified " + "together with --"OPT_XEN_DOM0"\n"); eal_usage(prgname); return -1; }