summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2020-02-09 18:09:31 +0000
committerDave Barach <openvpp@barachs.net>2020-02-10 20:12:40 +0000
commit4c9599574929f624a218b963d268d97799289945 (patch)
treed0fd96ed24813d9bfd88e681f676d598fb409350
parentf1ecb6555326f8a7d5bba6f56aa676f064675dc0 (diff)
vppinfra: use vm memory allocator for numa mapping
Type: refactor Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I13b239cd572ae6dfaec07019d3d9b7c0ed3edcfa
-rw-r--r--src/vlib/main.c1
-rw-r--r--src/vlib/threads.c8
-rw-r--r--src/vppinfra/CMakeLists.txt9
-rw-r--r--src/vppinfra/config.h.in1
-rw-r--r--src/vppinfra/mem.h3
-rw-r--r--src/vppinfra/mem_dlmalloc.c49
6 files changed, 21 insertions, 50 deletions
diff --git a/src/vlib/main.c b/src/vlib/main.c
index 28c8c789c0a..94218d3d9d8 100644
--- a/src/vlib/main.c
+++ b/src/vlib/main.c
@@ -1717,6 +1717,7 @@ vlib_main_or_worker_loop (vlib_main_t * vm, int is_main)
vm->cpu_id = clib_get_current_cpu_id ();
vm->numa_node = clib_get_current_numa_node ();
+ os_set_numa_index (vm->numa_node);
/* Start all processes. */
if (is_main)
diff --git a/src/vlib/threads.c b/src/vlib/threads.c
index 8a068875617..d9d781070a3 100644
--- a/src/vlib/threads.c
+++ b/src/vlib/threads.c
@@ -589,9 +589,8 @@ vlib_get_thread_core_numa (vlib_worker_thread_t * w, unsigned cpu_id)
p = format (p, "%s%u/topology/core_id%c", sys_cpu_path, cpu_id, 0);
clib_sysfs_read ((char *) p, "%d", &core_id);
vec_reset_length (p);
- p =
- format (p, "%s%u/topology/physical_package_id%c", sys_cpu_path, cpu_id,
- 0);
+ p = format (p, "%s%u/topology/physical_package_id%c", sys_cpu_path,
+ cpu_id, 0);
clib_sysfs_read ((char *) p, "%d", &numa_id);
vec_free (p);
@@ -608,7 +607,6 @@ vlib_launch_thread_int (void *fp, vlib_worker_thread_t * w, unsigned cpu_id)
w->cpu_id = cpu_id;
vlib_get_thread_core_numa (w, cpu_id);
- os_set_numa_index (w->numa_id);
/* Set up NUMA-bound heap if indicated */
if (clib_per_numa_mheaps[w->numa_id] == 0)
@@ -617,7 +615,7 @@ vlib_launch_thread_int (void *fp, vlib_worker_thread_t * w, unsigned cpu_id)
if (tm->numa_heap_size)
{
numa_heap = clib_mem_init_thread_safe_numa
- (0 /* DIY */ , tm->numa_heap_size);
+ (0 /* DIY */ , tm->numa_heap_size, w->numa_id);
clib_per_numa_mheaps[w->numa_id] = numa_heap;
}
else
diff --git a/src/vppinfra/CMakeLists.txt b/src/vppinfra/CMakeLists.txt
index 60e6eeff9fe..1c234cce234 100644
--- a/src/vppinfra/CMakeLists.txt
+++ b/src/vppinfra/CMakeLists.txt
@@ -24,13 +24,6 @@ else(VPP_USE_DLMALLOC)
set(DLMALLOC 0)
endif(VPP_USE_DLMALLOC)
-find_library(NUMA numa)
-if (NUMA)
- set(NUMA_LIBRARY_FOUND 1)
-else(NUMA)
- set(NUMA_LIBRARY_FOUND 0)
-endif()
-
configure_file(
${CMAKE_SOURCE_DIR}/vppinfra/config.h.in
${CMAKE_BINARY_DIR}/vppinfra/config.h
@@ -217,7 +210,7 @@ endif(VPP_USE_DLMALLOC)
add_vpp_library(vppinfra
SOURCES ${VPPINFRA_SRCS}
- LINK_LIBRARIES m ${NUMA}
+ LINK_LIBRARIES m
INSTALL_HEADERS ${VPPINFRA_HEADERS}
COMPONENT libvppinfra
)
diff --git a/src/vppinfra/config.h.in b/src/vppinfra/config.h.in
index b2366630447..a7a22a6a992 100644
--- a/src/vppinfra/config.h.in
+++ b/src/vppinfra/config.h.in
@@ -21,7 +21,6 @@
#endif
#define USE_DLMALLOC @DLMALLOC@
-#define HAVE_NUMA_LIBRARY @NUMA_LIBRARY_FOUND@
#define CLIB_TARGET_TRIPLET "@CMAKE_C_COMPILER_TARGET@"
#endif
diff --git a/src/vppinfra/mem.h b/src/vppinfra/mem.h
index c00c78ad9a4..0367c4a1213 100644
--- a/src/vppinfra/mem.h
+++ b/src/vppinfra/mem.h
@@ -308,7 +308,8 @@ clib_mem_set_heap (void *heap)
void *clib_mem_init (void *heap, uword size);
void *clib_mem_init_thread_safe (void *memory, uword memory_size);
-void *clib_mem_init_thread_safe_numa (void *memory, uword memory_size);
+void *clib_mem_init_thread_safe_numa (void *memory, uword memory_size,
+ u8 numa);
void clib_mem_exit (void);
diff --git a/src/vppinfra/mem_dlmalloc.c b/src/vppinfra/mem_dlmalloc.c
index 38226e26f8f..d62bb740c6c 100644
--- a/src/vppinfra/mem_dlmalloc.c
+++ b/src/vppinfra/mem_dlmalloc.c
@@ -243,46 +243,25 @@ clib_mem_init_thread_safe (void *memory, uword memory_size)
}
void *
-clib_mem_init_thread_safe_numa (void *memory, uword memory_size)
+clib_mem_init_thread_safe_numa (void *memory, uword memory_size, u8 numa)
{
+ clib_mem_vm_alloc_t alloc = { 0 };
+ clib_error_t *err;
void *heap;
- unsigned long this_numa;
- heap =
- clib_mem_init_internal (memory, memory_size,
- 0 /* do NOT clib_mem_set_heap */ );
-
- ASSERT (heap);
-
- this_numa = os_get_numa_index ();
-
-#if HAVE_NUMA_LIBRARY > 0
- unsigned long nodemask = 1 << this_numa;
- void *page_base;
- unsigned long page_mask;
- long rv;
-
- /*
- * Bind the heap to the current thread's NUMA node.
- * heap is not naturally page-aligned, so fix it.
- */
-
- page_mask = ~(clib_mem_get_page_size () - 1);
- page_base = (void *) (((unsigned long) heap) & page_mask);
-
- clib_warning ("Bind heap at %llx size %llx to NUMA numa %d",
- page_base, memory_size, this_numa);
+ alloc.size = memory_size;
+ alloc.flags = CLIB_MEM_VM_F_NUMA_FORCE;
+ alloc.numa_node = numa;
+ if ((err = clib_mem_vm_ext_alloc (&alloc)))
+ {
+ clib_error_report (err);
+ return 0;
+ }
- rv = mbind (page_base, memory_size, MPOL_BIND /* mode */ ,
- &nodemask /* nodemask */ ,
- BITS (nodemask) /* max node number */ ,
- MPOL_MF_MOVE /* flags */ );
+ heap = clib_mem_init_internal (memory, memory_size,
+ 0 /* do NOT clib_mem_set_heap */ );
- if (rv < 0)
- clib_unix_warning ("mbind");
-#else
- clib_warning ("mbind unavailable, can't bind to numa %d", this_numa);
-#endif
+ ASSERT (heap);
return heap;
}
span> { "program": "vpe", "version": "18.10-release", "build_date": "Tue Oct 23 07:03:38 UTC 2018", "build_directory": "/w/workspace/vpp-merge-1810-centos7" }, "interfaces": [ { "if_index": 0, "if_name": "local0", "if_tag": "", "if_mac": "", "if_admin_state": 0, "if_link_state": 0, "if_link_mtu": 0, "if_sub_dot1ad": 0, "if_sub_id": 0, "if_tx_bytes": 0, "if_tx_packets": 0, "if_tx_errors": 0, "if_rx_bytes": 0, "if_rx_packets": 0, "if_rx_errors": 0, "if_drops": 0, "if_punts": 0 }, { "if_index": 1, "if_name": "TenGigabitEthernet5e/0/2", "if_tag": "", "if_mac": "11:33:55:77:99:aa", "if_admin_state": 1, "if_link_state": 1, "if_link_mtu": 9202, "if_sub_dot1ad": 0, "if_sub_id": 0, "if_tx_bytes": 5024976, "if_tx_packets": 40524, "if_tx_errors": 0, "if_rx_bytes": 200094228, "if_rx_packets": 1685702, "if_rx_errors": 0, "if_drops": 1214356, "if_punts": 0 }, { "if_index": 2, "if_name": "TenGigabitEthernet5e/0/3", "if_tag": "", "if_mac": "11:33:55:77:99:aa", "if_admin_state": 1, "if_link_state": 1, "if_link_mtu": 9202, "if_sub_dot1ad": 0, "if_sub_id": 0, "if_tx_bytes": 5024976, "if_tx_packets": 40524, "if_tx_errors": 0, "if_rx_bytes": 233044788, "if_rx_packets": 2257762, "if_rx_errors": 0, "if_drops": 1214348, "if_punts": 0 }, { "if_index": 3, "if_name": "BondEthernet0", "if_tag": "net-vpp.physnet:physnet1", "if_mac": "11:33:55:77:99:bb", "if_admin_state": 1, "if_link_state": 1, "if_link_mtu": 9216, "if_sub_dot1ad": 0, "if_sub_id": 0, "if_tx_bytes": 0, "if_tx_packets": 0, "if_tx_errors": 0, "if_rx_bytes": 0, "if_rx_packets": 0, "if_rx_errors": 0, "if_drops": 1514852, "if_punts": 0 }, { "if_index": 4, "if_name": "BondEthernet0.549", "if_tag": "net-vpp.uplink:physnet1.vlan.549", "if_mac": "", "if_admin_state": 1, "if_link_state": 1, "if_link_mtu": 9216, "if_sub_dot1ad": 0, "if_sub_id": 549, "if_tx_bytes": 0, "if_tx_packets": 0, "if_tx_errors": 0, "if_rx_bytes": 1968, "if_rx_packets": 26, "if_rx_errors": 0, "if_drops": 78, "if_punts": 0 }, { "if_index": 5, "if_name": "VirtualEthernet0/0/0", "if_tag": "net-vpp.port:fb9b1ce8-f643-45be-9298-ccd18f9018c8", "if_mac": "dd:ff:11:33:55:77", "if_admin_state": 1, "if_link_state": 0, "if_link_mtu": 9216, "if_sub_dot1ad": 0, "if_sub_id": 0, "if_tx_bytes": 0, "if_tx_packets": 0, "if_tx_errors": 26, "if_rx_bytes": 0, "if_rx_packets": 0, "if_rx_errors": 0, "if_drops": 0, "if_punts": 0 }, { "if_index": 6, "if_name": "BondEthernet0.529", "if_tag": "net-vpp.uplink:physnet1.vlan.529", "if_mac": "", "if_admin_state": 1, "if_link_state": 1, "if_link_mtu": 9216, "if_sub_dot1ad": 0, "if_sub_id": 529, "if_tx_bytes": 0, "if_tx_packets": 0, "if_tx_errors": 0, "if_rx_bytes": 0, "if_rx_packets": 0, "if_rx_errors": 0, "if_drops": 0, "if_punts": 0 }, { "if_index": 7, "if_name": "VirtualEthernet0/0/1", "if_tag": "net-vpp.port:bc726b1c-526e-4a8d-9f9a-c19b5dfe2b28", "if_mac": "22:44:66:88:aa:cc", "if_admin_state": 1, "if_link_state": 0, "if_link_mtu": 9216, "if_sub_dot1ad": 0, "if_sub_id": 0, "if_tx_bytes": 0, "if_tx_packets": 0, "if_tx_errors": 0, "if_rx_bytes": 0, "if_rx_packets": 0, "if_rx_errors": 0, "if_drops": 0, "if_punts": 0 }, { "if_index": 8, "if_name": "VirtualEthernet0/0/2", "if_tag": "net-vpp.port:aaabbbcc-a86d-4eb5-a3bc-aaabbbcccddd", "if_mac": "12:34:56:78:9a:bc", "if_admin_state": 1, "if_link_state": 0, "if_link_mtu": 9216, "if_sub_dot1ad": 0, "if_sub_id": 0, "if_tx_bytes": 0, "if_tx_packets": 0, "if_tx_errors": 26, "if_rx_bytes": 0, "if_rx_packets": 0, "if_rx_errors": 0, "if_drops": 0, "if_punts": 0 }, { "if_index": 9, "if_name": "VirtualEthernet0/0/3", "if_tag": "net-vpp.port:dddeeeff-838e-4995-9bd2-eeefff000111", "if_mac": "fe:dc:ba:98:76:54", "if_admin_state": 1, "if_link_state": 0, "if_link_mtu": 9216, "if_sub_dot1ad": 0, "if_sub_id": 0, "if_tx_bytes": 0, "if_tx_packets": 0, "if_tx_errors": 26, "if_rx_bytes": 0, "if_rx_packets": 0, "if_rx_errors": 0, "if_drops": 0, "if_punts": 0 } ] }