summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorTomasz Jozwiak <tomaszx.jozwiak@intel.com>2019-03-01 09:46:16 +0100
committerThomas Monjalon <thomas@monjalon.net>2019-03-23 16:54:50 +0100
commita7cece2ead257183daed2e9a2b97cb82033daa9d (patch)
tree43781a552d9db30b99799346cdea79c5e8b26218 /app
parent1534cc6ab1d93041dcbb0bb6c7f1e111578dffd4 (diff)
downloaddpdk-next-eventdev-a7cece2ead257183daed2e9a2b97cb82033daa9d.zip
dpdk-next-eventdev-a7cece2ead257183daed2e9a2b97cb82033daa9d.tar.gz
dpdk-next-eventdev-a7cece2ead257183daed2e9a2b97cb82033daa9d.tar.xz
malloc: add NUMA-aware realloc function
Currently, rte_realloc will not respect original allocation's NUMA node when memory cannot be resized, and there is no NUMA-aware equivalent of rte_realloc. This patch adds such a function. The new API will ensure that reallocated memory stays on requested NUMA node, as well as allow moving allocated memory to a different NUMA node. Signed-off-by: Tomasz Jozwiak <tomaszx.jozwiak@intel.com> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Diffstat (limited to 'app')
-rw-r--r--app/test/test_malloc.c53
1 files changed, 51 insertions, 2 deletions
diff --git a/app/test/test_malloc.c b/app/test/test_malloc.c
index 6b6c6fe..f0e608c 100644
--- a/app/test/test_malloc.c
+++ b/app/test/test_malloc.c
@@ -1,5 +1,5 @@
/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2010-2014 Intel Corporation
+ * Copyright(c) 2010-2019 Intel Corporation
*/
#include <stdio.h>
@@ -26,6 +26,13 @@
#define N 10000
+
+static int
+is_mem_on_socket(int32_t socket);
+
+static int32_t
+addr_to_socket(void *addr);
+
/*
* Malloc
* ======
@@ -542,7 +549,49 @@ test_realloc(void)
return -1;
}
rte_free(ptr12);
- return 0;
+
+ /* check realloc_socket part */
+ int32_t socket_count = 0, socket_allocated, socket;
+ int ret = -1;
+ size_t size = 1024;
+
+ ptr1 = NULL;
+ for (socket = 0; socket < RTE_MAX_NUMA_NODES; socket++) {
+ if (is_mem_on_socket(socket)) {
+ int j = 2;
+
+ socket_count++;
+ while (j--) {
+ /* j == 1 -> resizing */
+ ptr2 = rte_realloc_socket(ptr1, size,
+ RTE_CACHE_LINE_SIZE,
+ socket);
+ if (ptr2 == NULL) {
+ printf("NULL pointer returned from rte_realloc_socket\n");
+ goto end;
+ }
+
+ ptr1 = ptr2;
+ socket_allocated = addr_to_socket(ptr2);
+ if (socket_allocated != socket) {
+ printf("Requested socket (%d) doesn't mach allocated one (%d)\n",
+ socket, socket_allocated);
+ goto end;
+ }
+ size += RTE_CACHE_LINE_SIZE;
+ }
+ }
+ }
+
+ /* Print warnign if only a single socket, but don't fail the test */
+ if (socket_count < 2)
+ printf("WARNING: realloc_socket test needs memory on multiple sockets!\n");
+
+ ret = 0;
+end:
+ rte_free(ptr1);
+
+ return ret;
}
static int