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 6D82C45952; Tue, 10 Sep 2024 08:30:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AF11B427A1; Tue, 10 Sep 2024 08:30:23 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2050.outbound.protection.outlook.com [40.107.22.50]) by mails.dpdk.org (Postfix) with ESMTP id DDEE940151 for ; Tue, 10 Sep 2024 08:30:18 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iLsBUfAU3Q/FXtZkz3pPH3n5rx+OdYfxnsYUtP3o3y2Hvtc/PJtvx83gxRmllnz7K8FQWQfHwW6rmLVyhr6cvlIMWKNLvBSYE6D80lT1fhbcp52t93ItbK8wdJgofwhRKrK/XshK3d0OAqwlv/CGQyOKxrvG7VYvxH/pfMHYvA4dgZRPtGm7firsRemR+IWbpq5yCJQee/fXVgSAIQ2PTYbk0mkfcw94/ZnR0U57BwEHpFn+lRl7yUnixJ7V87MGDAFpmdLRamMTIkC0E0SQrrbru6qWK/7x1KjPoyCJGKB+zezdpD0E54HcYaFolsdrNmmrtpAeyv5fE2O/ixMbjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=FORcAcTImC3VO+jULR5YD9MPGU81/5BIeguEUjIfy6I=; b=CcgrmrmESpTELVr1GMbt3q35J83g4VmLHIhUj+M02BxUjuMwgrmNQ2xJdHGteDdnneOdTy818VD3QAniHPIXl2/y3Rnc8N5xykovwhG9ht83Uod91hok2vtgoqvY7M4kmLLIWK8sozz0oFwQhIvKe8sUqMWgtiUJzCCRG8vCLdHkBujLNI9+xtbxTZIuq8/3QVLvuljkYxvzaAamreqKNfFpfZDNOJ3dUicoiEdgjYuEqSMws6Ll+OWnpv4fF/uZm5Ss4IhkGFZDN1uhN8vDGosVCusVcjLYbCFY5QNUnI6+4Uj2ZhEL5AIeGPs3O1Kz7X7iXQx3fFhFBUiUIcLiHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 192.176.1.74) smtp.rcpttodomain=dpdk.org smtp.mailfrom=ericsson.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=ericsson.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericsson.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FORcAcTImC3VO+jULR5YD9MPGU81/5BIeguEUjIfy6I=; b=FnEbdpj7eMM4gBkcZBSRpLaOUw94+mLKskNY/y4f+SZUzO2sau01zvy/5triwmwKb2J+Iya+JZ6Qds+VK5kaU72tUt2gjDihchd8iamT358KF3pfSY0VhhuvmvBDjwFxF1/M7Dew4pGaFdNQVm3OLi6VA6vXBmBhcOzIUeChtMRFBxGNamI6+V8828z3Z18K/1nOf8cEcRw5V8KlEdmVSEwL6SWX501uYqc6wriVtx8ujdOYAKUlHw2GMgZQacNb9mtkwSsxEqW/S3GHEhgvJK4sqYANKbccBUlwCDrOBNF683/jOR4kzjrwJPxiBsHz9+tmtD8v0tkH9NB9lSxnig== Received: from DUZPR01CA0139.eurprd01.prod.exchangelabs.com (2603:10a6:10:4bd::14) by VI1PR0701MB6990.eurprd07.prod.outlook.com (2603:10a6:800:19e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.23; Tue, 10 Sep 2024 06:30:14 +0000 Received: from DB5PEPF00014B88.eurprd02.prod.outlook.com (2603:10a6:10:4bd:cafe::bf) by DUZPR01CA0139.outlook.office365.com (2603:10a6:10:4bd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.25 via Frontend Transport; Tue, 10 Sep 2024 06:30:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 192.176.1.74) smtp.mailfrom=ericsson.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=ericsson.com; Received-SPF: Pass (protection.outlook.com: domain of ericsson.com designates 192.176.1.74 as permitted sender) receiver=protection.outlook.com; client-ip=192.176.1.74; helo=oa.msg.ericsson.com; pr=C Received: from oa.msg.ericsson.com (192.176.1.74) by DB5PEPF00014B88.mail.protection.outlook.com (10.167.8.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Tue, 10 Sep 2024 06:30:13 +0000 Received: from seliicinfr00050.seli.gic.ericsson.se (153.88.142.248) by smtp-central.internal.ericsson.com (100.87.178.68) with Microsoft SMTP Server id 15.2.1544.11; Tue, 10 Sep 2024 08:30:13 +0200 Received: from breslau.. (seliicwb00002.seli.gic.ericsson.se [10.156.25.100]) by seliicinfr00050.seli.gic.ericsson.se (Postfix) with ESMTP id DDCE81C006A; Tue, 10 Sep 2024 08:30:12 +0200 (CEST) From: =?UTF-8?q?Mattias=20R=C3=B6nnblom?= To: CC: , Heng Wang , "Stephen Hemminger" , Tyler Retzlaff , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Jack Bond-Preston , David Marchand , Chengwen Feng , =?UTF-8?q?Mattias=20R=C3=B6nnblom?= Subject: [PATCH v5 5/6] eal: add unit tests for atomic bit access functions Date: Tue, 10 Sep 2024 08:20:50 +0200 Message-ID: <20240910062051.699096-6-mattias.ronnblom@ericsson.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910062051.699096-1-mattias.ronnblom@ericsson.com> References: <20240909145743.697342-2-mattias.ronnblom@ericsson.com> <20240910062051.699096-1-mattias.ronnblom@ericsson.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB5PEPF00014B88:EE_|VI1PR0701MB6990:EE_ X-MS-Office365-Filtering-Correlation-Id: 356b6b5b-8fe9-4369-a03b-08dcd1620742 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: =?utf-8?B?Mmt5cGxoazRlemxxQVFOSk8zb3hzUkg0VEY3QmM5UDBGZ1pUaWNKOHpkMEY5?= =?utf-8?B?YnZXNDIyeVppem9ta24vTVRWbzlrc1RnVGUrQk95STRSWE9ZaUxKTUFydWpS?= =?utf-8?B?Q0swWExFTGo3eWtqRmNHMEhVMGFjc3RUMDR2a3N2VHVBQlZOZnEvL0lpYTJj?= =?utf-8?B?amoxTldWMjJnZUxSMUFKc1c3QWRaSVRIdUdhRUFUdDFnYVlxeG0wSUlYZ240?= =?utf-8?B?ZzNUSUtNOElwYmFpZ003NCs1bVNaVitZWFBwT0RHTGNMdnVBaFhiNEdqYTRk?= =?utf-8?B?QnpjbUhDVmdkcFFRUForMWhqbG05cUExVVR0UitMVlFLWGxSYjVBa1pScDBF?= =?utf-8?B?TzJYcWFYWWNWV05QekZyRTFDajFXNG82Z016MEw5ZENLZkZmSWFsSjF0YUx4?= =?utf-8?B?SGtKOGx4cCtUaWIwYzNhWk9JY2VJaXpIRENWQzFPZlJuMjNiVjM2YjNFVDhB?= =?utf-8?B?VXdnZkdzK0hVcTBFUk9YUExZeGJuWUpwa2NVRUFWcGMxR0RZU1ZITW44QStE?= =?utf-8?B?TWpxL1IvUkN2SkkyUnFDMlBVakwzeTVZdWpXV0JUeklsTkFnTTBuYWRZMnUv?= =?utf-8?B?ZWVBSVluVU50TU9wQW5LbWdQYzVKWi9raURPNmFvdXQzSEl3U3l4UkVVQzhS?= =?utf-8?B?WXJQVmd2cmw0b2QvTWdFNkFyNDEwa1NqdGo5TFVrMjdabkNRdVBSN3ZzZStE?= =?utf-8?B?SW5jN3BEMWtmcURIUWtMUzE5ZG9pOVBwWmpQTGpNSm9JRzhvK1Z0cnJuc2tU?= =?utf-8?B?TFFiWUV3UXA4R0c3OXdJSkg3aWcyOHFnSzZxbjJyNHpXSmFqd0h3cktnVzhw?= =?utf-8?B?UWRKZ0RaRzM0YWF2TXpaOFJtUFRVN2lHL0s0ZS9jVll4SWxqcENRcjlDMlVC?= =?utf-8?B?emFYYmFuOTE4MDNVdVVjVVAwNGtTeHBRR2VOSEhvaDdiYTkyOWw3ME5ER0tZ?= =?utf-8?B?OUg0NzI3MUxsWUdpM1RWWkJOQTI4cHlyQXBlN0NJOHBmb1dTcVRFQk1DblN1?= =?utf-8?B?QnhnWVZ6QU92M09TMElUaTdNRTNIRnJEWDdCWlVlUUlDbXpXQ29sM3pDeUtR?= =?utf-8?B?NzRxUFgrMmhHSjBoY0p2OUdYcnE0SVhCOHhOTmpHSHpMQlo5R0FMbmpodDIy?= =?utf-8?B?RW10WTlqOUIzWEpTa2hlNmdHYy9MVnUxcHhmamZJcE55UWk2SWdhVnZXUFZI?= =?utf-8?B?VWRQL0ZLUFg1aTFZblBEQkpUR01uTUpMak5wK1lmSWdVenRaTTRqR3VwZ2g2?= =?utf-8?B?VXhiYnpHLzNlYXFwTXZtMFRrN21HVi9lajJMSDdBekw4cEFtVFluSHdSMGFp?= =?utf-8?B?ZmpUbTR5bWU3MHBoL21WenRvN2Z1T3pNQmxoMnZMRTRWZjFVSE5idy9na3dQ?= =?utf-8?B?UW43dnR2dWdScjl5TUh1amJyOWVsWnpFQ21OR1FuSjZueElUL3lwTStVSytm?= =?utf-8?B?ZVArYVhCZlppWDV6YXNEdmVqbGpQVHhDNWtTeHFKeFdWUXhDRWl5aUZlR3E4?= =?utf-8?B?YzlobWpzb0hLcCtPOWl3blY3NEpORkxETkhybS9BZDg0YTJ5TmZuWTZIMWxQ?= =?utf-8?B?UkN5eW40L2x5NFpQYkViZXFHK2JpUVZ6UzJ4RjlUMGV3SGwvTm9WU3BQbHg5?= =?utf-8?B?bE9RY1kvWkFYTUhkMktPeGdHUzBNNHpsa1FpeFc0aFZ4SGJ1QW9HMTEzU3Ur?= =?utf-8?B?SmpGNWVNMDBHVURWL1k5UGo5dSthcGJMVmJZYWpQVHVkZElHSnFWVENabkxT?= =?utf-8?B?TWVLOWI2SitJN0tUcXhUZ1QrRnJZaFEvOGVRdWM1Q3M5cXlpekx3Y3NzdHV3?= =?utf-8?B?MWw4eENNNDdRNk9uVnEzYXlsTU52SFZtR0ZUb0ZQMThvWlJ3dWVFSWt6ejlQ?= =?utf-8?B?UFZkdWY0c2ZjNHBjVnQ3TnBzcXNEKzFvT1FoUlhGaWdjTGVkOURRNzA0b2k3?= =?utf-8?Q?CxavoiLxJ63Jl5ruaHOEOkJalWfsUMo0?= X-Forefront-Antispam-Report: CIP:192.176.1.74; CTRY:SE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:oa.msg.ericsson.com; PTR:office365.se.ericsson.net; CAT:NONE; SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: ericsson.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2024 06:30:13.7793 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 356b6b5b-8fe9-4369-a03b-08dcd1620742 X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=92e84ceb-fbfd-47ab-be52-080c6b87953f; Ip=[192.176.1.74]; Helo=[oa.msg.ericsson.com] X-MS-Exchange-CrossTenant-AuthSource: DB5PEPF00014B88.eurprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0701MB6990 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 Extend bitops tests to cover the rte_bit_atomic_*() family of functions. Signed-off-by: Mattias Rönnblom Acked-by: Morten Brørup Acked-by: Tyler Retzlaff Acked-by: Jack Bond-Preston -- RFC v4: * Add atomicity test for atomic bit flip. RFC v3: * Rename variable 'main' to make ICC happy. --- app/test/test_bitops.c | 313 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 312 insertions(+), 1 deletion(-) diff --git a/app/test/test_bitops.c b/app/test/test_bitops.c index 322f58c066..b80216a0a1 100644 --- a/app/test/test_bitops.c +++ b/app/test/test_bitops.c @@ -3,10 +3,13 @@ * Copyright(c) 2024 Ericsson AB */ +#include #include -#include #include +#include +#include +#include #include #include "test.h" @@ -61,6 +64,304 @@ GEN_TEST_BIT_ACCESS(test_bit_access32, rte_bit_set, rte_bit_clear, GEN_TEST_BIT_ACCESS(test_bit_access64, rte_bit_set, rte_bit_clear, rte_bit_assign, rte_bit_flip, rte_bit_test, 64) +#define bit_atomic_set(addr, nr) \ + rte_bit_atomic_set(addr, nr, rte_memory_order_relaxed) + +#define bit_atomic_clear(addr, nr) \ + rte_bit_atomic_clear(addr, nr, rte_memory_order_relaxed) + +#define bit_atomic_assign(addr, nr, value) \ + rte_bit_atomic_assign(addr, nr, value, rte_memory_order_relaxed) + +#define bit_atomic_flip(addr, nr) \ + rte_bit_atomic_flip(addr, nr, rte_memory_order_relaxed) + +#define bit_atomic_test(addr, nr) \ + rte_bit_atomic_test(addr, nr, rte_memory_order_relaxed) + +GEN_TEST_BIT_ACCESS(test_bit_atomic_access32, bit_atomic_set, + bit_atomic_clear, bit_atomic_assign, + bit_atomic_flip, bit_atomic_test, 32) + +GEN_TEST_BIT_ACCESS(test_bit_atomic_access64, bit_atomic_set, + bit_atomic_clear, bit_atomic_assign, + bit_atomic_flip, bit_atomic_test, 64) + +#define PARALLEL_TEST_RUNTIME 0.25 + +#define GEN_TEST_BIT_PARALLEL_ASSIGN(size) \ + \ + struct parallel_access_lcore ## size \ + { \ + unsigned int bit; \ + uint ## size ##_t *word; \ + bool failed; \ + }; \ + \ + static int \ + run_parallel_assign ## size(void *arg) \ + { \ + struct parallel_access_lcore ## size *lcore = arg; \ + uint64_t deadline = rte_get_timer_cycles() + \ + PARALLEL_TEST_RUNTIME * rte_get_timer_hz(); \ + bool value = false; \ + \ + do { \ + bool new_value = rte_rand() & 1; \ + bool use_test_and_modify = rte_rand() & 1; \ + bool use_assign = rte_rand() & 1; \ + \ + if (rte_bit_atomic_test(lcore->word, lcore->bit, \ + rte_memory_order_relaxed) != value) { \ + lcore->failed = true; \ + break; \ + } \ + \ + if (use_test_and_modify) { \ + bool old_value; \ + if (use_assign) \ + old_value = rte_bit_atomic_test_and_assign( \ + lcore->word, lcore->bit, new_value, \ + rte_memory_order_relaxed); \ + else { \ + old_value = new_value ? \ + rte_bit_atomic_test_and_set( \ + lcore->word, lcore->bit, \ + rte_memory_order_relaxed) : \ + rte_bit_atomic_test_and_clear( \ + lcore->word, lcore->bit, \ + rte_memory_order_relaxed); \ + } \ + if (old_value != value) { \ + lcore->failed = true; \ + break; \ + } \ + } else { \ + if (use_assign) \ + rte_bit_atomic_assign(lcore->word, lcore->bit, \ + new_value, \ + rte_memory_order_relaxed); \ + else { \ + if (new_value) \ + rte_bit_atomic_set( \ + lcore->word, lcore->bit, \ + rte_memory_order_relaxed); \ + else \ + rte_bit_atomic_clear( \ + lcore->word, lcore->bit, \ + rte_memory_order_relaxed); \ + } \ + } \ + \ + value = new_value; \ + } while (rte_get_timer_cycles() < deadline); \ + \ + return 0; \ + } \ + \ + static int \ + test_bit_atomic_parallel_assign ## size(void) \ + { \ + unsigned int worker_lcore_id; \ + uint ## size ## _t word = 0; \ + struct parallel_access_lcore ## size lmain = { \ + .word = &word \ + }; \ + struct parallel_access_lcore ## size lworker = { \ + .word = &word \ + }; \ + \ + if (rte_lcore_count() < 2) { \ + printf("Need multiple cores to run parallel test.\n"); \ + return TEST_SKIPPED; \ + } \ + \ + worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \ + \ + lmain.bit = rte_rand_max(size); \ + do { \ + lworker.bit = rte_rand_max(size); \ + } while (lworker.bit == lmain.bit); \ + \ + int rc = rte_eal_remote_launch(run_parallel_assign ## size, \ + &lworker, worker_lcore_id); \ + TEST_ASSERT(rc == 0, "Worker thread launch failed"); \ + \ + run_parallel_assign ## size(&lmain); \ + \ + rte_eal_mp_wait_lcore(); \ + \ + TEST_ASSERT(!lmain.failed, "Main lcore atomic access failed"); \ + TEST_ASSERT(!lworker.failed, "Worker lcore atomic access " \ + "failed"); \ + \ + return TEST_SUCCESS; \ + } + +GEN_TEST_BIT_PARALLEL_ASSIGN(32) +GEN_TEST_BIT_PARALLEL_ASSIGN(64) + +#define GEN_TEST_BIT_PARALLEL_TEST_AND_MODIFY(size) \ + \ + struct parallel_test_and_set_lcore ## size \ + { \ + uint ## size ##_t *word; \ + unsigned int bit; \ + uint64_t flips; \ + }; \ + \ + static int \ + run_parallel_test_and_modify ## size(void *arg) \ + { \ + struct parallel_test_and_set_lcore ## size *lcore = arg; \ + uint64_t deadline = rte_get_timer_cycles() + \ + PARALLEL_TEST_RUNTIME * rte_get_timer_hz(); \ + do { \ + bool old_value; \ + bool new_value = rte_rand() & 1; \ + bool use_assign = rte_rand() & 1; \ + \ + if (use_assign) \ + old_value = rte_bit_atomic_test_and_assign( \ + lcore->word, lcore->bit, new_value, \ + rte_memory_order_relaxed); \ + else \ + old_value = new_value ? \ + rte_bit_atomic_test_and_set( \ + lcore->word, lcore->bit, \ + rte_memory_order_relaxed) : \ + rte_bit_atomic_test_and_clear( \ + lcore->word, lcore->bit, \ + rte_memory_order_relaxed); \ + if (old_value != new_value) \ + lcore->flips++; \ + } while (rte_get_timer_cycles() < deadline); \ + \ + return 0; \ + } \ + \ + static int \ + test_bit_atomic_parallel_test_and_modify ## size(void) \ + { \ + unsigned int worker_lcore_id; \ + uint ## size ## _t word = 0; \ + unsigned int bit = rte_rand_max(size); \ + struct parallel_test_and_set_lcore ## size lmain = { \ + .word = &word, \ + .bit = bit \ + }; \ + struct parallel_test_and_set_lcore ## size lworker = { \ + .word = &word, \ + .bit = bit \ + }; \ + \ + if (rte_lcore_count() < 2) { \ + printf("Need multiple cores to run parallel test.\n"); \ + return TEST_SKIPPED; \ + } \ + \ + worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \ + \ + int rc = rte_eal_remote_launch(run_parallel_test_and_modify ## size, \ + &lworker, worker_lcore_id); \ + TEST_ASSERT(rc == 0, "Worker thread launch failed"); \ + \ + run_parallel_test_and_modify ## size(&lmain); \ + \ + rte_eal_mp_wait_lcore(); \ + \ + uint64_t total_flips = lmain.flips + lworker.flips; \ + bool expected_value = total_flips % 2; \ + \ + TEST_ASSERT(expected_value == rte_bit_test(&word, bit), \ + "After %"PRId64" flips, the bit value " \ + "should be %d", total_flips, expected_value); \ + \ + uint64_t expected_word = 0; \ + rte_bit_assign(&expected_word, bit, expected_value); \ + \ + TEST_ASSERT(expected_word == word, "Untouched bits have " \ + "changed value"); \ + \ + return TEST_SUCCESS; \ + } + +GEN_TEST_BIT_PARALLEL_TEST_AND_MODIFY(32) +GEN_TEST_BIT_PARALLEL_TEST_AND_MODIFY(64) + +#define GEN_TEST_BIT_PARALLEL_FLIP(size) \ + \ + struct parallel_flip_lcore ## size \ + { \ + uint ## size ##_t *word; \ + unsigned int bit; \ + uint64_t flips; \ + }; \ + \ + static int \ + run_parallel_flip ## size(void *arg) \ + { \ + struct parallel_flip_lcore ## size *lcore = arg; \ + uint64_t deadline = rte_get_timer_cycles() + \ + PARALLEL_TEST_RUNTIME * rte_get_timer_hz(); \ + do { \ + rte_bit_atomic_flip(lcore->word, lcore->bit, \ + rte_memory_order_relaxed); \ + lcore->flips++; \ + } while (rte_get_timer_cycles() < deadline); \ + \ + return 0; \ + } \ + \ + static int \ + test_bit_atomic_parallel_flip ## size(void) \ + { \ + unsigned int worker_lcore_id; \ + uint ## size ## _t word = 0; \ + unsigned int bit = rte_rand_max(size); \ + struct parallel_flip_lcore ## size lmain = { \ + .word = &word, \ + .bit = bit \ + }; \ + struct parallel_flip_lcore ## size lworker = { \ + .word = &word, \ + .bit = bit \ + }; \ + \ + if (rte_lcore_count() < 2) { \ + printf("Need multiple cores to run parallel test.\n"); \ + return TEST_SKIPPED; \ + } \ + \ + worker_lcore_id = rte_get_next_lcore(-1, 1, 0); \ + \ + int rc = rte_eal_remote_launch(run_parallel_flip ## size, \ + &lworker, worker_lcore_id); \ + TEST_ASSERT(rc == 0, "Worker thread launch failed"); \ + \ + run_parallel_flip ## size(&lmain); \ + \ + rte_eal_mp_wait_lcore(); \ + \ + uint64_t total_flips = lmain.flips + lworker.flips; \ + bool expected_value = total_flips % 2; \ + \ + TEST_ASSERT(expected_value == rte_bit_test(&word, bit), \ + "After %"PRId64" flips, the bit value " \ + "should be %d", total_flips, expected_value); \ + \ + uint64_t expected_word = 0; \ + rte_bit_assign(&expected_word, bit, expected_value); \ + \ + TEST_ASSERT(expected_word == word, "Untouched bits have " \ + "changed value"); \ + \ + return TEST_SUCCESS; \ + } + +GEN_TEST_BIT_PARALLEL_FLIP(32) +GEN_TEST_BIT_PARALLEL_FLIP(64) + static uint32_t val32; static uint64_t val64; @@ -177,6 +478,16 @@ static struct unit_test_suite test_suite = { .unit_test_cases = { TEST_CASE(test_bit_access32), TEST_CASE(test_bit_access64), + TEST_CASE(test_bit_access32), + TEST_CASE(test_bit_access64), + TEST_CASE(test_bit_atomic_access32), + TEST_CASE(test_bit_atomic_access64), + TEST_CASE(test_bit_atomic_parallel_assign32), + TEST_CASE(test_bit_atomic_parallel_assign64), + TEST_CASE(test_bit_atomic_parallel_test_and_modify32), + TEST_CASE(test_bit_atomic_parallel_test_and_modify64), + TEST_CASE(test_bit_atomic_parallel_flip32), + TEST_CASE(test_bit_atomic_parallel_flip64), TEST_CASE(test_bit_relaxed_set), TEST_CASE(test_bit_relaxed_clear), TEST_CASE(test_bit_relaxed_test_set_clear), -- 2.34.1