#include <rte_tailq.h>
#include <rte_memory.h>
#include <rte_memzone.h>
+#include <rte_malloc_heap.h>
#include <rte_rwlock.h>
#ifdef __cplusplus
struct rte_memseg free_memseg[RTE_MAX_MEMSEG];
struct rte_tailq_head tailq_head[RTE_MAX_TAILQ]; /**< Tailqs for objects */
+
+ /* Heaps of Malloc per socket */
+ struct malloc_heap malloc_heaps[RTE_MAX_NUMA_NODES];
} __attribute__((__packed__));
#include <rte_memzone.h>
#include <rte_tailq.h>
#include <rte_eal.h>
+#include <rte_eal_memconfig.h>
#include <rte_launch.h>
#include <rte_per_lcore.h>
#include <rte_lcore.h>
#include <rte_common.h>
#include <rte_string_fns.h>
#include <rte_spinlock.h>
+#include <rte_memcpy.h>
+#include <rte_atomic.h>
#include "malloc_elem.h"
#include "malloc_heap.h"
static void
malloc_heap_init(struct malloc_heap *heap)
{
- static rte_spinlock_t init_lock = RTE_SPINLOCK_INITIALIZER;
- rte_spinlock_lock(&init_lock);
- if (!heap->initialised) {
- heap->free_head = NULL;
- heap->mz_count = 0;
- heap->numa_socket = malloc_get_numa_socket();
- rte_spinlock_init(&heap->lock);
- heap->initialised = INITIALISED;
+ struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+
+ rte_eal_mcfg_wait_complete(mcfg);
+ while (heap->initialised != INITIALISED) {
+ if (rte_atomic32_cmpset(
+ (volatile uint32_t*)&heap->initialised,
+ NOT_INITIALISED, INITIALISING)) {
+
+ heap->free_head = NULL;
+ heap->mz_count = 0;
+ /*
+ * Find NUMA socket of heap that is being initialised, so that
+ * malloc_heaps[n].numa_socket == n
+ */
+ heap->numa_socket = heap - mcfg->malloc_heaps;
+ rte_spinlock_init(&heap->lock);
+ heap->initialised = INITIALISED;
+ }
}
- rte_spinlock_unlock(&init_lock);
}
/*
#include <rte_malloc.h>
#include "malloc_elem.h"
#include "malloc_heap.h"
+#include "malloc_heap.c"
-static struct malloc_heap malloc_heap[RTE_MAX_NUMA_NODES] = {
- { .initialised = NOT_INITIALISED }
-};
/* Free the memory space back to heap */
void rte_free(void *addr)
void *
rte_malloc_socket(const char *type, size_t size, unsigned align, int socket)
{
+ struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+
/* return NULL if size is 0 or alignment is not power-of-2 */
if (size == 0 || !rte_is_power_of_2(align))
return NULL;
if (socket >= RTE_MAX_NUMA_NODES)
return NULL;
- return malloc_heap_alloc(&malloc_heaps[socket], type,
+ return malloc_heap_alloc(&mcfg->malloc_heaps[socket], type,
size, align == 0 ? 1 : align);
}