From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 14F62A0556; Mon, 17 Oct 2022 05:47:34 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 435204282E; Mon, 17 Oct 2022 05:46:58 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 1633640143 for ; Mon, 17 Oct 2022 05:46:50 +0200 (CEST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MrNGB4dqqzHvh1; Mon, 17 Oct 2022 11:46:42 +0800 (CST) Received: from localhost.localdomain (10.67.165.24) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 17 Oct 2022 11:46:46 +0800 From: Chengwen Feng To: , , , , , CC: , Subject: [PATCH v10 7/7] app/test: add memarea to malloc-perf-autotest Date: Mon, 17 Oct 2022 03:40:58 +0000 Message-ID: <20221017034058.34176-8-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221017034058.34176-1-fengchengwen@huawei.com> References: <20220721044648.6817-1-fengchengwen@huawei.com> <20221017034058.34176-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500024.china.huawei.com (7.185.36.10) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch adds memarea perftest to malloc_perf_autotest. The memarea perftest contains two part: 1) rte_memarea.heap: the memory source comes from invoking rte_malloc_socket(). 2) rte_memarea.libc: the memory source comes from invoking malloc(). Test platform: Kunpeng920 Test command: dpdk-test -a 0000:7d:00.3 -l 10-12 Test result: USER1: Performance: rte_memarea.heap 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. USER1: Performance: rte_memarea.libc USER1: Size (B) Runs Alloc (us) Free (us) Total (us) memset (us) USER1: 64 10000 0.12 0.03 0.15 0.01 USER1: 128 10000 0.03 0.03 0.06 0.01 USER1: 1024 10000 0.15 0.04 0.19 0.19 USER1: 4096 10000 0.51 0.04 0.54 0.34 USER1: 65536 10000 9.40 0.06 9.46 2.14 USER1: 1048576 1023 48.39 0.07 48.46 29.15 USER1: 2097152 511 0.11 0.06 0.17 57.79 USER1: 4194304 255 0.11 0.06 0.18 114.82 USER1: 16777216 63 0.12 0.07 0.19 457.86 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 --- app/test/test_malloc_perf.c | 82 +++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/app/test/test_malloc_perf.c b/app/test/test_malloc_perf.c index ccec43ae84..0972f4dec7 100644 --- a/app/test/test_malloc_perf.c +++ b/app/test/test_malloc_perf.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "test.h" @@ -20,6 +21,8 @@ typedef void * (memset_t)(void *addr, int value, size_t size); static const uint64_t KB = 1 << 10; static const uint64_t GB = 1 << 30; +static struct rte_memarea *ma_perftest_handle; + static double tsc_to_us(uint64_t tsc, size_t runs) { @@ -147,6 +150,80 @@ memzone_free(void *addr) rte_memzone_free((struct rte_memzone *)addr); } +static const char * +memarea_perftest_source_name(enum rte_memarea_source source) +{ + if (source == RTE_MEMAREA_SOURCE_HEAP) + return "heap"; + else if (source == RTE_MEMAREA_SOURCE_LIBC) + return "libc"; + else + return "unknown"; +} + +static int +memarea_perftest_pre_env(enum rte_memarea_source source) +{ + struct rte_memarea_param init; + + memset(&init, 0, sizeof(init)); + snprintf(init.name, sizeof(init.name), "perftest"); + init.source = source; + init.alg = RTE_MEMAREA_ALG_NEXTFIT; + init.total_sz = GB; + init.mt_safe = 1; + init.numa_socket = SOCKET_ID_ANY; + + ma_perftest_handle = rte_memarea_create(&init); + if (ma_perftest_handle == NULL) { + fprintf(stderr, "memarea create failed, skip memarea source: %s perftest!\n", + memarea_perftest_source_name(source)); + return -1; + } + return 0; +} + +static void +memarea_perftest_clear_env(void) +{ + rte_memarea_destroy(ma_perftest_handle); + ma_perftest_handle = NULL; +} + +static void * +memarea_perftest_alloc(const char *name, size_t size, unsigned int align) +{ + RTE_SET_USED(name); + RTE_SET_USED(align); + return rte_memarea_alloc(ma_perftest_handle, size, 0); +} + +static void +memarea_perftest_free(void *addr) +{ + rte_memarea_free(ma_perftest_handle, addr); +} + +static int +memarea_perftest(enum rte_memarea_source source, double memset_gb_us, size_t max_runs) +{ + char test_name[64] = { 0 }; + + if (memarea_perftest_pre_env(source) < 0) + return 0; + + snprintf(test_name, sizeof(test_name), "rte_memarea.%s", + memarea_perftest_source_name(source)); + if (test_alloc_perf(test_name, memarea_perftest_alloc, memarea_perftest_free, + memset, memset_gb_us, max_runs) < 0) { + memarea_perftest_clear_env(); + return -1; + } + + memarea_perftest_clear_env(); + return 0; +} + static int test_malloc_perf(void) { @@ -168,6 +245,11 @@ test_malloc_perf(void) NULL, memset_us_gb, RTE_MAX_MEMZONE - 1) < 0) return -1; + if (memarea_perftest(RTE_MEMAREA_SOURCE_HEAP, memset_us_gb, MAX_RUNS) < 0) + return -1; + if (memarea_perftest(RTE_MEMAREA_SOURCE_LIBC, memset_us_gb, MAX_RUNS) < 0) + return -1; + return 0; } -- 2.17.1