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 3C592A04F1; Thu, 18 Jun 2020 23:17:02 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E11FA1B952; Thu, 18 Jun 2020 23:16:46 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 6F34E5B3A for ; Thu, 18 Jun 2020 23:16:42 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from talshn@mellanox.com) with SMTP; 19 Jun 2020 00:16:36 +0300 Received: from l-wincomp04-vm.labs.mlnx (l-wincomp04-vm.mtl.labs.mlnx [10.237.1.5]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 05ILGaF4006303; Fri, 19 Jun 2020 00:16:36 +0300 From: talshn@mellanox.com To: dev@dpdk.org Cc: thomas@monjalon.net, pallavi.kadam@intel.com, dmitry.kozliuk@gmail.com, david.marchand@redhat.com, grive@u256.net, ranjit.menon@intel.com, navasile@linux.microsoft.com, harini.ramakrishnan@microsoft.com, ocardona@microsoft.com, anatoly.burakov@intel.com, fady@mellanox.com, bruce.richardson@intel.com, Tal Shnaiderman Date: Fri, 19 Jun 2020 00:15:38 +0300 Message-Id: <20200618211546.24496-2-talshn@mellanox.com> X-Mailer: git-send-email 2.16.1.windows.4 In-Reply-To: <20200618211546.24496-1-talshn@mellanox.com> References: <20200609103139.22168-2-talshn@mellanox.com> <20200618211546.24496-1-talshn@mellanox.com> Subject: [dpdk-dev] [PATCH v6 1/9] eal: move OS common functions to single file 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" From: Tal Shnaiderman Move common functions between Unix and Windows to eal_common_config.c. Those functions are getter functions for IOVA, configuration, Multi-process. Move rte_config, internal_config, early_mem_config and runtime_dir to be defined in a common file. Signed-off-by: Tal Shnaiderman --- lib/librte_eal/common/eal_common_config.c | 118 ++++++++++++++ lib/librte_eal/common/eal_private.h | 1 + lib/librte_eal/common/meson.build | 2 + lib/librte_eal/freebsd/Makefile | 1 + lib/librte_eal/freebsd/eal.c | 231 ++++++++++----------------- lib/librte_eal/include/rte_eal.h | 25 +++ lib/librte_eal/linux/Makefile | 1 + lib/librte_eal/linux/eal.c | 253 +++++++++++++----------------- lib/librte_eal/windows/eal.c | 90 +++-------- 9 files changed, 365 insertions(+), 357 deletions(-) create mode 100644 lib/librte_eal/common/eal_common_config.c diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c new file mode 100644 index 0000000000..4a61972539 --- /dev/null +++ b/lib/librte_eal/common/eal_common_config.c @@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020 Mellanox Technologies, Ltd + */ +#include + +#include + +#include +#include + +/* early configuration structure, when memory config is not mmapped */ +static struct rte_mem_config early_mem_config; + +/* Address of global and public configuration */ +static struct rte_config rte_config = { + .mem_config = &early_mem_config, +}; + +/* platform-specific runtime dir */ +static char runtime_dir[PATH_MAX]; + +/* internal configuration */ +struct internal_config internal_config; + +/* Allow the application to print its usage message too if set */ +static rte_usage_hook_t rte_application_usage_hook = NULL; + +const char * +rte_eal_get_runtime_dir(void) +{ + return runtime_dir; +} + +void +rte_eal_set_runtime_dir(char *run_dir, size_t size) +{ + strncpy(runtime_dir, run_dir, size); +} + +/* Return a pointer to the configuration structure */ +struct rte_config * +rte_eal_get_configuration(void) +{ + return &rte_config; +} + +/* Return a pointer to theinternal configuration structure */ +struct internal_config * +rte_eal_get_internal_configuration(void) +{ + return &internal_config; +} + +/* Return a pointer to rte_usage_hook_t */ +rte_usage_hook_t * +rte_eal_get_application_usage_hook(void) +{ + return &rte_application_usage_hook; +} + +enum rte_iova_mode +rte_eal_iova_mode(void) +{ + return rte_eal_get_configuration()->iova_mode; +} + +enum rte_proc_type_t +rte_eal_process_type(void) +{ + return rte_config.process_type; +} + +void +rte_eal_config_remap(void *mem_cfg_addr) +{ + memcpy(mem_cfg_addr, &early_mem_config, sizeof(early_mem_config)); + rte_config.mem_config = mem_cfg_addr; + + /* store address of the config in the config itself so that secondary + * processes could later map the config into this exact location + */ + rte_config.mem_config->mem_cfg_addr = (uintptr_t) mem_cfg_addr; + + rte_config.mem_config->dma_maskbits = 0; +} + +/* Return user provided mbuf pool ops name */ +const char * +rte_eal_mbuf_user_pool_ops(void) +{ + return internal_config.user_mbuf_pool_ops_name; +} + +/* Set a per-application usage message */ +rte_usage_hook_t +rte_set_application_usage_hook(rte_usage_hook_t usage_func) +{ + rte_usage_hook_t old_func; + + /* Will be NULL on the first call to denote the last usage routine. */ + old_func = rte_application_usage_hook; + rte_application_usage_hook = usage_func; + + return old_func; +} + +/* return non-zero if hugepages are enabled. */ +int +rte_eal_has_hugepages(void) +{ + return !internal_config.no_hugetlbfs; +} + +int +rte_eal_has_pci(void) +{ + return !internal_config.no_pci; +} diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 0592fcd694..97cfd6a325 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -62,6 +62,7 @@ struct rte_config { struct rte_mem_config *mem_config; } __rte_packed; + /** * Get the global configuration structure. * diff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build index 3108442697..a16f002a3e 100644 --- a/lib/librte_eal/common/meson.build +++ b/lib/librte_eal/common/meson.build @@ -7,6 +7,7 @@ if is_windows sources += files( 'eal_common_bus.c', 'eal_common_class.c', + 'eal_common_config.c', 'eal_common_devargs.c', 'eal_common_dynmem.c', 'eal_common_errno.c', @@ -34,6 +35,7 @@ sources += files( 'eal_common_bus.c', 'eal_common_cpuflags.c', 'eal_common_class.c', + 'eal_common_config.c', 'eal_common_devargs.c', 'eal_common_dev.c', 'eal_common_errno.c', diff --git a/lib/librte_eal/freebsd/Makefile b/lib/librte_eal/freebsd/Makefile index 2374ba0b7d..7762b3ede4 100644 --- a/lib/librte_eal/freebsd/Makefile +++ b/lib/librte_eal/freebsd/Makefile @@ -38,6 +38,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_alarm.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_dev.c # from common dir +SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_config.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_FREEBSD) += eal_common_memzone.c diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c index c41f265fac..8d7b693a3b 100644 --- a/lib/librte_eal/freebsd/eal.c +++ b/lib/librte_eal/freebsd/eal.c @@ -56,11 +56,6 @@ #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) -/* Allow the application to print its usage message too if set */ -static rte_usage_hook_t rte_application_usage_hook = NULL; -/* early configuration structure, when memory config is not mmapped */ -static struct rte_mem_config early_mem_config; - /* define fd variable here, because file needs to be kept open for the * duration of the program, as we hold a write lock on it in the primary proc */ static int mem_cfg_fd = -1; @@ -69,26 +64,15 @@ static struct flock wr_lock = { .l_type = F_WRLCK, .l_whence = SEEK_SET, .l_start = offsetof(struct rte_mem_config, memsegs), - .l_len = sizeof(early_mem_config.memsegs), -}; - -/* Address of global and public configuration */ -static struct rte_config rte_config = { - .mem_config = &early_mem_config, + .l_len = RTE_SIZEOF_FIELD(struct rte_mem_config, memsegs), }; /* internal configuration (per-core) */ struct lcore_config lcore_config[RTE_MAX_LCORE]; -/* internal configuration */ -struct internal_config internal_config; - /* used by rte_rdtsc() */ int rte_cycles_vmware_tsc_map; -/* platform-specific runtime dir */ -static char runtime_dir[PATH_MAX]; - static const char *default_runtime_dir = "/var/run"; int @@ -97,6 +81,7 @@ eal_create_runtime_dir(void) const char *directory = default_runtime_dir; const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"); const char *fallback = "/tmp"; + char run_dir[PATH_MAX]; char tmp[PATH_MAX]; int ret; @@ -115,9 +100,9 @@ eal_create_runtime_dir(void) } /* create prefix-specific subdirectory under DPDK runtime dir */ - ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s", + ret = snprintf(run_dir, sizeof(run_dir), "%s/%s", tmp, eal_get_hugefile_prefix()); - if (ret < 0 || ret == sizeof(runtime_dir)) { + if (ret < 0 || ret == sizeof(run_dir)) { RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n"); return -1; } @@ -132,13 +117,15 @@ eal_create_runtime_dir(void) return -1; } - ret = mkdir(runtime_dir, 0700); + ret = mkdir(run_dir, 0700); if (ret < 0 && errno != EEXIST) { RTE_LOG(ERR, EAL, "Error creating '%s': %s\n", - runtime_dir, strerror(errno)); + run_dir, strerror(errno)); return -1; } + rte_eal_set_runtime_dir(run_dir, sizeof(run_dir)); + return 0; } @@ -151,33 +138,6 @@ eal_clean_runtime_dir(void) return 0; } - -const char * -rte_eal_get_runtime_dir(void) -{ - return runtime_dir; -} - -/* Return user provided mbuf pool ops name */ -const char * -rte_eal_mbuf_user_pool_ops(void) -{ - return internal_config.user_mbuf_pool_ops_name; -} - -/* Return a pointer to the configuration structure */ -struct rte_config * -rte_eal_get_configuration(void) -{ - return &rte_config; -} - -enum rte_iova_mode -rte_eal_iova_mode(void) -{ - return rte_eal_get_configuration()->iova_mode; -} - /* parse a sysfs (or other) file containing one integer value */ int eal_parse_sysfs_value(const char *filename, unsigned long *val) @@ -219,21 +179,24 @@ eal_parse_sysfs_value(const char *filename, unsigned long *val) static int rte_eal_config_create(void) { + struct rte_config *config = rte_eal_get_configuration(); + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); size_t page_sz = sysconf(_SC_PAGE_SIZE); - size_t cfg_len = sizeof(*rte_config.mem_config); + size_t cfg_len = sizeof(*config->mem_config); size_t cfg_len_aligned = RTE_ALIGN(cfg_len, page_sz); void *rte_mem_cfg_addr, *mapped_mem_cfg_addr; int retval; const char *pathname = eal_runtime_config_path(); - if (internal_config.no_shconf) + if (internal_conf->no_shconf) return 0; /* map the config before base address so that we don't waste a page */ - if (internal_config.base_virtaddr != 0) + if (internal_conf->base_virtaddr != 0) rte_mem_cfg_addr = (void *) - RTE_ALIGN_FLOOR(internal_config.base_virtaddr - + RTE_ALIGN_FLOOR(internal_conf->base_virtaddr - sizeof(struct rte_mem_config), page_sz); else rte_mem_cfg_addr = NULL; @@ -287,13 +250,7 @@ rte_eal_config_create(void) return -1; } - memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config)); - rte_config.mem_config = rte_mem_cfg_addr; - - /* store address of the config in the config itself so that secondary - * processes could later map the config into this exact location - */ - rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr; + rte_eal_config_remap(rte_mem_cfg_addr); return 0; } @@ -304,8 +261,12 @@ rte_eal_config_attach(void) { void *rte_mem_cfg_addr; const char *pathname = eal_runtime_config_path(); + struct rte_config *config = rte_eal_get_configuration(); + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); - if (internal_config.no_shconf) + + if (internal_conf->no_shconf) return 0; if (mem_cfg_fd < 0){ @@ -317,7 +278,7 @@ rte_eal_config_attach(void) } } - rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config), + rte_mem_cfg_addr = mmap(NULL, sizeof(*config->mem_config), PROT_READ, MAP_SHARED, mem_cfg_fd, 0); /* don't close the fd here, it will be closed on reattach */ if (rte_mem_cfg_addr == MAP_FAILED) { @@ -328,7 +289,7 @@ rte_eal_config_attach(void) return -1; } - rte_config.mem_config = rte_mem_cfg_addr; + config->mem_config = rte_mem_cfg_addr; return 0; } @@ -339,16 +300,19 @@ rte_eal_config_reattach(void) { struct rte_mem_config *mem_config; void *rte_mem_cfg_addr; + struct rte_config *config = rte_eal_get_configuration(); + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); - if (internal_config.no_shconf) + if (internal_conf->no_shconf) return 0; /* save the address primary process has mapped shared config to */ rte_mem_cfg_addr = - (void *)(uintptr_t)rte_config.mem_config->mem_cfg_addr; + (void *)(uintptr_t)config->mem_config->mem_cfg_addr; /* unmap original config */ - munmap(rte_config.mem_config, sizeof(struct rte_mem_config)); + munmap(config->mem_config, sizeof(struct rte_mem_config)); /* remap the config at proper address */ mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr, @@ -372,7 +336,7 @@ rte_eal_config_reattach(void) return -1; } - rte_config.mem_config = mem_config; + config->mem_config = mem_config; return 0; } @@ -383,9 +347,11 @@ eal_proc_type_detect(void) { enum rte_proc_type_t ptype = RTE_PROC_PRIMARY; const char *pathname = eal_runtime_config_path(); + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); /* if there no shared config, there can be no secondary processes */ - if (!internal_config.no_shconf) { + if (!internal_conf->no_shconf) { /* if we can open the file but not get a write-lock we are a * secondary process. NOTE: if we get a file handle back, we * keep that open and don't close it to prevent a race condition @@ -406,9 +372,13 @@ eal_proc_type_detect(void) static int rte_config_init(void) { - rte_config.process_type = internal_config.process_type; + struct rte_config *config = rte_eal_get_configuration(); + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); + + config->process_type = internal_conf->process_type; - switch (rte_config.process_type){ + switch (config->process_type) { case RTE_PROC_PRIMARY: if (rte_eal_config_create() < 0) return -1; @@ -429,7 +399,7 @@ rte_config_init(void) case RTE_PROC_AUTO: case RTE_PROC_INVALID: RTE_LOG(ERR, EAL, "Invalid process type %d\n", - rte_config.process_type); + config->process_type); return -1; } @@ -440,46 +410,17 @@ rte_config_init(void) static void eal_usage(const char *prgname) { + rte_usage_hook_t *hook = rte_eal_get_application_usage_hook(); + printf("\nUsage: %s ", prgname); eal_common_usage(); /* Allow the application to print its usage message too if hook is set */ - if ( rte_application_usage_hook ) { + if (*hook) { printf("===== Application Usage =====\n\n"); - rte_application_usage_hook(prgname); + (*hook)(prgname); } } -/* Set a per-application usage message */ -rte_usage_hook_t -rte_set_application_usage_hook( rte_usage_hook_t usage_func ) -{ - rte_usage_hook_t old_func; - - /* Will be NULL on the first call to denote the last usage routine. */ - old_func = rte_application_usage_hook; - rte_application_usage_hook = usage_func; - - return old_func; -} - -static inline size_t -eal_get_hugepage_mem_size(void) -{ - uint64_t size = 0; - unsigned i, j; - - for (i = 0; i < internal_config.num_hugepage_sizes; i++) { - struct hugepage_info *hpi = &internal_config.hugepage_info[i]; - if (strnlen(hpi->hugedir, sizeof(hpi->hugedir)) != 0) { - for (j = 0; j < RTE_MAX_NUMA_NODES; j++) { - size += hpi->hugepage_sz * hpi->num_pages[j]; - } - } - } - - return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX; -} - /* Parse the arguments for --log-level only */ static void eal_log_level_parse(int argc, char **argv) @@ -491,6 +432,8 @@ eal_log_level_parse(int argc, char **argv) const int old_optopt = optopt; const int old_optreset = optreset; char * const old_optarg = optarg; + struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); argvopt = argv; optind = 1; @@ -506,7 +449,7 @@ eal_log_level_parse(int argc, char **argv) break; ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, &internal_config) : 0; + eal_parse_common_option(opt, optarg, internal_conf) : 0; /* common parser is not happy */ if (ret < 0) @@ -532,6 +475,8 @@ eal_parse_args(int argc, char **argv) const int old_optopt = optopt; const int old_optreset = optreset; char * const old_optarg = optarg; + struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); argvopt = argv; optind = 1; @@ -547,7 +492,7 @@ eal_parse_args(int argc, char **argv) goto out; } - ret = eal_parse_common_option(opt, optarg, &internal_config); + ret = eal_parse_common_option(opt, optarg, internal_conf); /* common parser is not happy */ if (ret < 0) { eal_usage(prgname); @@ -566,11 +511,11 @@ eal_parse_args(int argc, char **argv) RTE_LOG(ERR, EAL, "Could not store mbuf pool ops name\n"); else { /* free old ops name */ - if (internal_config.user_mbuf_pool_ops_name != + if (internal_conf->user_mbuf_pool_ops_name != NULL) - free(internal_config.user_mbuf_pool_ops_name); + free(internal_conf->user_mbuf_pool_ops_name); - internal_config.user_mbuf_pool_ops_name = + internal_conf->user_mbuf_pool_ops_name = ops_name; } break; @@ -598,20 +543,20 @@ eal_parse_args(int argc, char **argv) } /* create runtime data directory */ - if (internal_config.no_shconf == 0 && + if (internal_conf->no_shconf == 0 && eal_create_runtime_dir() < 0) { RTE_LOG(ERR, EAL, "Cannot create runtime directory\n"); ret = -1; goto out; } - if (eal_adjust_config(&internal_config) != 0) { + if (eal_adjust_config(internal_conf) != 0) { ret = -1; goto out; } /* sanity checks */ - if (eal_check_common_options(&internal_config) != 0) { + if (eal_check_common_options(internal_conf) != 0) { eal_usage(prgname); ret = -1; goto out; @@ -649,8 +594,9 @@ static void eal_check_mem_on_local_socket(void) { int socket_id; + const struct rte_config *config = rte_eal_get_configuration(); - socket_id = rte_lcore_to_socket_id(rte_config.master_lcore); + socket_id = rte_lcore_to_socket_id(config->master_lcore); if (rte_memseg_list_walk(check_socket, &socket_id) == 0) RTE_LOG(WARNING, EAL, "WARNING: Master core has no memory on local socket!\n"); @@ -662,13 +608,6 @@ sync_func(__rte_unused void *arg) { return 0; } - -/* return non-zero if hugepages are enabled. */ -int rte_eal_has_hugepages(void) -{ - return !internal_config.no_hugetlbfs; -} - /* Abstraction for port I/0 privilege */ int rte_eal_iopl_init(void) @@ -699,6 +638,9 @@ rte_eal_init(int argc, char **argv) static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0); char cpuset[RTE_CPU_AFFINITY_STR_LEN]; char thread_name[RTE_MAX_THREAD_NAME_LEN]; + const struct rte_config *config = rte_eal_get_configuration(); + struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); /* checks if the machine is adequate */ if (!rte_cpu_is_supported()) { @@ -715,7 +657,7 @@ rte_eal_init(int argc, char **argv) thread_id = pthread_self(); - eal_reset_internal_config(&internal_config); + eal_reset_internal_config(internal_conf); /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); @@ -738,7 +680,7 @@ rte_eal_init(int argc, char **argv) } /* FreeBSD always uses legacy memory model */ - internal_config.legacy_mem = true; + internal_conf->legacy_mem = true; if (eal_plugins_init() < 0) { rte_eal_init_alert("Cannot init plugins"); @@ -795,7 +737,7 @@ rte_eal_init(int argc, char **argv) } /* if no EAL option "--iova-mode=", use bus IOVA scheme */ - if (internal_config.iova_mode == RTE_IOVA_DC) { + if (internal_conf->iova_mode == RTE_IOVA_DC) { /* autodetect the IOVA mapping mode (default is RTE_IOVA_PA) */ enum rte_iova_mode iova_mode = rte_bus_get_iommu_class(); @@ -804,15 +746,15 @@ rte_eal_init(int argc, char **argv) rte_eal_get_configuration()->iova_mode = iova_mode; } else { rte_eal_get_configuration()->iova_mode = - internal_config.iova_mode; + internal_conf->iova_mode; } RTE_LOG(INFO, EAL, "Selected IOVA mode '%s'\n", rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA"); - if (internal_config.no_hugetlbfs == 0) { + if (internal_conf->no_hugetlbfs == 0) { /* rte_config isn't initialized yet */ - ret = internal_config.process_type == RTE_PROC_PRIMARY ? + ret = internal_conf->process_type == RTE_PROC_PRIMARY ? eal_hugepage_info_init() : eal_hugepage_info_read(); if (ret < 0) { @@ -823,14 +765,14 @@ rte_eal_init(int argc, char **argv) } } - if (internal_config.memory == 0 && internal_config.force_sockets == 0) { - if (internal_config.no_hugetlbfs) - internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE; + if (internal_conf->memory == 0 && internal_conf->force_sockets == 0) { + if (internal_conf->no_hugetlbfs) + internal_conf->memory = MEMSIZE_IF_NO_HUGE_PAGE; else - internal_config.memory = eal_get_hugepage_mem_size(); + internal_conf->memory = eal_get_hugepage_mem_size(); } - if (internal_config.vmware_tsc_map == 1) { + if (internal_conf->vmware_tsc_map == 1) { #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT rte_cycles_vmware_tsc_map = 1; RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, " @@ -877,12 +819,12 @@ rte_eal_init(int argc, char **argv) eal_check_mem_on_local_socket(); - eal_thread_init_master(rte_config.master_lcore); + eal_thread_init_master(config->master_lcore); ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset)); RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n", - rte_config.master_lcore, thread_id, cpuset, + config->master_lcore, thread_id, cpuset, ret == 0 ? "" : "..."); RTE_LCORE_FOREACH_SLAVE(i) { @@ -951,14 +893,14 @@ rte_eal_init(int argc, char **argv) * In no_shconf mode, no runtime directory is created in the first * place, so no cleanup needed. */ - if (!internal_config.no_shconf && eal_clean_runtime_dir() < 0) { + if (!internal_conf->no_shconf && eal_clean_runtime_dir() < 0) { rte_eal_init_alert("Cannot clear runtime directory\n"); return -1; } - if (!internal_config.no_telemetry) { + if (!internal_conf->no_telemetry) { const char *error_str = NULL; if (rte_telemetry_init(rte_eal_get_runtime_dir(), - &internal_config.ctrl_cpuset, &error_str) + &internal_conf->ctrl_cpuset, &error_str) != 0) { rte_eal_init_alert(error_str); return -1; @@ -975,28 +917,21 @@ rte_eal_init(int argc, char **argv) int rte_eal_cleanup(void) { + struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); rte_service_finalize(); rte_mp_channel_cleanup(); rte_trace_save(); eal_trace_fini(); - eal_cleanup_config(&internal_config); + eal_cleanup_config(internal_conf); return 0; } -enum rte_proc_type_t -rte_eal_process_type(void) -{ - return rte_config.process_type; -} - -int rte_eal_has_pci(void) -{ - return !internal_config.no_pci; -} - int rte_eal_create_uio_dev(void) { - return internal_config.create_uio_dev; + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); + return internal_conf->create_uio_dev; } enum rte_intr_mode diff --git a/lib/librte_eal/include/rte_eal.h b/lib/librte_eal/include/rte_eal.h index 2f9ed298de..c55a564020 100644 --- a/lib/librte_eal/include/rte_eal.h +++ b/lib/librte_eal/include/rte_eal.h @@ -488,6 +488,31 @@ rte_eal_mbuf_user_pool_ops(void); const char * rte_eal_get_runtime_dir(void); +void +rte_eal_set_runtime_dir(char *run_dir, size_t size); + +void +rte_eal_config_remap(void *mem_cfg_addr); + +const char * +rte_eal_mbuf_user_pool_ops(void); + +rte_usage_hook_t +rte_set_application_usage_hook(rte_usage_hook_t usage_func); + +int +rte_eal_has_hugepages(void); + +int +rte_eal_has_pci(void); + +struct internal_config * +rte_eal_get_internal_configuration(void); + +rte_usage_hook_t * +rte_eal_get_application_usage_hook(void); + + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/linux/Makefile b/lib/librte_eal/linux/Makefile index 07ce643bae..28404b0534 100644 --- a/lib/librte_eal/linux/Makefile +++ b/lib/librte_eal/linux/Makefile @@ -45,6 +45,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_alarm.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_dev.c # from common dir +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_config.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_lcore.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_timer.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUX) += eal_common_memzone.c diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c index f162124a37..473c7ac67c 100644 --- a/lib/librte_eal/linux/eal.c +++ b/lib/librte_eal/linux/eal.c @@ -69,12 +69,6 @@ #define KERNEL_IOMMU_GROUPS_PATH "/sys/kernel/iommu_groups" -/* Allow the application to print its usage message too if set */ -static rte_usage_hook_t rte_application_usage_hook = NULL; - -/* early configuration structure, when memory config is not mmapped */ -static struct rte_mem_config early_mem_config; - /* define fd variable here, because file needs to be kept open for the * duration of the program, as we hold a write lock on it in the primary proc */ static int mem_cfg_fd = -1; @@ -83,26 +77,15 @@ static struct flock wr_lock = { .l_type = F_WRLCK, .l_whence = SEEK_SET, .l_start = offsetof(struct rte_mem_config, memsegs), - .l_len = sizeof(early_mem_config.memsegs), -}; - -/* Address of global and public configuration */ -static struct rte_config rte_config = { - .mem_config = &early_mem_config, + .l_len = RTE_SIZEOF_FIELD(struct rte_mem_config, memsegs), }; /* internal configuration (per-core) */ struct lcore_config lcore_config[RTE_MAX_LCORE]; -/* internal configuration */ -struct internal_config internal_config; - /* used by rte_rdtsc() */ int rte_cycles_vmware_tsc_map; -/* platform-specific runtime dir */ -static char runtime_dir[PATH_MAX]; - static const char *default_runtime_dir = "/var/run"; int @@ -111,6 +94,7 @@ eal_create_runtime_dir(void) const char *directory = default_runtime_dir; const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"); const char *fallback = "/tmp"; + char run_dir[PATH_MAX]; char tmp[PATH_MAX]; int ret; @@ -129,9 +113,9 @@ eal_create_runtime_dir(void) } /* create prefix-specific subdirectory under DPDK runtime dir */ - ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s", + ret = snprintf(run_dir, sizeof(run_dir), "%s/%s", tmp, eal_get_hugefile_prefix()); - if (ret < 0 || ret == sizeof(runtime_dir)) { + if (ret < 0 || ret == sizeof(run_dir)) { RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n"); return -1; } @@ -146,19 +130,22 @@ eal_create_runtime_dir(void) return -1; } - ret = mkdir(runtime_dir, 0700); + ret = mkdir(run_dir, 0700); if (ret < 0 && errno != EEXIST) { RTE_LOG(ERR, EAL, "Error creating '%s': %s\n", - runtime_dir, strerror(errno)); + run_dir, strerror(errno)); return -1; } + rte_eal_set_runtime_dir(run_dir, sizeof(run_dir)); + return 0; } int eal_clean_runtime_dir(void) { + const char *runtime_dir = rte_eal_get_runtime_dir(); DIR *dir; struct dirent *dirent; int dir_fd, fd, lck_result; @@ -241,32 +228,6 @@ eal_clean_runtime_dir(void) return -1; } -const char * -rte_eal_get_runtime_dir(void) -{ - return runtime_dir; -} - -/* Return user provided mbuf pool ops name */ -const char * -rte_eal_mbuf_user_pool_ops(void) -{ - return internal_config.user_mbuf_pool_ops_name; -} - -/* Return a pointer to the configuration structure */ -struct rte_config * -rte_eal_get_configuration(void) -{ - return &rte_config; -} - -enum rte_iova_mode -rte_eal_iova_mode(void) -{ - return rte_eal_get_configuration()->iova_mode; -} - /* parse a sysfs (or other) file containing one integer value */ int eal_parse_sysfs_value(const char *filename, unsigned long *val) @@ -308,21 +269,24 @@ eal_parse_sysfs_value(const char *filename, unsigned long *val) static int rte_eal_config_create(void) { + struct rte_config *config = rte_eal_get_configuration(); size_t page_sz = sysconf(_SC_PAGE_SIZE); - size_t cfg_len = sizeof(*rte_config.mem_config); + size_t cfg_len = sizeof(*config->mem_config); size_t cfg_len_aligned = RTE_ALIGN(cfg_len, page_sz); void *rte_mem_cfg_addr, *mapped_mem_cfg_addr; int retval; + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); const char *pathname = eal_runtime_config_path(); - if (internal_config.no_shconf) + if (internal_conf->no_shconf) return 0; /* map the config before hugepage address so that we don't waste a page */ - if (internal_config.base_virtaddr != 0) + if (internal_conf->base_virtaddr != 0) rte_mem_cfg_addr = (void *) - RTE_ALIGN_FLOOR(internal_config.base_virtaddr - + RTE_ALIGN_FLOOR(internal_conf->base_virtaddr - sizeof(struct rte_mem_config), page_sz); else rte_mem_cfg_addr = NULL; @@ -376,14 +340,7 @@ rte_eal_config_create(void) return -1; } - memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config)); - rte_config.mem_config = rte_mem_cfg_addr; - - /* store address of the config in the config itself so that secondary - * processes could later map the config into this exact location */ - rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr; - - rte_config.mem_config->dma_maskbits = 0; + rte_eal_config_remap(rte_mem_cfg_addr); return 0; } @@ -392,11 +349,14 @@ rte_eal_config_create(void) static int rte_eal_config_attach(void) { + struct rte_config *config = rte_eal_get_configuration(); struct rte_mem_config *mem_config; + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); const char *pathname = eal_runtime_config_path(); - if (internal_config.no_shconf) + if (internal_conf->no_shconf) return 0; if (mem_cfg_fd < 0){ @@ -419,7 +379,7 @@ rte_eal_config_attach(void) return -1; } - rte_config.mem_config = mem_config; + config->mem_config = mem_config; return 0; } @@ -428,17 +388,20 @@ rte_eal_config_attach(void) static int rte_eal_config_reattach(void) { + struct rte_config *config = rte_eal_get_configuration(); struct rte_mem_config *mem_config; void *rte_mem_cfg_addr; + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); - if (internal_config.no_shconf) + if (internal_conf->no_shconf) return 0; /* save the address primary process has mapped shared config to */ - rte_mem_cfg_addr = (void *) (uintptr_t) rte_config.mem_config->mem_cfg_addr; + rte_mem_cfg_addr = (void *) (uintptr_t) config->mem_config->mem_cfg_addr; /* unmap original config */ - munmap(rte_config.mem_config, sizeof(struct rte_mem_config)); + munmap(config->mem_config, sizeof(struct rte_mem_config)); /* remap the config at proper address */ mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr, @@ -462,7 +425,7 @@ rte_eal_config_reattach(void) return -1; } - rte_config.mem_config = mem_config; + config->mem_config = mem_config; return 0; } @@ -473,9 +436,11 @@ eal_proc_type_detect(void) { enum rte_proc_type_t ptype = RTE_PROC_PRIMARY; const char *pathname = eal_runtime_config_path(); + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); /* if there no shared config, there can be no secondary processes */ - if (!internal_config.no_shconf) { + if (!internal_conf->no_shconf) { /* if we can open the file but not get a write-lock we are a * secondary process. NOTE: if we get a file handle back, we * keep that open and don't close it to prevent a race condition @@ -496,9 +461,13 @@ eal_proc_type_detect(void) static int rte_config_init(void) { - rte_config.process_type = internal_config.process_type; + struct rte_config *config = rte_eal_get_configuration(); + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); - switch (rte_config.process_type){ + config->process_type = internal_conf->process_type; + + switch (config->process_type) { case RTE_PROC_PRIMARY: if (rte_eal_config_create() < 0) return -1; @@ -519,7 +488,7 @@ rte_config_init(void) case RTE_PROC_AUTO: case RTE_PROC_INVALID: RTE_LOG(ERR, EAL, "Invalid process type %d\n", - rte_config.process_type); + config->process_type); return -1; } @@ -531,17 +500,19 @@ static void eal_hugedirs_unlock(void) { int i; + struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) { /* skip uninitialized */ - if (internal_config.hugepage_info[i].lock_descriptor < 0) + if (internal_conf->hugepage_info[i].lock_descriptor < 0) continue; /* unlock hugepage file */ - flock(internal_config.hugepage_info[i].lock_descriptor, LOCK_UN); - close(internal_config.hugepage_info[i].lock_descriptor); + flock(internal_conf->hugepage_info[i].lock_descriptor, LOCK_UN); + close(internal_conf->hugepage_info[i].lock_descriptor); /* reset the field */ - internal_config.hugepage_info[i].lock_descriptor = -1; + internal_conf->hugepage_info[i].lock_descriptor = -1; } } @@ -549,6 +520,8 @@ eal_hugedirs_unlock(void) static void eal_usage(const char *prgname) { + rte_usage_hook_t *hook = rte_eal_get_application_usage_hook(); + printf("\nUsage: %s ", prgname); eal_common_usage(); printf("EAL Linux options:\n" @@ -563,25 +536,12 @@ eal_usage(const char *prgname) " --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n" "\n"); /* Allow the application to print its usage message too if hook is set */ - if ( rte_application_usage_hook ) { + if (*hook) { printf("===== Application Usage =====\n\n"); - rte_application_usage_hook(prgname); + (*hook)(prgname); } } -/* Set a per-application usage message */ -rte_usage_hook_t -rte_set_application_usage_hook( rte_usage_hook_t usage_func ) -{ - rte_usage_hook_t old_func; - - /* Will be NULL on the first call to denote the last usage routine. */ - old_func = rte_application_usage_hook; - rte_application_usage_hook = usage_func; - - return old_func; -} - static int eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg) { @@ -630,6 +590,8 @@ eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg) static int eal_parse_vfio_intr(const char *mode) { + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); unsigned i; static struct { const char *name; @@ -642,7 +604,7 @@ eal_parse_vfio_intr(const char *mode) for (i = 0; i < RTE_DIM(map); i++) { if (!strcmp(mode, map[i].name)) { - internal_config.vfio_intr_mode = map[i].value; + internal_conf->vfio_intr_mode = map[i].value; return 0; } } @@ -659,6 +621,8 @@ eal_log_level_parse(int argc, char **argv) const int old_optind = optind; const int old_optopt = optopt; char * const old_optarg = optarg; + struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); argvopt = argv; optind = 1; @@ -673,7 +637,7 @@ eal_log_level_parse(int argc, char **argv) break; ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, &internal_config) : 0; + eal_parse_common_option(opt, optarg, internal_conf) : 0; /* common parser is not happy */ if (ret < 0) @@ -697,6 +661,8 @@ eal_parse_args(int argc, char **argv) const int old_optind = optind; const int old_optopt = optopt; char * const old_optarg = optarg; + struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); argvopt = argv; optind = 1; @@ -711,7 +677,7 @@ eal_parse_args(int argc, char **argv) goto out; } - ret = eal_parse_common_option(opt, optarg, &internal_config); + ret = eal_parse_common_option(opt, optarg, internal_conf); /* common parser is not happy */ if (ret < 0) { eal_usage(prgname); @@ -734,9 +700,9 @@ eal_parse_args(int argc, char **argv) RTE_LOG(ERR, EAL, "Could not store hugepage directory\n"); else { /* free old hugepage dir */ - if (internal_config.hugepage_dir != NULL) - free(internal_config.hugepage_dir); - internal_config.hugepage_dir = hdir; + if (internal_conf->hugepage_dir != NULL) + free(internal_conf->hugepage_dir); + internal_conf->hugepage_dir = hdir; } break; } @@ -747,34 +713,34 @@ eal_parse_args(int argc, char **argv) RTE_LOG(ERR, EAL, "Could not store file prefix\n"); else { /* free old prefix */ - if (internal_config.hugefile_prefix != NULL) - free(internal_config.hugefile_prefix); - internal_config.hugefile_prefix = prefix; + if (internal_conf->hugefile_prefix != NULL) + free(internal_conf->hugefile_prefix); + internal_conf->hugefile_prefix = prefix; } break; } case OPT_SOCKET_MEM_NUM: if (eal_parse_socket_arg(optarg, - internal_config.socket_mem) < 0) { + internal_conf->socket_mem) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" OPT_SOCKET_MEM "\n"); eal_usage(prgname); ret = -1; goto out; } - internal_config.force_sockets = 1; + internal_conf->force_sockets = 1; break; case OPT_SOCKET_LIMIT_NUM: if (eal_parse_socket_arg(optarg, - internal_config.socket_limit) < 0) { + internal_conf->socket_limit) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" OPT_SOCKET_LIMIT "\n"); eal_usage(prgname); ret = -1; goto out; } - internal_config.force_socket_limits = 1; + internal_conf->force_socket_limits = 1; break; case OPT_VFIO_INTR_NUM: @@ -788,7 +754,7 @@ eal_parse_args(int argc, char **argv) break; case OPT_CREATE_UIO_DEV_NUM: - internal_config.create_uio_dev = 1; + internal_conf->create_uio_dev = 1; break; case OPT_MBUF_POOL_OPS_NAME_NUM: @@ -798,17 +764,17 @@ eal_parse_args(int argc, char **argv) RTE_LOG(ERR, EAL, "Could not store mbuf pool ops name\n"); else { /* free old ops name */ - if (internal_config.user_mbuf_pool_ops_name != + if (internal_conf->user_mbuf_pool_ops_name != NULL) - free(internal_config.user_mbuf_pool_ops_name); + free(internal_conf->user_mbuf_pool_ops_name); - internal_config.user_mbuf_pool_ops_name = + internal_conf->user_mbuf_pool_ops_name = ops_name; } break; } case OPT_MATCH_ALLOCATIONS_NUM: - internal_config.match_allocations = 1; + internal_conf->match_allocations = 1; break; default: @@ -831,20 +797,20 @@ eal_parse_args(int argc, char **argv) } /* create runtime data directory */ - if (internal_config.no_shconf == 0 && + if (internal_conf->no_shconf == 0 && eal_create_runtime_dir() < 0) { RTE_LOG(ERR, EAL, "Cannot create runtime directory\n"); ret = -1; goto out; } - if (eal_adjust_config(&internal_config) != 0) { + if (eal_adjust_config(internal_conf) != 0) { ret = -1; goto out; } /* sanity checks */ - if (eal_check_common_options(&internal_config) != 0) { + if (eal_check_common_options(internal_conf) != 0) { eal_usage(prgname); ret = -1; goto out; @@ -878,8 +844,9 @@ static void eal_check_mem_on_local_socket(void) { int socket_id; + const struct rte_config *config = rte_eal_get_configuration(); - socket_id = rte_lcore_to_socket_id(rte_config.master_lcore); + socket_id = rte_lcore_to_socket_id(config->master_lcore); if (rte_memseg_list_walk(check_socket, &socket_id) == 0) RTE_LOG(WARNING, EAL, "WARNING: Master core has no memory on local socket!\n"); @@ -961,6 +928,9 @@ rte_eal_init(int argc, char **argv) char cpuset[RTE_CPU_AFFINITY_STR_LEN]; char thread_name[RTE_MAX_THREAD_NAME_LEN]; bool phys_addrs; + const struct rte_config *config = rte_eal_get_configuration(); + struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); /* checks if the machine is adequate */ if (!rte_cpu_is_supported()) { @@ -979,7 +949,7 @@ rte_eal_init(int argc, char **argv) strlcpy(logid, p ? p + 1 : argv[0], sizeof(logid)); thread_id = pthread_self(); - eal_reset_internal_config(&internal_config); + eal_reset_internal_config(internal_conf); /* set log level as early as possible */ eal_log_level_parse(argc, argv); @@ -1063,7 +1033,7 @@ rte_eal_init(int argc, char **argv) phys_addrs = rte_eal_using_phys_addrs() != 0; /* if no EAL option "--iova-mode=", use bus IOVA scheme */ - if (internal_config.iova_mode == RTE_IOVA_DC) { + if (internal_conf->iova_mode == RTE_IOVA_DC) { /* autodetect the IOVA mapping mode */ enum rte_iova_mode iova_mode = rte_bus_get_iommu_class(); @@ -1110,7 +1080,7 @@ rte_eal_init(int argc, char **argv) rte_eal_get_configuration()->iova_mode = iova_mode; } else { rte_eal_get_configuration()->iova_mode = - internal_config.iova_mode; + internal_conf->iova_mode; } if (rte_eal_iova_mode() == RTE_IOVA_PA && !phys_addrs) { @@ -1122,9 +1092,9 @@ rte_eal_init(int argc, char **argv) RTE_LOG(INFO, EAL, "Selected IOVA mode '%s'\n", rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA"); - if (internal_config.no_hugetlbfs == 0) { + if (internal_conf->no_hugetlbfs == 0) { /* rte_config isn't initialized yet */ - ret = internal_config.process_type == RTE_PROC_PRIMARY ? + ret = internal_conf->process_type == RTE_PROC_PRIMARY ? eal_hugepage_info_init() : eal_hugepage_info_read(); if (ret < 0) { @@ -1135,12 +1105,12 @@ rte_eal_init(int argc, char **argv) } } - if (internal_config.memory == 0 && internal_config.force_sockets == 0) { - if (internal_config.no_hugetlbfs) - internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE; + if (internal_conf->memory == 0 && internal_conf->force_sockets == 0) { + if (internal_conf->no_hugetlbfs) + internal_conf->memory = MEMSIZE_IF_NO_HUGE_PAGE; } - if (internal_config.vmware_tsc_map == 1) { + if (internal_conf->vmware_tsc_map == 1) { #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT rte_cycles_vmware_tsc_map = 1; RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, " @@ -1151,7 +1121,7 @@ rte_eal_init(int argc, char **argv) #endif } - if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0) { + if (rte_eal_log_init(logid, internal_conf->syslog_facility) < 0) { rte_eal_init_alert("Cannot init logging."); rte_errno = ENOMEM; rte_atomic32_clear(&run_once); @@ -1205,12 +1175,12 @@ rte_eal_init(int argc, char **argv) eal_check_mem_on_local_socket(); - eal_thread_init_master(rte_config.master_lcore); + eal_thread_init_master(config->master_lcore); ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset)); RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n", - rte_config.master_lcore, (uintptr_t)thread_id, cpuset, + config->master_lcore, (uintptr_t)thread_id, cpuset, ret == 0 ? "" : "..."); RTE_LCORE_FOREACH_SLAVE(i) { @@ -1289,14 +1259,14 @@ rte_eal_init(int argc, char **argv) * In no_shconf mode, no runtime directory is created in the first * place, so no cleanup needed. */ - if (!internal_config.no_shconf && eal_clean_runtime_dir() < 0) { + if (!internal_conf->no_shconf && eal_clean_runtime_dir() < 0) { rte_eal_init_alert("Cannot clear runtime directory\n"); return -1; } - if (!internal_config.no_telemetry) { + if (!internal_conf->no_telemetry) { const char *error_str = NULL; if (rte_telemetry_init(rte_eal_get_runtime_dir(), - &internal_config.ctrl_cpuset, &error_str) + &internal_conf->ctrl_cpuset, &error_str) != 0) { rte_eal_init_alert(error_str); return -1; @@ -1333,41 +1303,34 @@ rte_eal_cleanup(void) /* if we're in a primary process, we need to mark hugepages as freeable * so that finalization can release them back to the system. */ + struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); + if (rte_eal_process_type() == RTE_PROC_PRIMARY) rte_memseg_walk(mark_freeable, NULL); rte_service_finalize(); rte_mp_channel_cleanup(); rte_trace_save(); eal_trace_fini(); - eal_cleanup_config(&internal_config); + eal_cleanup_config(internal_conf); return 0; } -enum rte_proc_type_t -rte_eal_process_type(void) -{ - return rte_config.process_type; -} - -int rte_eal_has_hugepages(void) -{ - return ! internal_config.no_hugetlbfs; -} - -int rte_eal_has_pci(void) -{ - return !internal_config.no_pci; -} - int rte_eal_create_uio_dev(void) { - return internal_config.create_uio_dev; + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); + + return internal_conf->create_uio_dev; } enum rte_intr_mode rte_eal_vfio_intr_mode(void) { - return internal_config.vfio_intr_mode; + const struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); + + return internal_conf->vfio_intr_mode; } int diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c index 427a5557fa..eeebc211b2 100644 --- a/lib/librte_eal/windows/eal.c +++ b/lib/librte_eal/windows/eal.c @@ -24,50 +24,21 @@ #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) - /* Allow the application to print its usage message too if set */ -static rte_usage_hook_t rte_application_usage_hook; - /* define fd variable here, because file needs to be kept open for the * duration of the program, as we hold a write lock on it in the primary proc */ static int mem_cfg_fd = -1; -/* early configuration structure, when memory config is not mmapped */ -static struct rte_mem_config early_mem_config; - -/* Address of global and public configuration */ -static struct rte_config rte_config = { - .mem_config = &early_mem_config, -}; - /* internal configuration (per-core) */ struct lcore_config lcore_config[RTE_MAX_LCORE]; -/* internal configuration */ -struct internal_config internal_config; - -/* platform-specific runtime dir */ -static char runtime_dir[PATH_MAX]; - -const char * -rte_eal_get_runtime_dir(void) -{ - return runtime_dir; -} - -/* Return a pointer to the configuration structure */ -struct rte_config * -rte_eal_get_configuration(void) -{ - return &rte_config; -} - /* Detect if we are a primary or a secondary process */ enum rte_proc_type_t eal_proc_type_detect(void) { enum rte_proc_type_t ptype = RTE_PROC_PRIMARY; const char *pathname = eal_runtime_config_path(); + const struct rte_config *config = rte_eal_get_configuration(); /* if we can open the file but not get a write-lock we are a secondary * process. NOTE: if we get a file handle back, we keep that open @@ -77,14 +48,14 @@ eal_proc_type_detect(void) _O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE); if (err == 0) { OVERLAPPED soverlapped = { 0 }; - soverlapped.Offset = sizeof(*rte_config.mem_config); + soverlapped.Offset = sizeof(*config->mem_config); soverlapped.OffsetHigh = 0; HANDLE hwinfilehandle = (HANDLE)_get_osfhandle(mem_cfg_fd); if (!LockFileEx(hwinfilehandle, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, - sizeof(*rte_config.mem_config), 0, &soverlapped)) + sizeof(*config->mem_config), 0, &soverlapped)) ptype = RTE_PROC_SECONDARY; } @@ -94,36 +65,20 @@ eal_proc_type_detect(void) return ptype; } -enum rte_proc_type_t -rte_eal_process_type(void) -{ - return rte_config.process_type; -} - -int -rte_eal_has_hugepages(void) -{ - return !internal_config.no_hugetlbfs; -} - -enum rte_iova_mode -rte_eal_iova_mode(void) -{ - return rte_config.iova_mode; -} - /* display usage */ static void eal_usage(const char *prgname) { + rte_usage_hook_t *hook = rte_eal_get_application_usage_hook(); + printf("\nUsage: %s ", prgname); eal_common_usage(); /* Allow the application to print its usage message too * if hook is set */ - if (rte_application_usage_hook) { + if (*hook) { printf("===== Application Usage =====\n\n"); - rte_application_usage_hook(prgname); + (*hook)(prgname); } } @@ -134,10 +89,12 @@ eal_log_level_parse(int argc, char **argv) int opt; char **argvopt; int option_index; + struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); argvopt = argv; - eal_reset_internal_config(&internal_config); + eal_reset_internal_config(internal_conf); while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { @@ -150,7 +107,7 @@ eal_log_level_parse(int argc, char **argv) ret = (opt == OPT_LOG_LEVEL_NUM) ? eal_parse_common_option(opt, optarg, - &internal_config) : 0; + internal_conf) : 0; /* common parser is not happy */ if (ret < 0) @@ -168,6 +125,8 @@ eal_parse_args(int argc, char **argv) char **argvopt; int option_index; char *prgname = argv[0]; + struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); argvopt = argv; @@ -182,7 +141,7 @@ eal_parse_args(int argc, char **argv) return -1; } - ret = eal_parse_common_option(opt, optarg, &internal_config); + ret = eal_parse_common_option(opt, optarg, internal_conf); /* common parser is not happy */ if (ret < 0) { eal_usage(prgname); @@ -214,11 +173,11 @@ eal_parse_args(int argc, char **argv) } } - if (eal_adjust_config(&internal_config) != 0) + if (eal_adjust_config(internal_conf) != 0) return -1; /* sanity checks */ - if (eal_check_common_options(&internal_config) != 0) { + if (eal_check_common_options(internal_conf) != 0) { eal_usage(prgname); return -1; } @@ -279,6 +238,9 @@ int rte_eal_init(int argc, char **argv) { int i, fctret; + const struct rte_config *config = rte_eal_get_configuration(); + struct internal_config *internal_conf = + rte_eal_get_internal_configuration(); rte_eal_log_init(NULL, 0); @@ -301,21 +263,21 @@ rte_eal_init(int argc, char **argv) exit(1); /* Prevent creation of shared memory files. */ - if (internal_config.in_memory == 0) { + if (internal_conf->in_memory == 0) { RTE_LOG(WARNING, EAL, "Multi-process support is requested, " "but not available.\n"); - internal_config.in_memory = 1; + internal_conf->in_memory = 1; } - if (!internal_config.no_hugetlbfs && (eal_hugepage_info_init() < 0)) { + if (!internal_conf->no_hugetlbfs && (eal_hugepage_info_init() < 0)) { rte_eal_init_alert("Cannot get hugepage information"); rte_errno = EACCES; return -1; } - if (internal_config.memory == 0 && !internal_config.force_sockets) { - if (internal_config.no_hugetlbfs) - internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE; + if (internal_conf->memory == 0 && !internal_conf->force_sockets) { + if (internal_conf->no_hugetlbfs) + internal_conf->memory = MEMSIZE_IF_NO_HUGE_PAGE; } if (eal_mem_win32api_init() < 0) { @@ -354,7 +316,7 @@ rte_eal_init(int argc, char **argv) return -1; } - eal_thread_init_master(rte_config.master_lcore); + eal_thread_init_master(config->master_lcore); RTE_LCORE_FOREACH_SLAVE(i) { -- 2.16.1.windows.4