summaryrefslogtreecommitdiffstats
path: root/src/vppinfra/mem.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra/mem.h')
-rw-r--r--src/vppinfra/mem.h37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/vppinfra/mem.h b/src/vppinfra/mem.h
index 31c5fd841ad..99097263dfa 100644
--- a/src/vppinfra/mem.h
+++ b/src/vppinfra/mem.h
@@ -71,42 +71,49 @@ typedef enum
CLIB_MEM_PAGE_SZ_16G = 34,
} clib_mem_page_sz_t;
+typedef struct
+{
+ /* per CPU heaps */
+ void *per_cpu_mheaps[CLIB_MAX_MHEAPS];
+
+ /* per NUMA heaps */
+ void *per_numa_mheaps[CLIB_MAX_NUMAS];
+} clib_mem_main_t;
+
+extern clib_mem_main_t clib_mem_main;
+
/* Unspecified NUMA socket */
#define VEC_NUMA_UNSPECIFIED (0xFF)
-/* Per CPU heaps. */
-extern void *clib_per_cpu_mheaps[CLIB_MAX_MHEAPS];
-extern void *clib_per_numa_mheaps[CLIB_MAX_NUMAS];
-
always_inline void *
clib_mem_get_per_cpu_heap (void)
{
int cpu = os_get_thread_index ();
- return clib_per_cpu_mheaps[cpu];
+ return clib_mem_main.per_cpu_mheaps[cpu];
}
always_inline void *
clib_mem_set_per_cpu_heap (u8 * new_heap)
{
int cpu = os_get_thread_index ();
- void *old = clib_per_cpu_mheaps[cpu];
- clib_per_cpu_mheaps[cpu] = new_heap;
+ void *old = clib_mem_main.per_cpu_mheaps[cpu];
+ clib_mem_main.per_cpu_mheaps[cpu] = new_heap;
return old;
}
always_inline void *
clib_mem_get_per_numa_heap (u32 numa_id)
{
- ASSERT (numa_id < ARRAY_LEN (clib_per_numa_mheaps));
- return clib_per_numa_mheaps[numa_id];
+ ASSERT (numa_id < ARRAY_LEN (clib_mem_main.per_numa_mheaps));
+ return clib_mem_main.per_numa_mheaps[numa_id];
}
always_inline void *
clib_mem_set_per_numa_heap (u8 * new_heap)
{
int numa = os_get_numa_index ();
- void *old = clib_per_numa_mheaps[numa];
- clib_per_numa_mheaps[numa] = new_heap;
+ void *old = clib_mem_main.per_numa_mheaps[numa];
+ clib_mem_main.per_numa_mheaps[numa] = new_heap;
return old;
}
@@ -121,9 +128,9 @@ clib_mem_set_thread_index (void)
int i;
if (__os_thread_index != 0)
return;
- for (i = 0; i < ARRAY_LEN (clib_per_cpu_mheaps); i++)
- if (clib_atomic_bool_cmp_and_swap (&clib_per_cpu_mheaps[i],
- 0, clib_per_cpu_mheaps[0]))
+ for (i = 0; i < ARRAY_LEN (clib_mem_main.per_cpu_mheaps); i++)
+ if (clib_atomic_bool_cmp_and_swap (&clib_mem_main.per_cpu_mheaps[i],
+ 0, clib_mem_main.per_cpu_mheaps[0]))
{
os_set_thread_index (i);
break;
@@ -154,7 +161,7 @@ clib_mem_alloc_aligned_at_offset (uword size, uword align, uword align_offset,
}
cpu = os_get_thread_index ();
- heap = clib_per_cpu_mheaps[cpu];
+ heap = clib_mem_main.per_cpu_mheaps[cpu];
p = mspace_get_aligned (heap, size, align, align_offset);