#include <rte_common.h>
#include <rte_memory.h>
+#include <rte_eal_memconfig.h>
#include <rte_per_lcore.h>
#include <rte_launch.h>
#include <rte_eal.h>
struct rte_malloc_socket_stats pre_stats, post_stats ,first_stats, second_stats;
size_t size = 2048;
int align = 1024;
-#ifndef RTE_MALLOC_DEBUG
- int trailer_size = 0;
-#else
- int trailer_size = RTE_CACHE_LINE_SIZE;
-#endif
- int overhead = RTE_CACHE_LINE_SIZE + trailer_size;
+ int overhead = 0;
+ /* Dynamically calculate the overhead by allocating one cacheline and
+ * then comparing what was allocated from the heap.
+ */
+ rte_malloc_get_socket_stats(socket, &pre_stats);
+
+ void *dummy = rte_malloc_socket(NULL, RTE_CACHE_LINE_SIZE, 0, socket);
+ if (dummy == NULL)
+ return -1;
+
+ rte_malloc_get_socket_stats(socket, &post_stats);
+
+ /* after subtracting cache line, remainder is overhead */
+ overhead = post_stats.heap_allocsz_bytes - pre_stats.heap_allocsz_bytes;
+ overhead -= RTE_CACHE_LINE_SIZE;
+
+ rte_free(dummy);
+
+ /* Now start the real tests */
rte_malloc_get_socket_stats(socket, &pre_stats);
void *p1 = rte_malloc_socket("stats", size , align, socket);
}
static int
-check_socket_mem(const struct rte_memseg *ms, void *arg)
+check_socket_mem(const struct rte_memseg_list *msl, void *arg)
{
int32_t *socket = arg;
- return *socket == ms->socket_id;
+ if (msl->external)
+ return 0;
+
+ return *socket == msl->socket_id;
}
/* Check if memory is available on a specific socket */
static int
is_mem_on_socket(int32_t socket)
{
- return rte_memseg_walk(check_socket_mem, &socket);
+ return rte_memseg_list_walk(check_socket_mem, &socket);
}
-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;
-}
/*
* Find what socket a memory address is on. Only works for addresses within
static int32_t
addr_to_socket(void * addr)
{
- struct walk_param param = {.addr = addr, .socket = 0};
- if (rte_memseg_walk(find_socket, ¶m) > 0)
- return param.socket;
- return -1;
+ const struct rte_memseg *ms = rte_mem_virt2memseg(addr, NULL);
+ return ms == NULL ? -1 : ms->socket_id;
+
}
/* Test using rte_[c|m|zm]alloc_socket() on a specific socket */