From nobody Mon May 13 12:57:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682680826; cv=none; d=zohomail.com; s=zohoarc; b=CzmHoFPl69KDmRXG1/u9Wp94VgMdZFHssb0ZTB+zh4vp7wnSnhcuDCSYcxvXjyf7HkrmG1rx/3lWXyJLhQhJ9HT5YE1kpszwZoFyWQRSDhjjGsP8m/I+2u9mFxatBYHvGGFCgRhxc+SPFO+Ow0cZrFo6E8g75MPOgxe20hF8H+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682680826; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=w22ZoYzuaf2sz2c1ipVwaRyI7mhhdaNxLz0g55lEH3U=; b=YrWtHTivSguo7plKzh/zNk2IPSrinZ6wn9IvxbfV9A1xnZVwHvTaHioP3dQbEtj6tEOSEYzDJR7hk2AGJZmksMAv9/BnawAgORrGcR87OGE4M00b4GaEWLXGsLNDroIpdjMGZxox+QCpupk7VhO2y2sp0xgKhY8rT018/CjDd5I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168268082608164.27301023796429; Fri, 28 Apr 2023 04:20:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1psM8k-0007ES-3N; Fri, 28 Apr 2023 07:19:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psM8i-0007Dz-KT for qemu-devel@nongnu.org; Fri, 28 Apr 2023 07:19:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1psM8h-00019L-5K for qemu-devel@nongnu.org; Fri, 28 Apr 2023 07:19:48 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-96-k5m8b2JBODGr-4yp7nkr1w-1; Fri, 28 Apr 2023 07:19:44 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-3f3157128b4so37707515e9.0 for ; Fri, 28 Apr 2023 04:19:44 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:63a7:c72e:ea0e:6045]) by smtp.gmail.com with ESMTPSA id l2-20020a05600c4f0200b003ee74c25f12sm27828590wmq.35.2023.04.28.04.19.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Apr 2023 04:19:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682680786; 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; bh=w22ZoYzuaf2sz2c1ipVwaRyI7mhhdaNxLz0g55lEH3U=; b=SITrcC4+F4tGV6108wgewtPAy50w/kTs00JlNBVp4mbiLP3M8LJoYLnzOuAeec9Nxus8Oe 68agQELaSxVxzAaoD7oboAytS6mVU6bdXFpBo9th6gwFeimpCxi//NL4aIGPXpCFdKwXLU T9SePiQAKZ9K6GLCa2VVqWErDtlqCw4= X-MC-Unique: k5m8b2JBODGr-4yp7nkr1w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682680783; x=1685272783; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=w22ZoYzuaf2sz2c1ipVwaRyI7mhhdaNxLz0g55lEH3U=; b=SEdPd7ibKWleCQQ3Hxppz2VUs0MFIEwgkPERZ6mVRVGXIAy83ySZnnUlRecEB+ZRL6 /E4vIISkPq1KJFLkkZpVsIAiE4+bevcV6Sk4103a2NpR+GBx0N87OdqJFJKmqMgMw6gi slQsMsuK3KzDEZXz9fVo1BjACQ7jz8XWfCP2BruMnWy15aTmVVgK5Fc97e/XM2fWAPPn 5sxT21F3p3suBEYHwcKKTTJxVVfjHjsxuX+Z+Tssqz83z7iyEqWl6u5JqI9FZsjXSeZV bbbzLSB/1S2Pljj37aLhdoObIKeXYnvgUOaJHN6ChjatuQOrNHtBIhtpIxSSJryt5izf 47NQ== X-Gm-Message-State: AC+VfDwimZT+P0+W0Ybvp1oRWMvCoLf11+8BxZG6NYC7/krzbsdcysfG NfNsK0GBHGVPfQ8fr4Iy8N4GTZsSd1HXNJquoFi07s9pE9OcIRkfzcuo4bQbbN7zPKkr8f6HDIJ CEJ688/A/hdVNSdsgxrhuWSbISLTf4fzz2HSXTXR1E9qhBgIC/v3ujed69/u73amexnZ2yTDrOy A= X-Received: by 2002:a05:600c:1ca2:b0:3f1:939e:2e3b with SMTP id k34-20020a05600c1ca200b003f1939e2e3bmr6731661wms.19.1682680783357; Fri, 28 Apr 2023 04:19:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5mRvA0rXas+pUvwNC3HCqBo/Ix5D+QazkVMaS6bVQONFxR+wZIrqTlEzlw1dTsb+Alv1cRAA== X-Received: by 2002:a05:600c:1ca2:b0:3f1:939e:2e3b with SMTP id k34-20020a05600c1ca200b003f1939e2e3bmr6731634wms.19.1682680782872; Fri, 28 Apr 2023 04:19:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: stefanha@redhat.com Subject: [PATCH] test-aio-multithread: simplify test_multi_co_schedule Date: Fri, 28 Apr 2023 13:19:41 +0200 Message-Id: <20230428111941.149568-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682680828225100003 Content-Type: text/plain; charset="utf-8" Instead of using qatomic_mb_{read,set} mindlessly, just use a per-coroutine flag that requires no synchronization. Signed-off-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi --- tests/unit/test-aio-multithread.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/unit/test-aio-multithread.c b/tests/unit/test-aio-multit= hread.c index 3c61526a0b46..80c5d4e2e6e3 100644 --- a/tests/unit/test-aio-multithread.c +++ b/tests/unit/test-aio-multithread.c @@ -107,8 +107,7 @@ static void test_lifecycle(void) /* aio_co_schedule test. */ =20 static Coroutine *to_schedule[NUM_CONTEXTS]; - -static bool now_stopping; +static bool stop[NUM_CONTEXTS]; =20 static int count_retry; static int count_here; @@ -136,6 +135,7 @@ static bool schedule_next(int n) =20 static void finish_cb(void *opaque) { + stop[id] =3D true; schedule_next(id); } =20 @@ -143,13 +143,19 @@ static coroutine_fn void test_multi_co_schedule_entry= (void *opaque) { g_assert(to_schedule[id] =3D=3D NULL); =20 - while (!qatomic_mb_read(&now_stopping)) { + /* + * The next iteration will set to_schedule[id] again, but once finish_= cb + * is scheduled there is no guarantee that it will actually be woken u= p, + * so at that point it must not go to sleep. + */ + while (!stop[id]) { int n; =20 n =3D g_test_rand_int_range(0, NUM_CONTEXTS); schedule_next(n); =20 qatomic_mb_set(&to_schedule[id], qemu_coroutine_self()); + /* finish_cb can run here. */ qemu_coroutine_yield(); g_assert(to_schedule[id] =3D=3D NULL); } @@ -161,7 +167,6 @@ static void test_multi_co_schedule(int seconds) int i; =20 count_here =3D count_other =3D count_retry =3D 0; - now_stopping =3D false; =20 create_aio_contexts(); for (i =3D 0; i < NUM_CONTEXTS; i++) { @@ -171,10 +176,10 @@ static void test_multi_co_schedule(int seconds) =20 g_usleep(seconds * 1000000); =20 - qatomic_mb_set(&now_stopping, true); + /* Guarantee that each AioContext is woken up from its last wait. */ for (i =3D 0; i < NUM_CONTEXTS; i++) { ctx_run(i, finish_cb, NULL); - to_schedule[i] =3D NULL; + g_assert(to_schedule[i] =3D=3D NULL); } =20 join_aio_contexts(); @@ -199,6 +204,7 @@ static uint32_t atomic_counter; static uint32_t running; static uint32_t counter; static CoMutex comutex; +static bool now_stopping; =20 static void coroutine_fn test_multi_co_mutex_entry(void *opaque) { --=20 2.40.0