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 3E527A0A0F; Mon, 5 Jul 2021 14:50:28 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 940C4411EF; Mon, 5 Jul 2021 14:50:13 +0200 (CEST) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2053.outbound.protection.outlook.com [40.107.212.53]) by mails.dpdk.org (Postfix) with ESMTP id B4307411DD for ; Mon, 5 Jul 2021 14:50:11 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YTNAzdk8tScE9v/vE+mLclMQ28Vs3XgYujOBKb5NPtpqEFZcemBHeWhtfZIUo9wcWQuiNpYBkQwqKr5ZUnSFqB9YOwGdqjClECuPRIrD9kJNGh/vwE4V+Eq3/DCSErtK6e9ikSannF6h9hTE1TNAPNUji6d6R4QO0mmImNuhy9gzK+ksDYnzCSYD+8yXRKHdSGF/TDzP4E4iUs0OUh+I7uIJJWzk3s0+WdtdeD40j+l2DWIvJCpI5KlPZgY6B/DVbS612+uO4RoOUkZAAnZjx3Q+zFg8Ke1QbVYw7MLrYZWtamsDrrwxUsUkAzBl9k5B2/axWQ/Qdkq0KdhiQ97kzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8p4Rx+/oRoTR30lZCa6Xcumd3Rb+3bF1cH86hWueeEQ=; b=Js7PM+Hl03H3qbrOMdUBWR6cQpJjQuYNs7YtxKuHrbL5qDMJHrHC1BXvQN7dWP1Kd9hCT5akTdEAcbjdCrpRUuQpI8TDoAtdV5g1MaxJ3HdOnLZo6OCqg7qnQSmRRgvQC2QCNm6v2rEBO5hEQiICCEzgbmZJpb8s0n4YzHu5TL8OjD4BmvCrjyO3hnursV69aUTD8nGiysPDKRuyY3SDoXJr8J/w0zM/ekc5XphAyEx+XkzQLaEDoVaMEnef8mpFJ5dBCwELDmssO17ua4Ww99ri5CelXnch0P8wJoO8IMD7tTQJC+8v27sUa/8V12X9fupz1jhDYPaE6fgnafsKjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=intel.com smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8p4Rx+/oRoTR30lZCa6Xcumd3Rb+3bF1cH86hWueeEQ=; b=SWfl0bmOS/dCy8ttTw7D5zlQvJNQ0HuuFO+/h31XzMlLTMLzSEAJxeqOUEu9uZFwQKc3VB9/rfwPhCpK2s3RjvO8MH7yDvCXXYNIGZa2vlaIs0eHrIqTM/kAjyfIa5gSmpcQhu64xEES75lSIvhZC+UNrQiRZfa1Yl55hee+E0FTg2P3SHxYsgQdTSPQOoKMrdHPp2IZUmWqyebRwqGdprkGDVD+PJhAyKA2+TTGuyqaYTccr4br5yyzvjTWLBuo07d4PGemeT4LZQauTcZXRBXI8w4peN4asyDbmqU5D+tVnsEcqkkc5m48+63lZtmbweYLJKDFDbLEZWuzxc2tJA== Received: from MWHPR15CA0037.namprd15.prod.outlook.com (2603:10b6:300:ad::23) by DM6PR12MB4354.namprd12.prod.outlook.com (2603:10b6:5:28f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23; Mon, 5 Jul 2021 12:50:10 +0000 Received: from CO1NAM11FT059.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ad:cafe::cb) by MWHPR15CA0037.outlook.office365.com (2603:10b6:300:ad::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22 via Frontend Transport; Mon, 5 Jul 2021 12:50:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by CO1NAM11FT059.mail.protection.outlook.com (10.13.174.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4287.22 via Frontend Transport; Mon, 5 Jul 2021 12:50:10 +0000 Received: from nvidia.com (172.20.187.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 5 Jul 2021 12:50:08 +0000 From: Dmitry Kozlyuk To: CC: Anatoly Burakov , Viacheslav Ovsiienko Date: Mon, 5 Jul 2021 15:49:49 +0300 Message-ID: <20210705124950.902701-4-dkozlyuk@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210705124950.902701-1-dkozlyuk@nvidia.com> References: <20210705124950.902701-1-dkozlyuk@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9ae81123-e8e9-4ed2-ac29-08d93fb36c80 X-MS-TrafficTypeDiagnostic: DM6PR12MB4354: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1923; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7liDfoTYbrlb2xpE8Mu8UL36r5JDEbdaM3GpqnSUz82TIxWYs5bclxZr2vVsBNtjyS5RLDst0poDVgihiKEjtwLAjWnsHNateBwyNz6hpSU3IG5/LP8r1HcVHA8tTJR+G742lzr8mVrSbGD3zAwRnB6BYAkmP7rbNImzBnFdXSEP/8fpcXO9myfkOSRZ02p849MqTsQ5HZNAOctXVA/jC67TS34iAiXNCU0FSMcHRGAFTUNNM5YoCvJSEV204aDgyfYgXjsskHIP4wqKgnMJnYChtWnQcJbybyLtIItlbyNpykuqfR125GXRFVceLai25yPtl0ft+6eMIhWNhBB1TfHhQVI+S6Fe2p4oydIZApmIq+u9R15CiZheY5NwlG/3wbBCUVtbHUIBvzFcpRMKqwAl30H+fYD9yheOHH0B2JVvkAxichayXsfGyqBd8Ddb5kiWLbvEEEc/uSpCWF+Y8KWnlF93wg4PmWzPX9l0eTMBTZmvoxnuTmIGXZ+7EUfc4P6DHKw8UdFL9C74/ymDI5/kMMnrEXXi80ndOjMvjdC175bn0k/Jsab5Dw9bulyGNYJWbbQ6wLS8qRqROUrFEcJcQo1VOTOthw43qNhlJQX+4zEEV6qXeQ4KaVvKVGPA8NS07xWnip+we2pMXkSJHwlUE8A5xxtPjMHbvQvI5DOXd6OHGGNH2cgi6c8tvodP X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(346002)(376002)(396003)(136003)(46966006)(36840700001)(36756003)(82740400003)(70206006)(107886003)(47076005)(55016002)(70586007)(16526019)(36860700001)(26005)(4326008)(82310400003)(6666004)(54906003)(7696005)(5660300002)(6286002)(186003)(356005)(478600001)(1076003)(86362001)(316002)(36906005)(8676002)(7636003)(336012)(2906002)(2616005)(8936002)(426003)(6916009); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jul 2021 12:50:10.0654 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ae81123-e8e9-4ed2-ac29-08d93fb36c80 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT059.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4354 Subject: [dpdk-dev] [PATCH 21.11 3/3] app/test: add allocator performance autotest 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 Sender: "dev" Memory allocator performance is crucial to applications that deal with large amount of memory or allocate frequently. DPDK allocator performance is affected by EAL options, API used and, at least, allocation size. New autotest is intended to be run with different EAL options. It measures performance with a range of sizes for dirrerent APIs: rte_malloc, rte_zmalloc, and rte_memzone_reserve. Work distribution between allocation and deallocation depends on EAL options. The test prints both times and total time to ease comparison. Memory can be filled with zeroes at different points of allocation path, but it always takes considerable fraction of overall timing. This is why the test measures filling speed and prints how long clearing would take for each size as a hint. Signed-off-by: Dmitry Kozlyuk Reviewed-by: Viacheslav Ovsiienko --- app/test/meson.build | 2 + app/test/test_malloc_perf.c | 155 ++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 app/test/test_malloc_perf.c diff --git a/app/test/meson.build b/app/test/meson.build index 0a5f425578..4fd2694267 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -77,6 +77,7 @@ test_sources = files( 'test_lpm6_perf.c', 'test_lpm_perf.c', 'test_malloc.c', + 'test_malloc_perf.c', 'test_mbuf.c', 'test_member.c', 'test_member_perf.c', @@ -273,6 +274,7 @@ fast_tests = [ perf_test_names = [ 'ring_perf_autotest', + 'malloc_perf_autotest', 'mempool_perf_autotest', 'memcpy_perf_autotest', 'hash_perf_autotest', diff --git a/app/test/test_malloc_perf.c b/app/test/test_malloc_perf.c new file mode 100644 index 0000000000..5e9396a5d8 --- /dev/null +++ b/app/test/test_malloc_perf.c @@ -0,0 +1,155 @@ +#include +#include +#include +#include + +#include "test.h" + +typedef void * (alloc_t)(const char *name, size_t size, unsigned int align); +typedef void (free_t)(void *addr); + +static const uint64_t KB = 1 << 10; +static const uint64_t GB = 1 << 30; + +static double +tsc_to_us(uint64_t tsc, size_t runs) +{ + return (double)tsc / rte_get_tsc_hz() * US_PER_S / runs; +} + +static int +test_memset_perf(double *us_per_gb) +{ + static const size_t RUNS = 20; + + void *ptr; + size_t i; + uint64_t tsc; + + puts("Performance: memset"); + + ptr = rte_malloc(NULL, GB, 0); + if (ptr == NULL) { + printf("rte_malloc(size=%"PRIx64") failed\n", GB); + return -1; + } + + tsc = rte_rdtsc_precise(); + for (i = 0; i < RUNS; i++) + memset(ptr, 0, GB); + tsc = rte_rdtsc_precise() - tsc; + + *us_per_gb = tsc_to_us(tsc, RUNS); + printf("Result: %f.3 GiB/s <=> %.2f us/MiB\n", + US_PER_S / *us_per_gb, *us_per_gb / KB); + + rte_free(ptr); + putchar('\n'); + return 0; +} + +static int +test_alloc_perf(const char *name, alloc_t *alloc_fn, free_t free_fn, + size_t max_runs, double memset_gb_us) +{ + static const size_t SIZES[] = { + 1 << 6, 1 << 7, 1 << 10, 1 << 12, 1 << 16, 1 << 20, + 1 << 21, 1 << 22, 1 << 24, 1 << 30 }; + + size_t i, j; + void **ptrs; + + printf("Performance: %s\n", name); + + ptrs = calloc(max_runs, sizeof(ptrs[0])); + if (ptrs == NULL) { + puts("Cannot allocate memory for pointers"); + return -1; + } + + printf("%12s%8s%12s%12s%12s%12s\n", + "Size (B)", "Runs", "Alloc (us)", "Free (us)", + "Total (us)", "memset (us)"); + for (i = 0; i < RTE_DIM(SIZES); i++) { + size_t size = SIZES[i]; + size_t runs_done; + uint64_t tsc_start, tsc_alloc, tsc_free; + double alloc_time, free_time, memset_time; + + tsc_start = rte_rdtsc_precise(); + for (j = 0; j < max_runs; j++) { + ptrs[j] = alloc_fn(NULL, size, 0); + if (ptrs[j] == NULL) + break; + } + tsc_alloc = rte_rdtsc_precise() - tsc_start; + + if (j == 0) { + printf("%12zu Interrupted: out of memory.\n", size); + break; + } + runs_done = j; + + tsc_start = rte_rdtsc_precise(); + for (j = 0; j < runs_done && ptrs[j] != NULL; j++) + free_fn(ptrs[j]); + tsc_free = rte_rdtsc_precise() - tsc_start; + + alloc_time = tsc_to_us(tsc_alloc, runs_done); + free_time = tsc_to_us(tsc_free, runs_done); + memset_time = memset_gb_us * size / GB; + printf("%12zu%8lu%12.2f%12.2f%12.2f%12.2f\n", + size, runs_done, alloc_time, free_time, + alloc_time + free_time, memset_time); + + memset(ptrs, 0, max_runs * sizeof(ptrs[0])); + } + + free(ptrs); + putchar('\n'); + return 0; +} + +static void * +memzone_alloc(const char *name __rte_unused, size_t size, unsigned int align) +{ + const struct rte_memzone *mz; + char gen_name[RTE_MEMZONE_NAMESIZE]; + + snprintf(gen_name, sizeof(gen_name), "test-mz-%"PRIx64, rte_rdtsc()); + mz = rte_memzone_reserve_aligned(gen_name, size, SOCKET_ID_ANY, + RTE_MEMZONE_1GB | RTE_MEMZONE_SIZE_HINT_ONLY, align); + return (void *)(uintptr_t)mz; +} + +static void +memzone_free(void *addr) +{ + rte_memzone_free((struct rte_memzone *)addr); +} + +static int +test_malloc_perf(void) +{ + static const size_t MAX_RUNS = 10000; + + double memset_gb_us; + + if (test_memset_perf(&memset_gb_us) < 0) + return -1; + + if (test_alloc_perf("rte_malloc", rte_malloc, rte_free, + MAX_RUNS, memset_gb_us) < 0) + return -1; + if (test_alloc_perf("rte_zmalloc", rte_zmalloc, rte_free, + MAX_RUNS, memset_gb_us) < 0) + return -1; + + if (test_alloc_perf("rte_memzone_reserve", memzone_alloc, memzone_free, + RTE_MAX_MEMZONE - 1, memset_gb_us) < 0) + return -1; + + return 0; +} + +REGISTER_TEST_COMMAND(malloc_perf_autotest, test_malloc_perf); -- 2.25.1