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;
}
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;
}
* - 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
}
/* 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; j<mem[i].len; j++) {
- *((volatile uint8_t *) mem[i].addr + j);
- }
- }
+ rte_memseg_walk(check_mem, NULL);
return 0;
}
return 0;
}
+struct walk_arg {
+ int hugepage_2MB_avail;
+ int hugepage_1GB_avail;
+ int hugepage_16MB_avail;
+ int hugepage_16GB_avail;
+};
+static int
+find_available_pagesz(const struct rte_memseg *ms, void *arg)
+{
+ struct walk_arg *wa = arg;
+
+ if (ms->hugepage_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");