env/dpdk: add support for DPDK 18.05 dynamic memory allocation
This brings DPDK 18.05 support and introduces
dynamic hugepage memory allocation.
The following is now possible:
./spdk_tgt -s 32
rpc.py construct_malloc_bdev 128 512
or even:
./spdk_tgt -s 0
Note that if no -s param is given, DPDK will still
allocate all available hugepage memory.
This has been tested with DPDK 18.05-rc6.
Fixes #281
This is a cherry-pick of commit b6fce1912d
from master.
Change-Id: I04e23cfcd8c0af913ed402a310fd596bc25d685c
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/410540
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/412868
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
parent
5f59d919a4
commit
e110a0d1e6
@ -80,7 +80,8 @@ endif
|
||||
|
||||
DPDK_LIB = $(DPDK_LIB_LIST:%=$(DPDK_ABS_DIR)/lib/lib%$(DPDK_LIB_EXT))
|
||||
|
||||
ENV_CFLAGS = $(DPDK_INC)
|
||||
# SPDK memory registration requires experimental (deprecated) rte_memory API for DPDK 18.05
|
||||
ENV_CFLAGS = $(DPDK_INC) -Wno-deprecated-declarations
|
||||
ENV_CXXFLAGS = $(ENV_CFLAGS)
|
||||
ENV_DPDK_FILE = $(call spdk_lib_list_to_files,env_dpdk)
|
||||
ENV_LIBS = $(ENV_DPDK_FILE) $(DPDK_LIB)
|
||||
|
@ -498,12 +498,29 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr)
|
||||
return map_2mb->translation_2mb;
|
||||
}
|
||||
|
||||
#if RTE_VERSION >= RTE_VERSION_NUM(18, 05, 0, 0)
|
||||
static void
|
||||
memory_hotplug_cb(enum rte_mem_event event_type,
|
||||
const void *addr, size_t len, void *arg)
|
||||
{
|
||||
if (event_type == RTE_MEM_EVENT_ALLOC) {
|
||||
spdk_mem_register((void *)addr, len);
|
||||
} else if (event_type == RTE_MEM_EVENT_FREE) {
|
||||
spdk_mem_unregister((void *)addr, len);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
memory_iter_cb(const struct rte_memseg_list *msl,
|
||||
const struct rte_memseg *ms, size_t len, void *arg)
|
||||
{
|
||||
return spdk_mem_register(ms->addr, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
spdk_mem_map_init(void)
|
||||
{
|
||||
struct rte_mem_config *mcfg;
|
||||
size_t seg_idx;
|
||||
|
||||
g_mem_reg_map = spdk_mem_map_alloc(0, NULL, NULL);
|
||||
if (g_mem_reg_map == NULL) {
|
||||
DEBUG_PRINT("memory registration map allocation failed\n");
|
||||
@ -514,8 +531,14 @@ spdk_mem_map_init(void)
|
||||
* Walk all DPDK memory segments and register them
|
||||
* with the master memory map
|
||||
*/
|
||||
mcfg = rte_eal_get_configuration()->mem_config;
|
||||
#if RTE_VERSION >= RTE_VERSION_NUM(18, 05, 0, 0)
|
||||
rte_mem_event_callback_register("spdk", memory_hotplug_cb, NULL);
|
||||
rte_memseg_contig_walk(memory_iter_cb, NULL);
|
||||
#else
|
||||
struct rte_mem_config *mcfg;
|
||||
size_t seg_idx;
|
||||
|
||||
mcfg = rte_eal_get_configuration()->mem_config;
|
||||
for (seg_idx = 0; seg_idx < RTE_MAX_MEMSEG; seg_idx++) {
|
||||
struct rte_memseg *seg = &mcfg->memseg[seg_idx];
|
||||
|
||||
@ -525,5 +548,6 @@ spdk_mem_map_init(void)
|
||||
|
||||
spdk_mem_register(seg->addr, seg->len);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -214,12 +214,23 @@ static uint64_t
|
||||
vtophys_get_paddr_memseg(uint64_t vaddr)
|
||||
{
|
||||
uintptr_t paddr;
|
||||
struct rte_mem_config *mcfg;
|
||||
struct rte_memseg *seg;
|
||||
|
||||
#if RTE_VERSION >= RTE_VERSION_NUM(18, 05, 0, 0)
|
||||
seg = rte_mem_virt2memseg((void *)(uintptr_t)vaddr, NULL);
|
||||
if (seg != NULL) {
|
||||
paddr = seg->phys_addr;
|
||||
if (paddr == RTE_BAD_IOVA) {
|
||||
return SPDK_VTOPHYS_ERROR;
|
||||
}
|
||||
paddr += (vaddr - (uintptr_t)seg->addr);
|
||||
return paddr;
|
||||
}
|
||||
#else
|
||||
struct rte_mem_config *mcfg;
|
||||
uint32_t seg_idx;
|
||||
|
||||
mcfg = rte_eal_get_configuration()->mem_config;
|
||||
|
||||
for (seg_idx = 0; seg_idx < RTE_MAX_MEMSEG; seg_idx++) {
|
||||
seg = &mcfg->memseg[seg_idx];
|
||||
if (seg->addr == NULL) {
|
||||
@ -240,6 +251,7 @@ vtophys_get_paddr_memseg(uint64_t vaddr)
|
||||
return paddr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return SPDK_VTOPHYS_ERROR;
|
||||
}
|
||||
|
10
test/env/memory/memory_ut.c
vendored
10
test/env/memory/memory_ut.c
vendored
@ -50,6 +50,16 @@ rte_eal_get_configuration(void)
|
||||
return &g_cfg;
|
||||
}
|
||||
|
||||
#if RTE_VERSION >= RTE_VERSION_NUM(18, 05, 0, 0)
|
||||
typedef void (*rte_mem_event_callback_t)(enum rte_mem_event event_type,
|
||||
const void *addr, size_t len, void *arg);
|
||||
typedef int (*rte_memseg_contig_walk_t)(const struct rte_memseg_list *msl,
|
||||
const struct rte_memseg *ms, size_t len, void *arg);
|
||||
DEFINE_STUB(rte_mem_event_callback_register, int, (const char *name, rte_mem_event_callback_t clb,
|
||||
void *arg), 0);
|
||||
DEFINE_STUB(rte_memseg_contig_walk, int, (rte_memseg_contig_walk_t func, void *arg), 0);
|
||||
#endif
|
||||
|
||||
#define PAGE_ARRAY_SIZE (100)
|
||||
static struct spdk_bit_array *g_page_array;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user