diff options
author | Damjan Marion <damarion@cisco.com> | 2020-09-16 21:15:44 +0200 |
---|---|---|
committer | Damjan Marion <damarion@cisco.com> | 2020-09-16 21:19:51 +0200 |
commit | 57d1ec00a953620ff59242db07c369843bb16820 (patch) | |
tree | 7badde39e261f24c7a69221a87843a9acf030413 /src/vppinfra/mem.h | |
parent | 33ce5e568f8b4fb1254bf5ee32865e9443c0185a (diff) |
vppinfra: introduce clib_mem_main
To hold more data later...
Type: improvement
Change-Id: I4006d22dcacd788988c4907f2c263fd4e4a9d398
Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/mem.h')
-rw-r--r-- | src/vppinfra/mem.h | 37 |
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); |