aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2020-09-16 21:15:44 +0200
committerDamjan Marion <damarion@cisco.com>2020-09-16 21:19:51 +0200
commit57d1ec00a953620ff59242db07c369843bb16820 (patch)
tree7badde39e261f24c7a69221a87843a9acf030413 /src/vppinfra
parent33ce5e568f8b4fb1254bf5ee32865e9443c0185a (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')
-rw-r--r--src/vppinfra/CMakeLists.txt1
-rw-r--r--src/vppinfra/mem.c30
-rw-r--r--src/vppinfra/mem.h37
-rw-r--r--src/vppinfra/mem_dlmalloc.c3
4 files changed, 53 insertions, 18 deletions
diff --git a/src/vppinfra/CMakeLists.txt b/src/vppinfra/CMakeLists.txt
index 8648275e0da..9e8bc3c442c 100644
--- a/src/vppinfra/CMakeLists.txt
+++ b/src/vppinfra/CMakeLists.txt
@@ -55,6 +55,7 @@ set(VPPINFRA_SRCS
longjmp.S
macros.c
maplog.c
+ mem.c
mem_dlmalloc.c
mhash.c
mpcap.c
diff --git a/src/vppinfra/mem.c b/src/vppinfra/mem.c
new file mode 100644
index 00000000000..3477e5f3c17
--- /dev/null
+++ b/src/vppinfra/mem.c
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vppinfra/clib.h>
+#include <vppinfra/mem.h>
+#include <vppinfra/time.h>
+#include <vppinfra/format.h>
+#include <vppinfra/clib_error.h>
+
+clib_mem_main_t clib_mem_main;
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
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);
diff --git a/src/vppinfra/mem_dlmalloc.c b/src/vppinfra/mem_dlmalloc.c
index 1b0dbb24500..2cd924a605d 100644
--- a/src/vppinfra/mem_dlmalloc.c
+++ b/src/vppinfra/mem_dlmalloc.c
@@ -21,9 +21,6 @@
#include <vppinfra/elf_clib.h>
#include <vppinfra/sanitizer.h>
-void *clib_per_cpu_mheaps[CLIB_MAX_MHEAPS];
-void *clib_per_numa_mheaps[CLIB_MAX_NUMAS];
-
typedef struct
{
/* Address of callers: outer first, inner last. */