summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatoly Burakov <anatoly.burakov@intel.com>2018-04-19 10:40:48 +0100
committerThomas Monjalon <thomas@monjalon.net>2018-04-27 23:52:51 +0200
commit046aa5c4477bbd61718317e9c115c5d3ed42eabf (patch)
treea1f185512797bebf7fb4209c4033157f86bd4924
parent1be7644986261377a588f2ee7e1cdcbab4710896 (diff)
downloaddpdk-046aa5c4477bbd61718317e9c115c5d3ed42eabf.zip
dpdk-046aa5c4477bbd61718317e9c115c5d3ed42eabf.tar.gz
dpdk-046aa5c4477bbd61718317e9c115c5d3ed42eabf.tar.xz
mem: add memalloc init stage
Currently, memseg lists for secondary process are allocated on sync (triggered by init), when they are accessed for the first time. Move this initialization to a separate init stage for memalloc. Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
-rw-r--r--lib/librte_eal/bsdapp/eal/eal_memalloc.c6
-rw-r--r--lib/librte_eal/common/eal_common_memory.c3
-rw-r--r--lib/librte_eal/common/eal_memalloc.h3
-rw-r--r--lib/librte_eal/linuxapp/eal/eal_memalloc.c66
4 files changed, 52 insertions, 26 deletions
diff --git a/lib/librte_eal/bsdapp/eal/eal_memalloc.c b/lib/librte_eal/bsdapp/eal/eal_memalloc.c
index 461732f..f7f07ab 100644
--- a/lib/librte_eal/bsdapp/eal/eal_memalloc.c
+++ b/lib/librte_eal/bsdapp/eal/eal_memalloc.c
@@ -46,3 +46,9 @@ eal_memalloc_sync_with_primary(void)
RTE_LOG(ERR, EAL, "Memory hotplug not supported on FreeBSD\n");
return -1;
}
+
+int
+eal_memalloc_init(void)
+{
+ return 0;
+}
diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c
index e29b93b..4c943b0 100644
--- a/lib/librte_eal/common/eal_common_memory.c
+++ b/lib/librte_eal/common/eal_common_memory.c
@@ -896,6 +896,9 @@ rte_eal_memory_init(void)
if (retval < 0)
goto fail;
+ if (eal_memalloc_init() < 0)
+ goto fail;
+
retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
rte_eal_hugepage_init() :
rte_eal_hugepage_attach();
diff --git a/lib/librte_eal/common/eal_memalloc.h b/lib/librte_eal/common/eal_memalloc.h
index 6736fa3..662b3b5 100644
--- a/lib/librte_eal/common/eal_memalloc.h
+++ b/lib/librte_eal/common/eal_memalloc.h
@@ -76,4 +76,7 @@ eal_memalloc_mem_alloc_validator_unregister(const char *name, int socket_id);
int
eal_memalloc_mem_alloc_validate(int socket_id, size_t new_len);
+int
+eal_memalloc_init(void);
+
#endif /* EAL_MEMALLOC_H */
diff --git a/lib/librte_eal/linuxapp/eal/eal_memalloc.c b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
index f94f388..1f34c70 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memalloc.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memalloc.c
@@ -1069,33 +1069,11 @@ sync_walk(const struct rte_memseg_list *msl, void *arg __rte_unused)
struct hugepage_info *hi = NULL;
unsigned int i;
int msl_idx;
- bool new_msl = false;
msl_idx = msl - mcfg->memsegs;
primary_msl = &mcfg->memsegs[msl_idx];
local_msl = &local_memsegs[msl_idx];
- /* check if secondary has this memseg list set up */
- if (local_msl->base_va == NULL) {
- char name[PATH_MAX];
- int ret;
- new_msl = true;
-
- /* create distinct fbarrays for each secondary */
- snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
- primary_msl->memseg_arr.name, getpid());
-
- ret = rte_fbarray_init(&local_msl->memseg_arr, name,
- primary_msl->memseg_arr.len,
- primary_msl->memseg_arr.elt_sz);
- if (ret < 0) {
- RTE_LOG(ERR, EAL, "Cannot initialize local memory map\n");
- return -1;
- }
-
- local_msl->base_va = primary_msl->base_va;
- }
-
for (i = 0; i < RTE_DIM(internal_config.hugepage_info); i++) {
uint64_t cur_sz =
internal_config.hugepage_info[i].hugepage_sz;
@@ -1110,10 +1088,8 @@ sync_walk(const struct rte_memseg_list *msl, void *arg __rte_unused)
return -1;
}
- /* if versions don't match or if we have just allocated a new
- * memseg list, synchronize everything
- */
- if ((new_msl || local_msl->version != primary_msl->version) &&
+ /* if versions don't match, synchronize everything */
+ if (local_msl->version != primary_msl->version &&
sync_existing(primary_msl, local_msl, hi, msl_idx))
return -1;
return 0;
@@ -1131,3 +1107,41 @@ eal_memalloc_sync_with_primary(void)
return -1;
return 0;
}
+
+static int
+secondary_msl_create_walk(const struct rte_memseg_list *msl,
+ void *arg __rte_unused)
+{
+ struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+ struct rte_memseg_list *primary_msl, *local_msl;
+ char name[PATH_MAX];
+ int msl_idx, ret;
+
+ msl_idx = msl - mcfg->memsegs;
+ primary_msl = &mcfg->memsegs[msl_idx];
+ local_msl = &local_memsegs[msl_idx];
+
+ /* create distinct fbarrays for each secondary */
+ snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
+ primary_msl->memseg_arr.name, getpid());
+
+ ret = rte_fbarray_init(&local_msl->memseg_arr, name,
+ primary_msl->memseg_arr.len,
+ primary_msl->memseg_arr.elt_sz);
+ if (ret < 0) {
+ RTE_LOG(ERR, EAL, "Cannot initialize local memory map\n");
+ return -1;
+ }
+ local_msl->base_va = primary_msl->base_va;
+
+ return 0;
+}
+
+int
+eal_memalloc_init(void)
+{
+ if (rte_eal_process_type() == RTE_PROC_SECONDARY)
+ if (rte_memseg_list_walk(secondary_msl_create_walk, NULL) < 0)
+ return -1;
+ return 0;
+}