[v9,7/7] app/test: add memarea to malloc-perf-autotest
Checks
Commit Message
This patch adds memarea to malloc_perf_autotest.
Test platform: Kunpeng920
Test command: dpdk-test -a 0000:7d:00.3 -l 10-12
Test result:
USER1: Performance: rte_memarea
USER1: Size (B) Runs Alloc (us) Free (us) Total (us) memset (us)
USER1: 64 10000 0.04 0.04 0.08 0.01
USER1: 128 10000 0.03 0.03 0.06 0.01
USER1: 1024 10000 0.03 0.04 0.07 0.20
USER1: 4096 10000 0.03 0.05 0.08 0.34
USER1: 65536 10000 0.10 0.06 0.16 2.15
USER1: 1048576 1023 0.11 0.04 0.15 29.15
USER1: 2097152 511 0.12 0.04 0.16 57.72
USER1: 4194304 255 0.14 0.04 0.17 114.93
USER1: 16777216 63 0.15 0.07 0.21 457.51
USER1: 1073741824 Interrupted: out of memory.
Compared with rte_malloc:
USER1: Performance: rte_malloc
USER1: Size (B) Runs Alloc (us) Free (us) Total (us) memset (us)
USER1: 64 10000 0.14 0.07 0.21 0.01
USER1: 128 10000 0.10 0.05 0.15 0.01
USER1: 1024 10000 0.11 0.18 0.29 0.21
USER1: 4096 10000 0.13 0.39 0.53 0.35
USER1: 65536 10000 0.17 2.27 2.44 2.15
USER1: 1048576 10000 37.21 71.63 108.84 29.08
USER1: 2097152 10000 8831.15 160.02 8991.17 63.52
USER1: 4194304 10000 47131.88 413.75 47545.62 173.79
USER1: 16777216 4221 119604.60 2209.73 121814.34 964.42
USER1: 1073741824 31 335058.32 223369.31 558427.63 62440.87
Note: The rte_malloc time includes obtaining memory from the system,
but rte_memarea time don't includes these (it uses pre-allocated
policy).
Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
app/test/test_malloc_perf.c | 75 +++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
@@ -147,6 +147,78 @@ memzone_free(void *addr)
rte_memzone_free((struct rte_memzone *)addr);
}
+#ifndef RTE_EXEC_ENV_WINDOWS
+#include <rte_memarea.h>
+
+static struct rte_memarea *test_ma;
+
+static int
+memarea_pre_env(void)
+{
+ struct rte_memarea_param init;
+
+ memset(&init, 0, sizeof(init));
+ snprintf(init.name, sizeof(init.name), "perftest");
+ init.source = RTE_MEMAREA_SOURCE_HEAP;
+ init.alg = RTE_MEMAREA_ALG_NEXTFIT;
+ init.total_sz = GB;
+ init.mt_safe = 1;
+ init.numa_socket = SOCKET_ID_ANY;
+
+ test_ma = rte_memarea_create(&init);
+ if (test_ma == NULL) {
+ fprintf(stderr, "memarea create failed, skip memarea perftest!\n");
+ return -1;
+ }
+ return 0;
+}
+
+static void
+memarea_clear_env(void)
+{
+ rte_memarea_destroy(test_ma);
+ test_ma = NULL;
+}
+
+static void *
+memarea_alloc(const char *name, size_t size, unsigned int align)
+{
+ RTE_SET_USED(name);
+ RTE_SET_USED(align);
+ return rte_memarea_alloc(test_ma, size, 0);
+}
+
+static void
+memarea_free(void *addr)
+{
+ rte_memarea_free(test_ma, addr);
+}
+
+static int
+memarea_perftest(double memset_gb_us, size_t max_runs)
+{
+ if (memarea_pre_env() < 0)
+ return 0;
+
+ if (test_alloc_perf("rte_memarea", memarea_alloc, memarea_free,
+ memset, memset_gb_us, max_runs) < 0) {
+ memarea_clear_env();
+ return -1;
+ }
+
+ memarea_clear_env();
+ return 0;
+}
+#else
+static int
+memarea_perftest(double memset_gb_us, size_t max_runs)
+{
+ RTE_SET_USED(memset_gb_us);
+ RTE_SET_USED(max_runs);
+ return 0;
+}
+#endif /* !RTE_EXEC_ENV_WINDOWS */
+
static int
test_malloc_perf(void)
{
@@ -168,6 +240,9 @@ test_malloc_perf(void)
NULL, memset_us_gb, RTE_MAX_MEMZONE - 1) < 0)
return -1;
+ if (memarea_perftest(memset_us_gb, MAX_RUNS) < 0)
+ return -1;
+
return 0;
}