From patchwork Thu Jun 18 21:15:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tal Shnaiderman X-Patchwork-Id: 71765 X-Patchwork-Delegate: thomas@monjalon.net 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 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) { From patchwork Thu Jun 18 21:15:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tal Shnaiderman X-Patchwork-Id: 71763 X-Patchwork-Delegate: thomas@monjalon.net 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 85847A04F1; Thu, 18 Jun 2020 23:16:46 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 42DCB5B3A; Thu, 18 Jun 2020 23:16:44 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 79CD95B3C 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 05ILGaF5006303; 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:39 +0300 Message-Id: <20200618211546.24496-3-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 2/9] pci: use OS generic memory mapping functions 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 Changing all of PCIs Unix memory mapping to the new memory allocation API wrapper. Change all of PCI mapping function usage in bus/pci to support the new API. Signed-off-by: Tal Shnaiderman --- drivers/bus/pci/bsd/pci.c | 2 +- drivers/bus/pci/linux/pci_uio.c | 2 +- drivers/bus/pci/linux/pci_vfio.c | 9 +++++---- drivers/bus/pci/pci_common_uio.c | 2 +- lib/librte_pci/rte_pci.c | 15 ++++++++------- lib/librte_pci/rte_pci.h | 2 +- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c index 6ec27b4b5b..8bc473eb9a 100644 --- a/drivers/bus/pci/bsd/pci.c +++ b/drivers/bus/pci/bsd/pci.c @@ -192,7 +192,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, mapaddr = pci_map_resource(NULL, fd, (off_t)offset, (size_t)dev->mem_resource[res_idx].len, 0); close(fd); - if (mapaddr == MAP_FAILED) + if (mapaddr == NULL) goto error; maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr; diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c index 097dc19225..b622001539 100644 --- a/drivers/bus/pci/linux/pci_uio.c +++ b/drivers/bus/pci/linux/pci_uio.c @@ -345,7 +345,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, mapaddr = pci_map_resource(pci_map_addr, fd, 0, (size_t)dev->mem_resource[res_idx].len, 0); close(fd); - if (mapaddr == MAP_FAILED) + if (mapaddr == NULL) goto error; pci_map_addr = RTE_PTR_ADD(mapaddr, diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index 64cd84a689..bde9ad56fd 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -524,11 +525,11 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, map_addr = pci_map_resource(bar_addr, vfio_dev_fd, memreg[0].offset, memreg[0].size, - MAP_FIXED); + RTE_MAP_FORCE_ADDRESS); } /* if there's a second part, try to map it */ - if (map_addr != MAP_FAILED + if (map_addr != NULL && memreg[1].offset && memreg[1].size) { void *second_addr = RTE_PTR_ADD(bar_addr, (uintptr_t)(memreg[1].offset - @@ -537,10 +538,10 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, vfio_dev_fd, memreg[1].offset, memreg[1].size, - MAP_FIXED); + RTE_MAP_FORCE_ADDRESS); } - if (map_addr == MAP_FAILED || !map_addr) { + if (map_addr == NULL) { munmap(bar_addr, bar->size); bar_addr = MAP_FAILED; RTE_LOG(ERR, EAL, "Failed to map pci BAR%d\n", diff --git a/drivers/bus/pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c index f4dca9da91..793dfd0a7c 100644 --- a/drivers/bus/pci/pci_common_uio.c +++ b/drivers/bus/pci/pci_common_uio.c @@ -58,7 +58,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev) "Cannot mmap device resource file %s to address: %p\n", uio_res->maps[i].path, uio_res->maps[i].addr); - if (mapaddr != MAP_FAILED) { + if (mapaddr != NULL) { /* unmap addrs correctly mapped */ for (j = 0; j < i; j++) pci_unmap_resource( diff --git a/lib/librte_pci/rte_pci.c b/lib/librte_pci/rte_pci.c index 9c80c4b71d..734d7a5f77 100644 --- a/lib/librte_pci/rte_pci.c +++ b/lib/librte_pci/rte_pci.c @@ -9,12 +9,12 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include @@ -154,14 +154,15 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size, void *mapaddr; /* Map the PCI memory resource of device */ - mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE, - MAP_SHARED | additional_flags, fd, offset); - if (mapaddr == MAP_FAILED) { + mapaddr = rte_mem_map(requested_addr, size, + RTE_PROT_READ | RTE_PROT_WRITE, + RTE_MAP_SHARED | additional_flags, fd, offset); + if (mapaddr == NULL) { RTE_LOG(ERR, EAL, - "%s(): cannot mmap(%d, %p, 0x%zx, 0x%llx): %s (%p)\n", + "%s(): cannot map resource(%d, %p, 0x%zx, 0x%llx): %s (%p)\n", __func__, fd, requested_addr, size, (unsigned long long)offset, - strerror(errno), mapaddr); + strerror(rte_errno), mapaddr); } else RTE_LOG(DEBUG, EAL, " PCI memory mapped at %p\n", mapaddr); @@ -176,7 +177,7 @@ pci_unmap_resource(void *requested_addr, size_t size) return; /* Unmap the PCI memory resource of device */ - if (munmap(requested_addr, size)) { + if (rte_mem_unmap(requested_addr, size)) { RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, %#zx): %s\n", __func__, requested_addr, size, strerror(errno)); diff --git a/lib/librte_pci/rte_pci.h b/lib/librte_pci/rte_pci.h index 4087771c1e..b721bbf580 100644 --- a/lib/librte_pci/rte_pci.h +++ b/lib/librte_pci/rte_pci.h @@ -159,7 +159,7 @@ int rte_pci_addr_parse(const char *str, struct rte_pci_addr *addr); * The additional flags for the mapping range. * @return * - On success, the function returns a pointer to the mapped area. - * - On error, the value MAP_FAILED is returned. + * - On error, NULL is returned. */ void *pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size, int additional_flags); From patchwork Thu Jun 18 21:15:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tal Shnaiderman X-Patchwork-Id: 71764 X-Patchwork-Delegate: thomas@monjalon.net 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 3A85FA04F1; Thu, 18 Jun 2020 23:16:53 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 88C211B13C; Thu, 18 Jun 2020 23:16:45 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 85D325F2F 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:37 +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 05ILGaF6006303; 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:40 +0300 Message-Id: <20200618211546.24496-4-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 3/9] pci: build on Windows 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 Added in rte_pci header file to include off_t type since it is missing for Windows. Signed-off-by: Tal Shnaiderman --- lib/librte_eal/rte_eal_exports.def | 1 + lib/librte_pci/rte_pci.h | 1 + lib/meson.build | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def index e2eb24f01b..8ed5fad987 100644 --- a/lib/librte_eal/rte_eal_exports.def +++ b/lib/librte_eal/rte_eal_exports.def @@ -1,5 +1,6 @@ EXPORTS __rte_panic + per_lcore__rte_errno rte_calloc rte_calloc_socket rte_eal_get_configuration diff --git a/lib/librte_pci/rte_pci.h b/lib/librte_pci/rte_pci.h index b721bbf580..9337079178 100644 --- a/lib/librte_pci/rte_pci.h +++ b/lib/librte_pci/rte_pci.h @@ -20,6 +20,7 @@ extern "C" { #include #include #include +#include /** Formatting string for PCI device identifier: Ex: 0000:00:01.0 */ #define PCI_PRI_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8 diff --git a/lib/meson.build b/lib/meson.build index d190d84eff..a8fd317a18 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -36,7 +36,10 @@ libraries = [ 'flow_classify', 'bpf', 'graph', 'node'] if is_windows - libraries = ['kvargs','eal'] # only supported libraries for windows + libraries = [ + 'kvargs','eal', + 'pci', + ] # only supported libraries for windows endif default_cflags = machine_args From patchwork Thu Jun 18 21:15:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tal Shnaiderman X-Patchwork-Id: 71767 X-Patchwork-Delegate: thomas@monjalon.net 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 67316A04F1; Thu, 18 Jun 2020 23:17:20 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AD39C1BE9B; Thu, 18 Jun 2020 23:16:49 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 8AA3F5F69 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:37 +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 05ILGaF7006303; Fri, 19 Jun 2020 00:16:37 +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:41 +0300 Message-Id: <20200618211546.24496-5-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 4/9] pci: fix format warning on Windows 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 the struct rte_pci_addr defines domain as uint32_t variable however the PCI_PRI_FMT macro used for logging the struct sets the format of domain to uint16_t. The mismatch causes the following warning messages in Windows clang build: format specifies type 'unsigned short' but the argument has type 'uint32_t' (aka 'unsigned int') [-Wformat] Signed-off-by: Tal Shnaiderman --- lib/librte_pci/rte_pci.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/librte_pci/rte_pci.h b/lib/librte_pci/rte_pci.h index 9337079178..104b2bb858 100644 --- a/lib/librte_pci/rte_pci.h +++ b/lib/librte_pci/rte_pci.h @@ -23,7 +23,7 @@ extern "C" { #include /** Formatting string for PCI device identifier: Ex: 0000:00:01.0 */ -#define PCI_PRI_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8 +#define PCI_PRI_FMT "%.4" PRIx32 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8 #define PCI_PRI_STR_SIZE sizeof("XXXXXXXX:XX:XX.X") /** Short formatting string, without domain, for PCI device: Ex: 00:01.0 */ From patchwork Thu Jun 18 21:15:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tal Shnaiderman X-Patchwork-Id: 71766 X-Patchwork-Delegate: thomas@monjalon.net 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 B1ABFA04F1; Thu, 18 Jun 2020 23:17:12 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 429711BE81; Thu, 18 Jun 2020 23:16:48 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 90242AAD5 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:37 +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 05ILGaF8006303; Fri, 19 Jun 2020 00:16:37 +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:42 +0300 Message-Id: <20200618211546.24496-6-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 5/9] drivers: ignore pmdinfogen generation for Windows 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 pmdinfogen generation is currently unsupported for Windows. The relevant part in meson.build is skipped. Signed-off-by: Tal Shnaiderman --- drivers/meson.build | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/meson.build b/drivers/meson.build index cfb6a833c9..f4b6cbf3a6 100644 --- a/drivers/meson.build +++ b/drivers/meson.build @@ -111,19 +111,20 @@ foreach class:dpdk_driver_classes # lib and then running pmdinfogen on the contents of # that lib. The final lib reuses the object files and # adds in the new source file. - out_filename = lib_name + '.pmd.c' - tmp_lib = static_library('tmp_' + lib_name, - sources, - include_directories: includes, - dependencies: static_deps, - c_args: cflags) - objs += tmp_lib.extract_all_objects() - sources = custom_target(out_filename, - command: [pmdinfo, tmp_lib.full_path(), - '@OUTPUT@', pmdinfogen], - output: out_filename, - depends: [pmdinfogen, tmp_lib]) - + if host_machine.system() != 'windows' + out_filename = lib_name + '.pmd.c' + tmp_lib = static_library('tmp_' + lib_name, + sources, + include_directories: includes, + dependencies: static_deps, + c_args: cflags) + objs += tmp_lib.extract_all_objects() + sources = custom_target(out_filename, + command: [pmdinfo, tmp_lib.full_path(), + '@OUTPUT@', pmdinfogen], + output: out_filename, + depends: [pmdinfogen, tmp_lib]) + endif version_map = '@0@/@1@/@2@_version.map'.format( meson.current_source_dir(), drv_path, lib_name) From patchwork Thu Jun 18 21:15:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tal Shnaiderman X-Patchwork-Id: 71768 X-Patchwork-Delegate: thomas@monjalon.net 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 C64A4A04F1; Thu, 18 Jun 2020 23:17:26 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D2E601BEAC; Thu, 18 Jun 2020 23:16:50 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 94C5D14581 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:37 +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 05ILGaF9006303; Fri, 19 Jun 2020 00:16:37 +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:43 +0300 Message-Id: <20200618211546.24496-7-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 6/9] drivers: fix incorrect meson import folder for Windows 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 import library (/IMPLIB) in meson.build should use the 'drivers' and not 'libs' folder. The error is: fatal error LNK1149: output filename matches input filename. The fix uses the correct folder. Fixes: 5ed3766981 ("drivers: process shared link dependencies as for libs") Signed-off-by: Tal Shnaiderman --- drivers/meson.build | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/meson.build b/drivers/meson.build index f4b6cbf3a6..dea0ba2cca 100644 --- a/drivers/meson.build +++ b/drivers/meson.build @@ -153,7 +153,7 @@ foreach class:dpdk_driver_classes version_map = '@0@/@1@/@2@_version.map'.format( meson.current_source_dir(), drv_path, lib_name) - implib = dir_name + '.dll.a' + implib = 'lib' + lib_name + '.dll.a' def_file = custom_target(lib_name + '_def', command: [map_to_def_cmd, '@INPUT@', '@OUTPUT@'], @@ -161,8 +161,12 @@ foreach class:dpdk_driver_classes output: '@0@_exports.def'.format(lib_name)) lk_deps = [version_map, def_file] if is_windows - lk_args = ['-Wl,/def:' + def_file.full_path(), - '-Wl,/implib:lib\\' + implib] + if is_ms_linker + lk_args = ['-Wl,/def:' + def_file.full_path(), + '-Wl,/implib:drivers\\' + implib] + else + lk_args = [] + endif else lk_args = ['-Wl,--version-script=' + version_map] # on unix systems check the output of the From patchwork Thu Jun 18 21:15:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tal Shnaiderman X-Patchwork-Id: 71769 X-Patchwork-Delegate: thomas@monjalon.net 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 6BCB8A04F1; Thu, 18 Jun 2020 23:17:33 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 399E11BED9; Thu, 18 Jun 2020 23:16:52 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id A5FFF14583 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:37 +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 05ILGaFA006303; Fri, 19 Jun 2020 00:16:37 +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:44 +0300 Message-Id: <20200618211546.24496-8-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 7/9] bus/pci: introduce Windows support with stubs 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 Addition of stub eal and bus/pci functions to compile bus/pci for Windows. Signed-off-by: Tal Shnaiderman --- drivers/baseband/meson.build | 4 + drivers/bus/ifpga/meson.build | 6 ++ drivers/bus/pci/meson.build | 14 ++- drivers/bus/pci/pci_common.c | 2 - drivers/bus/pci/windows/pci.c | 169 +++++++++++++++++++++++++++++++++++++ drivers/bus/vdev/meson.build | 6 ++ drivers/bus/vmbus/meson.build | 7 ++ drivers/common/meson.build | 4 + drivers/compress/meson.build | 4 + drivers/crypto/meson.build | 4 + drivers/event/meson.build | 4 + drivers/mempool/meson.build | 4 + drivers/meson.build | 4 - drivers/net/meson.build | 4 + drivers/raw/meson.build | 4 + drivers/vdpa/meson.build | 4 + lib/librte_eal/common/meson.build | 1 + lib/librte_eal/rte_eal_exports.def | 8 ++ lib/librte_eal/windows/eal.c | 28 +++++- lib/librte_eal/windows/eal_mp.c | 15 ++++ 20 files changed, 285 insertions(+), 11 deletions(-) create mode 100644 drivers/bus/pci/windows/pci.c diff --git a/drivers/baseband/meson.build b/drivers/baseband/meson.build index 4d909f9a62..b299c3a063 100644 --- a/drivers/baseband/meson.build +++ b/drivers/baseband/meson.build @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 Luca Boccassi +if host_machine.system() == 'windows' + subdir_done() +endif + drivers = ['null', 'turbo_sw', 'fpga_lte_fec', 'fpga_5gnr_fec'] config_flag_fmt = 'RTE_LIBRTE_PMD_BBDEV_@0@' diff --git a/drivers/bus/ifpga/meson.build b/drivers/bus/ifpga/meson.build index 4ea31f1741..15339e065c 100644 --- a/drivers/bus/ifpga/meson.build +++ b/drivers/bus/ifpga/meson.build @@ -1,6 +1,12 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2010-2018 Intel Corporation +if host_machine.system() == 'windows' + build = false + reason = 'not supported on Windows' + subdir_done() +endif + deps += ['pci', 'kvargs', 'rawdev'] install_headers('rte_bus_ifpga.h') sources = files('ifpga_common.c', 'ifpga_bus.c') diff --git a/drivers/bus/pci/meson.build b/drivers/bus/pci/meson.build index b520bdfc14..31c492021e 100644 --- a/drivers/bus/pci/meson.build +++ b/drivers/bus/pci/meson.build @@ -4,16 +4,22 @@ deps += ['pci'] install_headers('rte_bus_pci.h') sources = files('pci_common.c', - 'pci_common_uio.c', 'pci_params.c') if is_linux - sources += files('linux/pci.c', + sources += files('pci_common_uio.c', + 'linux/pci.c', 'linux/pci_uio.c', 'linux/pci_vfio.c') includes += include_directories('linux') -else - sources += files('bsd/pci.c') +endif +if host_machine.system() == 'bsd' + sources += files('pci_common_uio.c', + 'bsd/pci.c') includes += include_directories('bsd') endif +if host_machine.system() == 'windows' + sources += files('windows/pci.c') + includes += include_directories('windows') +endif deps += ['kvargs'] diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 245d94f59c..eb0231f403 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -10,8 +10,6 @@ #include #include #include -#include - #include #include #include diff --git a/drivers/bus/pci/windows/pci.c b/drivers/bus/pci/windows/pci.c new file mode 100644 index 0000000000..b1d34ae11c --- /dev/null +++ b/drivers/bus/pci/windows/pci.c @@ -0,0 +1,169 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2020 Mellanox Technologies, Ltd + */ +#include +#include + +#include +#include + +#include "private.h" + +/* The functions below are not implemented on Windows, + * but need to be defined for compilation purposes + */ + +/* Map pci device */ +int +rte_pci_map_device(struct rte_pci_device *dev __rte_unused) +{ + /* This function is not implemented on Windows. + * We really should short-circuit the call to these functions by + * clearing the RTE_PCI_DRV_NEED_MAPPING flag + * in the rte_pci_driver flags. + */ + return 0; +} + +/* Unmap pci device */ +void +rte_pci_unmap_device(struct rte_pci_device *dev __rte_unused) +{ + /* This function is not implemented on Windows. + * We really should short-circuit the call to these functions by + * clearing the RTE_PCI_DRV_NEED_MAPPING flag + * in the rte_pci_driver flags. + */ +} + +int +pci_update_device(const struct rte_pci_addr *addr __rte_unused) +{ + /* This function is not implemented on Windows. + * We really should short-circuit the call to these functions by + * clearing the RTE_PCI_DRV_NEED_MAPPING flag + * in the rte_pci_driver flags. + */ + return 0; +} + +/* Read PCI config space. */ +int +rte_pci_read_config(const struct rte_pci_device *dev __rte_unused, + void *buf __rte_unused, size_t len __rte_unused, + off_t offset __rte_unused) +{ + /* This function is not implemented on Windows. + * We really should short-circuit the call to these functions by + * clearing the RTE_PCI_DRV_NEED_MAPPING flag + * in the rte_pci_driver flags. + */ + return 0; +} + +/* Write PCI config space. */ +int +rte_pci_write_config(const struct rte_pci_device *dev __rte_unused, + const void *buf __rte_unused, size_t len __rte_unused, + off_t offset __rte_unused) +{ + /* This function is not implemented on Windows. + * We really should short-circuit the call to these functions by + * clearing the RTE_PCI_DRV_NEED_MAPPING flag + * in the rte_pci_driver flags. + */ + return 0; +} + +enum rte_iova_mode +pci_device_iova_mode(const struct rte_pci_driver *pdrv __rte_unused, + const struct rte_pci_device *pdev __rte_unused) +{ + /* This function is not implemented on Windows. + * We really should short-circuit the call to these functions by + * clearing the RTE_PCI_DRV_NEED_MAPPING flag + * in the rte_pci_driver flags. + */ + return RTE_IOVA_DC; +} + +int +rte_pci_ioport_map(struct rte_pci_device *dev __rte_unused, + int bar __rte_unused, struct rte_pci_ioport *p __rte_unused) +{ + /* This function is not implemented on Windows. + * We really should short-circuit the call to these functions by + * clearing the RTE_PCI_DRV_NEED_MAPPING flag + * in the rte_pci_driver flags. + */ + return -1; +} + + +void +rte_pci_ioport_read(struct rte_pci_ioport *p __rte_unused, + void *data __rte_unused, size_t len __rte_unused, + off_t offset __rte_unused) +{ + /* This function is not implemented on Windows. + * We really should short-circuit the call to these functions by + * clearing the RTE_PCI_DRV_NEED_MAPPING flag + * in the rte_pci_driver flags. + */ +} + +int +rte_pci_ioport_unmap(struct rte_pci_ioport *p __rte_unused) +{ + /* This function is not implemented on Windows. + * We really should short-circuit the call to these functions by + * clearing the RTE_PCI_DRV_NEED_MAPPING flag + * in the rte_pci_driver flags. + */ + return -1; +} + +bool +pci_device_iommu_support_va(const struct rte_pci_device *dev __rte_unused) +{ + /* This function is not implemented on Windows. + * We really should short-circuit the call to these functions by + * clearing the RTE_PCI_DRV_NEED_MAPPING flag + * in the rte_pci_driver flags. + */ + return false; +} + +void +rte_pci_ioport_write(struct rte_pci_ioport *p __rte_unused, + const void *data __rte_unused, size_t len __rte_unused, + off_t offset __rte_unused) +{ + /* This function is not implemented on Windows. + * We really should short-circuit the call to these functions by + * clearing the RTE_PCI_DRV_NEED_MAPPING flag + * in the rte_pci_driver flags. + */ +} + + +/* remap the PCI resource of a PCI device in anonymous virtual memory */ +int +pci_uio_remap_resource(struct rte_pci_device *dev __rte_unused) +{ + /* This function is not implemented on Windows. + * We really should short-circuit the call to these functions by + * clearing the RTE_PCI_DRV_NEED_MAPPING flag + * in the rte_pci_driver flags. + */ + return -1; +} +/* + * Scan the contents of the PCI bus + * and add all network class devices into the devices list. + */ +int +rte_pci_scan(void) +{ + return 0; +} diff --git a/drivers/bus/vdev/meson.build b/drivers/bus/vdev/meson.build index 967d54e4f8..abaf36f1dd 100644 --- a/drivers/bus/vdev/meson.build +++ b/drivers/bus/vdev/meson.build @@ -1,6 +1,12 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation +if host_machine.system() == 'windows' + build = false + reason = 'not supported on Windows' + subdir_done() +endif + sources = files('vdev.c', 'vdev_params.c') install_headers('rte_bus_vdev.h') diff --git a/drivers/bus/vmbus/meson.build b/drivers/bus/vmbus/meson.build index a68a1de9d5..7c9865fe85 100644 --- a/drivers/bus/vmbus/meson.build +++ b/drivers/bus/vmbus/meson.build @@ -1,5 +1,12 @@ # SPDX-License-Identifier: BSD-3-Clause +if host_machine.system() == 'windows' + build = false + reason = 'not supported on Windows' + subdir_done() +endif + + install_headers('rte_bus_vmbus.h','rte_vmbus_reg.h') sources = files('vmbus_common.c', diff --git a/drivers/common/meson.build b/drivers/common/meson.build index ffd06e2c3c..1cdcd95d6e 100644 --- a/drivers/common/meson.build +++ b/drivers/common/meson.build @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 Cavium, Inc +if host_machine.system() == 'windows' + subdir_done() +endif + std_deps = ['eal'] drivers = ['cpt', 'dpaax', 'iavf', 'mlx5', 'mvep', 'octeontx', 'octeontx2', 'qat'] config_flag_fmt = 'RTE_LIBRTE_@0@_COMMON' diff --git a/drivers/compress/meson.build b/drivers/compress/meson.build index 817ef3be42..e6c7d564e3 100644 --- a/drivers/compress/meson.build +++ b/drivers/compress/meson.build @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 Intel Corporation +if host_machine.system() == 'windows' + subdir_done() +endif + drivers = ['isal', 'octeontx', 'qat', 'zlib'] std_deps = ['compressdev'] # compressdev pulls in all other needed deps diff --git a/drivers/crypto/meson.build b/drivers/crypto/meson.build index 7fa1fbe269..2c591eaf02 100644 --- a/drivers/crypto/meson.build +++ b/drivers/crypto/meson.build @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation +if host_machine.system() == 'windows' + subdir_done() +endif + drivers = ['aesni_gcm', 'aesni_mb', 'armv8', diff --git a/drivers/event/meson.build b/drivers/event/meson.build index 50d30c53fc..264d4887f9 100644 --- a/drivers/event/meson.build +++ b/drivers/event/meson.build @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation +if host_machine.system() == 'windows' + subdir_done() +endif + drivers = ['dpaa', 'dpaa2', 'octeontx2', 'opdl', 'skeleton', 'sw', 'dsw'] if not (toolchain == 'gcc' and cc.version().version_compare('<4.8.6') and dpdk_conf.has('RTE_ARCH_ARM64')) diff --git a/drivers/mempool/meson.build b/drivers/mempool/meson.build index 7520e489f4..0c6e700823 100644 --- a/drivers/mempool/meson.build +++ b/drivers/mempool/meson.build @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation +if host_machine.system() == 'windows' + subdir_done() +endif + drivers = ['bucket', 'dpaa', 'dpaa2', 'octeontx', 'octeontx2', 'ring', 'stack'] std_deps = ['mempool'] config_flag_fmt = 'RTE_LIBRTE_@0@_MEMPOOL' diff --git a/drivers/meson.build b/drivers/meson.build index dea0ba2cca..646a7d5eb5 100644 --- a/drivers/meson.build +++ b/drivers/meson.build @@ -1,10 +1,6 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017-2019 Intel Corporation -if is_windows - subdir_done() -endif - # Defines the order in which the drivers are buit. dpdk_driver_classes = ['common', 'bus', diff --git a/drivers/net/meson.build b/drivers/net/meson.build index 266448ff26..7a6ea648f5 100644 --- a/drivers/net/meson.build +++ b/drivers/net/meson.build @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation +if host_machine.system() == 'windows' + subdir_done() +endif + drivers = ['af_packet', 'af_xdp', 'ark', diff --git a/drivers/raw/meson.build b/drivers/raw/meson.build index bb57977606..334b14ac37 100644 --- a/drivers/raw/meson.build +++ b/drivers/raw/meson.build @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright 2018 NXP +if host_machine.system() == 'windows' + subdir_done() +endif + drivers = ['dpaa2_cmdif', 'dpaa2_qdma', 'ifpga', 'ioat', 'ntb', 'octeontx2_dma', diff --git a/drivers/vdpa/meson.build b/drivers/vdpa/meson.build index e3ed54a257..7eedf826d4 100644 --- a/drivers/vdpa/meson.build +++ b/drivers/vdpa/meson.build @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright 2019 Mellanox Technologies, Ltd +if host_machine.system() == 'windows' + subdir_done() +endif + drivers = ['ifc', 'mlx5',] std_deps = ['bus_pci', 'kvargs'] diff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build index a16f002a3e..ffa349f9a4 100644 --- a/lib/librte_eal/common/meson.build +++ b/lib/librte_eal/common/meson.build @@ -8,6 +8,7 @@ if is_windows 'eal_common_bus.c', 'eal_common_class.c', 'eal_common_config.c', + 'eal_common_dev.c', 'eal_common_devargs.c', 'eal_common_dynmem.c', 'eal_common_errno.c', diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def index 8ed5fad987..441f646707 100644 --- a/lib/librte_eal/rte_eal_exports.def +++ b/lib/librte_eal/rte_eal_exports.def @@ -3,6 +3,11 @@ EXPORTS per_lcore__rte_errno rte_calloc rte_calloc_socket + per_lcore__rte_errno + rte_bus_register + rte_dev_is_probed + rte_devargs_next + rte_devargs_remove rte_eal_get_configuration rte_eal_has_hugepages rte_eal_init @@ -47,6 +52,9 @@ EXPORTS rte_memzone_reserve_aligned rte_memzone_reserve_bounded rte_memzone_walk + rte_strsplit + rte_vfio_container_dma_map + rte_vfio_container_dma_unmap rte_vlog rte_realloc rte_zmalloc diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c index eeebc211b2..2692802efb 100644 --- a/lib/librte_eal/windows/eal.c +++ b/lib/librte_eal/windows/eal.c @@ -18,6 +18,7 @@ #include #include #include +#include #include "eal_hugepages.h" #include "eal_windows.h" @@ -237,7 +238,7 @@ __rte_trace_point_register(rte_trace_point_t *trace, const char *name, int rte_eal_init(int argc, char **argv) { - int i, fctret; + int i, fctret, bscan; const struct rte_config *config = rte_eal_get_configuration(); struct internal_config *internal_conf = rte_eal_get_internal_configuration(); @@ -318,6 +319,13 @@ rte_eal_init(int argc, char **argv) eal_thread_init_master(config->master_lcore); + bscan = rte_bus_scan(); + if (bscan < 0) { + rte_eal_init_alert("Cannot init PCI"); + rte_errno = ENODEV; + return -1; + } + RTE_LCORE_FOREACH_SLAVE(i) { /* @@ -346,3 +354,21 @@ rte_eal_init(int argc, char **argv) rte_eal_mp_wait_lcore(); return fctret; } + +int +rte_vfio_container_dma_map(__rte_unused int container_fd, + __rte_unused uint64_t vaddr, + __rte_unused uint64_t iova, + __rte_unused uint64_t len) +{ + return -1; +} + +int +rte_vfio_container_dma_unmap(__rte_unused int container_fd, + __rte_unused uint64_t vaddr, + __rte_unused uint64_t iova, + __rte_unused uint64_t len) +{ + return -1; +} diff --git a/lib/librte_eal/windows/eal_mp.c b/lib/librte_eal/windows/eal_mp.c index 16a5e8ba03..f2fa9366f6 100644 --- a/lib/librte_eal/windows/eal_mp.c +++ b/lib/librte_eal/windows/eal_mp.c @@ -16,6 +16,7 @@ #include "eal_private.h" #include "eal_windows.h" #include "malloc_mp.h" +#include "hotplug_mp.h" void rte_mp_channel_cleanup(void) @@ -101,3 +102,17 @@ request_sync(void) EAL_LOG_STUB(); return 0; } + +int +eal_dev_hotplug_request_to_primary(struct eal_dev_mp_req *req) +{ + RTE_SET_USED(req); + return 0; +} + +int +eal_dev_hotplug_request_to_secondary(struct eal_dev_mp_req *req) +{ + RTE_SET_USED(req); + return 0; +} From patchwork Thu Jun 18 21:15:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tal Shnaiderman X-Patchwork-Id: 71770 X-Patchwork-Delegate: thomas@monjalon.net 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 F2A8EA04F1; Thu, 18 Jun 2020 23:17:42 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 795131BEE1; Thu, 18 Jun 2020 23:16:53 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id AA9081B13C 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:37 +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 05ILGaFB006303; Fri, 19 Jun 2020 00:16:37 +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:45 +0300 Message-Id: <20200618211546.24496-9-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 8/9] bus/pci: support Windows with bifurcated drivers 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 Uses SetupAPI.h functions to scan PCI tree. Uses DEVPKEY_Device_Numa_Node to get the PCI NUMA node. Uses SPDRP_BUSNUMBER and SPDRP_BUSNUMBER to get the BDF. scanning currently supports types RTE_KDRV_NONE. Signed-off-by: Tal Shnaiderman --- drivers/bus/pci/windows/pci.c | 247 ++++++++++++++++++++++++++- lib/librte_eal/rte_eal_exports.def | 1 + lib/librte_eal/windows/include/rte_windows.h | 1 + 3 files changed, 246 insertions(+), 3 deletions(-) diff --git a/drivers/bus/pci/windows/pci.c b/drivers/bus/pci/windows/pci.c index b1d34ae11c..e916a13ca4 100644 --- a/drivers/bus/pci/windows/pci.c +++ b/drivers/bus/pci/windows/pci.c @@ -1,14 +1,27 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright 2020 Mellanox Technologies, Ltd */ +#include #include #include - -#include #include +#include #include "private.h" +#include + +#ifdef RTE_TOOLCHAIN_GCC +#include +DEFINE_DEVPROPKEY(DEVPKEY_Device_Numa_Node, 0x540b947e, 0x8b40, 0x45bc, + 0xa8, 0xa2, 0x6a, 0x0b, 0x89, 0x4c, 0xbd, 0xa2, 3); +#endif + +/* + * This code is used to simulate a PCI probe by parsing information in + * the registry hive for PCI devices. + */ + /* The functions below are not implemented on Windows, * but need to be defined for compilation purposes */ @@ -146,7 +159,6 @@ rte_pci_ioport_write(struct rte_pci_ioport *p __rte_unused, */ } - /* remap the PCI resource of a PCI device in anonymous virtual memory */ int pci_uio_remap_resource(struct rte_pci_device *dev __rte_unused) @@ -158,6 +170,196 @@ pci_uio_remap_resource(struct rte_pci_device *dev __rte_unused) */ return -1; } + +static int +get_device_pci_address(HDEVINFO dev_info, + PSP_DEVINFO_DATA device_info_data, struct rte_pci_addr *addr) +{ + BOOL res; + ULONG bus_num, dev_and_func; + + res = SetupDiGetDeviceRegistryProperty(dev_info, device_info_data, + SPDRP_BUSNUMBER, NULL, (PBYTE)&bus_num, sizeof(bus_num), NULL); + if (!res) { + RTE_LOG_WIN32_ERR( + "SetupDiGetDeviceRegistryProperty(SPDRP_BUSNUMBER)"); + return -1; + } + + res = SetupDiGetDeviceRegistryProperty(dev_info, device_info_data, + SPDRP_ADDRESS, NULL, (PBYTE)&dev_and_func, sizeof(dev_and_func), + NULL); + if (!res) { + RTE_LOG_WIN32_ERR( + "SetupDiGetDeviceRegistryProperty(SPDRP_ADDRESS)"); + return -1; + } + + addr->domain = 0; + addr->bus = bus_num; + addr->devid = dev_and_func >> 16; + addr->function = dev_and_func & 0xffff; + return 0; +} + +static int +get_device_resource_info(HDEVINFO dev_info, + PSP_DEVINFO_DATA dev_info_data, struct rte_pci_device *dev) +{ + DEVPROPTYPE property_type; + DWORD numa_node; + BOOL res; + + switch (dev->kdrv) { + case RTE_KDRV_NONE: + /* Get NUMA node using DEVPKEY_Device_Numa_Node */ + res = SetupDiGetDevicePropertyW(dev_info, dev_info_data, + &DEVPKEY_Device_Numa_Node, &property_type, + (BYTE *)&numa_node, sizeof(numa_node), NULL, 0); + if (!res) { + RTE_LOG_WIN32_ERR( + "SetupDiGetDevicePropertyW" + "(DEVPKEY_Device_Numa_Node)"); + return -1; + } + dev->device.numa_node = numa_node; + /* mem_resource - Unneeded for RTE_KDRV_NONE */ + dev->mem_resource[0].phys_addr = 0; + dev->mem_resource[0].len = 0; + dev->mem_resource[0].addr = NULL; + break; + default: + /* kernel driver type is unsupported */ + RTE_LOG(DEBUG, EAL, + "kernel driver type for PCI device " PCI_PRI_FMT "," + " is unsupported", + dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); + return -1; + } + + return ERROR_SUCCESS; +} +/* + * get_pci_hardware_info from the SPDRP_HARDWAREID output + */ +static int +get_pci_hardware_info(const char *buf, struct rte_pci_id *pci_id) +{ + int ids = 0; + uint16_t vendor_id, device_id, subvendor_id = 0; + + ids = sscanf_s(buf, "PCI\\VEN_%x&DEV_%x&SUBSYS_%x", &vendor_id, + &device_id, &subvendor_id); + if (ids != 3) + return -1; + + pci_id->vendor_id = vendor_id; + pci_id->device_id = device_id; + pci_id->subsystem_vendor_id = subvendor_id >> 16; + pci_id->subsystem_device_id = subvendor_id & 0xffff; + return 0; +} + +static void +get_kernel_driver_type(struct rte_pci_device *dev __rte_unused) +{ + /* + * If another kernel driver is supported the relevant checking + * functions should be here + */ + dev->kdrv = RTE_KDRV_NONE; +} + +static int +pci_scan_one(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data) +{ + struct rte_pci_device *dev; + int ret = -1; + + dev = malloc(sizeof(*dev)); + if (dev == NULL) { + ret = -1; + goto end; + } + + memset(dev, 0, sizeof(*dev)); + + char pci_device_info[PATH_MAX]; + BOOL res; + struct rte_pci_addr addr; + struct rte_pci_id pci_id; + + /* Retrieve PCI device IDs */ + res = SetupDiGetDeviceRegistryPropertyA(dev_info, device_info_data, + SPDRP_HARDWAREID, NULL, (BYTE *)&pci_device_info, + sizeof(pci_device_info), NULL); + if (!res) { + RTE_LOG_WIN32_ERR( + "SetupDiGetDeviceRegistryPropertyA(SPDRP_HARDWAREID)"); + return -1; + } + + ret = get_pci_hardware_info((const char *)&pci_device_info, &pci_id); + if (ret != 0) { + /* + * We won't add this device, but we want to continue + * looking for supported devices + */ + ret = ERROR_CONTINUE; + goto end; + } + + ret = get_device_pci_address(dev_info, device_info_data, &addr); + if (ret != 0) + goto end; + + dev->addr = addr; + dev->id = pci_id; + dev->max_vfs = 0; /* TODO: get max_vfs */ + + pci_name_set(dev); + + get_kernel_driver_type(dev); + + /* get resources */ + if (get_device_resource_info(dev_info, device_info_data, dev) + != ERROR_SUCCESS) { + goto end; + } + + /* device is valid, add in list (sorted) */ + if (TAILQ_EMPTY(&rte_pci_bus.device_list)) { + rte_pci_add_device(dev); + } else { + struct rte_pci_device *dev2 = NULL; + int ret; + + TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) { + ret = rte_pci_addr_cmp(&dev->addr, &dev2->addr); + if (ret > 0) { + continue; + } else if (ret < 0) { + rte_pci_insert_device(dev2, dev); + } else { /* already registered */ + dev2->kdrv = dev->kdrv; + dev2->max_vfs = dev->max_vfs; + memmove(dev2->mem_resource, dev->mem_resource, + sizeof(dev->mem_resource)); + free(dev); + } + return 0; + } + rte_pci_add_device(dev); + } + + return 0; +end: + if (dev) + free(dev); + return ret; +} + /* * Scan the contents of the PCI bus * and add all network class devices into the devices list. @@ -165,5 +367,44 @@ pci_uio_remap_resource(struct rte_pci_device *dev __rte_unused) int rte_pci_scan(void) { + int ret = -1; + DWORD device_index = 0, found_device = 0; + HDEVINFO dev_info; + SP_DEVINFO_DATA device_info_data; + + /* for debug purposes, PCI can be disabled */ + if (!rte_eal_has_pci()) + return 0; + + dev_info = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, TEXT("PCI"), NULL, + DIGCF_PRESENT); + if (dev_info == INVALID_HANDLE_VALUE) { + RTE_LOG_WIN32_ERR("SetupDiGetClassDevs(pci_scan)"); + RTE_LOG(ERR, EAL, "Unable to enumerate PCI devices.\n"); + goto end; + } + + device_info_data.cbSize = sizeof(SP_DEVINFO_DATA); + device_index = 0; + + while (SetupDiEnumDeviceInfo(dev_info, device_index, + &device_info_data)) { + device_index++; + ret = pci_scan_one(dev_info, &device_info_data); + if (ret == ERROR_SUCCESS) + found_device++; + else if (ret != ERROR_CONTINUE) + goto end; + + memset(&device_info_data, 0, sizeof(SP_DEVINFO_DATA)); + device_info_data.cbSize = sizeof(SP_DEVINFO_DATA); + } + + RTE_LOG(DEBUG, EAL, "PCI scan found %lu devices\n", found_device); return 0; +end: + if (dev_info != INVALID_HANDLE_VALUE) + SetupDiDestroyDeviceInfoList(dev_info); + + return ret; } diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def index 441f646707..441215d42e 100644 --- a/lib/librte_eal/rte_eal_exports.def +++ b/lib/librte_eal/rte_eal_exports.def @@ -10,6 +10,7 @@ EXPORTS rte_devargs_remove rte_eal_get_configuration rte_eal_has_hugepages + rte_eal_has_pci rte_eal_init rte_eal_iova_mode rte_eal_mp_remote_launch diff --git a/lib/librte_eal/windows/include/rte_windows.h b/lib/librte_eal/windows/include/rte_windows.h index 899ed7d874..725ac4f9b2 100644 --- a/lib/librte_eal/windows/include/rte_windows.h +++ b/lib/librte_eal/windows/include/rte_windows.h @@ -25,6 +25,7 @@ #include #include #include +#include /* Have GUIDs defined. */ #ifndef INITGUID From patchwork Thu Jun 18 21:15:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tal Shnaiderman X-Patchwork-Id: 71771 X-Patchwork-Delegate: thomas@monjalon.net 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 2C32FA04F1; Thu, 18 Jun 2020 23:17:54 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CD7EC1BEF2; Thu, 18 Jun 2020 23:16:54 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id AD6C21B5E1 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:37 +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 05ILGaFC006303; Fri, 19 Jun 2020 00:16:37 +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:46 +0300 Message-Id: <20200618211546.24496-10-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 9/9] build: generate version.map file for MingW on Windows 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 The MingW build for Windows has special cases where exported function contain additional prefix: __emutls_v.per_lcore__* To avoid adding those prefixed functions to the version.map file the map_to_def.py script was modified to create a map file for Mingw with the needed changed. The file name was changed to map_to_win.py Signed-off-by: Tal Shnaiderman --- buildtools/{map_to_def.py => map_to_win.py} | 21 ++++++++++++++++----- buildtools/meson.build | 4 ++-- drivers/meson.build | 12 +++++++++--- lib/meson.build | 15 ++++++++++++--- 4 files changed, 39 insertions(+), 13 deletions(-) rename buildtools/{map_to_def.py => map_to_win.py} (51%) diff --git a/buildtools/map_to_def.py b/buildtools/map_to_win.py similarity index 51% rename from buildtools/map_to_def.py rename to buildtools/map_to_win.py index 6775b54a9d..dfb0748159 100644 --- a/buildtools/map_to_def.py +++ b/buildtools/map_to_win.py @@ -13,23 +13,34 @@ def is_function_line(ln): def main(args): if not args[1].endswith('version.map') or \ - not args[2].endswith('exports.def'): + not args[2].endswith('exports.def') and \ + not args[2].endswith('mingw.map'): return 1 # special case, allow override if an def file already exists alongside map file +# for mingw also replace per_lcore__* to __emutls_v.per_lcore__* override_file = join(dirname(args[1]), basename(args[2])) if exists(override_file): with open(override_file) as f_in: - functions = f_in.readlines() + lines = f_in.readlines() + if args[2].endswith('mingw.map'): + lines = [l.replace('per_lcore__', '__emutls_v.per_lcore__') for l in lines] + functions = lines # generate def file from map file. -# This works taking indented lines only which end with a ";" and which don't +# For clang this works taking indented lines only which end with a ";" and which don't # have a colon in them, i.e. the lines defining functions only. +# mingw keeps the original .map file but replaces per_lcore__* to __emutls_v.per_lcore__* else: with open(args[1]) as f_in: - functions = [ln[:-2] + '\n' for ln in sorted(f_in.readlines()) + lines = f_in.readlines() + if args[2].endswith('mingw.map'): + lines = [l.replace('per_lcore__', '__emutls_v.per_lcore__') for l in lines] + functions = lines + else: + functions = [ln[:-2] + '\n' for ln in sorted(lines) if is_function_line(ln)] - functions = ["EXPORTS\n"] + functions + functions = ["EXPORTS\n"] + functions with open(args[2], 'w') as f_out: f_out.writelines(functions) diff --git a/buildtools/meson.build b/buildtools/meson.build index d5f8291beb..f9d2fdf74b 100644 --- a/buildtools/meson.build +++ b/buildtools/meson.build @@ -9,14 +9,14 @@ list_dir_globs = find_program('list-dir-globs.py') check_symbols = find_program('check-symbols.sh') ldflags_ibverbs_static = find_program('options-ibverbs-static.sh') -# set up map-to-def script using python, either built-in or external +# set up map-to-win script using python, either built-in or external python3 = import('python').find_installation(required: false) if python3.found() py3 = [python3] else py3 = ['meson', 'runpython'] endif -map_to_def_cmd = py3 + files('map_to_def.py') +map_to_win_cmd = py3 + files('map_to_win.py') sphinx_wrapper = py3 + files('call-sphinx-build.py') # stable ABI always starts with "DPDK_" diff --git a/drivers/meson.build b/drivers/meson.build index 646a7d5eb5..b25a368531 100644 --- a/drivers/meson.build +++ b/drivers/meson.build @@ -152,16 +152,22 @@ foreach class:dpdk_driver_classes implib = 'lib' + lib_name + '.dll.a' def_file = custom_target(lib_name + '_def', - command: [map_to_def_cmd, '@INPUT@', '@OUTPUT@'], + command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'], input: version_map, output: '@0@_exports.def'.format(lib_name)) - lk_deps = [version_map, def_file] + + mingw_map = custom_target(name + '_mingw', + command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'], + input: version_map, + output: '@0@_mingw.map'.format(name)) + + lk_deps = [version_map, def_file, mingw_map] if is_windows if is_ms_linker lk_args = ['-Wl,/def:' + def_file.full_path(), '-Wl,/implib:drivers\\' + implib] else - lk_args = [] + lk_args = ['-Wl,--version-script=' + mingw_map.full_path()] endif else lk_args = ['-Wl,--version-script=' + version_map] diff --git a/lib/meson.build b/lib/meson.build index a8fd317a18..9f6c85a3e1 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -150,18 +150,27 @@ foreach l:libraries implib = dir_name + '.dll.a' def_file = custom_target(name + '_def', - command: [map_to_def_cmd, '@INPUT@', '@OUTPUT@'], + command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'], input: version_map, output: 'rte_@0@_exports.def'.format(name)) + mingw_map = custom_target(name + '_mingw', + command: [map_to_win_cmd, '@INPUT@', '@OUTPUT@'], + input: version_map, + output: 'rte_@0@_mingw.map'.format(name)) + if is_ms_linker lk_args = ['-Wl,/def:' + def_file.full_path(), '-Wl,/implib:lib\\' + implib] else - lk_args = ['-Wl,--version-script=' + version_map] + if is_windows + lk_args = ['-Wl,--version-script=' + mingw_map.full_path()] + else + lk_args = ['-Wl,--version-script=' + version_map] + endif endif - lk_deps = [version_map, def_file] + lk_deps = [version_map, def_file, mingw_map] if not is_windows # on unix systems check the output of the # check-symbols.sh script, using it as a