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 8480045B03; Thu, 10 Oct 2024 13:56:01 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 22F5C402D8; Thu, 10 Oct 2024 13:56:01 +0200 (CEST) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by mails.dpdk.org (Postfix) with ESMTP id 9E9164029C for ; Thu, 10 Oct 2024 13:55:59 +0200 (CEST) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 577AF1EE17 for ; Thu, 10 Oct 2024 13:55:59 +0200 (CEST) Received: by mail.lysator.liu.se (Postfix, from userid 1004) id 4BAAC1EDBB; Thu, 10 Oct 2024 13:55:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on hermod.lysator.liu.se X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,AWL, T_SCC_BODY_TEXT_LINE autolearn=disabled version=4.0.0 X-Spam-Score: -1.2 Received: from [192.168.1.85] (h-62-63-215-114.A163.priv.bahnhof.se [62.63.215.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id A24651ED53; Thu, 10 Oct 2024 13:55:56 +0200 (CEST) Message-ID: Date: Thu, 10 Oct 2024 13:55:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v12 6/7] eal: add unit tests for atomic bit access functions To: David Marchand , =?UTF-8?Q?Mattias_R=C3=B6nnblom?= Cc: dev@dpdk.org, Heng Wang , Stephen Hemminger , Tyler Retzlaff , =?UTF-8?Q?Morten_Br=C3=B8rup?= , Jack Bond-Preston , Chengwen Feng References: <20240920062437.738706-2-mattias.ronnblom@ericsson.com> <20240920104754.739033-1-mattias.ronnblom@ericsson.com> <20240920104754.739033-7-mattias.ronnblom@ericsson.com> Content-Language: en-US From: =?UTF-8?Q?Mattias_R=C3=B6nnblom?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP 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 On 2024-10-10 12:45, David Marchand wrote: > On Fri, Sep 20, 2024 at 12:57 PM Mattias Rönnblom > wrote: >> + 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) > > It appears this test failed once in the CI for an unrelated series > (uAPI kernel header import): > https://lab.dpdk.org/results/dashboard/testruns/logs/1385993/ > > + TestCase [ 0] : test_bit_access32 succeeded > + TestCase [ 1] : test_bit_access64 succeeded > + TestCase [ 2] : test_bit_access32 succeeded > + TestCase [ 3] : test_bit_access64 succeeded > + TestCase [ 4] : test_bit_v_access32 succeeded > + TestCase [ 5] : test_bit_v_access64 succeeded > + TestCase [ 6] : test_bit_atomic_access32 succeeded > + TestCase [ 7] : test_bit_atomic_access64 succeeded > + TestCase [ 8] : test_bit_atomic_v_access32 succeeded > + TestCase [ 9] : test_bit_atomic_v_access64 succeeded > + TestCase [10] : test_bit_atomic_parallel_assign32 succeeded > + TestCase [11] : test_bit_atomic_parallel_assign64 succeeded > + TestCase [12] : test_bit_atomic_parallel_test_and_modify32 failed > + TestCase [13] : test_bit_atomic_parallel_test_and_modify64 succeeded > + TestCase [14] : test_bit_atomic_parallel_flip32 succeeded > + TestCase [15] : test_bit_atomic_parallel_flip64 succeeded > + TestCase [16] : test_bit_relaxed_set succeeded > + TestCase [17] : test_bit_relaxed_clear succeeded > + TestCase [18] : test_bit_relaxed_test_set_clear succeeded > > EAL: Test assert test_bit_atomic_parallel_test_and_modify32 line 236 > failed: After 1070523 flips, the bit value should be 1 > > Please have a look. > > OK. Nothing obvious from what I can see in the code. Unrelated: why did you remove all empty lines in the "template" macros? Makes them much harder to read. I've been unable to reproduce this on my Raptor Lake x86_64 with GCC 12.3 (CI machine used GCC 12.2). I'll try if I have better luck on some other systems.