eal: fix header file install with meson
[dpdk.git] / lib / librte_eal / common / rte_malloc.c
index b119eba..d6026a2 100644 (file)
@@ -25,6 +25,8 @@
 #include "malloc_elem.h"
 #include "malloc_heap.h"
 #include "eal_memalloc.h"
+#include "eal_memcfg.h"
+#include "eal_private.h"
 
 
 /* Free the memory space back to heap */
@@ -148,7 +150,8 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket)
        void *new_ptr = rte_malloc_socket(NULL, size, align, socket);
        if (new_ptr == NULL)
                return NULL;
-       const unsigned old_size = elem->size - MALLOC_ELEM_OVERHEAD;
+       /* elem: |pad|data_elem|data|trailer| */
+       const size_t old_size = elem->size - elem->pad - MALLOC_ELEM_OVERHEAD;
        rte_memcpy(new_ptr, ptr, old_size < size ? old_size : size);
        rte_free(ptr);
 
@@ -223,7 +226,7 @@ rte_malloc_heap_get_socket(const char *name)
                rte_errno = EINVAL;
                return -1;
        }
-       rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_read_lock();
        for (idx = 0; idx < RTE_MAX_HEAPS; idx++) {
                struct malloc_heap *tmp = &mcfg->malloc_heaps[idx];
 
@@ -239,7 +242,7 @@ rte_malloc_heap_get_socket(const char *name)
                rte_errno = ENOENT;
                ret = -1;
        }
-       rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_read_unlock();
 
        return ret;
 }
@@ -254,7 +257,7 @@ rte_malloc_heap_socket_is_external(int socket_id)
        if (socket_id == SOCKET_ID_ANY)
                return 0;
 
-       rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_read_lock();
        for (idx = 0; idx < RTE_MAX_HEAPS; idx++) {
                struct malloc_heap *tmp = &mcfg->malloc_heaps[idx];
 
@@ -264,7 +267,7 @@ rte_malloc_heap_socket_is_external(int socket_id)
                        break;
                }
        }
-       rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_read_unlock();
 
        return ret;
 }
@@ -352,7 +355,6 @@ int
 rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len,
                rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz)
 {
-       struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
        struct malloc_heap *heap = NULL;
        struct rte_memseg_list *msl;
        unsigned int n;
@@ -369,7 +371,7 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len,
                rte_errno = EINVAL;
                return -1;
        }
-       rte_rwlock_write_lock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_write_lock();
 
        /* find our heap */
        heap = find_named_heap(heap_name);
@@ -395,10 +397,11 @@ rte_malloc_heap_memory_add(const char *heap_name, void *va_addr, size_t len,
 
        rte_spinlock_lock(&heap->lock);
        ret = malloc_heap_add_external_memory(heap, msl);
+       msl->heap = 1; /* mark it as heap segment */
        rte_spinlock_unlock(&heap->lock);
 
 unlock:
-       rte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_write_unlock();
 
        return ret;
 }
@@ -406,7 +409,6 @@ unlock:
 int
 rte_malloc_heap_memory_remove(const char *heap_name, void *va_addr, size_t len)
 {
-       struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
        struct malloc_heap *heap = NULL;
        struct rte_memseg_list *msl;
        int ret;
@@ -418,7 +420,7 @@ rte_malloc_heap_memory_remove(const char *heap_name, void *va_addr, size_t len)
                rte_errno = EINVAL;
                return -1;
        }
-       rte_rwlock_write_lock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_write_lock();
        /* find our heap */
        heap = find_named_heap(heap_name);
        if (heap == NULL) {
@@ -448,7 +450,7 @@ rte_malloc_heap_memory_remove(const char *heap_name, void *va_addr, size_t len)
        ret = malloc_heap_destroy_external_seg(msl);
 
 unlock:
-       rte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_write_unlock();
 
        return ret;
 }
@@ -456,7 +458,6 @@ unlock:
 static int
 sync_memory(const char *heap_name, void *va_addr, size_t len, bool attach)
 {
-       struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
        struct malloc_heap *heap = NULL;
        struct rte_memseg_list *msl;
        int ret;
@@ -468,7 +469,7 @@ sync_memory(const char *heap_name, void *va_addr, size_t len, bool attach)
                rte_errno = EINVAL;
                return -1;
        }
-       rte_rwlock_read_lock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_read_lock();
 
        /* find our heap */
        heap = find_named_heap(heap_name);
@@ -516,7 +517,7 @@ sync_memory(const char *heap_name, void *va_addr, size_t len, bool attach)
                }
        }
 unlock:
-       rte_rwlock_read_unlock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_read_unlock();
        return ret;
 }
 
@@ -549,7 +550,7 @@ rte_malloc_heap_create(const char *heap_name)
        /* check if there is space in the heap list, or if heap with this name
         * already exists.
         */
-       rte_rwlock_write_lock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_write_lock();
 
        for (i = 0; i < RTE_MAX_HEAPS; i++) {
                struct malloc_heap *tmp = &mcfg->malloc_heaps[i];
@@ -578,7 +579,7 @@ rte_malloc_heap_create(const char *heap_name)
        /* we're sure that we can create a new heap, so do it */
        ret = malloc_heap_create(heap, heap_name);
 unlock:
-       rte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_write_unlock();
 
        return ret;
 }
@@ -586,7 +587,6 @@ unlock:
 int
 rte_malloc_heap_destroy(const char *heap_name)
 {
-       struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
        struct malloc_heap *heap = NULL;
        int ret;
 
@@ -597,7 +597,7 @@ rte_malloc_heap_destroy(const char *heap_name)
                rte_errno = EINVAL;
                return -1;
        }
-       rte_rwlock_write_lock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_write_lock();
 
        /* start from non-socket heaps */
        heap = find_named_heap(heap_name);
@@ -621,7 +621,7 @@ rte_malloc_heap_destroy(const char *heap_name)
        if (ret < 0)
                rte_spinlock_unlock(&heap->lock);
 unlock:
-       rte_rwlock_write_unlock(&mcfg->memory_hotplug_lock);
+       rte_mcfg_mem_write_unlock();
 
        return ret;
 }