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 1DC3945E6B; Tue, 10 Dec 2024 17:33:13 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 122674060C; Tue, 10 Dec 2024 17:33:06 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 68D2A402E9 for ; Tue, 10 Dec 2024 17:33:02 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1213) id 7A66320BCAEA; Tue, 10 Dec 2024 08:33:01 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7A66320BCAEA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1733848381; bh=nO8ztryLH1aG5PgzxXvCX39wYqi/wh1aMujYUBcd/NY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AsKjUjT92lGU9W/ymiOWMqCz80BCUC4J6V8LXAFTeU8/JG0uBELL5TUaQpEuiuDL/ IH8n37HbhyjHET2mBURbgiDedHeNl6zympvKmBWyPAzOrxl/zTATuVZdrc+Du7yLjz v5jKkgD2w+d0clJoQO0b25SVympx77yqJJF5g+8U= From: Andre Muezerie To: Tyler Retzlaff Cc: dev@dpdk.org, Andre Muezerie Subject: [PATCH 2/3] app/test: add basic test for rte_atomic128_cmp_exchange Date: Tue, 10 Dec 2024 08:32:33 -0800 Message-Id: <1733848355-19048-3-git-send-email-andremue@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1733848355-19048-1-git-send-email-andremue@linux.microsoft.com> References: <1733848355-19048-1-git-send-email-andremue@linux.microsoft.com> 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 A basic test for rte_atomic128_cmp_exchange that can also be compiled with MSVC and run on Windows is being added. This is relevant as rte_atomic128_cmp_exchange uses a different implementation when compiled with MSVC and the existing tests for this function are not compatible with MSVC. Signed-off-by: Andre Muezerie --- app/test/test_atomic.c | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/app/test/test_atomic.c b/app/test/test_atomic.c index db07159e81..d3d9de0a41 100644 --- a/app/test/test_atomic.c +++ b/app/test/test_atomic.c @@ -20,6 +20,7 @@ #include "test.h" +#ifndef RTE_TOOLCHAIN_MSVC /* * Atomic Variables * ================ @@ -441,9 +442,41 @@ test_atomic_exchange(__rte_unused void *arg) return 0; } +#endif /* RTE_TOOLCHAIN_MSVC */ + +#if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_ARM64) +static rte_int128_t big_int; + +/* + * This function atomically performs: + * big_int.val[1] += big_int.val[0] + * big_int.val[0] += 1 + */ +static void +test_atomic_128_bit_compare_and_swap_basic_test(void) +{ + rte_int128_t comparand = big_int; + + rte_int128_t src; + src.val[0] = big_int.val[0] + 1; + src.val[1] = big_int.val[0] + big_int.val[1]; + + do { + ; /* nothing */ + } while (rte_atomic128_cmp_exchange(&big_int, + &comparand, + &src, + 1, + 0, + 0 + )); +} +#endif + static int test_atomic(void) { +#ifndef RTE_TOOLCHAIN_MSVC rte_atomic16_init(&a16); rte_atomic32_init(&a32); rte_atomic64_init(&a64); @@ -628,6 +661,32 @@ test_atomic(void) printf("Atomic exchange test failed\n"); return -1; } +#endif /* RTE_TOOLCHAIN_MSVC */ + +#if defined(RTE_ARCH_X86_64) || defined(RTE_ARCH_ARM64) + /* + * This is a basic test case for rte_atomic128_cmp_exchange. + * On MSVC this test provides the confirmation that + * rte_atomic128_cmp_exchange passes the parameters correctly + * to the underlying intrinsic function responsible for the + * operation. + * + * The test atomically performs: + * big_int.val[1] += big_int.val[0] + * big_int.val[0] += 1 + */ + printf("128-bit compare and swap basic test\n"); + + big_int.val[1] = 23; /* should become 34 */ + big_int.val[0] = 11; /* should become 12 */ + + test_atomic_128_bit_compare_and_swap_basic_test(); + + if (big_int.val[1] != 34 || big_int.val[0] != 12) { + printf("128-bit compare and swap basic test failed\n"); + return -1; + } +#endif return 0; } -- 2.47.0.vfs.0.3