From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 1F57345B13;
	Fri, 11 Oct 2024 17:11:25 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 95CAC402BB;
	Fri, 11 Oct 2024 17:11:24 +0200 (CEST)
Received: from us-smtp-delivery-124.mimecast.com
 (us-smtp-delivery-124.mimecast.com [170.10.133.124])
 by mails.dpdk.org (Postfix) with ESMTP id ABE6C4025F
 for <dev@dpdk.org>; Fri, 11 Oct 2024 17:11:22 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
 s=mimecast20190719; t=1728659482;
 h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
 content-transfer-encoding:content-transfer-encoding:
 in-reply-to:in-reply-to:references:references;
 bh=Fz3wyI8MdfZSHJFvAQtPG6mUcxhTRbLNJ5tkAHGJB/s=;
 b=fBqOfAYFzBj4F70w0oHfLrr9Symdnj3BRejF242Hicv/NEqlxqeVNNaBueUxXqZagLq+BN
 1G6yDq7SSjacNFcshbBzB+OEnigmZxdzwJaLHFay4cov09ze6/rq4Z+I8WcUJBdDs2Timo
 MDgpJSssRIF+aOkTIt7yBec1OIdKvAk=
Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com
 [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS
 (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id
 us-mta-456-cMJE2isQPpq53qI_oUEXSA-1; Fri, 11 Oct 2024 11:11:19 -0400
X-MC-Unique: cMJE2isQPpq53qI_oUEXSA-1
Received: by mail-lf1-f69.google.com with SMTP id
 2adb3069b0e04-5398b9176dcso2208436e87.2
 for <dev@dpdk.org>; Fri, 11 Oct 2024 08:11:18 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1728659477; x=1729264277;
 h=content-transfer-encoding:cc:to:subject:message-id:date:from
 :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=Fz3wyI8MdfZSHJFvAQtPG6mUcxhTRbLNJ5tkAHGJB/s=;
 b=ViBJWCty/X4VExjaZ/9iXjhCkGBxy0GPvh/vNXT0AJMjddzT4OB5aKa4BsYv/Ct/bq
 W2XKxEsu1Lzw6YG6Z0+fLE6Ltgpw1grChm86Q5jkA0fpizCmwYqRjr5kbDATWJjkh1Ng
 GfDZCwYznPqmkx6Pf3v76U+sJgpIv7iJPtiGiuNimSCFNpUsxol3NISHa37QUvTMXcEP
 JwCcSun9z+KhCELQi2tvaYv024Kgb1Ps+dKu1DQIleej47VLjJFsp7o4oucxIOVTksbP
 BWwalAghBqFvaOoboTXXXsYKJbLqIBLItKzw4QeXJCahd0ppjJ4nI5GxM9wVaCjUd5aY
 4mfA==
X-Forwarded-Encrypted: i=1;
 AJvYcCU0uZe6s3Rx+GQx2P+HVwXxhSmHh6p6q943gKA5p59rGDxtj7C8Oem0aD+Lj2UyAxGxENg=@dpdk.org
X-Gm-Message-State: AOJu0YwPo/H1caLNiVNBNww+iMt2jnSAQUYLjMdXkRBjNqcSrD+WG1qd
 Bp5J2TDtwJU9uz05+E2+7Yd+V6wj8wZFCXm22KxT5PFfLUriX5IBlE1JHyUe7ZZHDATc435NlkN
 Qv6ZayZhjwHEpK6D5CSnBAixdZQk5EM0QZq0hmRDohztXOtrA9Kl/ZTkDF2y1zESJGg734Wpw3O
 wPL6gC4+miehAqCqw=
X-Received: by 2002:a05:6512:3b0d:b0:535:6cf6:92fc with SMTP id
 2adb3069b0e04-539da3b44damr1601181e87.8.1728659477492; 
 Fri, 11 Oct 2024 08:11:17 -0700 (PDT)
X-Google-Smtp-Source: AGHT+IFI39OYuFPRGtwDhKm5ZVwdjCkA1PZQflmgSgLN4hQEot0BpiC1TfEiASCKUfW6bO7AHD4WnGcjkvWOfQUBwqQ=
X-Received: by 2002:a05:6512:3b0d:b0:535:6cf6:92fc with SMTP id
 2adb3069b0e04-539da3b44damr1601161e87.8.1728659477028; Fri, 11 Oct 2024
 08:11:17 -0700 (PDT)
MIME-Version: 1.0
References: <20240920062437.738706-2-mattias.ronnblom@ericsson.com>
 <20240920104754.739033-1-mattias.ronnblom@ericsson.com>
 <20240920104754.739033-7-mattias.ronnblom@ericsson.com>
 <CAJFAV8yAxL2VLeFS2yaq-+8NdFB6PpvT9OGViw1xRazQuJ0nfg@mail.gmail.com>
 <98CBD80474FA8B44BF855DF32C47DC35E9F7C1@smartserver.smartshare.dk>
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9F7C1@smartserver.smartshare.dk>
From: David Marchand <david.marchand@redhat.com>
Date: Fri, 11 Oct 2024 17:11:05 +0200
Message-ID: <CAJFAV8yDnD9UraEi2==KDq4CLRoUeoOy9sKUe-gKi7cCOeG9XA@mail.gmail.com>
Subject: Re: [PATCH v12 6/7] eal: add unit tests for atomic bit access
 functions
To: =?UTF-8?Q?Morten_Br=C3=B8rup?= <mb@smartsharesystems.com>
Cc: =?UTF-8?Q?Mattias_R=C3=B6nnblom?= <mattias.ronnblom@ericsson.com>, 
 dev@dpdk.org, hofors@lysator.liu.se, Heng Wang <heng.wang@ericsson.com>, 
 Stephen Hemminger <stephen@networkplumber.org>,
 Tyler Retzlaff <roretzla@linux.microsoft.com>, 
 Jack Bond-Preston <jack.bond-preston@foss.arm.com>,
 Chengwen Feng <fengchengwen@huawei.com>
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

On Fri, Oct 11, 2024 at 5:06=E2=80=AFPM Morten Br=C3=B8rup <mb@smartsharesy=
stems.com> wrote:
>
> > From: David Marchand [mailto:david.marchand@redhat.com]
> > Sent: Thursday, 10 October 2024 12.45
> >
> > On Fri, Sep 20, 2024 at 12:57=E2=80=AFPM Mattias R=C3=B6nnblom
> > <mattias.ronnblom@ericsson.com> wrote:
> > > +       static int
> > \
> > > +       run_parallel_test_and_modify ## size(void *arg)         \
> > > +       {
> > \
> > > +               struct parallel_test_and_set_lcore ## size *lcore =3D
> > arg; \
> > > +               uint64_t deadline =3D rte_get_timer_cycles() +
> > \
> > > +                       PARALLEL_TEST_RUNTIME * rte_get_timer_hz();
> > \
> > > +               do {
> > \
> > > +                       bool old_value;
> > \
> > > +                       bool new_value =3D rte_rand() & 1;
> > \
> > > +                       bool use_assign =3D rte_rand() & 1;
> > \
> > > +
> > \
> > > +                       if (use_assign)
> > \
> > > +                               old_value =3D
> > rte_bit_atomic_test_and_assign( \
> > > +                                       lcore->word, lcore->bit,
> > new_value, \
> > > +                                       rte_memory_order_relaxed);
> > \
> > > +                       else
> > \
> > > +                               old_value =3D 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 !=3D 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 =3D 0;
> > \
> > > +               unsigned int bit =3D rte_rand_max(size);
> > \
> > > +               struct parallel_test_and_set_lcore ## size lmain =3D =
{
> > \
> > > +                       .word =3D &word,
> > \
> > > +                       .bit =3D bit
> > \
> > > +               };
> > \
> > > +               struct parallel_test_and_set_lcore ## size lworker =
=3D
> > {  \
> > > +                       .word =3D &word,
> > \
> > > +                       .bit =3D bit
> > \
> > > +               };
> > \
> > > +
> > \
> > > +               if (rte_lcore_count() < 2) {
> > \
> > > +                       printf("Need multiple cores to run parallel
> > test.\n"); \
> > > +                       return TEST_SKIPPED;
> > \
> > > +               }
> > \
> > > +
> > \
> > > +               worker_lcore_id =3D rte_get_next_lcore(-1, 1, 0);
> > \
> > > +
> > \
> > > +               int rc =3D
> > rte_eal_remote_launch(run_parallel_test_and_modify ## size, \
> > > +                                              &lworker,
> > worker_lcore_id); \
> > > +               TEST_ASSERT(rc =3D=3D 0, "Worker thread launch failed=
");
> > \
> > > +
> > \
> > > +               run_parallel_test_and_modify ## size(&lmain);
> > \
> > > +
> > \
> > > +               rte_eal_mp_wait_lcore();
> > \
> > > +
> > \
> > > +               uint64_t total_flips =3D lmain.flips + lworker.flips;
> > \
> > > +               bool expected_value =3D total_flips % 2;
> > \
> > > +
> > \
> > > +               TEST_ASSERT(expected_value =3D=3D rte_bit_test(&word,
> > bit), \
> > > +                           "After %"PRId64" flips, the bit value "
> > \
> > > +                           "should be %d", total_flips,
> > expected_value); \
> > > +
> > \
> > > +               uint64_t expected_word =3D 0;
> > \
> > > +               rte_bit_assign(&expected_word, bit, expected_value);
> > \
> > > +
> > \
> > > +               TEST_ASSERT(expected_word =3D=3D word, "Untouched bit=
s
> > 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.
>
> The Coverity report [1] just gave me an idea:
>
> worker_lcore_id =3D rte_get_next_lcore(-1, 1, 0);
> + TEST_ASSERT(worker_lcore_id < RTE_MAX_LCORE, "Worker thread allocation =
failed");
>
> Or even better:
> Improve rte_eal_remote_launch() by checking the validity of the worker_id=
 parameter.
>
> [1]: https://scan4.scan.coverity.com/#/project-view/60887/10075?selectedI=
ssue=3D445384
>

I have the same fix in my workdir, I was about to send, but if you
want to do it, go ahead.


--=20
David Marchand