From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 43C2E7CBF for ; Tue, 30 May 2017 10:33:31 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 May 2017 01:33:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,417,1491289200"; d="scan'208";a="93354084" Received: from gklab-246-073.igk.intel.com (HELO Sent) ([10.217.246.73]) by orsmga002.jf.intel.com with SMTP; 30 May 2017 01:33:27 -0700 Received: by Sent (sSMTP sendmail emulation); Tue, 30 May 2017 10:31:33 +0200 From: Jacek Piasecki To: dev@dpdk.org Cc: bruce.richardson@intel.com, deepak.k.jain@intel.com, michalx.k.jastrzebski@intel.com, Kuba Kozak Date: Tue, 30 May 2017 10:30:36 +0200 Message-Id: <1496133037-3014-3-git-send-email-jacekx.piasecki@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496133037-3014-1-git-send-email-jacekx.piasecki@intel.com> References: <1496133037-3014-1-git-send-email-jacekx.piasecki@intel.com> Subject: [dpdk-dev] [PATCH 2/3] eal: add functions parsing EAL arguments 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: , X-List-Received-Date: Tue, 30 May 2017 08:33:32 -0000 From: Kuba Kozak added function rte_eal_configure which translate options from config file into argc, **argv form. changed function rte_eal_init to meld argc, argv** options from config file with these from command line and then parse as before Signed-off-by: Kuba Kozak Suggested-by: Bruce Richardson --- lib/Makefile | 6 +- lib/librte_cfgfile/rte_cfgfile.h | 2 + lib/librte_eal/bsdapp/eal/Makefile | 4 + lib/librte_eal/bsdapp/eal/eal.c | 128 ++++++++++++++++++++++- lib/librte_eal/bsdapp/eal/rte_eal_version.map | 5 + lib/librte_eal/common/include/rte_eal.h | 6 ++ lib/librte_eal/linuxapp/eal/Makefile | 3 + lib/librte_eal/linuxapp/eal/eal.c | 108 ++++++++++++++++++- lib/librte_eal/linuxapp/eal/rte_eal_version.map | 4 + mk/rte.app.mk | 2 +- 10 files changed, 261 insertions(+), 7 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 07e1fd0..fc5df3a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -32,7 +32,11 @@ include $(RTE_SDK)/mk/rte.vars.mk DIRS-y += librte_compat +DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile DIRS-$(CONFIG_RTE_LIBRTE_EAL) += librte_eal +ifeq ($(CONFIG_RTE_LIBRTE_CFGFILE),y) +DEPDIRS-librte_eal := librte_cfgfile +endif DIRS-$(CONFIG_RTE_LIBRTE_RING) += librte_ring DEPDIRS-librte_ring := librte_eal DIRS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += librte_mempool @@ -41,8 +45,6 @@ DIRS-$(CONFIG_RTE_LIBRTE_MBUF) += librte_mbuf DEPDIRS-librte_mbuf := librte_eal librte_mempool DIRS-$(CONFIG_RTE_LIBRTE_TIMER) += librte_timer DEPDIRS-librte_timer := librte_eal -DIRS-$(CONFIG_RTE_LIBRTE_CFGFILE) += librte_cfgfile -DEPDIRS-librte_cfgfile := librte_eal DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline DEPDIRS-librte_cmdline := librte_eal DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ether diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h index 902ec69..8808aa7 100644 --- a/lib/librte_cfgfile/rte_cfgfile.h +++ b/lib/librte_cfgfile/rte_cfgfile.h @@ -49,6 +49,8 @@ * ***/ +struct rte_cfgfile; /* forward declaration of struct */ + #ifndef CFG_NAME_LEN #define CFG_NAME_LEN 64 #endif diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile index a0f9950..d70eefb 100644 --- a/lib/librte_eal/bsdapp/eal/Makefile +++ b/lib/librte_eal/bsdapp/eal/Makefile @@ -50,6 +50,10 @@ EXPORT_MAP := rte_eal_version.map LIBABIVER := 4 +ifeq ($(CONFIG_RTE_LIBRTE_CFGFILE),y) +LDLIBS += -lrte_cfgfile +endif + # specific to bsdapp exec-env SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) := eal.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_memory.c diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 05f0c1f..e5e11c8 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -73,6 +73,7 @@ #include #include #include +#include #include "eal_private.h" #include "eal_thread.h" @@ -92,6 +93,12 @@ * duration of the program, as we hold a write lock on it in the primary proc */ static int mem_cfg_fd = -1; +static int cfg_argc; +#ifdef RTE_LIBRTE_CFGFILE +static char **cfg_argv; +#endif + + static struct flock wr_lock = { .l_type = F_WRLCK, .l_whence = SEEK_SET, @@ -492,10 +499,28 @@ static void rte_eal_init_alert(const char *msg) RTE_LOG(ERR, EAL, "%s\n", msg); } +#ifdef RTE_LIBRTE_CFGFILE +static void +free_pointer_array(char **pkt) +{ + int i = 0; + + if (pkt) { + while (pkt[i]) { + free(pkt[i]); + pkt[i++] = 0; + } + free(pkt); + pkt = 0; + } +} +#endif + /* Launch threads, called at application init(). */ int rte_eal_init(int argc, char **argv) { + int combined_argc; /* combine cfg and param versions */ int i, fctret, ret; pthread_t thread_id; static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0); @@ -519,8 +544,25 @@ static void rte_eal_init_alert(const char *msg) eal_reset_internal_config(&internal_config); +#ifdef RTE_LIBRTE_CFGFILE + combined_argc = argc + cfg_argc; + char *combined_argv[combined_argc + 1]; + + combined_argv[0] = argv[0]; + for (i = 0; i < cfg_argc; i++) + combined_argv[i + 1] = cfg_argv[i]; + for (i = 1; i < argc; i++) + combined_argv[i + cfg_argc] = argv[i]; + combined_argv[combined_argc] = NULL; +#else + combined_argc = argc; + char **combined_argv; + + combined_argv = argv; +#endif + /* set log level as early as possible */ - eal_log_level_parse(argc, argv); + eal_log_level_parse(combined_argc, combined_argv); if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); @@ -528,13 +570,21 @@ static void rte_eal_init_alert(const char *msg) return -1; } - fctret = eal_parse_args(argc, argv); + fctret = eal_parse_args(combined_argc, combined_argv); if (fctret < 0) { rte_eal_init_alert("Invalid 'command line' arguments."); rte_errno = EINVAL; rte_atomic32_clear(&run_once); return -1; } + fctret -= cfg_argc; + +#ifdef RTE_LIBRTE_CFGFILE + free_pointer_array(cfg_argv); +#endif + + if (fctret) + argv[fctret] = argv[0]; if (internal_config.no_hugetlbfs == 0 && internal_config.process_type != RTE_PROC_SECONDARY && @@ -677,3 +727,77 @@ enum rte_proc_type_t { return rte_config.process_type; } + +#ifdef RTE_LIBRTE_CFGFILE + +static char *strdup_with_prefix(const char *p) +{ + char *np; + + if (strlen(p) > 1) { + np = (char *)malloc(strlen(p)+3); + if (np) + strcpy(np, "--"); + } else { + np = (char *)malloc(strlen(p)+2); + if (np) + strcpy(np, "-"); + } + return np ? strcat(np, p) : np; +} + +int +rte_eal_configure(struct rte_cfgfile *cfg) +{ + int i, num_entries; + + if (cfg == NULL) { + rte_errno = -EINVAL; + return -1; + } + + if (!rte_cfgfile_has_section(cfg, "DPDK")) + return 0; + + num_entries = rte_cfgfile_section_num_entries(cfg, "DPDK"); + if (num_entries <= 0) + return 0; + + cfg_argv = malloc((num_entries * 2 + 1) * sizeof(cfg_argv[0])); + if (cfg_argv == NULL) { + rte_errno = -ENOMEM; + return -1; + } + + struct rte_cfgfile_entry cfg_entries[num_entries]; + + rte_cfgfile_section_entries(cfg, "DPDK", cfg_entries, num_entries); + + cfg_argc = 0; + for (i = 0; i < num_entries; i++) { + cfg_argv[cfg_argc] = strdup_with_prefix(cfg_entries[i].name); + if (!(cfg_argv[cfg_argc])) + goto allocation_error; + cfg_argc++; + if (strlen(cfg_entries[i].value)) { + cfg_argv[cfg_argc] = strdup(cfg_entries[i].value); + if (!(cfg_argv[cfg_argc])) + goto allocation_error; + cfg_argc++; + } + } + /* set last pointer to 0 */ + cfg_argv[cfg_argc] = 0; + + return cfg_argc; + +allocation_error: + rte_eal_init_alert("Cannot allocate memory in rte_eal_configure()\n"); + rte_errno = ENOMEM; + for (i = 1; i < cfg_argc; i++) { + free(cfg_argv[i]); + cfg_argv[i] = 0; + } + return -1; +} +#endif diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 2e48a73..a9b637b 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -193,3 +193,8 @@ DPDK_17.05 { vfio_get_group_no; } DPDK_17.02; + +DPDK_17.08 { + rte_eal_configure; +} DPDK_17.05; + diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h index abf020b..6a0b18b 100644 --- a/lib/librte_eal/common/include/rte_eal.h +++ b/lib/librte_eal/common/include/rte_eal.h @@ -46,6 +46,8 @@ #include #include +struct rte_cfgfile; /* forward declaration of struct */ + #ifdef __cplusplus extern "C" { #endif @@ -188,6 +190,10 @@ struct rte_config { */ int rte_eal_init(int argc, char **argv); +#ifdef RTE_LIBRTE_CFGFILE +int rte_eal_configure(struct rte_cfgfile *cfg); +#endif + /** * Check if a primary process is currently alive * diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile index 640afd0..656033e 100644 --- a/lib/librte_eal/linuxapp/eal/Makefile +++ b/lib/librte_eal/linuxapp/eal/Makefile @@ -50,6 +50,9 @@ LDLIBS += -ldl LDLIBS += -lpthread LDLIBS += -lgcc_s LDLIBS += -lrt +ifeq ($(CONFIG_RTE_LIBRTE_CFGFILE),y) +LDLIBS += -lrte_cfgfile +endif # specific to linuxapp exec-env SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) := eal.c diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 7c78f2d..b4078b5 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -78,6 +78,7 @@ #include #include #include +#include #include "eal_private.h" #include "eal_thread.h" @@ -122,6 +123,12 @@ /* used by rte_rdtsc() */ int rte_cycles_vmware_tsc_map; + +static int cfg_argc; +#ifdef RTE_LIBRTE_CFGFILE +static char **cfg_argv; +#endif + /* Return a pointer to the configuration structure */ struct rte_config * rte_eal_get_configuration(void) @@ -745,10 +752,12 @@ static void rte_eal_init_alert(const char *msg) RTE_LOG(ERR, EAL, "%s\n", msg); } + /* Launch threads, called at application init(). */ int rte_eal_init(int argc, char **argv) { + int combined_argc; /* combine cfg and param versions */ int i, fctret, ret; pthread_t thread_id; static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0); @@ -776,8 +785,25 @@ static void rte_eal_init_alert(const char *msg) eal_reset_internal_config(&internal_config); +#ifdef RTE_LIBRTE_CFGFILE + combined_argc = argc + cfg_argc; + char *combined_argv[combined_argc + 1]; + + combined_argv[0] = argv[0]; + for (i = 0; i < cfg_argc; i++) + combined_argv[i + 1] = cfg_argv[i]; + for (i = 1; i < argc; i++) + combined_argv[i + cfg_argc] = argv[i]; + combined_argv[combined_argc] = NULL; +#else + combined_argc = argc; + char **combined_argv; + + combined_argv = argv; +#endif + /* set log level as early as possible */ - eal_log_level_parse(argc, argv); + eal_log_level_parse(combined_argc, combined_argv); if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); @@ -785,13 +811,17 @@ static void rte_eal_init_alert(const char *msg) return -1; } - fctret = eal_parse_args(argc, argv); + fctret = eal_parse_args(combined_argc, combined_argv); if (fctret < 0) { rte_eal_init_alert("Invalid 'command line' arguments."); rte_errno = EINVAL; rte_atomic32_clear(&run_once); return -1; } + fctret -= cfg_argc; + + if (fctret) + argv[fctret] = argv[0]; if (internal_config.no_hugetlbfs == 0 && internal_config.process_type != RTE_PROC_SECONDARY && @@ -995,3 +1025,77 @@ int rte_eal_has_hugepages(void) /* Module has been found */ return 1; } + +#ifdef RTE_LIBRTE_CFGFILE + +static char *strdup_with_prefix(const char *p) +{ + char *np; + + if (strlen(p) > 1) { + np = (char *)malloc(strlen(p)+3); + if (np) + strcpy(np, "--"); + } else { + np = (char *)malloc(strlen(p)+2); + if (np) + strcpy(np, "-"); + } + return np ? strcat(np, p) : np; +} + +int +rte_eal_configure(struct rte_cfgfile *cfg) +{ + int i, num_entries; + + if (cfg == NULL) { + rte_errno = -EINVAL; + return -1; + } + + if (!rte_cfgfile_has_section(cfg, "DPDK")) + return 0; + + num_entries = rte_cfgfile_section_num_entries(cfg, "DPDK"); + if (num_entries <= 0) + return 0; + + cfg_argv = malloc((num_entries * 2 + 1) * sizeof(cfg_argv[0])); + if (cfg_argv == NULL) { + rte_errno = -ENOMEM; + return -1; + } + + struct rte_cfgfile_entry cfg_entries[num_entries]; + + rte_cfgfile_section_entries(cfg, "DPDK", cfg_entries, num_entries); + + cfg_argc = 0; + for (i = 0; i < num_entries; i++) { + cfg_argv[cfg_argc] = strdup_with_prefix(cfg_entries[i].name); + if (!(cfg_argv[cfg_argc])) + goto allocation_error; + cfg_argc++; + if (strlen(cfg_entries[i].value)) { + cfg_argv[cfg_argc] = strdup(cfg_entries[i].value); + if (!(cfg_argv[cfg_argc])) + goto allocation_error; + cfg_argc++; + } + } + /* set last pointer to 0 */ + cfg_argv[cfg_argc] = 0; + + return cfg_argc; + +allocation_error: + rte_eal_init_alert("Cannot allocate memory in rte_eal_configure()\n"); + rte_errno = ENOMEM; + for (i = 1; i < cfg_argc; i++) { + free(cfg_argv[i]); + cfg_argv[i] = 0; + } + return -1; +} +#endif diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index 670bab3..c93e6d9 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -198,3 +198,7 @@ DPDK_17.05 { vfio_get_group_no; } DPDK_17.02; + +DPDK_17.08 { + rte_eal_configure; +} DPDK_17.05; diff --git a/mk/rte.app.mk b/mk/rte.app.mk index bcaf1b3..642af92 100644 --- a/mk/rte.app.mk +++ b/mk/rte.app.mk @@ -80,7 +80,6 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_POWER) += -lrte_power _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER) += -lrte_timer _LDLIBS-$(CONFIG_RTE_LIBRTE_EFD) += -lrte_efd -_LDLIBS-$(CONFIG_RTE_LIBRTE_CFGFILE) += -lrte_cfgfile _LDLIBS-y += --whole-archive @@ -96,6 +95,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL) += -lrte_mempool _LDLIBS-$(CONFIG_RTE_DRIVER_MEMPOOL_RING) += -lrte_mempool_ring _LDLIBS-$(CONFIG_RTE_LIBRTE_RING) += -lrte_ring _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL) += -lrte_eal +_LDLIBS-$(CONFIG_RTE_LIBRTE_CFGFILE) += -lrte_cfgfile _LDLIBS-$(CONFIG_RTE_LIBRTE_CMDLINE) += -lrte_cmdline _LDLIBS-$(CONFIG_RTE_LIBRTE_REORDER) += -lrte_reorder -- 1.7.9.5