eal: fix crash when allocating memory on a control thread
[dpdk.git] / lib / eal / common / malloc_heap.c
index ee400f3..054d92b 100644 (file)
@@ -694,6 +694,24 @@ alloc_unlock:
        return ret;
 }
 
+static unsigned
+malloc_get_numa_socket(void)
+{
+       const struct internal_config *internal_conf =
+               eal_get_internal_configuration();
+       unsigned socket_id = rte_socket_id();
+
+       if (socket_id != (unsigned)SOCKET_ID_ANY)
+               return socket_id;
+
+       /* return first id where memory is available, otherwise 0 */
+       for (socket_id = 0; socket_id < RTE_MAX_NUMA_NODES; ++socket_id)
+               if (internal_conf->socket_mem[socket_id] != 0)
+                       return socket_id;
+
+       return 0;
+}
+
 void *
 malloc_heap_alloc(const char *type, size_t size, int socket_arg,
                unsigned int flags, size_t align, size_t bound, bool contig)