From: Anatoly Burakov Date: Wed, 11 Apr 2018 12:30:06 +0000 (+0100) Subject: test: use memseg walk instead of iteration X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=ced746fc312923bbb494cd933b09ae31f9657558;p=dpdk.git test: use memseg walk instead of iteration Reduce dependency on internal details of EAL memory subsystem, and simplify code. Signed-off-by: Anatoly Burakov Tested-by: Santosh Shukla Tested-by: Hemant Agrawal Tested-by: Gowrishankar Muthukrishnan --- diff --git a/test/test/test_malloc.c b/test/test/test_malloc.c index ccc5feaec7..28c241f711 100644 --- a/test/test/test_malloc.c +++ b/test/test/test_malloc.c @@ -705,16 +705,34 @@ err_return: return -1; } +static int +check_socket_mem(const struct rte_memseg *ms, void *arg) +{ + int32_t *socket = arg; + + return *socket == ms->socket_id; +} + /* Check if memory is available on a specific socket */ static int is_mem_on_socket(int32_t socket) { - const struct rte_memseg *ms = rte_eal_get_physmem_layout(); - unsigned i; + return rte_memseg_walk(check_socket_mem, &socket); +} - for (i = 0; i < RTE_MAX_MEMSEG; i++) { - if (socket == ms[i].socket_id) - return 1; +struct walk_param { + void *addr; + int32_t socket; +}; +static int +find_socket(const struct rte_memseg *ms, void *arg) +{ + struct walk_param *param = arg; + + if (param->addr >= ms->addr && + param->addr < RTE_PTR_ADD(ms->addr, ms->len)) { + param->socket = ms->socket_id; + return 1; } return 0; } @@ -726,15 +744,9 @@ is_mem_on_socket(int32_t socket) static int32_t addr_to_socket(void * addr) { - const struct rte_memseg *ms = rte_eal_get_physmem_layout(); - unsigned i; - - for (i = 0; i < RTE_MAX_MEMSEG; i++) { - if ((ms[i].addr <= addr) && - ((uintptr_t)addr < - ((uintptr_t)ms[i].addr + (uintptr_t)ms[i].len))) - return ms[i].socket_id; - } + struct walk_param param = {.addr = addr, .socket = 0}; + if (rte_memseg_walk(find_socket, ¶m) > 0) + return param.socket; return -1; } diff --git a/test/test/test_memory.c b/test/test/test_memory.c index 972321f1bd..c9b287c3fc 100644 --- a/test/test/test_memory.c +++ b/test/test/test_memory.c @@ -22,13 +22,21 @@ * - Try to read all memory; it should not segfault. */ +static int +check_mem(const struct rte_memseg *ms, void *arg __rte_unused) +{ + volatile uint8_t *mem = (volatile uint8_t *) ms->addr; + size_t i; + + for (i = 0; i < ms->len; i++, mem++) + *mem; + return 0; +} + static int test_memory(void) { uint64_t s; - unsigned i; - size_t j; - const struct rte_memseg *mem; /* * dump the mapped memory: the python-expect script checks @@ -45,14 +53,7 @@ test_memory(void) } /* try to read memory (should not segfault) */ - mem = rte_eal_get_physmem_layout(); - for (i = 0; i < RTE_MAX_MEMSEG && mem[i].addr != NULL ; i++) { - - /* check memory */ - for (j = 0; jhugepage_sz == RTE_PGSIZE_2M) + wa->hugepage_2MB_avail = 1; + if (ms->hugepage_sz == RTE_PGSIZE_1G) + wa->hugepage_1GB_avail = 1; + if (ms->hugepage_sz == RTE_PGSIZE_16M) + wa->hugepage_16MB_avail = 1; + if (ms->hugepage_sz == RTE_PGSIZE_16G) + wa->hugepage_16GB_avail = 1; + + return 0; +} + static int test_memzone_reserve_flags(void) { const struct rte_memzone *mz; - const struct rte_memseg *ms; - int hugepage_2MB_avail = 0; - int hugepage_1GB_avail = 0; - int hugepage_16MB_avail = 0; - int hugepage_16GB_avail = 0; + struct walk_arg wa; + int hugepage_2MB_avail, hugepage_1GB_avail; + int hugepage_16MB_avail, hugepage_16GB_avail; const size_t size = 100; - int i = 0; - ms = rte_eal_get_physmem_layout(); - for (i = 0; i < RTE_MAX_MEMSEG; i++) { - if (ms[i].hugepage_sz == RTE_PGSIZE_2M) - hugepage_2MB_avail = 1; - if (ms[i].hugepage_sz == RTE_PGSIZE_1G) - hugepage_1GB_avail = 1; - if (ms[i].hugepage_sz == RTE_PGSIZE_16M) - hugepage_16MB_avail = 1; - if (ms[i].hugepage_sz == RTE_PGSIZE_16G) - hugepage_16GB_avail = 1; - } + + memset(&wa, 0, sizeof(wa)); + + rte_memseg_walk(find_available_pagesz, &wa); + + hugepage_2MB_avail = wa.hugepage_2MB_avail; + hugepage_1GB_avail = wa.hugepage_1GB_avail; + hugepage_16MB_avail = wa.hugepage_16MB_avail; + hugepage_16GB_avail = wa.hugepage_16GB_avail; + /* Display the availability of 2MB ,1GB, 16MB, 16GB pages */ if (hugepage_2MB_avail) printf("2MB Huge pages available\n");