From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646919029761683.4324518540392; Thu, 10 Mar 2022 05:30:29 -0800 (PST) Received: from localhost ([::1]:53440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIs9-0005wA-Bx for importer@patchew.org; Thu, 10 Mar 2022 08:30:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9W-0006bT-Gt; Thu, 10 Mar 2022 07:44:23 -0500 Received: from [2a00:1450:4864:20::42f] (port=37519 helo=mail-wr1-x42f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9U-00059i-IZ; Thu, 10 Mar 2022 07:44:21 -0500 Received: by mail-wr1-x42f.google.com with SMTP id q14so7786580wrc.4; Thu, 10 Mar 2022 04:44:19 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cBZTbExiCYKj3VfEz2N2nz7XUaXwl3lG9di4rcEwsYk=; b=fzq40MSt9ngkqD7fL1f19b6QKisFMP0oIcIQsB2+zr7VpE7+PNx34tiqkZtwBXbeRp +rZ0V8ANEnG2UVNGkRDLUgivGN9WUglh/q8xtuiWUFN1g1psZsHMZypHvSggqhtymqMp Ky2SXs+AelTi9ucdWSIG3YDZ+/GbWAEH/DWSh/8wJvsDSvoVQBAGKT5kvKxiZ+r6WB1e YOmEGRdGQ3tiCOFhsJODlixvrcIztYRovOLwq83oRHvKE2JR0KLcatz4Q9kTsgHBypm0 0SZue0A4gbejVWN1/8vl0v13vPvuqeb5qH7t48xQHOrcELb+GCfs5L6hDNkBYyH7WsoV 8XFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=cBZTbExiCYKj3VfEz2N2nz7XUaXwl3lG9di4rcEwsYk=; b=sIQ7h8O2Ig4dR87eQlcEyY9DoB9V5f+vXKfav/ohaxY1PE0mVW8wjppIOhP3NAZSze TAN9hJN+sENKIWAXDI+SwurXz+F4KLWvCpNw9RSrIyDIe//9Vem6LBCxWQAz5dtchbX2 3/gvGHNRVtdvFOj/Va+oQubafZjViVJuasrZ92vGnBeD4t47ZqaNk78Bjlh+rzAvDrMy 2ZDMUYUMsOEsNde92LSdZOdM8fYdT5hP51PIK9M4SshxSPZ3PBHfz6VcqAPdDx5hIMsv DzVjlQbFHO0iOMKI4BAJZm3OC8LTtY407hIfEmy+oXIyREb1F6x1znkdINwO17n+XTyF eVww== X-Gm-Message-State: AOAM532sXCWhVNNFH+oviYKR25/6nrGPQDmMXhK1hPEfsWqnAyF0QA8M IfQ65HiGZ6+/8vCk3WtgYjBbBvoFlEk= X-Google-Smtp-Source: ABdhPJxNzCPI7CATy0vuq1yjaWxFsXFfUeiQrXfqc/ai2ZLMef5QLWtZXXZ61m3JeOXWFN+qo0SFPw== X-Received: by 2002:a5d:64e3:0:b0:203:85ed:49a2 with SMTP id g3-20020a5d64e3000000b0020385ed49a2mr2742432wri.483.1646916258378; Thu, 10 Mar 2022 04:44:18 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 01/35] coroutine: add missing coroutine_fn annotations for CoRwlock functions Date: Thu, 10 Mar 2022 13:43:39 +0100 Message-Id: <20220310124413.1102441-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42f (failed) 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=2a00:1450:4864:20::42f; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42f.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646919047178100001 Content-Type: text/plain; charset="utf-8" CoRwlock can only be taken or released from a coroutine, and it can yield. Mark it as coroutine_fn. Signed-off-by: Paolo Bonzini --- include/qemu/coroutine.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index c828a95ee0..da68be5ad2 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -261,7 +261,7 @@ void qemu_co_rwlock_init(CoRwlock *lock); * of a parallel writer, control is transferred to the caller of the curre= nt * coroutine. */ -void qemu_co_rwlock_rdlock(CoRwlock *lock); +void coroutine_fn qemu_co_rwlock_rdlock(CoRwlock *lock); =20 /** * Write Locks the CoRwlock from a reader. This is a bit more efficient t= han @@ -270,7 +270,7 @@ void qemu_co_rwlock_rdlock(CoRwlock *lock); * to the caller of the current coroutine; another writer might run while * @qemu_co_rwlock_upgrade blocks. */ -void qemu_co_rwlock_upgrade(CoRwlock *lock); +void coroutine_fn qemu_co_rwlock_upgrade(CoRwlock *lock); =20 /** * Downgrades a write-side critical section to a reader. Downgrading with @@ -278,20 +278,20 @@ void qemu_co_rwlock_upgrade(CoRwlock *lock); * followed by @qemu_co_rwlock_rdlock. This makes it more efficient, but * may also sometimes be necessary for correctness. */ -void qemu_co_rwlock_downgrade(CoRwlock *lock); +void coroutine_fn qemu_co_rwlock_downgrade(CoRwlock *lock); =20 /** * Write Locks the mutex. If the lock cannot be taken immediately because * of a parallel reader, control is transferred to the caller of the curre= nt * coroutine. */ -void qemu_co_rwlock_wrlock(CoRwlock *lock); +void coroutine_fn qemu_co_rwlock_wrlock(CoRwlock *lock); =20 /** * Unlocks the read/write lock and schedules the next coroutine that was * waiting for this lock to be run. */ -void qemu_co_rwlock_unlock(CoRwlock *lock); +void coroutine_fn qemu_co_rwlock_unlock(CoRwlock *lock); =20 typedef struct QemuCoSleep { Coroutine *to_wake; --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646919258677540.1050203604796; Thu, 10 Mar 2022 05:34:18 -0800 (PST) Received: from localhost ([::1]:57846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIvm-0000es-BU for importer@patchew.org; Thu, 10 Mar 2022 08:34:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9X-0006c3-LD; Thu, 10 Mar 2022 07:44:23 -0500 Received: from [2a00:1450:4864:20::42e] (port=36525 helo=mail-wr1-x42e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9V-00059t-Hp; Thu, 10 Mar 2022 07:44:22 -0500 Received: by mail-wr1-x42e.google.com with SMTP id r10so7797585wrp.3; Thu, 10 Mar 2022 04:44:20 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oXz+BWP/LDeXYvsbVe7m9SlkJdCNLdNyBH4D7wYcyC8=; b=DMzhyHo4m8WeRW05Rip3apho/Au+iwj6yRJNI8e3M8KMy1kRtoivmFLtBX13EW4AKp aGJafU8AcnLbn74GxFy7JflBihmuPgtJgcw92zmOvYSpEql4NWnqPwgqZEIy1uOFikys kqZ6XGbaVNeXdW8LVvZLencugNap/2xSCpszTM07wU6wkRal0oCvIPSMG56XTjAnbk2S oY6Fmrel7S0Dx9yzZmKyZEnZdaAITS8S56oGpIPFNbXGFhpqxlFfnL0E329OSEdKT7T1 VPhoO6ucdAYgkM3JPMwynY9QTC8uxRElB0DA3KJ1lftYwSutRKcWSuCUcECambuPggo0 z5Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=oXz+BWP/LDeXYvsbVe7m9SlkJdCNLdNyBH4D7wYcyC8=; b=8JR8fWs8zQPZf0mgdcDiiwJ6VH0NFEZHktXOkd4FxL6BrzMYis66rUp/7ylcanXwmM U/jzqyytt/03+xPjAHr4dzzrnvH3/ggzLAwtFO+mIwwtBLY0943b4z0c6r8Knd8aWQyx ORADVGk/A1ZlJVS+TDuKo0kUtgVoYyfTOVJJBZi7CaAO3+culS1JWTKQHAd4vj3fhrmR pi8X0vplj3CWHbHEM5bsCqHgZygyyVPVb/8DGtZ3Wez/3hz2L8qhAur/+JunNMJ1haw7 SDCPj5CUQ4uTa0rZBzBID9KU/3ItewvCnf5/XkSc4EdGcfnVNy+FbtXCvQV4MPHPU8/R Bfug== X-Gm-Message-State: AOAM5326Pksrwl/XGJC5CTPpE2otf2zjLVhDzQaIdS3tLqdD9s2q/WJ/ Fr9tzwqcwo+QX1dGII1A99cjR5pnA+Q= X-Google-Smtp-Source: ABdhPJzioqCrmSIVfW54LqfGr7KhYWsnopNnf8fC24PV014DE2pLGm9tOgWa9GYnECYIX73eNOQ81g== X-Received: by 2002:a05:6000:1786:b0:1f0:36a5:e573 with SMTP id e6-20020a056000178600b001f036a5e573mr3439439wrg.428.1646916259671; Thu, 10 Mar 2022 04:44:19 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 02/35] coroutine: qemu_coroutine_get_aio_context is not a coroutine_fn Date: Thu, 10 Mar 2022 13:43:40 +0100 Message-Id: <20220310124413.1102441-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42e (failed) 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=2a00:1450:4864:20::42e; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42e.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646919259756100001 Content-Type: text/plain; charset="utf-8" Since it operates on a given coroutine, qemu_coroutine_get_aio_context can be called from outside coroutine context. This is for example how qio_channel_restart_read uses it. Signed-off-by: Paolo Bonzini --- include/qemu/coroutine.h | 2 +- util/qemu-coroutine.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index da68be5ad2..666f3ba0e0 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -92,7 +92,7 @@ void coroutine_fn qemu_coroutine_yield(void); /** * Get the AioContext of the given coroutine */ -AioContext *coroutine_fn qemu_coroutine_get_aio_context(Coroutine *co); +AioContext *qemu_coroutine_get_aio_context(Coroutine *co); =20 /** * Get the currently executing coroutine diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c index c03b2422ff..9f2bd96fa0 100644 --- a/util/qemu-coroutine.c +++ b/util/qemu-coroutine.c @@ -200,7 +200,7 @@ bool qemu_coroutine_entered(Coroutine *co) return co->caller; } =20 -AioContext *coroutine_fn qemu_coroutine_get_aio_context(Coroutine *co) +AioContext *qemu_coroutine_get_aio_context(Coroutine *co) { return co->ctx; } --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646916627348283.00783948277524; Thu, 10 Mar 2022 04:50:27 -0800 (PST) Received: from localhost ([::1]:50612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIFN-0002CC-QN for importer@patchew.org; Thu, 10 Mar 2022 07:50:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9Y-0006cu-Ps; Thu, 10 Mar 2022 07:44:29 -0500 Received: from [2a00:1450:4864:20::42b] (port=40785 helo=mail-wr1-x42b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9W-0005A7-Jd; Thu, 10 Mar 2022 07:44:24 -0500 Received: by mail-wr1-x42b.google.com with SMTP id k24so7761594wrd.7; Thu, 10 Mar 2022 04:44:21 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ijSTqD5Qu/0QXONMXtyJFiFkOCsxqGeZGIi83ibgBoo=; b=msdrB/WCOQnFpWsAgTF++dzx6VMHpv/BpGPtzo7dBEePpvwwMAl+kaDdqbgHYjyvPx BEARzd0L2iCqmwt1kvdtcDfD6P0amoBGQ3mHZfxrHW6JdTVGcm6PcuWPJYiFKRBBT0pv o1NVcNc7h4sIlnoCHB7ANo9LIm8payRFJyVyS3RnHugD5cIGTdMcQgqPXNz/KHGHFjbX XIj/AbUvUQ8GXVm/jW+x+aGymMaxQ74Gtam2tMQ9JmW3nMAmqgi/oyWCarauQuGKxf6J tTg9qYbtkrCUiPMJ5XgIfGM1KPtZruUD9VbZizDNxwrax0V1QKtG40clkmw43XLd2En7 Yv+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ijSTqD5Qu/0QXONMXtyJFiFkOCsxqGeZGIi83ibgBoo=; b=U3kb0DSzXvJIb68sH9aLlUgHhHO8ccdf68wxuQ6oav/6UTDusLolv6GoD825ml12GP zgS6gYAQk2S8GaqveI7dbeyLgVxE/2xw7HRXORDVNv7KKOb0zfp2XLP4HzGUPM6LSUWN tx8qheDJDikMtudapSqvLKTqpIUNIBlE0Zyn9B/myfiiHWKdU/q4A++Fk1Qmj4o/n4hs kGgqJbF6oQQHYqf9jrp4xZoUfYSgHatj/18n3G3+N6SvliwSx3eOv5wpqdRuahWh0dMn TrB3yiwyKiaYt6QjnirFO6qvepbksFG7E3OuW2zhQgKwPn3E/faWZncSl1l0Bjerg+6U yV5w== X-Gm-Message-State: AOAM532y31nF1r91fPm5tGPgOmJgIPqg+/3BlVSop45skeuDdi51RvPG LQcH0M/ANEzCl14ursAGfYfDYqfuC1U= X-Google-Smtp-Source: ABdhPJz0wYzAAae7uD7pskTVFiXguwPKmd06UkqR5HMXORIQ/1nvn1e03kp2q2nYITgOkEnAQkk/lg== X-Received: by 2002:adf:f389:0:b0:1ef:5f0f:cb83 with SMTP id m9-20020adff389000000b001ef5f0fcb83mr3394964wro.26.1646916260745; Thu, 10 Mar 2022 04:44:20 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 03/35] coroutine: introduce QemuCoLockable Date: Thu, 10 Mar 2022 13:43:41 +0100 Message-Id: <20220310124413.1102441-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42b (failed) 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=2a00:1450:4864:20::42b; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42b.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646916629470100003 Content-Type: text/plain; charset="utf-8" In preparation for splitting "from coroutine" ("awaitable" in other languages) and "not from coroutine" functions, remove the CoMutex case from QemuLockable---thus making qemu_lockable_lock and qemu_lockable_unlock "not awaitable". To satisfy the qemu_co_queue_wait use case, introduce QemuCoLockable which can be used for both QemuMutex (which will trivially never yield) and CoMutex. qemu_co_lockable_lock and qemu_co_lockable_unlock are coroutine_fns. Signed-off-by: Paolo Bonzini --- include/qemu/co-lockable.h | 98 +++++++++++++++++++++++++++++++++++++ include/qemu/coroutine.h | 5 +- include/qemu/lockable.h | 13 ++--- include/qemu/typedefs.h | 1 + tests/unit/test-coroutine.c | 10 ++-- util/qemu-coroutine-lock.c | 6 +-- 6 files changed, 114 insertions(+), 19 deletions(-) create mode 100644 include/qemu/co-lockable.h diff --git a/include/qemu/co-lockable.h b/include/qemu/co-lockable.h new file mode 100644 index 0000000000..09f4620017 --- /dev/null +++ b/include/qemu/co-lockable.h @@ -0,0 +1,98 @@ +/* + * Polymorphic locking functions (aka poor man templates) + * + * Copyright Red Hat, Inc. 2017, 2018 + * + * Author: Paolo Bonzini + * + * This work is licensed under the terms of the GNU LGPL, version 2 or lat= er. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#ifndef QEMU_CO_LOCKABLE_H +#define QEMU_CO_LOCKABLE_H + +#include "qemu/coroutine.h" +#include "qemu/thread.h" + +typedef void coroutine_fn QemuCoLockUnlockFunc(void *); + +struct QemuCoLockable { + void *object; + QemuCoLockUnlockFunc *lock; + QemuCoLockUnlockFunc *unlock; +}; + +static inline __attribute__((__always_inline__)) QemuCoLockable * +qemu_make_co_lockable(void *x, QemuCoLockable *lockable) +{ + /* + * We cannot test this in a macro, otherwise we get compiler + * warnings like "the address of 'm' will always evaluate as 'true'". + */ + return x ? lockable : NULL; +} + +static inline __attribute__((__always_inline__)) QemuCoLockable * +qemu_null_co_lockable(void *x) +{ + if (x !=3D NULL) { + qemu_build_not_reached(); + } + return NULL; +} + +/* + * In C, compound literals have the lifetime of an automatic variable. + * In C++ it would be different, but then C++ wouldn't need QemuCoLockable + * either... + */ +#define QMCL_OBJ_(x, name) (&(QemuCoLockable) { \ + .object =3D (x), \ + .lock =3D (QemuCoLockUnlockFunc *) qemu_ ## name ## _lock, \ + .unlock =3D (QemuCoLockUnlockFunc *) qemu_ ## name ## _unlock \ + }) + +/** + * QEMU_MAKE_CO_LOCKABLE - Make a polymorphic QemuCoLockable + * + * @x: a lock object (currently one of QemuMutex, CoMutex). + * + * Returns a QemuCoLockable object that can be passed around + * to a function that can operate with locks of any kind, or + * NULL if @x is %NULL. + * + * Note the special case for void *, so that we may pass "NULL". + */ +#define QEMU_MAKE_CO_LOCKABLE(x) = \ + _Generic((x), QemuCoLockable *: (x), = \ + void *: qemu_null_co_lockable(x), = \ + QemuMutex *: qemu_make_co_lockable(x, QMCL_OBJ_(x, mutex)), = \ + CoMutex *: qemu_make_co_lockable(x, QMCL_OBJ_(x, co_mutex))) = \ + +/** + * QEMU_MAKE_CO_LOCKABLE_NONNULL - Make a polymorphic QemuCoLockable + * + * @x: a lock object (currently one of QemuMutex, QemuRecMutex, + * CoMutex, QemuSpin). + * + * Returns a QemuCoLockable object that can be passed around + * to a function that can operate with locks of any kind. + */ +#define QEMU_MAKE_CO_LOCKABLE_NONNULL(x) \ + _Generic((x), QemuCoLockable *: (x), \ + QemuMutex *: QMCL_OBJ_(x, mutex), \ + CoMutex *: QMCL_OBJ_(x, co_mutex)) + +static inline void coroutine_fn qemu_co_lockable_lock(QemuCoLockable *x) +{ + x->lock(x->object); +} + +static inline void coroutine_fn qemu_co_lockable_unlock(QemuCoLockable *x) +{ + x->unlock(x->object); +} + +#endif diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index 666f3ba0e0..6f4596fc5b 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -204,8 +204,8 @@ void qemu_co_queue_init(CoQueue *queue); * locked again afterwards. */ #define qemu_co_queue_wait(queue, lock) \ - qemu_co_queue_wait_impl(queue, QEMU_MAKE_LOCKABLE(lock)) -void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue, QemuLockable *lo= ck); + qemu_co_queue_wait_impl(queue, QEMU_MAKE_CO_LOCKABLE(lock)) +void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue, QemuCoLockable *= lock); =20 /** * Removes the next coroutine from the CoQueue, and wake it up. @@ -342,5 +342,6 @@ void qemu_coroutine_increase_pool_batch_size(unsigned i= nt additional_pool_size); void qemu_coroutine_decrease_pool_batch_size(unsigned int additional_pool_= size); =20 #include "qemu/lockable.h" +#include "qemu/co-lockable.h" =20 #endif /* QEMU_COROUTINE_H */ diff --git a/include/qemu/lockable.h b/include/qemu/lockable.h index 86db7cb04c..c860f81737 100644 --- a/include/qemu/lockable.h +++ b/include/qemu/lockable.h @@ -13,7 +13,6 @@ #ifndef QEMU_LOCKABLE_H #define QEMU_LOCKABLE_H =20 -#include "qemu/coroutine.h" #include "qemu/thread.h" =20 typedef void QemuLockUnlockFunc(void *); @@ -57,8 +56,7 @@ qemu_null_lockable(void *x) /** * QEMU_MAKE_LOCKABLE - Make a polymorphic QemuLockable * - * @x: a lock object (currently one of QemuMutex, QemuRecMutex, - * CoMutex, QemuSpin). + * @x: a lock object (currently one of QemuMutex, QemuRecMutex, QemuSpin). * * Returns a QemuLockable object that can be passed around * to a function that can operate with locks of any kind, or @@ -71,14 +69,12 @@ qemu_null_lockable(void *x) void *: qemu_null_lockable(x), \ QemuMutex *: qemu_make_lockable(x, QML_OBJ_(x, mutex)), \ QemuRecMutex *: qemu_make_lockable(x, QML_OBJ_(x, rec_mutex))= , \ - CoMutex *: qemu_make_lockable(x, QML_OBJ_(x, co_mutex)), \ QemuSpin *: qemu_make_lockable(x, QML_OBJ_(x, spin))) =20 /** * QEMU_MAKE_LOCKABLE_NONNULL - Make a polymorphic QemuLockable * - * @x: a lock object (currently one of QemuMutex, QemuRecMutex, - * CoMutex, QemuSpin). + * @x: a lock object (currently one of QemuMutex, QemuRecMutex, QemuSpin). * * Returns a QemuLockable object that can be passed around * to a function that can operate with locks of any kind. @@ -87,7 +83,6 @@ qemu_null_lockable(void *x) _Generic((x), QemuLockable *: (x), \ QemuMutex *: QML_OBJ_(x, mutex), \ QemuRecMutex *: QML_OBJ_(x, rec_mutex), \ - CoMutex *: QML_OBJ_(x, co_mutex), \ QemuSpin *: QML_OBJ_(x, spin)) =20 static inline void qemu_lockable_lock(QemuLockable *x) @@ -124,7 +119,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuLockable, qemu_lockab= le_auto_unlock) /** * WITH_QEMU_LOCK_GUARD - Lock a lock object for scope * - * @x: a lock object (currently one of QemuMutex, CoMutex, QemuSpin). + * @x: a lock object (currently one of QemuMutex, QemuRecMutex, QemuSpin). * * This macro defines a lock scope such that entering the scope takes the = lock * and leaving the scope releases the lock. Return statements are allowed @@ -149,7 +144,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuLockable, qemu_lockab= le_auto_unlock) /** * QEMU_LOCK_GUARD - Lock an object until the end of the scope * - * @x: a lock object (currently one of QemuMutex, CoMutex, QemuSpin). + * @x: a lock object (currently one of QemuMutex, QemuRecMutex, QemuSpin). * * This macro takes a lock until the end of the scope. Return statements * release the lock. diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 42f4ceb701..144ce82b8b 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -103,6 +103,7 @@ typedef struct QBool QBool; typedef struct QDict QDict; typedef struct QEMUBH QEMUBH; typedef struct QemuConsole QemuConsole; +typedef struct QemuCoLockable QemuCoLockable; typedef struct QEMUFile QEMUFile; typedef struct QemuLockable QemuLockable; typedef struct QemuMutex QemuMutex; diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index aa77a3bcb3..82e22db070 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -213,13 +213,13 @@ static void coroutine_fn mutex_fn(void *opaque) =20 static void coroutine_fn lockable_fn(void *opaque) { - QemuLockable *x =3D opaque; - qemu_lockable_lock(x); + QemuCoLockable *x =3D opaque; + qemu_co_lockable_lock(x); assert(!locked); locked =3D true; qemu_coroutine_yield(); locked =3D false; - qemu_lockable_unlock(x); + qemu_co_lockable_unlock(x); done++; } =20 @@ -259,9 +259,9 @@ static void test_co_mutex_lockable(void) CoMutex *null_pointer =3D NULL; =20 qemu_co_mutex_init(&m); - do_test_co_mutex(lockable_fn, QEMU_MAKE_LOCKABLE(&m)); + do_test_co_mutex(lockable_fn, QEMU_MAKE_CO_LOCKABLE(&m)); =20 - g_assert(QEMU_MAKE_LOCKABLE(null_pointer) =3D=3D NULL); + g_assert(QEMU_MAKE_CO_LOCKABLE(null_pointer) =3D=3D NULL); } =20 static CoRwlock rwlock; diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index 2669403839..c29cb69f5e 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -39,13 +39,13 @@ void qemu_co_queue_init(CoQueue *queue) QSIMPLEQ_INIT(&queue->entries); } =20 -void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue, QemuLockable *lo= ck) +void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue, QemuCoLockable *= lock) { Coroutine *self =3D qemu_coroutine_self(); QSIMPLEQ_INSERT_TAIL(&queue->entries, self, co_queue_next); =20 if (lock) { - qemu_lockable_unlock(lock); + qemu_co_lockable_unlock(lock); } =20 /* There is no race condition here. Other threads will call @@ -63,7 +63,7 @@ void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue,= QemuLockable *lock) * other cases of QemuLockable. */ if (lock) { - qemu_lockable_lock(lock); + qemu_co_lockable_lock(lock); } } =20 --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646916627252537.6532293174713; Thu, 10 Mar 2022 04:50:27 -0800 (PST) Received: from localhost ([::1]:50536 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIFN-00028z-Su for importer@patchew.org; Thu, 10 Mar 2022 07:50:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9a-0006cy-DY; Thu, 10 Mar 2022 07:44:29 -0500 Received: from [2a00:1450:4864:20::42d] (port=37518 helo=mail-wr1-x42d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9X-0005AI-Om; Thu, 10 Mar 2022 07:44:24 -0500 Received: by mail-wr1-x42d.google.com with SMTP id q14so7786847wrc.4; Thu, 10 Mar 2022 04:44:22 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2RZShYOopr9nsq75F7S8Tql1GSMxw9kb3WS3HyQD9ak=; b=JvrEmnocL3Wr16EdnOZkNU75SobLytLbSh5oo4jvcK/tFI/6RiWMctRV7iXJ/bY9sw nMTGv5k6Bk87VicFB8WivkRGE/Nh1oWKPPvZmvfULECziR8oP5zeqndoqkmy9i7W5wuw 3Yx5yelzyAL+TRZi2SSAb3hXgKu65gJlUg6GWRgYnjnb0rkuJa3O97PBLz3OzOILkLoN 4w/y0WWvdV2T/BGn4xwWoOVhM/ogzLjK3mNysaRrsAIu+7JUTv3nP4jRCd+YsxuzvO4q 2T5vTbzjCfFd7TWQlQ0amW8YJoaU/P14ghZQooQ1ilqwbKAzNq5NIA9ifmleV5boJkgL e1yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=2RZShYOopr9nsq75F7S8Tql1GSMxw9kb3WS3HyQD9ak=; b=aw+X+pEXXPzURCMJPs0zEDopCBL4O1FjlG3YPtfr//g3OgsljSpU/DE83AVxi13kkl 2acKd37c4Hr1swgu0t0VagTgJkAVPfbkZ5/c+AZ8EHxCaguKhItCBukP5KlzP3Vvccla 7EVj1poU7i6w/zYPA4OQN7bGY9RrNuwO8UcpxF5IYsGQVxjNaRGioo2Z27z9FWBuFr4g cE6A6+ZIU6pALjNbZa/lU/NdtYZ2pbJIVmmiwZ0oqDw3HKyElD4cuU6H0sOG1QZTlUd7 ujYLR0hip9Hn3DpDkbSVl+8Xjzyv7DZoh/3jE5tFKOTvQXcoRO+GV8kGvPzSny3PbupV hVKQ== X-Gm-Message-State: AOAM533pv6zuGl5U4vWBEv9Z09tS6PgyL+LQDasjFJ7yXdRhth7KsvDO mF0M+e8PV4mxh8eZOEC8XJKrtg19DmE= X-Google-Smtp-Source: ABdhPJykNkSOHVDs9kLx8RyYmyJzeseCWtASzus90CTwaYQPUMlEpryuq9CB1sNzSCDyK4U5gGV9zg== X-Received: by 2002:a5d:4d4b:0:b0:1f1:d99e:1122 with SMTP id a11-20020a5d4d4b000000b001f1d99e1122mr3477829wru.604.1646916261665; Thu, 10 Mar 2022 04:44:21 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 04/35] coroutine: introduce coroutine_only_fn Date: Thu, 10 Mar 2022 13:43:42 +0100 Message-Id: <20220310124413.1102441-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42d (failed) 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=2a00:1450:4864:20::42d; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42d.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646916629487100004 Content-Type: text/plain; charset="utf-8" Some functions only make sense from coroutine context, but never yield. Mark them as "coroutine_only_fn". Signed-off-by: Paolo Bonzini --- include/qemu/coroutine.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index 6f4596fc5b..b23fba88c2 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -43,6 +43,7 @@ * } */ #define coroutine_fn +#define coroutine_only_fn =20 typedef struct Coroutine Coroutine; =20 @@ -97,7 +98,7 @@ AioContext *qemu_coroutine_get_aio_context(Coroutine *co); /** * Get the currently executing coroutine */ -Coroutine *coroutine_fn qemu_coroutine_self(void); +Coroutine *coroutine_only_fn qemu_coroutine_self(void); =20 /** * Return whether or not currently inside a coroutine @@ -170,7 +171,7 @@ void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex); /** * Assert that the current coroutine holds @mutex. */ -static inline coroutine_fn void qemu_co_mutex_assert_locked(CoMutex *mutex) +static inline void coroutine_only_fn qemu_co_mutex_assert_locked(CoMutex *= mutex) { /* * mutex->holder doesn't need any synchronisation if the assertion hol= ds --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646919432188588.1207910666363; Thu, 10 Mar 2022 05:37:12 -0800 (PST) Received: from localhost ([::1]:34148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIyc-0003ts-NI for importer@patchew.org; Thu, 10 Mar 2022 08:37:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9b-0006d0-Eg; Thu, 10 Mar 2022 07:44:29 -0500 Received: from [2a00:1450:4864:20::436] (port=41655 helo=mail-wr1-x436.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9Y-0005Ai-Qo; Thu, 10 Mar 2022 07:44:27 -0500 Received: by mail-wr1-x436.google.com with SMTP id i8so7759854wrr.8; Thu, 10 Mar 2022 04:44:24 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RkDt/izp2j6Oiv3m+c6ng2LauFU8ekC/1Rot470iJKQ=; b=OHCPh2KJ/BKh7qFLFSL6XRCBnr3e15GvckVElqE2c5LmhDxei5QA0qQA0Yfe7MVd0X KDMMpswdEbtgrKzRUJH3NGPWy76ZFZPRUmWW58x1d96fmRWCr71CQ2eFzotdMcxIxzwq w2pJaTQRMI7w/1xt99U8ePqxklq0rnMPGDpL9Gy28Vr2siYpnemHpK1bwFGR10+36gGT G8vhMskG39PKRNXv5G0TEgAJ2Aa2FIpPYhm+Tp9DWFrcIhy7baxmQh0EUbJJmmGm4iKP QDNYYKXN6wqhCo3Be+90Hhm9vbNJKiLymxyzkK0+F3YOCXiPT+/OsvZafrL81wPJ29yc XWSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=RkDt/izp2j6Oiv3m+c6ng2LauFU8ekC/1Rot470iJKQ=; b=fKFBQpVzQh2MzWGwpThv69gXKe19W19dcpXDdL44km1UGi4e3jdBMPNs+KBvVCHWxC nSlZUbfpOnQJsZXxA8g2tZuWf4C0juEtFaA/tJWbAX8vesW/AUIehvNdEZnSKxyo5Gxs HNvKGy+4ftcCEoxYNZZEyXX085H75cKCzNKusG19QmNtXyYcu73BgH4YTtH0mW9PAP/r OsGptce/gEakmktwacMJ6A9zpH2JPk2JfYub89mLQzbhkU5mdQTzp61Fhem3hM5cGaHo FC4v2MgxNsTORLe/jA/5ZS/Ig0rZIqS1sMgue7IOaSinauVs0/anmXNR8yKzFAKR1Nem ozew== X-Gm-Message-State: AOAM532qEzuoBuSjx8aKg/EVQ5LBIAueFmMpXw2s8q75p/0fbXXwhIFQ FDuwf/qlIEDh2iQ8DjZkdvq+UpUiPvk= X-Google-Smtp-Source: ABdhPJyhwtsmeYgkRK4AJpsliQ917Q3y2ebTaLXPWR/Ed2lE5jCnrhCmuzPyak2LVO7MnlrrCNXNWQ== X-Received: by 2002:a5d:6c61:0:b0:203:70ec:e77c with SMTP id r1-20020a5d6c61000000b0020370ece77cmr3403180wrz.692.1646916263176; Thu, 10 Mar 2022 04:44:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 05/35] coroutine: small code cleanup in qemu_co_rwlock_wrlock Date: Thu, 10 Mar 2022 13:43:43 +0100 Message-Id: <20220310124413.1102441-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::436 (failed) 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=2a00:1450:4864:20::436; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x436.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646919434128100001 Content-Type: text/plain; charset="utf-8" qemu_co_rwlock_wrlock stores the current coroutine in a local variable, use it instead of calling qemu_coroutine_self() again. Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- util/qemu-coroutine-lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index c29cb69f5e..3f12b53a31 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -436,7 +436,7 @@ void qemu_co_rwlock_wrlock(CoRwlock *lock) lock->owners =3D -1; qemu_co_mutex_unlock(&lock->mutex); } else { - CoRwTicket my_ticket =3D { false, qemu_coroutine_self() }; + CoRwTicket my_ticket =3D { false, self }; =20 QSIMPLEQ_INSERT_TAIL(&lock->tickets, &my_ticket, next); qemu_co_mutex_unlock(&lock->mutex); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16469195833131011.9663188043083; Thu, 10 Mar 2022 05:39:43 -0800 (PST) Received: from localhost ([::1]:38688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSJ14-00073J-AG for importer@patchew.org; Thu, 10 Mar 2022 08:39:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9c-0006d1-7R; Thu, 10 Mar 2022 07:44:29 -0500 Received: from [2a00:1450:4864:20::436] (port=43711 helo=mail-wr1-x436.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9a-0005Ay-FU; Thu, 10 Mar 2022 07:44:27 -0500 Received: by mail-wr1-x436.google.com with SMTP id e24so7740069wrc.10; Thu, 10 Mar 2022 04:44:25 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6kzF4fk/7WGa9iQWNCNiXF89/inZenZW77T19RelLEw=; b=gSHudhEZYF4pyVidcb5E384sVoSaVcsA7nbT9DTiJFVJ5ohAANAli0wSBl+4pEha8W +K0yTkaFVkZ/YS4TrassqU+HZHZaiGT+UPrgvyL6udYfKA2awdH5qsvpVyenCMXSwUa1 Rw1VAr3cBhd0BbggiDfm47xBg6eRRmhakX5mOTEoNT27Oxt23tfxs7e4ocH1Ruj1ojPK UZXxAK4xSbNNDEmrooKnLhqe6gG2dYkGEXl76rVh5BHlcAzSRAVBvzsFOLxeg8bJoiaY Gs2Jvkit97mr0uIs+7CycNoVM4/1z2MYa9kUXHGqXrhruEgkF1Wnm9DRp8NqwiNAO9/c pUBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=6kzF4fk/7WGa9iQWNCNiXF89/inZenZW77T19RelLEw=; b=r/IZhceDKHtAxKgmqKDluXHntkSUQQKqROYSf7eufNGo+LItXWowChOczKbzjl9Iou u7xbYP/1gX5lTpsdWBuaaB29c0Ylxzvz/MaXsK4Nk+mL2DDJSt1MjYnbC9qTUaKi+1Fg 7PVbr6mz0SZPvAc/mCwaf8IVL4yYcYbT/oLEPoePCeQsDeRyc8rXxE9QyJs646vJucWI nm5JQ+E+zm8yovQigB33G7dDAfWihNKlk38ogfi6o6rdpOzTtuXYMKad8Op1w31AD6ry 9MUGyuGY/n4mNM7n1J/txOvXJfH4DVlD8T4tz0rHuELaPLhB4j1q/pnZsh63c7ysDK4Q mkwg== X-Gm-Message-State: AOAM533er8PDswsqFuhXmti4nsgqkZIVLiZcPnF+++lCS+27nSAcY4oV dDlvxy9KYWVnQFVX5D1h3KYhs4cqmH0= X-Google-Smtp-Source: ABdhPJwIdltThobXnUfgESeglDJdBDt4AEcnDZt53a4jl5h5EDsimdaWh+taD1/A2KYJhQIdGqW3QQ== X-Received: by 2002:a5d:64e5:0:b0:1fb:5b9a:1a20 with SMTP id g5-20020a5d64e5000000b001fb5b9a1a20mr3431851wri.34.1646916264056; Thu, 10 Mar 2022 04:44:24 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 06/35] disable some code Date: Thu, 10 Mar 2022 13:43:44 +0100 Message-Id: <20220310124413.1102441-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::436 (failed) 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=2a00:1450:4864:20::436; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x436.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646919584284100001 Content-Type: text/plain; charset="utf-8" Disable a lot of code that I can't be bothered to convert right now. Signed-off-by: Paolo Bonzini --- tests/unit/meson.build | 2 +- tests/unit/test-coroutine.c | 6 ++++++ util/meson.build | 10 +++++----- util/qemu-coroutine-lock.c | 2 ++ util/qemu-coroutine-sleep.c | 2 ++ 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/unit/meson.build b/tests/unit/meson.build index 96b295263e..4ca5fdb699 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -61,7 +61,7 @@ endif =20 if have_block tests +=3D { - 'test-coroutine': [testblock], + 'test-coroutine': [], 'test-aio': [testblock], 'test-aio-multithread': [testblock], 'test-throttle': [testblock], diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index 82e22db070..c230c2fa6e 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -16,6 +16,7 @@ #include "qemu/coroutine_int.h" #include "qemu/lockable.h" =20 +#if 0 /* * Check that qemu_in_coroutine() works */ @@ -638,11 +639,13 @@ static void perf_cost(void) duration, ops, (unsigned long)(1000000000.0 * duration / maxcycles)); } +#endif =20 int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); =20 +#if 0 /* This test assumes there is a freelist and marks freed coroutine mem= ory * with a sentinel value. If there is no freelist this would legitima= tely * crash, so skip it. @@ -650,7 +653,9 @@ int main(int argc, char **argv) if (CONFIG_COROUTINE_POOL) { g_test_add_func("/basic/no-dangling-access", test_no_dangling_acce= ss); } +#endif =20 +#if 0 g_test_add_func("/basic/lifecycle", test_lifecycle); g_test_add_func("/basic/yield", test_yield); g_test_add_func("/basic/nesting", test_nesting); @@ -669,5 +674,6 @@ int main(int argc, char **argv) g_test_add_func("/perf/function-call", perf_baseline); g_test_add_func("/perf/cost", perf_cost); } +#endif return g_test_run(); } diff --git a/util/meson.build b/util/meson.build index f6ee74ad0c..30949cd481 100644 --- a/util/meson.build +++ b/util/meson.build @@ -76,13 +76,13 @@ if have_block util_ss.add(files('lockcnt.c')) util_ss.add(files('main-loop.c')) util_ss.add(files('nvdimm-utils.c')) - util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-cor= outine-io.c')) - util_ss.add(when: 'CONFIG_LINUX', if_true: [ - files('vhost-user-server.c'), vhost_user - ]) + util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c')) # 'qemu-= coroutine-io.c' +# util_ss.add(when: 'CONFIG_LINUX', if_true: [ +# files('vhost-user-server.c'), vhost_user +# ]) util_ss.add(files('block-helpers.c')) util_ss.add(files('qemu-coroutine-sleep.c')) - util_ss.add(files('qemu-co-shared-resource.c')) +# util_ss.add(files('qemu-co-shared-resource.c')) util_ss.add(files('thread-pool.c', 'qemu-timer.c')) util_ss.add(files('readline.c')) util_ss.add(files('throttle.c')) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index 3f12b53a31..d6c0565ba5 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -34,6 +34,7 @@ #include "block/aio.h" #include "trace.h" =20 +#if 0 void qemu_co_queue_init(CoQueue *queue) { QSIMPLEQ_INIT(&queue->entries); @@ -465,3 +466,4 @@ void qemu_co_rwlock_upgrade(CoRwlock *lock) assert(lock->owners =3D=3D -1); } } +#endif diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index 571ab521ff..b5bfb4ad18 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -17,6 +17,7 @@ #include "qemu/timer.h" #include "block/aio.h" =20 +#if 0 static const char *qemu_co_sleep_ns__scheduled =3D "qemu_co_sleep_ns"; =20 void qemu_co_sleep_wake(QemuCoSleep *w) @@ -78,3 +79,4 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *= w, qemu_co_sleep(w); timer_del(&ts); } +#endif --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646919840553388.20174132620457; Thu, 10 Mar 2022 05:44:00 -0800 (PST) Received: from localhost ([::1]:46488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSJ5C-0004Ao-Nx for importer@patchew.org; Thu, 10 Mar 2022 08:43:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9e-0006eg-MJ; Thu, 10 Mar 2022 07:44:30 -0500 Received: from [2a00:1450:4864:20::42a] (port=37516 helo=mail-wr1-x42a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9b-0005BE-3A; Thu, 10 Mar 2022 07:44:29 -0500 Received: by mail-wr1-x42a.google.com with SMTP id q14so7787133wrc.4; Thu, 10 Mar 2022 04:44:26 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FZTGpKD1V1daCcQooV+d3hKY0yPYSonlzjUhTBgMbvI=; b=m4OEVtbicg0iaYVYLcQpIgr4jQArcTqsNqGBw6pEZj48+Cod7Fx7B8B7t4ebP5+Nc/ O7/zZMDE56xaKc7kD4JrisK2om02tDRd8pOqOmJrblDY1+mQA5uw9RFLaHCqsPr4q6rO OOGy8b8l7qwPc0vt3QHKugjPQMjOvXr0vPtadSvZU50SMXMRKimMRjLQ5aVq1BktcXtj LVb3HBW+6UQkbk+TvF+8DJv8KhFCxyClenf8DXfOXBZul71P1h7GD8dRx2mM2nEHX7LQ 1pRrLCUGr8vHacvQ58Ltz1r717/1RwdMkm4Hu5Ua9z2oqwQdAEg1kOh9JN+rJuFmFL9b 55/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=FZTGpKD1V1daCcQooV+d3hKY0yPYSonlzjUhTBgMbvI=; b=G4v0hMv5sy1mflQ2i3xvMcTdGNBlPMxnFGrF9E+4Q2bXaJwWFSxJyKGhT9ZsJ2Glzj 5GCA/AuJuqowf6D/lLN8b+fajGGXLcgN/hyoHvAxg/Jv8lQpLl8vq6ZOiO3bVyENGlgh 32kX/oXaPhe9J9JmTQHtSVOarms9top3R+KB0ClKcxOgEtTq5ByTEgEkdPkABX6NOori 8efddoXP9n96yVBxl7gfbD9jbQfb99b7a/hunB1DIB5PYjovYnQ3a9WroTku8v1KrCdf HwrUgmXyg5tdNyaBdj6BeSkS8ZzXKpSjIZEQVC2TN9gMInU6jXxwwlPhxuMIjh6l5bOi qokQ== X-Gm-Message-State: AOAM532W3Rljuyjc79IFe0D/GG4u8Szt2Rnli+zMHImA2A5Vx28fH421 ksjyozmgLFyO9vAsSs37GcvckTaVsZU= X-Google-Smtp-Source: ABdhPJxLm0djZ8weu8IB+cLYt1CtRpOD78sOmHGLXk3zEbbvCdtUkzV2sb26G+9JR0zOPozVFKelCg== X-Received: by 2002:a5d:598a:0:b0:1f1:fa29:1ba6 with SMTP id n10-20020a5d598a000000b001f1fa291ba6mr3379849wri.90.1646916265213; Thu, 10 Mar 2022 04:44:25 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 07/35] coroutine: introduce the "stackless coroutine" backend Date: Thu, 10 Mar 2022 13:43:45 +0100 Message-Id: <20220310124413.1102441-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42a (failed) 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=2a00:1450:4864:20::42a; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646919842947100001 Content-Type: text/plain; charset="utf-8" This backend is similar to the one that was written for the "Continuation Passing C" precompiler[1]. The main advantages of stackless coroutines, in the context of QEMU, are two. First, they do not make any assumption on the layout of the stack (e.g. they do not need any special treatment for control-flow protection technologies such as SafeStack or CET). Second, they do not hide from the compiler the fact that coroutines can and will move across threads. Stackless coroutines actually do have a stack, but the frames of awaitable functions are kept outside the *processor* stack. The qemu_coroutine_switch function from the runtime repeatedly invokes the "handler" for the topmost entry of the coroutine call stack, so that there is nothing on the processor stack between qemu_coroutine_switch and a function that can yield. Therefore, yielding can be done simply by returning back to qemu_coroutine_switch. An awaitable function is split in two parts. User code calls an external function that sets up the stack frame with the arguments and calls into the second part. The second part takes a single void* argument pointing to the stack frame, so that it can be called on resumption from qemu_coroutine_switch. You can already see a bit of this separation in the runtime, where qemu_coroutine_new sets up a frame for coroutine_trampoline, which is the function that is actually invoked by qemu_coroutine_switch. Both parts return a CoroutineAction enum: COROUTINE_CONTINUE to just go on with the execution loop (typically because an awaitable function reached the end of the function and popped a stack frame, more on this below), COROUTINE_YIELD to exit to the caller, COROUTINE_TERMINATE to clean up the current coroutine and exit to the caller. COROUTINE_TERMINATE actually is only returned by the runtime's internal coroutine_trampoline. The fact that the return value is always a CoroutineAction (the actual return value must be done with a pointer argument, pointing into the caller's stack frame) means that code changes are necessary for the coroutine themselves; that's a separate topic which I'll get to in a moment. Compared to other backends, the only extra change needed to common code is in the implementation of qemu_coroutine_yield(). The implementation for fiber-based backends cannot be reused because qemu_coroutine_yield() now needs to return a CoroutineAction enum, just like any other awaitable function[2]. There are two possible implementation of the stackless coroutine handlers. The first is to change the handler address every time an awaitable function yields, pointing the handler to a function that executes the rest of the function. This effectively means transforming the function to continuation-passing style and is what Continuation Passing C did. The alternative is to turn the function into a state machine (a large switch statement); the information on where to restart execution is stored in the stack frame. This is the approach that I chose for these conversions. Because the yield points can be arbitrarily inside loops or conditionals, this would be a very hard thing to do for a source-to-sour= ce translator in any normal language. But C is not a normal language, and especially its switch statement is not normal. A construction similar to Duff's device makes it possible to do this in a source-to-source manner: switch (t->_step) { case 0: do_something_without_yielding(); for (i =3D 0; i < n; i++) { ... t->_step =3D 1; t->i =3D i; t->n =3D n; return another_coroutine(...); case 1: i =3D t->i; n =3D t->n; ... } } Putting everything in a single function *should* reduces code size somewhat (due to prologs and epilogs), and would also provide chances for optimization when an awaitable function is called but does not yield. I have not done this in this series, but it basically would entail changing all occurrences of "return awaitable_function();" to if (awaitable_function() =3D=3D COROUTINE_YIELD) return COROUTINE_YIELD; fallthrough; Because of the code transformations that are needed, stackless coroutines require compiler support. Manual conversion is something I did for this experiment but I don't recommend for your sanity; it should be restricted to internal functions such as coroutine_trampoline or qemu_coroutine_yield(). Therefore, the idea would be to use a source-to-source translator, again similar to Continuation Passing C. Debugging support on the level of the current gdb script is probably possible too. A basic translator should produce code roughly similar to the one that I have written by hand, except when I applied a little more care or sophistication to simplify the translation. For example, if a function does not call an awaitable function except in tail calls, it is not necessary to construct a stack frame and tear it away immediately after the tail calls return. I have sometimes done this because it makes the conversion simpler. In addition, the translator need not save variables that are not written on any path from a previous yield point to the current one, and need not load variables that are not read on any path from the current yield point to the next one. This looks complicated but is a relatively simple data flow problem---but anyway it's not important for a basic translator. A final design point is the implementation of the per-coroutine stack. In this implementation I chose to have no allocations while coroutines run: the per-coroutine stack is really a stack that carves out frames from a large COROUTINE_STACK_SIZE-bytes block. However, it is also possible to implement coroutine_stack_alloc and coroutine_stack_free using malloc/free. [1] https://arxiv.org/pdf/1310.3404.pdf [2] The QEMU/CPC paper kept the target-independent qemu_coroutine_yield, by special casing it in the runtime. I chose not to because, if QEMU were to switch to stackless coroutines, the other backends would likely be dropped at the same time. Signed-off-by: Paolo Bonzini --- configure | 44 +--------- include/qemu/co-lockable.h | 26 ++++-- include/qemu/coroutine.h | 48 +++++++---- include/qemu/coroutine_int.h | 6 -- util/coroutine-stackless.c | 159 +++++++++++++++++++++++++++++++++++ util/qemu-coroutine.c | 16 ---- 6 files changed, 212 insertions(+), 87 deletions(-) create mode 100644 util/coroutine-stackless.c diff --git a/configure b/configure index 886000346a..e45d2c3b9c 100755 --- a/configure +++ b/configure @@ -1220,8 +1220,6 @@ Advanced options (experts only): --with-trace-file=3DNAME Full PATH,NAME of file to store traces Default:trace- --cpu=3DCPU Build for host CPU [$cpu] - --with-coroutine=3DBACKEND coroutine backend. Supported options: - ucontext, sigaltstack, windows --enable-gcov enable test coverage analysis with gcov --tls-priority default TLS protocol/cipher priority string --enable-plugins @@ -1242,7 +1240,7 @@ cat << EOF debug-info debugging information lto Enable Link-Time Optimization. safe-stack SafeStack Stack Smash Protection. Depends on - clang/llvm >=3D 3.7 and requires coroutine backend ucont= ext. + clang/llvm >=3D 3.7 rdma Enable RDMA-based migration pvrdma Enable PVRDMA support vhost-net vhost-net kernel acceleration support @@ -2338,39 +2336,7 @@ EOF fi fi =20 -if test "$coroutine" =3D ""; then - if test "$mingw32" =3D "yes"; then - coroutine=3Dwin32 - elif test "$ucontext_works" =3D "yes"; then - coroutine=3Ducontext - else - coroutine=3Dsigaltstack - fi -else - case $coroutine in - windows) - if test "$mingw32" !=3D "yes"; then - error_exit "'windows' coroutine backend only valid for Windows" - fi - # Unfortunately the user visible backend name doesn't match the - # coroutine-*.c filename for this case, so we have to adjust it here. - coroutine=3Dwin32 - ;; - ucontext) - if test "$ucontext_works" !=3D "yes"; then - feature_not_found "ucontext" - fi - ;; - sigaltstack) - if test "$mingw32" =3D "yes"; then - error_exit "only the 'windows' coroutine backend is valid for Window= s" - fi - ;; - *) - error_exit "unknown coroutine backend $coroutine" - ;; - esac -fi +coroutine=3Dstackless =20 ################################################## # SafeStack @@ -2395,9 +2361,6 @@ EOF else error_exit "SafeStack not supported by your compiler" fi - if test "$coroutine" !=3D "ucontext"; then - error_exit "SafeStack is only supported by the coroutine backend ucont= ext" - fi else cat > $TMPC << EOF int main(int argc, char *argv[]) @@ -2427,9 +2390,6 @@ else # "$safe_stack" =3D "" safe_stack=3D"no" else safe_stack=3D"yes" - if test "$coroutine" !=3D "ucontext"; then - error_exit "SafeStack is only supported by the coroutine backend uco= ntext" - fi fi fi fi diff --git a/include/qemu/co-lockable.h b/include/qemu/co-lockable.h index 09f4620017..95d058e2c9 100644 --- a/include/qemu/co-lockable.h +++ b/include/qemu/co-lockable.h @@ -16,7 +16,7 @@ #include "qemu/coroutine.h" #include "qemu/thread.h" =20 -typedef void coroutine_fn QemuCoLockUnlockFunc(void *); +typedef CoroutineAction QemuCoLockUnlockFunc(void *); =20 struct QemuCoLockable { void *object; @@ -24,6 +24,18 @@ struct QemuCoLockable { QemuCoLockUnlockFunc *unlock; }; =20 +static inline CoroutineAction qemu_mutex_co_lock(QemuMutex *mutex) +{ + qemu_mutex_lock(mutex); + return COROUTINE_CONTINUE; +} + +static inline CoroutineAction qemu_mutex_co_unlock(QemuMutex *mutex) +{ + qemu_mutex_unlock(mutex); + return COROUTINE_CONTINUE; +} + static inline __attribute__((__always_inline__)) QemuCoLockable * qemu_make_co_lockable(void *x, QemuCoLockable *lockable) { @@ -68,7 +80,7 @@ qemu_null_co_lockable(void *x) #define QEMU_MAKE_CO_LOCKABLE(x) = \ _Generic((x), QemuCoLockable *: (x), = \ void *: qemu_null_co_lockable(x), = \ - QemuMutex *: qemu_make_co_lockable(x, QMCL_OBJ_(x, mutex)), = \ + QemuMutex *: qemu_make_co_lockable(x, QMCL_OBJ_(x, mutex_co))= , \ CoMutex *: qemu_make_co_lockable(x, QMCL_OBJ_(x, co_mutex))) = \ =20 /** @@ -82,17 +94,17 @@ qemu_null_co_lockable(void *x) */ #define QEMU_MAKE_CO_LOCKABLE_NONNULL(x) \ _Generic((x), QemuCoLockable *: (x), \ - QemuMutex *: QMCL_OBJ_(x, mutex), \ + QemuMutex *: QMCL_OBJ_(x, mutex_co), \ CoMutex *: QMCL_OBJ_(x, co_mutex)) =20 -static inline void coroutine_fn qemu_co_lockable_lock(QemuCoLockable *x) +static inline CoroutineAction qemu_co_lockable_lock(QemuCoLockable *x) { - x->lock(x->object); + return x->lock(x->object); } =20 -static inline void coroutine_fn qemu_co_lockable_unlock(QemuCoLockable *x) +static inline CoroutineAction qemu_co_lockable_unlock(QemuCoLockable *x) { - x->unlock(x->object); + return x->unlock(x->object); } =20 #endif diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index b23fba88c2..2f2be6abfe 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -18,6 +18,20 @@ #include "qemu/queue.h" #include "qemu/timer.h" =20 +typedef enum { + COROUTINE_YIELD =3D 1, + COROUTINE_TERMINATE =3D 2, + COROUTINE_ENTER =3D 3, + COROUTINE_CONTINUE =3D 4, +} CoroutineAction; + +typedef CoroutineAction CoroutineImpl(void *opaque); + +typedef struct { + CoroutineImpl *caller_func; + void *caller_frame; +} CoroutineFrame; + /** * Coroutines are a mechanism for stack switching and can be used for * cooperative userspace threading. These functions provide a simple but @@ -56,7 +70,7 @@ typedef struct Coroutine Coroutine; * When this function returns, the coroutine is destroyed automatically and * execution continues in the caller who last entered the coroutine. */ -typedef void coroutine_fn CoroutineEntry(void *opaque); +typedef CoroutineAction CoroutineEntry(void *opaque); =20 /** * Create a new coroutine @@ -88,7 +102,7 @@ void qemu_aio_coroutine_enter(AioContext *ctx, Coroutine= *co); * This function does not return until the coroutine is re-entered using * qemu_coroutine_enter(). */ -void coroutine_fn qemu_coroutine_yield(void); +CoroutineAction qemu_coroutine_yield(void); =20 /** * Get the AioContext of the given coroutine @@ -160,13 +174,13 @@ void qemu_co_mutex_init(CoMutex *mutex); * Locks the mutex. If the lock cannot be taken immediately, control is * transferred to the caller of the current coroutine. */ -void coroutine_fn qemu_co_mutex_lock(CoMutex *mutex); +CoroutineAction qemu_co_mutex_lock(CoMutex *mutex); =20 /** * Unlocks the mutex and schedules the next coroutine that was waiting for= this * lock to be run. */ -void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex); +CoroutineAction qemu_co_mutex_unlock(CoMutex *mutex); =20 /** * Assert that the current coroutine holds @mutex. @@ -206,7 +220,7 @@ void qemu_co_queue_init(CoQueue *queue); */ #define qemu_co_queue_wait(queue, lock) \ qemu_co_queue_wait_impl(queue, QEMU_MAKE_CO_LOCKABLE(lock)) -void coroutine_fn qemu_co_queue_wait_impl(CoQueue *queue, QemuCoLockable *= lock); +CoroutineAction qemu_co_queue_wait_impl(CoQueue *queue, QemuCoLockable *lo= ck); =20 /** * Removes the next coroutine from the CoQueue, and wake it up. @@ -262,7 +276,7 @@ void qemu_co_rwlock_init(CoRwlock *lock); * of a parallel writer, control is transferred to the caller of the curre= nt * coroutine. */ -void coroutine_fn qemu_co_rwlock_rdlock(CoRwlock *lock); +CoroutineAction qemu_co_rwlock_rdlock(CoRwlock *lock); =20 /** * Write Locks the CoRwlock from a reader. This is a bit more efficient t= han @@ -271,7 +285,7 @@ void coroutine_fn qemu_co_rwlock_rdlock(CoRwlock *lock); * to the caller of the current coroutine; another writer might run while * @qemu_co_rwlock_upgrade blocks. */ -void coroutine_fn qemu_co_rwlock_upgrade(CoRwlock *lock); +CoroutineAction qemu_co_rwlock_upgrade(CoRwlock *lock); =20 /** * Downgrades a write-side critical section to a reader. Downgrading with @@ -279,20 +293,20 @@ void coroutine_fn qemu_co_rwlock_upgrade(CoRwlock *lo= ck); * followed by @qemu_co_rwlock_rdlock. This makes it more efficient, but * may also sometimes be necessary for correctness. */ -void coroutine_fn qemu_co_rwlock_downgrade(CoRwlock *lock); +CoroutineAction qemu_co_rwlock_downgrade(CoRwlock *lock); =20 /** * Write Locks the mutex. If the lock cannot be taken immediately because * of a parallel reader, control is transferred to the caller of the curre= nt * coroutine. */ -void coroutine_fn qemu_co_rwlock_wrlock(CoRwlock *lock); +CoroutineAction qemu_co_rwlock_wrlock(CoRwlock *lock); =20 /** * Unlocks the read/write lock and schedules the next coroutine that was * waiting for this lock to be run. */ -void coroutine_fn qemu_co_rwlock_unlock(CoRwlock *lock); +CoroutineAction qemu_co_rwlock_unlock(CoRwlock *lock); =20 typedef struct QemuCoSleep { Coroutine *to_wake; @@ -303,18 +317,18 @@ typedef struct QemuCoSleep { * during this yield, it can be passed to qemu_co_sleep_wake() to * terminate the sleep. */ -void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, +CoroutineAction qemu_co_sleep_ns_wakeable(QemuCoSleep *w, QEMUClockType type, int64_t ns= ); =20 /** * Yield the coroutine until the next call to qemu_co_sleep_wake. */ -void coroutine_fn qemu_co_sleep(QemuCoSleep *w); +CoroutineAction qemu_co_sleep(QemuCoSleep *w); =20 -static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64= _t ns) +static inline CoroutineAction qemu_co_sleep_ns(QEMUClockType type, int64_t= ns) { QemuCoSleep w =3D { 0 }; - qemu_co_sleep_ns_wakeable(&w, type, ns); + return qemu_co_sleep_ns_wakeable(&w, type, ns); } =20 /** @@ -330,7 +344,7 @@ void qemu_co_sleep_wake(QemuCoSleep *w); * * Note that this function clobbers the handlers for the file descriptor. */ -void coroutine_fn yield_until_fd_readable(int fd); +CoroutineAction yield_until_fd_readable(int fd); =20 /** * Increase coroutine pool size @@ -342,7 +356,9 @@ void qemu_coroutine_increase_pool_batch_size(unsigned i= nt additional_pool_size); */ void qemu_coroutine_decrease_pool_batch_size(unsigned int additional_pool_= size); =20 -#include "qemu/lockable.h" #include "qemu/co-lockable.h" =20 +void *coroutine_only_fn stack_alloc(CoroutineImpl *func, size_t bytes); +CoroutineAction coroutine_only_fn stack_free(CoroutineFrame *f); + #endif /* QEMU_COROUTINE_H */ diff --git a/include/qemu/coroutine_int.h b/include/qemu/coroutine_int.h index 1da148552f..1989370194 100644 --- a/include/qemu/coroutine_int.h +++ b/include/qemu/coroutine_int.h @@ -35,12 +35,6 @@ extern __thread void *__safestack_unsafe_stack_ptr; =20 #define COROUTINE_STACK_SIZE (1 << 20) =20 -typedef enum { - COROUTINE_YIELD =3D 1, - COROUTINE_TERMINATE =3D 2, - COROUTINE_ENTER =3D 3, -} CoroutineAction; - struct Coroutine { CoroutineEntry *entry; void *entry_arg; diff --git a/util/coroutine-stackless.c b/util/coroutine-stackless.c new file mode 100644 index 0000000000..7ba3b0cf63 --- /dev/null +++ b/util/coroutine-stackless.c @@ -0,0 +1,159 @@ +/* + * stackless coroutine initialization code + * + * Copyright (C) 2022 Paolo BOnzini + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + */ + +#include "qemu/osdep.h" +#include "trace.h" +#include "qemu/coroutine_int.h" + +typedef struct { + Coroutine base; + void *stack; + void *stack_ptr; + CoroutineImpl *current_func; + void *current_frame; +} CoroutineStackless; + +static __thread CoroutineStackless leader; +static __thread Coroutine *current; + +static void *coroutine_stack_alloc(CoroutineStackless *co, CoroutineImpl *= func, size_t bytes) +{ + CoroutineFrame *ret =3D co->stack_ptr; + + bytes =3D ROUND_UP(bytes, 16); + assert(bytes <=3D COROUTINE_STACK_SIZE - (co->stack_ptr - co->stack)); + co->stack_ptr +=3D bytes; + ret->caller_func =3D co->current_func; + ret->caller_frame =3D co->current_frame; + co->current_func =3D func; + co->current_frame =3D ret; + return ret; +} + +static void coroutine_stack_free(CoroutineStackless *co, CoroutineFrame *f) +{ + assert((void *)f >=3D co->stack && (void *)f < co->stack_ptr); + co->current_func =3D f->caller_func; + co->current_frame =3D f->caller_frame; + co->stack_ptr =3D f; +} + +struct FRAME__coroutine_trampoline { + CoroutineFrame common; + bool back; +}; + +static CoroutineAction coroutine_trampoline(void *_frame) +{ + struct FRAME__coroutine_trampoline *_f =3D _frame; + Coroutine *co =3D current; + if (!_f->back) { + _f->back =3D true; + // or: + // if (co->entry(co->entry_arg) =3D=3D COROUTINE_YIELD) return C= OROUTINE_YIELD; + return co->entry(co->entry_arg); + } + + _f->back =3D false; + current =3D co->caller; + co->caller =3D NULL; + return COROUTINE_TERMINATE; +} + +Coroutine *qemu_coroutine_new(void) +{ + CoroutineStackless *co; + struct FRAME__coroutine_trampoline *frame; + + co =3D g_malloc0(sizeof(*co)); + co->stack =3D g_malloc(COROUTINE_STACK_SIZE); + co->stack_ptr =3D co->stack; + + frame =3D coroutine_stack_alloc(co, coroutine_trampoline, sizeof(*fram= e)); + frame->back =3D false; + return &co->base; +} + +void qemu_coroutine_delete(Coroutine *co_) +{ + CoroutineStackless *co =3D DO_UPCAST(CoroutineStackless, base, co_); + struct FRAME__coroutine_trampoline *frame =3D co->current_frame; + + assert(!frame->back); + coroutine_stack_free(co, co->current_frame); + assert(co->stack_ptr =3D=3D co->stack); + g_free(co->stack); + g_free(co); +} + +CoroutineAction +qemu_coroutine_switch(Coroutine *from, Coroutine *to, + CoroutineAction action) +{ + assert(action =3D=3D COROUTINE_ENTER); + assert(to->caller !=3D NULL); + current =3D to; + do { + CoroutineStackless *co =3D DO_UPCAST(CoroutineStackless, base, to); + action =3D co->current_func(co->current_frame); + } while (action =3D=3D COROUTINE_CONTINUE); + assert(action !=3D COROUTINE_ENTER); + return action; +} + +CoroutineAction qemu_coroutine_yield(void) +{ + Coroutine *from =3D current; + Coroutine *to =3D from->caller; + trace_qemu_coroutine_yield(from, to); + if (!to) { + fprintf(stderr, "Co-routine is yielding to no one\n"); + abort(); + } + from->caller =3D NULL; + current =3D to; + return COROUTINE_YIELD; +} + +Coroutine *qemu_coroutine_self(void) +{ + if (!current) { + current =3D &leader.base; + } + return current; +} + +bool qemu_in_coroutine(void) +{ + return current && current->caller; +} + +void *stack_alloc(CoroutineImpl *func, size_t bytes) +{ + CoroutineStackless *co =3D DO_UPCAST(CoroutineStackless, base, current= ); + + return coroutine_stack_alloc(co, func, bytes); +} + +CoroutineAction stack_free(CoroutineFrame *f) +{ + CoroutineStackless *co =3D DO_UPCAST(CoroutineStackless, base, current= ); + coroutine_stack_free(co, f); + return COROUTINE_CONTINUE; +} diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c index 9f2bd96fa0..0ae2a4090f 100644 --- a/util/qemu-coroutine.c +++ b/util/qemu-coroutine.c @@ -179,22 +179,6 @@ void qemu_coroutine_enter_if_inactive(Coroutine *co) } } =20 -void coroutine_fn qemu_coroutine_yield(void) -{ - Coroutine *self =3D qemu_coroutine_self(); - Coroutine *to =3D self->caller; - - trace_qemu_coroutine_yield(self, to); - - if (!to) { - fprintf(stderr, "Co-routine is yielding to no one\n"); - abort(); - } - - self->caller =3D NULL; - qemu_coroutine_switch(self, to, COROUTINE_YIELD); -} - bool qemu_coroutine_entered(Coroutine *co) { return co->caller; --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646919721616939.214255359567; Thu, 10 Mar 2022 05:42:01 -0800 (PST) Received: from localhost ([::1]:42416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSJ3I-0001Sr-Lj for importer@patchew.org; Thu, 10 Mar 2022 08:42:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9d-0006dX-Hv; Thu, 10 Mar 2022 07:44:30 -0500 Received: from [2a00:1450:4864:20::436] (port=41656 helo=mail-wr1-x436.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9c-0005BR-1R; Thu, 10 Mar 2022 07:44:29 -0500 Received: by mail-wr1-x436.google.com with SMTP id i8so7760122wrr.8; Thu, 10 Mar 2022 04:44:27 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=svq297zy+T3gF7Thq7aDCBc0NI2G3Ftc2FuvIDZJFWk=; b=OeHeRQtTghGlgUYBd3wFNSlLZPWFE3BcD/H4+n2/v4fYQ/MC0QNaj337jCZxiTwTUR e3hEveWClkIbk/FRQ/AMA5hrpRu/CPqp6qXu147tErvwDiIrsgQl6yBdFBNb9PR9DPO8 PBwd0AP4N1xYKEJQXg5TKHa5G7HJ1/D3X9Xr15Sr2/zES8Vgmai3NG2BALJUhwb5Gpvi TelJrLpZNJ0F0vPEttXNhuoApoEx3wbN+jMv5oobCrAA1KQ8Pbco5GCWlORGEyFyXUtv BeNO/o884YWm7718wEwKOkIhZzVx9V3BkVGK++yZgUSDFjFPu6ieUm0QIi5tBBSZxWkk bfZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=svq297zy+T3gF7Thq7aDCBc0NI2G3Ftc2FuvIDZJFWk=; b=WNvHFJIbBzsyJzhnq6q56jDIC7HUeP58IUQSAHlKYrD1YhNgui/Myub5+popBmwB1Q E/kGuHBwwkH1bKGF59/q/qMIc53Z9IDgaoam3cQvPlp2Q7qWtzPCPvwlFaXLQClbQbYS OldyJyJhecf/wgczxDAFDNy68IYv3HoVPiCFVndffZInxBD5+UlWzB87watKbsKThH8m Us2WBcckaIzulQRWh3oD5m2GL7fbcrz8o21wFuGh17zMChYd8/yJHobl4083Vxy0RAVa Zsj7zq1wqtQmNrmwScIb26Pla2eIb1QhnA55mri2FwseTscfQK7fwJsB4NZaIiPiwqs8 JRKQ== X-Gm-Message-State: AOAM532M8lD0OOnY3ZU22Ei0E2XIwSsBFjsAU4ZMksXD8O1S4CYNwtHF oONn4Sj9zZyY1C6ELGsSCtzP+8Z5WIE= X-Google-Smtp-Source: ABdhPJyZFgjJxqzRugrp56q/3Gi+tH//9tarwQj0fDDUwPdJCjPGhC5Cn2BKMPiOxzYmsZQCy9aZCw== X-Received: by 2002:a05:6000:1d89:b0:1ed:b6d5:cbda with SMTP id bk9-20020a0560001d8900b001edb6d5cbdamr3377458wrb.514.1646916266518; Thu, 10 Mar 2022 04:44:26 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 08/35] /basic/lifecycle Date: Thu, 10 Mar 2022 13:43:46 +0100 Message-Id: <20220310124413.1102441-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::436 (failed) 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=2a00:1450:4864:20::436; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x436.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646919723248100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index c230c2fa6e..3670750c5b 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -423,16 +423,18 @@ static void test_co_rwlock_downgrade(void) =20 g_assert(c1_done); } +#endif =20 /* * Check that creation, enter, and return work */ =20 -static void coroutine_fn set_and_exit(void *opaque) +static CoroutineAction set_and_exit(void *opaque) { bool *done =3D opaque; =20 *done =3D true; + return COROUTINE_CONTINUE; } =20 static void test_lifecycle(void) @@ -452,6 +454,7 @@ static void test_lifecycle(void) g_assert(done); /* expect done to be true (second time) */ } =20 +#if 0 =20 #define RECORD_SIZE 10 /* Leave some room for expansion */ struct coroutine_position { @@ -655,8 +658,8 @@ int main(int argc, char **argv) } #endif =20 -#if 0 g_test_add_func("/basic/lifecycle", test_lifecycle); +#if 0 g_test_add_func("/basic/yield", test_yield); g_test_add_func("/basic/nesting", test_nesting); g_test_add_func("/basic/self", test_self); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646916847346237.74919357165686; Thu, 10 Mar 2022 04:54:07 -0800 (PST) Received: from localhost ([::1]:33244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIIw-0001Dk-Cx for importer@patchew.org; Thu, 10 Mar 2022 07:54:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9f-0006fm-2T; Thu, 10 Mar 2022 07:44:31 -0500 Received: from [2a00:1450:4864:20::32a] (port=50691 helo=mail-wm1-x32a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9d-0005Be-DP; Thu, 10 Mar 2022 07:44:30 -0500 Received: by mail-wm1-x32a.google.com with SMTP id l10so3196057wmb.0; Thu, 10 Mar 2022 04:44:28 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2cqgz/F/tq6WMZLaHRWJJzZQDdwgOx1eBo+ARCMxfoU=; b=I3UwZECtz27y88tNCRouI1XPB81OFgklj23vZdsVR7hLyVBNwIqE7386sRwBXI77Gs cTRzegjIyvF+KvqMIQt0dgdc/Sii3NZU05TU0xJVfjtvO8+VDPyMqTIg5z7X/y1WYGPG GpdYS83oUP0EpUZUxy5jv3w9NiB2BarQJW9QfrgpBYIkTLyMQhL5MN36htamNSlu7114 JkdkJ2t+inW6YGl0ICDsTKGIlvpBkiJfPQenCLktpv/nnp2g5AS1KCbsatYvr1MucVN4 LuWE0LSOLw9rDFy2mGJrfOOX/fGI7cx+ZHIlC0zb37tQaD7dtRFp+mpAeczfb422qR/J A+XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=2cqgz/F/tq6WMZLaHRWJJzZQDdwgOx1eBo+ARCMxfoU=; b=R1n5KbUHr5Uij0DOf1RFk2K3mu/qVI0RqmMjDIBkA2RONYr+ee/9whBDSaUyW8OFxQ CMf46qhxK/67BEVx3arBVyd3k7jWIE8XqR09faQpSnI1EYcnHxtahIQBwVAWtSd3oVi/ aMgKTulEYBfCwjZtOn89XbGgB9gLgRQ4FwWBkJfrLtrZlb7kXyhU6Y9fm4OuqivfHOVn IGMC6lx+xUWfD9ChqTCkxgYK86ticDdW4P1Wf1ZdTzIOMVPUahPN4EtIYY9fNJDH4h6t uCZiBZF+d/S8XmTsA2U8P6s6WaKVIQ1QTgIo9xhpA02UcW+/k+NGVEerM02eLgqKBiqH /osA== X-Gm-Message-State: AOAM533IWKmqnbBDiWbR67pEQZ0Zb++sEbJp9oqXv/fT//WDm9ZY3uOA vQ5/BSxs06/Bw4/HwodB+LRZRpfNx5M= X-Google-Smtp-Source: ABdhPJzd7bs0Tt9fIYbswdi2WtSws8yj0kuEUNNDPFfVj6//lRmGnlq7ViIHUoOBi07BWRFB3M66ng== X-Received: by 2002:a05:600c:2c49:b0:384:7202:358e with SMTP id r9-20020a05600c2c4900b003847202358emr11660574wmg.108.1646916267397; Thu, 10 Mar 2022 04:44:27 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 09/35] convert qemu-coroutine-sleep.c to stackless coroutines Date: Thu, 10 Mar 2022 13:43:47 +0100 Message-Id: <20220310124413.1102441-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32a (failed) 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=2a00:1450:4864:20::32a; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32a.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646916849443100001 Content-Type: text/plain; charset="utf-8" The main change is to qemu_co_sleep_ns_wakeable, which gets the full conversion treatment. It's important to note that variables that escape (have their address taken), such as "QEMUTimer ts" in this case, move entirely to the frame structure and do not have local variables anymore. For the others, always using the frame structure would be inefficient, so they need to be saved and restored. Perhaps "restrict" would be an idea too, I haven't investigated it. qemu_co_sleep almost has a tail call to qemu_coroutine_yield(), except for an assertion after qemu_coroutine_yield() returns. For simplicity and to demonstrate the optimization I'm removing the assertion. Signed-off-by: Paolo Bonzini --- util/qemu-coroutine-sleep.c | 59 ++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index b5bfb4ad18..3d0b1579b3 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -17,7 +17,6 @@ #include "qemu/timer.h" #include "block/aio.h" =20 -#if 0 static const char *qemu_co_sleep_ns__scheduled =3D "qemu_co_sleep_ns"; =20 void qemu_co_sleep_wake(QemuCoSleep *w) @@ -42,7 +41,7 @@ static void co_sleep_cb(void *opaque) qemu_co_sleep_wake(w); } =20 -void coroutine_fn qemu_co_sleep(QemuCoSleep *w) +CoroutineAction qemu_co_sleep(QemuCoSleep *w) { Coroutine *co =3D qemu_coroutine_self(); =20 @@ -56,27 +55,59 @@ void coroutine_fn qemu_co_sleep(QemuCoSleep *w) } =20 w->to_wake =3D co; - qemu_coroutine_yield(); + return qemu_coroutine_yield(); =20 /* w->to_wake is cleared before resuming this coroutine. */ - assert(w->to_wake =3D=3D NULL); + // assert(w->to_wake =3D=3D NULL); } =20 -void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, - QEMUClockType type, int64_t ns) -{ - AioContext *ctx =3D qemu_get_current_aio_context(); - QEMUTimer ts; +struct FRAME__qemu_co_sleep_ns_wakeable { + CoroutineFrame common; + uint32_t _step; + QemuCoSleep *w; + QEMUClockType type; + int64_t ns; + QEMUTimer ts; +}; =20 - aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w); - timer_mod(&ts, qemu_clock_get_ns(type) + ns); +static CoroutineAction co__qemu_co_sleep_ns_wakeable(void *_frame) +{ + struct FRAME__qemu_co_sleep_ns_wakeable *_f =3D _frame; + AioContext *ctx =3D qemu_get_current_aio_context(); + +switch(_f->_step) { +case 0: { + QemuCoSleep *w =3D _f->w; + QEMUClockType type =3D _f->type; + int64_t ns =3D _f->ns; + aio_timer_init(ctx, &_f->ts, type, SCALE_NS, co_sleep_cb, w); + timer_mod(&_f->ts, qemu_clock_get_ns(type) + ns); =20 /* * The timer will fire in the current AiOContext, so the callback * must happen after qemu_co_sleep yields and there is no race * between timer_mod and qemu_co_sleep. */ - qemu_co_sleep(w); - timer_del(&ts); +_f->_step =3D 1; + return qemu_co_sleep(w); +} +case 1: + timer_del(&_f->ts); + goto _out; +} +_out: +stack_free(&_f->common); +return COROUTINE_CONTINUE; +} + +CoroutineAction qemu_co_sleep_ns_wakeable(QemuCoSleep *w, + QEMUClockType type, int64_t ns) +{ + struct FRAME__qemu_co_sleep_ns_wakeable *f; + f =3D stack_alloc(co__qemu_co_sleep_ns_wakeable, sizeof(*f)); + f->w =3D w; + f->type =3D type; + f->ns =3D ns; + f->_step =3D 0; + return co__qemu_co_sleep_ns_wakeable(f); } -#endif --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646916973604334.5218317634625; Thu, 10 Mar 2022 04:56:13 -0800 (PST) Received: from localhost ([::1]:41702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIKy-0007AN-JL for importer@patchew.org; Thu, 10 Mar 2022 07:56:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9f-0006fv-Pt; Thu, 10 Mar 2022 07:44:32 -0500 Received: from [2a00:1450:4864:20::332] (port=46722 helo=mail-wm1-x332.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9d-0005Bl-Rd; Thu, 10 Mar 2022 07:44:31 -0500 Received: by mail-wm1-x332.google.com with SMTP id p184-20020a1c29c1000000b0037f76d8b484so3293919wmp.5; Thu, 10 Mar 2022 04:44:29 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dT+i83yAoZd+9rOLeIq77urD76H3LMrkKX/uEElWQyo=; b=T/iGyIUsvFykhWGbbVrd6ncd8YOrMw3wDhzqFhuTT4bR7uz4P8SWZzJ9Q7gHigrmxA 6bdXJzXhR2G2+JxPdz49bANFmcO9ZYuIt6aKjeEx3DZPqMqO90BDyKXXVv1Ud/g1dNY9 aK3MQqDUbWMvQKeuDauKzbfPj2km677cUtrOWt50W8a3lixLNFsmpFAk4IYI55QI9Dxd mkciZ9c4ZZBTQhg/TfDbPieMad1A5M1iS+lftAwpUWDMAxYiMQh3kZHC1KURPfFIgwtP SkE7Kpfn3TWjXnGfbFBJADuS7OS6F2Edtx92lHnEmBNR2R4SCaeYwgqiE5e9Q1d5wQrh QW1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=dT+i83yAoZd+9rOLeIq77urD76H3LMrkKX/uEElWQyo=; b=pnsOxRp2xDpu9rvCEEsi1NYHU9FH9KZw5PpESSv5wM45i+9/b2GyWmw3VFwHI84ISr unj9DjlaYOTIqEEo9CL28Ws2yLQvTIAYPR7KmzgZiKOT6yVl0DsznAlw3BTY4+C2e8gV jt+D7ciwi1zrgYK1tDe1pNfAQ9zzwJb4OrpkYS62qpItaApKRDE6MXLyyMVhTZN5IXPD RmfUvJWmgIFbwHENiDI0o6ArTvc2xnoo3AsMh4+br4R4+b1lZZOzjr4HRSNpld9JF4Zk g94k33KUeepF2yqYwnzVjHjjFqcUJkadbs6rgKrskM5WjuuXgKUXLBA1w22WEAxbnRYq GfUw== X-Gm-Message-State: AOAM532rGsx5J4xTtk9Nz5RwafXECc3D7cgPDAnTzTtTKBug/H8goL9x cenXwzj7+rdL/1qhWaptEVo6JXKyxP0= X-Google-Smtp-Source: ABdhPJwKUWciv+lvHNKs9R92wmAIPItHs9heNkd6/mlgZwI7DWSjmN8PFzdR7mhMcrJCjZ2SXQMjHw== X-Received: by 2002:a05:600c:42c1:b0:389:8310:1128 with SMTP id j1-20020a05600c42c100b0038983101128mr3482550wme.3.1646916268253; Thu, 10 Mar 2022 04:44:28 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 10/35] enable tail call optimization of qemu_co_mutex_lock Date: Thu, 10 Mar 2022 13:43:48 +0100 Message-Id: <20220310124413.1102441-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::332 (failed) 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=2a00:1450:4864:20::332; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x332.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646916974407100001 Content-Type: text/plain; charset="utf-8" Make qemu_co_mutex_lock_slowpath a tail call, so that qemu_co_mutex_lock does not need to build a stack frame of its own. Signed-off-by: Paolo Bonzini --- util/qemu-coroutine-lock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index d6c0565ba5..048cfcea71 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -231,6 +231,8 @@ static void coroutine_fn qemu_co_mutex_lock_slowpath(Ai= oContext *ctx, =20 qemu_coroutine_yield(); trace_qemu_co_mutex_lock_return(mutex, self); + mutex->holder =3D self; + self->locks_held++; } =20 void coroutine_fn qemu_co_mutex_lock(CoMutex *mutex) @@ -266,11 +268,11 @@ retry_fast_path: /* Uncontended. */ trace_qemu_co_mutex_lock_uncontended(mutex, self); mutex->ctx =3D ctx; + mutex->holder =3D self; + self->locks_held++; } else { qemu_co_mutex_lock_slowpath(ctx, mutex); } - mutex->holder =3D self; - self->locks_held++; } =20 void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex) --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646917136967542.1140123236013; Thu, 10 Mar 2022 04:58:56 -0800 (PST) Received: from localhost ([::1]:51088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSINb-00053V-VZ for importer@patchew.org; Thu, 10 Mar 2022 07:58:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9g-0006ip-SF; Thu, 10 Mar 2022 07:44:33 -0500 Received: from [2a00:1450:4864:20::431] (port=41652 helo=mail-wr1-x431.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9f-0005CA-7M; Thu, 10 Mar 2022 07:44:32 -0500 Received: by mail-wr1-x431.google.com with SMTP id i8so7760353wrr.8; Thu, 10 Mar 2022 04:44:30 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FQ9jxKI5I1M89vZzYqquoXBdkPU8bHNffna5C1ysXtM=; b=SJ/1MNM2DfoliLjnh72Keto3Cinco9tPyaddBuqlsg0Tk6Nh4qs7CrzYfkQmmcm3IV g5b5UIA8lBvxmYNrUP4Nt5Y9hbu8oRnQnBBqx1FYTqijvTAatsHm8dFvfRA2fUBs5/t8 OjapXsrtWf1p+uqytB4JHjaBUWHtUNn6BuMtWz/FTUgrISlMGB0thJe01ObJ/sf5QTO5 nakfj99SlRu/yb63NSeCdZK2b6E9uhN342o+57n5f83jgKfuXOwhFKBRGjpmx3UBk4Pj JDIZgG4j53HTm6t6MdZjzKdXfYXBRBQuONiEuerX4Lzn4V5mPfo1cqaaMsiYMF1Krrh1 RVoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=FQ9jxKI5I1M89vZzYqquoXBdkPU8bHNffna5C1ysXtM=; b=i7eF6Jt4VZfi27V0cmZIWQyihJAkDKgx3n9jj4oE5QLqvvC9Vlh42cLxHcpeSyr+/d Col1YAUtSm8Qpo14V3LR+gt6fnMpBQ2bMY3IVXTcgXaGisBls515nQ741E6uy5YreAbQ Qhe4Wu35HlLiq5fa4RaDThl/SaaUxiFKvMqWERQQfxU9PztHGHQLCm3qI5zwsgUAz0zD PgouQD60SkzyOdWNB9NEYVXhTnLeZeVcOV1jHDk4zjdnhcPP1GZKfsE+jupsag6lwVEv bYWY7uv342EQ1f4cXoSBWK0F1LM2uR3cuMVv98O/SA/EXt/sJdjTWh+mNXq58CFmV72j 7c1Q== X-Gm-Message-State: AOAM5306wdmjaUng61GSfyufu0jC4tbx0KvwqWDBNVUah92ns7st6b51 GU8axmJpYLZW7RcO2O66Ui/TCdUKp5Y= X-Google-Smtp-Source: ABdhPJxkzQSj4kBS8gG7J+lU07bK4mSut46oPbrMO3N72RTcDI62sFtQ1z1mOtwJmctwXBjyEokkPg== X-Received: by 2002:adf:e5cf:0:b0:203:7a50:98bd with SMTP id a15-20020adfe5cf000000b002037a5098bdmr3437946wrn.416.1646916269580; Thu, 10 Mar 2022 04:44:29 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 11/35] convert CoMutex to stackless coroutines Date: Thu, 10 Mar 2022 13:43:49 +0100 Message-Id: <20220310124413.1102441-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::431 (failed) 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=2a00:1450:4864:20::431; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x431.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646917138916100001 Content-Type: text/plain; charset="utf-8" Build the frame for qemu_co_mutex_lock_slowpath, because it has code that runs after qemu_coroutine_yield(). For qemu_co_mutex_lock() and qemu_co_mutex_unlock(), just return COROUTINE_CONTINUE on paths that do not go through an awaitable function, which is all of them in the case of qemu_co_mutex_unlock(). Signed-off-by: Paolo Bonzini --- util/qemu-coroutine-lock.c | 60 ++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index 048cfcea71..061a376aa4 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -120,6 +120,7 @@ bool qemu_co_queue_empty(CoQueue *queue) { return QSIMPLEQ_FIRST(&queue->entries) =3D=3D NULL; } +#endif =20 /* The wait records are handled with a multiple-producer, single-consumer * lock-free queue. There cannot be two concurrent pop_waiter() calls @@ -197,15 +198,28 @@ static void coroutine_fn qemu_co_mutex_wake(CoMutex *= mutex, Coroutine *co) aio_co_wake(co); } =20 -static void coroutine_fn qemu_co_mutex_lock_slowpath(AioContext *ctx, - CoMutex *mutex) -{ - Coroutine *self =3D qemu_coroutine_self(); +struct FRAME__qemu_co_mutex_lock_slowpath { + CoroutineFrame common; + uint32_t _step; + AioContext *ctx; + CoMutex *mutex; + Coroutine *self; CoWaitRecord w; +}; + +static CoroutineAction co__qemu_co_mutex_lock_slowpath(void *_frame) +{ + struct FRAME__qemu_co_mutex_lock_slowpath *_f =3D _frame; + AioContext *ctx =3D _f->ctx; + CoMutex *mutex =3D _f->mutex; + Coroutine *self; unsigned old_handoff; =20 +switch(_f->_step) { +case 0: { + self =3D qemu_coroutine_self(); trace_qemu_co_mutex_lock_entry(mutex, self); - push_waiter(mutex, &w); + push_waiter(mutex, &_f->w); =20 /* This is the "Responsibility Hand-Off" protocol; a lock() picks from * a concurrent unlock() the responsibility of waking somebody up. @@ -221,21 +235,40 @@ static void coroutine_fn qemu_co_mutex_lock_slowpath(= AioContext *ctx, Coroutine *co =3D to_wake->co; if (co =3D=3D self) { /* We got the lock ourselves! */ - assert(to_wake =3D=3D &w); + assert(to_wake =3D=3D &_f->w); mutex->ctx =3D ctx; - return; + goto _out; } =20 qemu_co_mutex_wake(mutex, co); } =20 - qemu_coroutine_yield(); +_f->_step =3D 1; +_f->self =3D self; + return qemu_coroutine_yield(); +} +case 1: +self =3D _f->self; trace_qemu_co_mutex_lock_return(mutex, self); mutex->holder =3D self; self->locks_held++; + goto _out; +} +_out: +return stack_free(&_f->common); } =20 -void coroutine_fn qemu_co_mutex_lock(CoMutex *mutex) +static CoroutineAction qemu_co_mutex_lock_slowpath(AioContext *ctx, CoMute= x *mutex) +{ + struct FRAME__qemu_co_mutex_lock_slowpath *f; + f =3D stack_alloc(co__qemu_co_mutex_lock_slowpath, sizeof(*f)); + f->ctx =3D ctx; + f->mutex =3D mutex; + f->_step =3D 0; + return co__qemu_co_mutex_lock_slowpath(f); +} + +CoroutineAction qemu_co_mutex_lock(CoMutex *mutex) { AioContext *ctx =3D qemu_get_current_aio_context(); Coroutine *self =3D qemu_coroutine_self(); @@ -270,12 +303,13 @@ retry_fast_path: mutex->ctx =3D ctx; mutex->holder =3D self; self->locks_held++; + return COROUTINE_CONTINUE; } else { - qemu_co_mutex_lock_slowpath(ctx, mutex); + return qemu_co_mutex_lock_slowpath(ctx, mutex); } } =20 -void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex) +CoroutineAction qemu_co_mutex_unlock(CoMutex *mutex) { Coroutine *self =3D qemu_coroutine_self(); =20 @@ -290,7 +324,7 @@ void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex) self->locks_held--; if (qatomic_fetch_dec(&mutex->locked) =3D=3D 1) { /* No waiting qemu_co_mutex_lock(). Pfew, that was easy! */ - return; + return COROUTINE_CONTINUE; } =20 for (;;) { @@ -328,8 +362,10 @@ void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex) } =20 trace_qemu_co_mutex_unlock_return(mutex, self); + return COROUTINE_CONTINUE; } =20 +#if 0 struct CoRwTicket { bool read; Coroutine *co; --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646916855887290.9672625482689; Thu, 10 Mar 2022 04:54:15 -0800 (PST) Received: from localhost ([::1]:33946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIJ4-0001lv-Jt for importer@patchew.org; Thu, 10 Mar 2022 07:54:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9i-0006jF-5b; Thu, 10 Mar 2022 07:44:35 -0500 Received: from [2a00:1450:4864:20::32a] (port=53065 helo=mail-wm1-x32a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9g-0005CW-Jy; Thu, 10 Mar 2022 07:44:33 -0500 Received: by mail-wm1-x32a.google.com with SMTP id r65so3176159wma.2; Thu, 10 Mar 2022 04:44:31 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kYPdnwd+qK4GoFiw8vkRkI9044PfsGfCMHgYYSi6n+s=; b=Asl0ewbfMM/ukbbWMQbuxiZ4CmtB6grkbCF0bE1wc/DDROVXwtciEPwh/YshY7E8R5 2w1wMOPTK+I8eZbAswwSyJjW6kWRTPucFKe9LiSBfz51jITrhaD5cz3XCgUi4iiJsmmY WehpaQ/Llmemi+XBDmvfCJC6U4vxp7WDVBjSJ1HCyBGrO0gT0nCkizvvUJyts3Tvmc2F 7H1BClk1OCH8L/tDieSxI4xpP2pXW4ZRIuXlXd7gBMuUKdl7asHyMUlPJ5fdTHLwvcYI FwCHlnmJhxYxr1LVQmqvEN+Y7PoKrcxWEDFZBsdR/z/Sr9orU4fU7NAkEq7Lks62V53l xndA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=kYPdnwd+qK4GoFiw8vkRkI9044PfsGfCMHgYYSi6n+s=; b=PWPap2MUvSYxlHDIU0+E6PtXRGdHWDJhYwBMiHrsOIXZ/mekLeGPcMqTcDvv8x1NHh atyRQaA/C1nlhncF8qssn77Sx9PqUZcCVZgqMbfKwQPBIQWUihj7r03jT54oIzUqjvqK OrbwblmI2P4+PeyOnVAqkjs9I5TVh2rEyGKQJpv561g2Pqt1iOcFa0oSJPd1o+yLSy28 3BLNVFauWoAbxv1sLpaMCyHHfaInVM5RwnIbF/rwkjZCPvNEODf6LrX7ZrwSKalMsIsq NmTi9tSsuN4g5o4C4mSQIcRVwLUcfY/nDrwYNmtqNrQicY07VmoVNpMIQilMt6ofrufl 2dxw== X-Gm-Message-State: AOAM531STM1AVuPs4Oo3196+N+nIFBRcCvJduh67pG6uFAt+yNZ1wLjc lpXWVelnx1GR5oW2O4/pPGV2K+XCB+8= X-Google-Smtp-Source: ABdhPJz0BRZe04EGV6byPUns9Gb4AQ4WOgNMXzkT2bMr5qtAAxcea2CHbqZk99mQG/5kchrfFBuzcw== X-Received: by 2002:a1c:e90a:0:b0:381:504e:b57d with SMTP id q10-20020a1ce90a000000b00381504eb57dmr11536979wmc.177.1646916270938; Thu, 10 Mar 2022 04:44:30 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 12/35] define magic macros for stackless coroutines Date: Thu, 10 Mar 2022 13:43:50 +0100 Message-Id: <20220310124413.1102441-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32a (failed) 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=2a00:1450:4864:20::32a; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32a.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646916856899100001 Content-Type: text/plain; charset="utf-8" Because conversion to stackless coroutines is incredibly repetitive, define some magic variable-argument macros that simplify the task: - CO_DECLARE_FRAME() declares a frame structure, with a couple common fields and the extras coming from variable arguments - CO_INIT_FRAME() allocates the frame structure, builds it using any argume= nts provided by the user, and continues with the second part of the awaitable function that takes the frame as its only argument - CO_ARG() declare variables and load them from the frame structure. It uses typeof() to avoid repetition of the type of the variable (it is need= ed only twice, in CO_DECLARE_FRAME() and in the declaration of the user-visi= ble awaitable function) - CO_DECLARE() also declares variables using typeof, but it's for locals th= at are not prepared by CO_INIT_FRAME() - CO_SAVE() and CO_LOAD() copy to and from the frame structure Signed-off-by: Paolo Bonzini --- include/qemu/coroutine.h | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index 2f2be6abfe..df148ff80e 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -361,4 +361,45 @@ void qemu_coroutine_decrease_pool_batch_size(unsigned = int additional_pool_size); void *coroutine_only_fn stack_alloc(CoroutineImpl *func, size_t bytes); CoroutineAction coroutine_only_fn stack_free(CoroutineFrame *f); =20 + +#define CO_DO(MACRO, ...) CO_DO_(MACRO, __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4,= 3, 2, 1, 0) +#define CO_DO_(MACRO, a0, a1, a2, a3, a4, a5, a6, a7, a8 , a9, n, ...) CO_= DO##n(MACRO, a0, a1, a2, a3, a4, a5, a6, a7, a8 , a9) +#define CO_DO0(MACRO, a0, ...) +#define CO_DO1(MACRO, a0, ...) MACRO(a0) +#define CO_DO2(MACRO, a0, ...) MACRO(a0); CO_DO1(MACRO, __VA_ARGS__) +#define CO_DO3(MACRO, a0, ...) MACRO(a0); CO_DO2(MACRO, __VA_ARGS__) +#define CO_DO4(MACRO, a0, ...) MACRO(a0); CO_DO3(MACRO, __VA_ARGS__) +#define CO_DO5(MACRO, a0, ...) MACRO(a0); CO_DO4(MACRO, __VA_ARGS__) +#define CO_DO6(MACRO, a0, ...) MACRO(a0); CO_DO5(MACRO, __VA_ARGS__) +#define CO_DO7(MACRO, a0, ...) MACRO(a0); CO_DO6(MACRO, __VA_ARGS__) +#define CO_DO8(MACRO, a0, ...) MACRO(a0); CO_DO7(MACRO, __VA_ARGS__) +#define CO_DO9(MACRO, a0, ...) MACRO(a0); CO_DO8(MACRO, __VA_ARGS__) + +#define CO_FRAME1(decl) decl +#define CO_SAVE1(var) _f->var =3D var +#define CO_LOAD1(var) var =3D _f->var +#define CO_DECLARE1(var) typeof(_f->var) var +#define CO_ARG1(var) typeof(_f->var) var =3D _f->var + +#define CO_SAVE(...) CO_DO(CO_SAVE1, __VA_ARGS__) +#define CO_LOAD(...) CO_DO(CO_LOAD1, __VA_ARGS__) +#define CO_DECLARE(...) CO_DO(CO_DECLARE1, __VA_ARGS__) +#define CO_ARG(...) CO_DO(CO_ARG1, __VA_ARGS__) + +#define CO_DECLARE_FRAME(func, ...) \ + struct FRAME__##func { \ + CoroutineFrame common; \ + uint32_t _step; \ + CO_DO(CO_FRAME1, __VA_ARGS__); \ + } + +#define CO_INIT_FRAME(func, ...) \ + co__##func(({ \ + struct FRAME__##func *_f; \ + _f =3D stack_alloc(co__##func, sizeof(*_f)); \ + __VA_OPT__(CO_SAVE(__VA_ARGS__);) \ + _f->_step =3D 0; \ + _f; \ + })) + #endif /* QEMU_COROUTINE_H */ --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16469169956101018.3247448538394; Thu, 10 Mar 2022 04:56:35 -0800 (PST) Received: from localhost ([::1]:42370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSILK-0007bj-A7 for importer@patchew.org; Thu, 10 Mar 2022 07:56:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9j-0006jT-Cz; Thu, 10 Mar 2022 07:44:35 -0500 Received: from [2a00:1450:4864:20::330] (port=55847 helo=mail-wm1-x330.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9h-0005Cr-U8; Thu, 10 Mar 2022 07:44:35 -0500 Received: by mail-wm1-x330.google.com with SMTP id i66so3152097wma.5; Thu, 10 Mar 2022 04:44:33 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=s2YITzhm5qYQs7ILNbrpRvxFL3ZwbyQCG5BGW9zcwqo=; b=H3x0GDSwAvHUXDOS+pASrLON+bOZ4CvO04rWjHybUuYo/zRGSxtHupPvbYUV6+M9q3 YJDKLmVa2ESEPTNvrmv4ElasbNzb1kL4d+6xvfayiJEg/tXDa02D9Cf36DyUzXKSs2JU DZx40y7avhyUJQnuCeZRZIPulheLvg1t49m15wKASd+7XEWf+LUjGapwJ/l3VeXfBxGP RtCXzUwBAM4rVN6XfzLqQN+GEDGkUV3FKdWhZNsCT7JZrJ04rIJFfxphaHHjtMZ4+bca 4tfkmdPxvF84hWV2KN8iG0DlTuWfQXr8G/PUEl+/mo/kvXgQDVcLtGpDQHC7rSnihrKk G4nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=s2YITzhm5qYQs7ILNbrpRvxFL3ZwbyQCG5BGW9zcwqo=; b=6nbAcSUJpkJFt/WDXmQFXb8ROYXJuYzgSMGQuUhPqgdTGt51oLThkteaELRjE8xR9z DbEREVyWWKn9awsXdGUa6pP+aN+fccStVSNYikLf2wTmISRs8Wu4I+sZqBgeRZD/2XpQ REUupWvvxRDvFeJHnXpvjtrILU0idsm5x/BP/gF6zdFVFgw0Hmbx/64r8KCpTbWWBLoH F5/x7p5atSKhcWF1hSE0c5OPanzm2I5Kd3dmPVFWCyP6jcg5JAmhwN/Ke4nFWhTfHV/i LvLh5C8PYW0HEWMONrQSDZyo1k25sB2T282DJt9w0qapon7X7XCTbyHks14yFKQHor7g /qcQ== X-Gm-Message-State: AOAM530fVqbTm7hS52nZKJJCKvdLO/IvPZfKdkHnIzOV8WVPgFsnE4Q/ fCuFxDriOeBKJkr45dcnxvO61b7fRqc= X-Google-Smtp-Source: ABdhPJwlHoUFYYTKR0fYEmHJtHntcPx/AHexdX0ohTo8+qcxw48NBgAt3Pk0LMQrw0RrAEy4P2hEDA== X-Received: by 2002:a05:600c:1d19:b0:389:bd65:34c8 with SMTP id l25-20020a05600c1d1900b00389bd6534c8mr3504469wms.89.1646916272206; Thu, 10 Mar 2022 04:44:32 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 13/35] /basic/yield Date: Thu, 10 Mar 2022 13:43:51 +0100 Message-Id: <20220310124413.1102441-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::330 (failed) 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=2a00:1450:4864:20::330; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646916996153100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index 3670750c5b..ae06e97c95 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -141,15 +141,33 @@ static void test_nesting(void) * Check that yield/enter transfer control correctly */ =20 -static void coroutine_fn yield_5_times(void *opaque) +#endif +CO_DECLARE_FRAME(yield_5_times, void *opaque, int i); +static CoroutineAction co__yield_5_times(void *_frame) { + struct FRAME__yield_5_times *_f =3D _frame; + CO_ARG(opaque); bool *done =3D opaque; - int i; + CO_DECLARE(i); =20 +switch(_f->_step) { +case 0: for (i =3D 0; i < 5; i++) { - qemu_coroutine_yield(); +CO_SAVE(i); +_f->_step =3D 1; + return qemu_coroutine_yield(); +case 1: +CO_LOAD(i); } *done =3D true; + break; +} +return stack_free(&_f->common); +} + +static CoroutineAction yield_5_times(void *opaque) +{ + return CO_INIT_FRAME(yield_5_times, opaque); } =20 static void test_yield(void) @@ -166,6 +184,7 @@ static void test_yield(void) g_assert_cmpint(i, =3D=3D, 5); /* coroutine must yield 5 times */ } =20 +#if 0 static void coroutine_fn c2_fn(void *opaque) { qemu_coroutine_yield(); @@ -659,8 +678,8 @@ int main(int argc, char **argv) #endif =20 g_test_add_func("/basic/lifecycle", test_lifecycle); -#if 0 g_test_add_func("/basic/yield", test_yield); +#if 0 g_test_add_func("/basic/nesting", test_nesting); g_test_add_func("/basic/self", test_self); g_test_add_func("/basic/entered", test_entered); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646920033407547.2765032830025; Thu, 10 Mar 2022 05:47:13 -0800 (PST) Received: from localhost ([::1]:49748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSJ8J-0006Ya-DW for importer@patchew.org; Thu, 10 Mar 2022 08:47:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9l-0006lp-4I; Thu, 10 Mar 2022 07:44:38 -0500 Received: from [2a00:1450:4864:20::42d] (port=36527 helo=mail-wr1-x42d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9j-0005D5-1b; Thu, 10 Mar 2022 07:44:36 -0500 Received: by mail-wr1-x42d.google.com with SMTP id r10so7798767wrp.3; Thu, 10 Mar 2022 04:44:34 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cKdtK321kFLCliuzyUSsNRmQeNups2GRo/9a3WM2ZiQ=; b=N2O/N0AlcFa0juxfh1qhJeS2JZct9UqxPtNbL+Dz8axsniwxGu6Tgws0JQqyKdFSSH 0r61BhSVxyoJdp+EGuDr30Nypr4ln2ofyF7FsaC0mL4MQWl4J8Iywo3WUXO5GGJ+7xEp 2W9g+AQrzQ/MizT5kcL/HMI5B4TExXWhVx4pq7lnTwemanqUqu5/n/Pc04FhHXAXUE31 ENSUDyuSwxfQF2TBWNS4MtM68iWEveydhtuFMy0jrbXpsZYfAc5Pk8uEZjYTJtk5kHv2 IQLAqq2iaREloj77DBg+CDIDVHG3m+R0a/tAuVY6PuPbhXd6ZaqHSyxtOdIckUno5bOh FiRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=cKdtK321kFLCliuzyUSsNRmQeNups2GRo/9a3WM2ZiQ=; b=AqWg7uD1MgqQk1GJtrrlUuQhhQmHxjX1ItVq7ZxH7fjFX4sNJ65YWs80zeR98y2GBq XEjIJw+61YHSW+JSOzpNOIOmPk0s5AONd4gHxpcE7D5ThNEPvKVbxgDOvRR9epPOINeF qY27SwgmM4DN1JYsKcKTZ7aLyE0HwwJ/FG9ZelkIBMlUlt1eq17gl8FLnvDmTa8YJ1Cy ja8uc7SzGG+jXXB+Qtctj6BbQqGGddt/AH9rDhKWlit9VRmypepknaXwZrFmR/b8BDS9 2X4qCF9qA37D2KLY/Qk1PBwFucJ4FpMf/EmrE3cePrEKbXVc4AC4d5yOcIkX6i3SroTI SQ/Q== X-Gm-Message-State: AOAM5307KrzWQDBcPnrDuOzXSAB4vzIASpMBEBiVsT62Z0PPMarGUjj+ V3s2oVeTH5lRaxdQLLmbrXZ00Wjd8E0= X-Google-Smtp-Source: ABdhPJzTC9AIksEmISttTayXzZERN9JiC/K5dGXlwOQKjDiv0vusSY5FlMhZjIFCarzE+QPaOFHbHA== X-Received: by 2002:adf:fd50:0:b0:1f0:7a8e:c922 with SMTP id h16-20020adffd50000000b001f07a8ec922mr3442572wrs.166.1646916273464; Thu, 10 Mar 2022 04:44:33 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 14/35] /basic/nesting Date: Thu, 10 Mar 2022 13:43:52 +0100 Message-Id: <20220310124413.1102441-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42d (failed) 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=2a00:1450:4864:20::42d; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42d.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646920035754100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index ae06e97c95..7aaadfd31a 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -93,6 +93,7 @@ static void test_entered(void) g_assert(!qemu_coroutine_entered(coroutine)); qemu_coroutine_enter(coroutine); } +#endif =20 /* * Check that coroutines may nest multiple levels @@ -104,7 +105,7 @@ typedef struct { unsigned int max; /* maximum level of nesting */ } NestData; =20 -static void coroutine_fn nest(void *opaque) +static CoroutineAction nest(void *opaque) { NestData *nd =3D opaque; =20 @@ -118,6 +119,7 @@ static void coroutine_fn nest(void *opaque) } =20 nd->n_return++; + return COROUTINE_CONTINUE; } =20 static void test_nesting(void) @@ -141,7 +143,6 @@ static void test_nesting(void) * Check that yield/enter transfer control correctly */ =20 -#endif CO_DECLARE_FRAME(yield_5_times, void *opaque, int i); static CoroutineAction co__yield_5_times(void *_frame) { @@ -679,8 +680,8 @@ int main(int argc, char **argv) =20 g_test_add_func("/basic/lifecycle", test_lifecycle); g_test_add_func("/basic/yield", test_yield); -#if 0 g_test_add_func("/basic/nesting", test_nesting); +#if 0 g_test_add_func("/basic/self", test_self); g_test_add_func("/basic/entered", test_entered); g_test_add_func("/basic/in_coroutine", test_in_coroutine); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646917134211717.0112201105031; Thu, 10 Mar 2022 04:58:54 -0800 (PST) Received: from localhost ([::1]:50704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSINY-0004ny-Ve for importer@patchew.org; Thu, 10 Mar 2022 07:58:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9p-0006pQ-Qe; Thu, 10 Mar 2022 07:44:42 -0500 Received: from [2a00:1450:4864:20::432] (port=37525 helo=mail-wr1-x432.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9k-0005DE-1g; Thu, 10 Mar 2022 07:44:38 -0500 Received: by mail-wr1-x432.google.com with SMTP id q14so7787796wrc.4; Thu, 10 Mar 2022 04:44:35 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vHuxLxSTxAolaSufQ6BUZcRlafg36voYkUOQRtUENB8=; b=N+xEDazMWr9kc5Ma8b9D7Uip1Y59eJAnGaU9SgR4G7k9yrseszZCSx8Fqh09MBGcua C+d1PYBYZ9ZlY3mU7sk2nneTXSg3OrOubqexTpz9Nm1buJ/D6EQBIwljPsT2XSaDKW4d dtk/Z9ouaXbcE/DlpvJE2eDc+LlJXbli02tOaRoQeQDBqspmHh2IbtAFzcfRx6GkiFde 1nCFeQTE0BDPD7HsruRli6+VXQk0irx5pKh0+16jRxt7A3ks/jIPFcOyrcMxmTxeRlhW jkU1VBUxMcEYMRGgB9hrz6PRzWPbd6ClKFIEQtk71ebCw7P5n3zoEG4nSom1U989PgTk 0WEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=vHuxLxSTxAolaSufQ6BUZcRlafg36voYkUOQRtUENB8=; b=fkPwboUAiN3kZIRtvDm29dg4Z4jzA5tKkMNqp4Rc03PawglU08YLySx39ExTjNp6wV eEwQ2ZxYRZjz8PzlT+3xOF+IZ9Z26Mhyk6YONtW/dlzyLQnNlsVGp+Z1rZjqgPIq6sme gcAJu0Oe7qfvQL3Bi4BdC4ygB8iwexsWh2BHZbFNDospelKNOJwQZAfNCGyzdfCPqRwG eKx+yShGP8lmvIrnIchqLtaAQmpSwExrdnOpaefeXE7MjNeHF93wISY5edDZkmxAfKC5 N8HaMZdiIl/BsCkgxRyDH/OdDY2GCie26T6z0D0uynkv7y88YVYbiZbMHDUyRrkg9x5L H1Yg== X-Gm-Message-State: AOAM533f+y1XPE/I1OahGpGQ8azeJbN5v6NY2GsMTdCB/UXJtWEmlQMQ DmXIrR3tJG+0D6qK8buixNPDlNBjTtc= X-Google-Smtp-Source: ABdhPJyFgMf8I2erlRFGmwG9GDsNfGNmj80TvKCX8IK2Zm+nJwRqct4YFYw0qAbX5tCHDdsWI2+XeA== X-Received: by 2002:a05:6000:184d:b0:203:92d6:93cb with SMTP id c13-20020a056000184d00b0020392d693cbmr94320wri.496.1646916274367; Thu, 10 Mar 2022 04:44:34 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 15/35] /basic/self Date: Thu, 10 Mar 2022 13:43:53 +0100 Message-Id: <20220310124413.1102441-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::432 (failed) 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=2a00:1450:4864:20::432; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x432.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646917136499100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index 7aaadfd31a..c701113d77 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -36,14 +36,16 @@ static void test_in_coroutine(void) qemu_coroutine_enter(coroutine); } =20 +#endif /* * Check that qemu_coroutine_self() works */ =20 -static void coroutine_fn verify_self(void *opaque) +static CoroutineAction verify_self(void *opaque) { Coroutine **p_co =3D opaque; g_assert(qemu_coroutine_self() =3D=3D *p_co); + return COROUTINE_CONTINUE; } =20 static void test_self(void) @@ -53,6 +55,7 @@ static void test_self(void) coroutine =3D qemu_coroutine_create(verify_self, &coroutine); qemu_coroutine_enter(coroutine); } +#if 0 =20 /* * Check that qemu_coroutine_entered() works @@ -681,8 +684,8 @@ int main(int argc, char **argv) g_test_add_func("/basic/lifecycle", test_lifecycle); g_test_add_func("/basic/yield", test_yield); g_test_add_func("/basic/nesting", test_nesting); -#if 0 g_test_add_func("/basic/self", test_self); +#if 0 g_test_add_func("/basic/entered", test_entered); g_test_add_func("/basic/in_coroutine", test_in_coroutine); g_test_add_func("/basic/order", test_order); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646917353512849.3975687170957; Thu, 10 Mar 2022 05:02:33 -0800 (PST) Received: from localhost ([::1]:33050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIR6-0003SS-Lk for importer@patchew.org; Thu, 10 Mar 2022 08:02:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9p-0006pR-RK; Thu, 10 Mar 2022 07:44:42 -0500 Received: from [2a00:1450:4864:20::42f] (port=43707 helo=mail-wr1-x42f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9l-0005Dd-9z; Thu, 10 Mar 2022 07:44:39 -0500 Received: by mail-wr1-x42f.google.com with SMTP id e24so7741077wrc.10; Thu, 10 Mar 2022 04:44:36 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NP0Ei/vqiEwTAvjNN9/HZJ4grZhsDkMiqmp8SfogxL4=; b=Npy0igV1JKdWSfZhK8GP8k1T2YAUSTTT0bFcL4gjPelSZnsZmIBAr1ghcUmAIVWYgP IJUgJf73L0xuoc+IBCbFqjgskB3mtYyCKPGUUXj7QY5RV4Y/2mzHCEHa9HiRbKOysFv/ j2IHWnrNx4ab2Rv6A2F7THO0peQ1CdBqQTFJecunMBN2h/zqL61yQ4Zvy8+i6bfv8nqR XOmvCaAgtuC0GSbua89zZvkLw6rTARLiCs1A1MMU0uU0C+lSeMkfGooNX1nHPA0CM91A 2DdihHV5+Kl9XrTilaIYYv3clFX+NeJ6VWjcPgK1GKQB5opVnU2++7rhh1HEJWOgN0Kw OLSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=NP0Ei/vqiEwTAvjNN9/HZJ4grZhsDkMiqmp8SfogxL4=; b=pd7RvprZ00HAOfqwgXkbsRDUGRnJMz4qLJ/PQ/pPMZjxPT6x/aN+br4sdE/+DRfiEo AXjD22gDZWm/37c48vcpvNZSiE7+q35VM2+ml6/277BMu9owWD6vTbnamfTuu+nlDISc d84mNdezuqM71imfolSnmlrxBlA3aC/7vZQYFrYkvVe2l4LwwYGlXPg7fx8f04Ex4Kla u7UdgfRJowa6h+pcfYUrk79liHdRTv5Z6BMqHl8kp9WP0avztWznbMZpwURd4oAbh+R6 4Z5FxSg1kCTrYYV6D4vxuT4PBTvnaGo03HPBQu3LsB+3H+mOv4NHtpsB4siNZhqw6piu TWYA== X-Gm-Message-State: AOAM530g0hxSt2+nYDIVLow9vbZ+RW9BoImp1Msv+Q6UdA6Pf0h2EJ0V BfddwwcjRKIOZhkKJ+vW1sl1tjKlpt0= X-Google-Smtp-Source: ABdhPJyrpxN1Hz/doivErdLN9RTzlQPPiVP0O3SxPoRbP6ylboztxYp0S6jPehe0AL0cJLsPPg5C+Q== X-Received: by 2002:a05:6000:2c4:b0:203:7e20:f828 with SMTP id o4-20020a05600002c400b002037e20f828mr3574291wry.232.1646916275743; Thu, 10 Mar 2022 04:44:35 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 16/35] /basic/entered Date: Thu, 10 Mar 2022 13:43:54 +0100 Message-Id: <20220310124413.1102441-17-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42f (failed) 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=2a00:1450:4864:20::42f; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42f.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646917355323100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index c701113d77..bc75050463 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -55,26 +55,40 @@ static void test_self(void) coroutine =3D qemu_coroutine_create(verify_self, &coroutine); qemu_coroutine_enter(coroutine); } -#if 0 =20 /* * Check that qemu_coroutine_entered() works */ =20 -static void coroutine_fn verify_entered_step_2(void *opaque) +CO_DECLARE_FRAME(verify_entered_step_2, Coroutine *caller); +static CoroutineAction co__verify_entered_step_2(void *_frame) { - Coroutine *caller =3D (Coroutine *)opaque; + struct FRAME__verify_entered_step_2 *_f =3D _frame; + CO_ARG(caller); =20 +switch(_f->_step) +{ +case 0: g_assert(qemu_coroutine_entered(caller)); g_assert(qemu_coroutine_entered(qemu_coroutine_self())); - qemu_coroutine_yield(); - + _f->_step =3D 1; + return qemu_coroutine_yield(); +case 1: /* Once more to check it still works after yielding */ g_assert(qemu_coroutine_entered(caller)); g_assert(qemu_coroutine_entered(qemu_coroutine_self())); + break; +} +return stack_free(&_f->common); } =20 -static void coroutine_fn verify_entered_step_1(void *opaque) +static CoroutineAction verify_entered_step_2(void *opaque) +{ + Coroutine *caller =3D (Coroutine *)opaque; + return CO_INIT_FRAME(verify_entered_step_2, caller); +} + +static CoroutineAction verify_entered_step_1(void *opaque) { Coroutine *self =3D qemu_coroutine_self(); Coroutine *coroutine; @@ -86,6 +100,7 @@ static void coroutine_fn verify_entered_step_1(void *opa= que) qemu_coroutine_enter(coroutine); g_assert(!qemu_coroutine_entered(coroutine)); qemu_coroutine_enter(coroutine); + return COROUTINE_CONTINUE; } =20 static void test_entered(void) @@ -96,7 +111,6 @@ static void test_entered(void) g_assert(!qemu_coroutine_entered(coroutine)); qemu_coroutine_enter(coroutine); } -#endif =20 /* * Check that coroutines may nest multiple levels @@ -685,8 +699,8 @@ int main(int argc, char **argv) g_test_add_func("/basic/yield", test_yield); g_test_add_func("/basic/nesting", test_nesting); g_test_add_func("/basic/self", test_self); -#if 0 g_test_add_func("/basic/entered", test_entered); +#if 0 g_test_add_func("/basic/in_coroutine", test_in_coroutine); g_test_add_func("/basic/order", test_order); g_test_add_func("/locking/co-mutex", test_co_mutex); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646917320799513.1452619643616; Thu, 10 Mar 2022 05:02:00 -0800 (PST) Received: from localhost ([::1]:59298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIQZ-00029K-Q5 for importer@patchew.org; Thu, 10 Mar 2022 08:01:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9r-0006qd-0z; Thu, 10 Mar 2022 07:44:43 -0500 Received: from [2a00:1450:4864:20::435] (port=34502 helo=mail-wr1-x435.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9n-0005Dq-Fa; Thu, 10 Mar 2022 07:44:42 -0500 Received: by mail-wr1-x435.google.com with SMTP id j26so7806453wrb.1; Thu, 10 Mar 2022 04:44:37 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=am/TeS80vxEOm9BXIFg633pgOE8+WRH4m0argteqkpg=; b=qHg6TlwwD5CdUOC6kYl6trqwS8tBU1xIh1C/qyoZl7iLHa+UyJQpzTL4aYCBn+Rvhe TIWJOFlODmCpiTcYjt/sAknS6pt5DcF0cLDfAf+3/h8mM9F3XAJ3PMCljzPZRC6l9NUK BaTo8zeWgzz8Ge/EpY8ncQh95KI8CKwQD0YjowXgdxNHKqVabInsnpy3/f4GSwQ88yf8 CELM4K/6eKa2AUkFnuJJXqUf3haIgljP9e2YoSVQuS7Qaq7Nau2PsjJlWLUecyT2Qy8H cXGqCI7iA4zeVhObkJLVBRKflAFQ8z2sHj6HP3dsRWbu9aXvoaCMt0c+3U0gxZpi0116 LyQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=am/TeS80vxEOm9BXIFg633pgOE8+WRH4m0argteqkpg=; b=Ut3c9ZFz4nVWQaprfSCwDjWyUCN4z9zvba27vuqAplLTGI2FSNPAhivKWOzJXPnUlK UUvt0tb/fXltyvE60wd4oXv04HFH0BslMxVTsF5E9VLW8YnEYMeumPIjP0PUSMWptr3e Y+vAf/dGDmE0FmWgtLC8cTxssi+hcgtzlhpuo0e4BRDh78sSTLWVKNE6ind0Vk6Ox7Lz QAe+3gJ8xNwZ6et/cAPSj4sN8RGyG6M1SSwC9XNYwtxaHOm7uz/ZxEgw9vmOPhKlhrgg OhgwULzxTtUHqyrwdI2FKAOjSpBwjZmtEuz13u43/BG/VxFDpLjGn0BpaQGKYyEA9D/q Mvyw== X-Gm-Message-State: AOAM530J+y72E47C19AYK7YSbPJVQuurYT0Om0/hO/sYwYgMnDrRiuIQ /GDeYNkJZub5bi3qX075hQdGtGsDQDw= X-Google-Smtp-Source: ABdhPJzPreD3s7gt3+jS9Qf6fX7WuxMJHRd/eYZCwblo+b1yPzg/aXlJPr2eyNsd/Yocs1HheTWYVA== X-Received: by 2002:a05:6000:1561:b0:203:7b90:1da0 with SMTP id 1-20020a056000156100b002037b901da0mr3502884wrz.629.1646916276638; Thu, 10 Mar 2022 04:44:36 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 17/35] /basic/in_coroutine Date: Thu, 10 Mar 2022 13:43:55 +0100 Message-Id: <20220310124413.1102441-18-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::435 (failed) 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=2a00:1450:4864:20::435; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x435.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646917323991100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index bc75050463..6ad653adda 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -16,14 +16,14 @@ #include "qemu/coroutine_int.h" #include "qemu/lockable.h" =20 -#if 0 /* * Check that qemu_in_coroutine() works */ =20 -static void coroutine_fn verify_in_coroutine(void *opaque) +static CoroutineAction verify_in_coroutine(void *opaque) { g_assert(qemu_in_coroutine()); + return COROUTINE_CONTINUE; } =20 static void test_in_coroutine(void) @@ -36,7 +36,6 @@ static void test_in_coroutine(void) qemu_coroutine_enter(coroutine); } =20 -#endif /* * Check that qemu_coroutine_self() works */ @@ -700,8 +699,8 @@ int main(int argc, char **argv) g_test_add_func("/basic/nesting", test_nesting); g_test_add_func("/basic/self", test_self); g_test_add_func("/basic/entered", test_entered); -#if 0 g_test_add_func("/basic/in_coroutine", test_in_coroutine); +#if 0 g_test_add_func("/basic/order", test_order); g_test_add_func("/locking/co-mutex", test_co_mutex); g_test_add_func("/locking/co-mutex/lockable", test_co_mutex_lockable); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646917289746666.8894538050926; Thu, 10 Mar 2022 05:01:29 -0800 (PST) Received: from localhost ([::1]:53954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIOh-0006zs-Dm for importer@patchew.org; Thu, 10 Mar 2022 08:00:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41548) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9s-0006ti-GY; Thu, 10 Mar 2022 07:44:44 -0500 Received: from [2a00:1450:4864:20::435] (port=40798 helo=mail-wr1-x435.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9p-0005Dy-Tm; Thu, 10 Mar 2022 07:44:44 -0500 Received: by mail-wr1-x435.google.com with SMTP id k24so7763016wrd.7; Thu, 10 Mar 2022 04:44:38 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ftsEDbeWlZ8knEuqLSqyr0cJ8reRYQXZ8KdP5LCtFtY=; b=h7vfPV4a6i/Pi0kVL1v5uu6WcQ8DTmxkHNEayAh817hNeuCAXjeapnsO8VABU4wNp8 gj4Q2+6lYkdGrW3a7rhDeIJDh+gcRsoIkpa31Ik7tYZ5/9jcJtEOL/dotCnB4iMT8PGZ nRO7Koz9Vhxstf560ZSnuBXPsNQCHJSwOga5rgoR8/doDXEDJ6/mgUmuOIKIAHKbi316 6el17qfOVuLgTht5idROvVnv2Kkb7cX+NpL1vN8XrBSpni2+gxxH8+NRq52zF+XzG/XJ 2nDGUoSk3mSTU/VVJsu3WDf3BLx9fSSkbSSFgzOdmhSbS24mHbQQqtIx4pW2YFW4k7FO oWMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ftsEDbeWlZ8knEuqLSqyr0cJ8reRYQXZ8KdP5LCtFtY=; b=gUnyJFH/wGAUq2Gahza/9LtJg1/r5EW9e/KDp7eFeQf1yK6eH5cr3byO64V11k5A4p 1Xuz1cntMGRi3o8caWgKmw5egNwZyZiMp40ch/o+02gFN5u+7ZA8Scyu0je/CluZPc6R OhTZgK5UsoolGckD0TZWleuidGsa60lvX/EbtEKpxXFNYwBw7JtplJAsqMRK3iU4t98B ClskalTZuEGWXbeJSlBumajaHy9m0Bx9QmYKun3sWm3y54hYluPP2oz2DazkGKcX+xuY yR+63yjlfneYV92Wx4KjwehRdsN1dWCl1ahYqGxP9avHuzcleOflIyb9B74DTAOo85MX TSrg== X-Gm-Message-State: AOAM531PTwIRWRyZ79n0nNJcYvX8V+xuM3lOOzPPU2CxBVmroRiW+U4t 25oFVtTcWnqgsjF8i4Gu8CD5eQg/08A= X-Google-Smtp-Source: ABdhPJxXsvRm4OjNwIQA4INcIpPy/BzFa22chKsWZIl2NJLx2ksAufjr201aWY504pSVUROmO9Q/DA== X-Received: by 2002:a5d:6c68:0:b0:203:691f:b95b with SMTP id r8-20020a5d6c68000000b00203691fb95bmr3442456wrz.375.1646916277702; Thu, 10 Mar 2022 04:44:37 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 18/35] /basic/order Date: Thu, 10 Mar 2022 13:43:56 +0100 Message-Id: <20220310124413.1102441-19-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::435 (failed) 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=2a00:1450:4864:20::435; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x435.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646917292478100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index 6ad653adda..3d898d50c6 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -490,8 +490,6 @@ static void test_lifecycle(void) g_assert(done); /* expect done to be true (second time) */ } =20 -#if 0 - #define RECORD_SIZE 10 /* Leave some room for expansion */ struct coroutine_position { int func; @@ -508,13 +506,27 @@ static void record_push(int func, int state) cp->state =3D state; } =20 -static void coroutine_fn co_order_test(void *opaque) +CO_DECLARE_FRAME(co_order_test); +static CoroutineAction co__co_order_test(void *_frame) { + struct FRAME__co_order_test *_f =3D _frame; +switch(_f->_step) { +case 0: record_push(2, 1); g_assert(qemu_in_coroutine()); - qemu_coroutine_yield(); +_f->_step =3D 1; + return qemu_coroutine_yield(); +case 1: record_push(2, 2); g_assert(qemu_in_coroutine()); + break; +} +return stack_free(&_f->common); +} + +static CoroutineAction co_order_test(void *opaque) +{ + return CO_INIT_FRAME(co_order_test); } =20 static void do_order_test(void) @@ -544,6 +556,7 @@ static void test_order(void) g_assert_cmpint(records[i].state, =3D=3D, expected_pos[i].state); } } +#if 0 /* * Lifecycle benchmark */ @@ -700,8 +713,8 @@ int main(int argc, char **argv) g_test_add_func("/basic/self", test_self); g_test_add_func("/basic/entered", test_entered); g_test_add_func("/basic/in_coroutine", test_in_coroutine); -#if 0 g_test_add_func("/basic/order", test_order); +#if 0 g_test_add_func("/locking/co-mutex", test_co_mutex); g_test_add_func("/locking/co-mutex/lockable", test_co_mutex_lockable); g_test_add_func("/locking/co-rwlock/upgrade", test_co_rwlock_upgrade); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164691756899427.632464166120712; Thu, 10 Mar 2022 05:06:08 -0800 (PST) Received: from localhost ([::1]:42314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIUa-0001Lt-5f for importer@patchew.org; Thu, 10 Mar 2022 08:06:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41524) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9r-0006rg-IL; Thu, 10 Mar 2022 07:44:43 -0500 Received: from [2a00:1450:4864:20::433] (port=38441 helo=mail-wr1-x433.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9p-0005E6-Tl; Thu, 10 Mar 2022 07:44:43 -0500 Received: by mail-wr1-x433.google.com with SMTP id t11so7757361wrm.5; Thu, 10 Mar 2022 04:44:40 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1noevvk+yS6kDKEd3uTDKlqenqWqhhk+85B17SAY4IQ=; b=dnNHBQ/KKYIQNsXAWYc6MJyRQ5i2ZO7SJFZwTzECEugtDOmUaf0E5A8OhQYgfXCEIl B+w7ZenUS2EILzuu5T8Ffmfl9Kur4qVm8vWFRQgYIup8GALo7tyxZ8dRxyJQcQVMMRNQ 7RNrNY2O0lBE0trd65V1uAPtLMkyPPDaWkiKzNHpJvIUCnxI3omkgMBaNOopMAhheXe9 kGwDPeGBlmkPRI74yg9By870hXHaQUCj1W9x137lBsR4/oDNt3pY0yYYHjMqYdXPOs0c j1197XdpaGIUqqzEg7HlmS89cX1QLwunrFR/mmk47P64udqfZ7yzD5KCQGRmGjGzj5gu uZkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=1noevvk+yS6kDKEd3uTDKlqenqWqhhk+85B17SAY4IQ=; b=2H8KOdm2iYesZcQQScbWI8y1ZXF5JlCvinzh/Fz3Xpkk5albkSlMvdXt3R2Y39n/d2 NzT941mO+nnSPL4GgsZFL76/pyk/lc78/6hOHD7fKMBoBD45pG+jf/GdOhHkoEKK8KS/ ieRV5SpycXDM1E2UWJeu6IlC3kazZ8mAT5Rv5zugJFnX+KYnTqj2UqD8EBkaNv5LsNPn 7hcLa1ZbDFqYLL/sBICuEowSigLRSfxTJ27RgwpoFyWNrdrlx72UToCOxCwUXlXbfUsF eL0iqZBgQgAF/HjrFhQq4EOb8bsLLRGjfP3q+eJWW7afa/PUghXFCniKO0yYiG35CvUZ Fo9w== X-Gm-Message-State: AOAM533wPtM7LhW1gtB3DNRqCb60QIR6xTLrVPkTgiNOkJx6ViHpKpCw 8PX93ADFvGPLs3rjlfJjVgDO0ZPi1u4= X-Google-Smtp-Source: ABdhPJwF6XvuwJX0nL63t5uyx0rQt/w1MpWArmXESBnLorpj6ve+4PbJs4bc6JZ6Lhbt7NHxy8+qjQ== X-Received: by 2002:a05:6000:1689:b0:203:71fb:3930 with SMTP id y9-20020a056000168900b0020371fb3930mr3365734wrd.122.1646916279102; Thu, 10 Mar 2022 04:44:39 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 19/35] /perf/lifecycle Date: Thu, 10 Mar 2022 13:43:57 +0100 Message-Id: <20220310124413.1102441-20-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::433 (failed) 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=2a00:1450:4864:20::433; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x433.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646917571537100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 44 ++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index 3d898d50c6..439bd269c9 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -556,14 +556,21 @@ static void test_order(void) g_assert_cmpint(records[i].state, =3D=3D, expected_pos[i].state); } } -#if 0 + /* * Lifecycle benchmark */ =20 -static void coroutine_fn empty_coroutine(void *opaque) +CO_DECLARE_FRAME(empty_coroutine); +static CoroutineAction co__empty_coroutine(void *_frame) { - /* Do nothing */ + struct FRAME__empty_coroutine *_f =3D _frame; + return stack_free(&_f->common); +} + +static CoroutineAction empty_coroutine(void *opaque) +{ + return CO_INIT_FRAME(empty_coroutine); } =20 static void perf_lifecycle(void) @@ -572,7 +579,7 @@ static void perf_lifecycle(void) unsigned int i, max; double duration; =20 - max =3D 1000000; + max =3D 10000000; =20 g_test_timer_start(); for (i =3D 0; i < max; i++) { @@ -584,6 +591,30 @@ static void perf_lifecycle(void) g_test_message("Lifecycle %u iterations: %f s", max, duration); } =20 +static CoroutineAction empty_coroutine_noalloc(void *opaque) +{ + return COROUTINE_CONTINUE; +} + +static void perf_lifecycle_noalloc(void) +{ + Coroutine *coroutine; + unsigned int i, max; + double duration; + + max =3D 10000000; + + g_test_timer_start(); + for (i =3D 0; i < max; i++) { + coroutine =3D qemu_coroutine_create(empty_coroutine_noalloc, NULL); + qemu_coroutine_enter(coroutine); + } + duration =3D g_test_timer_elapsed(); + + g_test_message("Lifecycle %u iterations: %f s", max, duration); +} + +#if 0 static void perf_nesting(void) { unsigned int i, maxcycles, maxnesting; @@ -719,13 +750,16 @@ int main(int argc, char **argv) g_test_add_func("/locking/co-mutex/lockable", test_co_mutex_lockable); g_test_add_func("/locking/co-rwlock/upgrade", test_co_rwlock_upgrade); g_test_add_func("/locking/co-rwlock/downgrade", test_co_rwlock_downgra= de); +#endif if (g_test_perf()) { g_test_add_func("/perf/lifecycle", perf_lifecycle); + g_test_add_func("/perf/lifecycle/noalloc", perf_lifecycle_noalloc); +#if 0 g_test_add_func("/perf/nesting", perf_nesting); g_test_add_func("/perf/yield", perf_yield); g_test_add_func("/perf/function-call", perf_baseline); g_test_add_func("/perf/cost", perf_cost); - } #endif + } return g_test_run(); } --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646917801537378.35559693786695; Thu, 10 Mar 2022 05:10:01 -0800 (PST) Received: from localhost ([::1]:50868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIYK-0007dW-2h for importer@patchew.org; Thu, 10 Mar 2022 08:10:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9s-0006tk-Fp; Thu, 10 Mar 2022 07:44:44 -0500 Received: from [2a00:1450:4864:20::336] (port=36734 helo=mail-wm1-x336.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9q-0005EF-NI; Thu, 10 Mar 2022 07:44:44 -0500 Received: by mail-wm1-x336.google.com with SMTP id n31-20020a05600c3b9f00b003898fc06f1eso5373779wms.1; Thu, 10 Mar 2022 04:44:41 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KMGJQJyg47oETIlu7zseDa10e+nmFOAp33O9axXT85I=; b=ZHOB+e7yDZyHcAeSWCHeruf9MeXz6Yvywr/gPhG1uvqUDsyTum4ck9GWokklaMxaZj W1tE9Xw/Pr05oDG+g7cRgNFPWT1XouQ4lVBgsmvnLFlnT/E+8+Mej6itwvi9gQnNCd/6 tAX6Wxe58yFPXG1BIOefJADaKItdUAENXx3YrAwzIRUAzt23BQE7zYxUARkw8SYr8qU3 VqE5uh8v6cDNddli67ZiW8FVIirnF5ixh/7fysHGi090my2waoSZWrNqKXEEdHyb+aN7 eVb+adgxfDszbfR1oWphpdHr217GvxmWM6H5a+siVZ681WYndqbY59vbSsG76FIl8zic F3Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=KMGJQJyg47oETIlu7zseDa10e+nmFOAp33O9axXT85I=; b=jl34iNOY1CBSGiu2jJwXrD6gAxjgL651FiJdKpPjQh2EvT9fOqmQnXmrQ85RcXtv9h 9UByhaIgXCSwO5sKTm6oWqXyCM2HzdbXkO9gjAUuLF+BBFSP/6kazRa344bMwG4LUCGf pqdWuyTdeYHyxqzXTs/kqb76HZJbm8Ebbs/JFirC9xqgN1hoplhA+9LpIniOJF1cPd+y XUrZ3BMh7EZQiCX3PbxHmQSgLC1vf6yakkunUpU/DQtY3n9JCE2ABrmkKVx3C7otKgS2 teLDTR4BZj8M8Au9w562nJFJgNqIdCOpsyNZKM6WqFx7L9ek4JRBBIYYkM+fWfP8hhHk FCTw== X-Gm-Message-State: AOAM533IGqdIB67lAmw/2CvXKXxCaZo0J3fno0X20So+lFqrM2t8dV2S KrZA1iUEejIqLrbq/5RlU/7QIqILTMs= X-Google-Smtp-Source: ABdhPJyya1hMFkSxAue8Qv7giRC/AQgBveNHv5yWS9a741Sr0T2cTt+des6yndrRsLFxwzbRvyq8HQ== X-Received: by 2002:a05:600c:4f55:b0:381:7e8d:e4a8 with SMTP id m21-20020a05600c4f5500b003817e8de4a8mr3471532wmq.16.1646916281009; Thu, 10 Mar 2022 04:44:41 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 20/35] /perf/nesting Date: Thu, 10 Mar 2022 13:43:58 +0100 Message-Id: <20220310124413.1102441-21-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::336 (failed) 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=2a00:1450:4864:20::336; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646917802739100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index 439bd269c9..75d54e5d29 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -614,7 +614,6 @@ static void perf_lifecycle_noalloc(void) g_test_message("Lifecycle %u iterations: %f s", max, duration); } =20 -#if 0 static void perf_nesting(void) { unsigned int i, maxcycles, maxnesting; @@ -640,6 +639,7 @@ static void perf_nesting(void) maxcycles, maxnesting, duration); } =20 +#if 0 /* * Yield benchmark */ @@ -754,8 +754,8 @@ int main(int argc, char **argv) if (g_test_perf()) { g_test_add_func("/perf/lifecycle", perf_lifecycle); g_test_add_func("/perf/lifecycle/noalloc", perf_lifecycle_noalloc); -#if 0 g_test_add_func("/perf/nesting", perf_nesting); +#if 0 g_test_add_func("/perf/yield", perf_yield); g_test_add_func("/perf/function-call", perf_baseline); g_test_add_func("/perf/cost", perf_cost); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646917391578721.007739480869; Thu, 10 Mar 2022 05:03:11 -0800 (PST) Received: from localhost ([::1]:34248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIRi-0004Fl-SW for importer@patchew.org; Thu, 10 Mar 2022 08:03:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9t-0006vb-5O; Thu, 10 Mar 2022 07:44:45 -0500 Received: from [2a00:1450:4864:20::32b] (port=33830 helo=mail-wm1-x32b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9r-0005Ee-Lb; Thu, 10 Mar 2022 07:44:44 -0500 Received: by mail-wm1-x32b.google.com with SMTP id k8-20020a05600c1c8800b003899c7ac55dso4092248wms.1; Thu, 10 Mar 2022 04:44:42 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8Ijv45d7frV8RtMMOtg6s/7AI2S2ZexSVTc9afgZNFg=; b=qZjGYBp+IgwE83TsDq/liN0yL4g7Pe3hYtefAY7JslSiOC+AVkL0Xr6ZeX2CeRfund 5XPN6XSCVkFI+6Lnj72S3gQ4YlWDB4ZLoMklxr/dTyukXxOAwFpdQ/jOZyu3Z6GpJdjj hMJdQ2RPZnMFEA3Lh8IHqoSg6/ab/B/Z5Z4Y9lMpfSz39AwVY2AKswOjgkRUFFWktazp Mc+4kKD8gz6Z5WgdF2RNg9Qtek4jo42iUomrcfAFoyYHgpeP6l+s837rRE7+f6aWljlD SsNutnCWj4tUWm8lh6KL+lXQsrw1eflQcAytnvnAn/+3RFUSZVYgSP8Qad9lkBZAp82b a05g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=8Ijv45d7frV8RtMMOtg6s/7AI2S2ZexSVTc9afgZNFg=; b=KkjT8Ez+c5Bgqgbl0aQw5WptPLKzlNGXIL80qr3CXh1mGLMGF9V2wOPtRmsSEVMXOf BPomcOoExy8XxjMlXKyevTGdwGd5SYw2PIdP+qbvT6m1DiNhJWWYHZSQOgyRLG45GCOq 21MePtghhqFoY6tmsvIj38XlhWUfhH8uWykZ2iXZg49bNxA8U5E/ZFue1aOqKPL9ac5O AoRteBFE2ybE6avDmptyQd/ko4bSGC5+ENDibySs6O3ggitq+kNdVZ8alTjbeN0WKXfB KMPv3cm6zH28S8tRSw0e3uh+M2F5A4+tmV/ZtTq08j18s0n3C6IYoeBFYCMLDOCB83JK GIqQ== X-Gm-Message-State: AOAM532t+wCNqKlNNa9v+Lf+Okiau59WhHYSk1ZRJEFjdaARofAEScgx 5KnK5gNab6kifs7d/faAHLkJvwp6khg= X-Google-Smtp-Source: ABdhPJzpKekIhRMWUg4RutngiEvxOuhh6Kq97EXmrEyWU0N/7IrYY7ROBGx7aeHLRgo/+0VKktoiTw== X-Received: by 2002:a05:600c:2c49:b0:384:7202:358e with SMTP id r9-20020a05600c2c4900b003847202358emr11661443wmg.108.1646916281975; Thu, 10 Mar 2022 04:44:41 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 21/35] /perf/yield Date: Thu, 10 Mar 2022 13:43:59 +0100 Message-Id: <20220310124413.1102441-22-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32b (failed) 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=2a00:1450:4864:20::32b; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32b.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646917393875100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index 75d54e5d29..0b7b4d6ef8 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -639,19 +639,33 @@ static void perf_nesting(void) maxcycles, maxnesting, duration); } =20 -#if 0 /* * Yield benchmark */ =20 -static void coroutine_fn yield_loop(void *opaque) +CO_DECLARE_FRAME(yield_loop, void *opaque); +static CoroutineAction co__yield_loop(void *_frame) { + struct FRAME__yield_loop *_f =3D _frame; + CO_ARG(opaque); unsigned int *counter =3D opaque; =20 +switch(_f->_step) { +case 0: while ((*counter) > 0) { (*counter)--; - qemu_coroutine_yield(); +_f->_step =3D 1; + return qemu_coroutine_yield(); +case 1: } + break; +} +return stack_free(&_f->common); +} + +static CoroutineAction yield_loop(void *opaque) +{ + return CO_INIT_FRAME(yield_loop, opaque); } =20 static void perf_yield(void) @@ -672,6 +686,7 @@ static void perf_yield(void) g_test_message("Yield %u iterations: %f s", maxcycles, duration); } =20 +#if 0 static __attribute__((noinline)) void dummy(unsigned *i) { (*i)--; @@ -755,8 +770,8 @@ int main(int argc, char **argv) g_test_add_func("/perf/lifecycle", perf_lifecycle); g_test_add_func("/perf/lifecycle/noalloc", perf_lifecycle_noalloc); g_test_add_func("/perf/nesting", perf_nesting); -#if 0 g_test_add_func("/perf/yield", perf_yield); +#if 0 g_test_add_func("/perf/function-call", perf_baseline); g_test_add_func("/perf/cost", perf_cost); #endif --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 164692020484291.57832492875536; Thu, 10 Mar 2022 05:50:04 -0800 (PST) Received: from localhost ([::1]:55604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSJB5-0002dE-35 for importer@patchew.org; Thu, 10 Mar 2022 08:50:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9u-0006yf-QS; Thu, 10 Mar 2022 07:44:47 -0500 Received: from [2a00:1450:4864:20::42a] (port=43704 helo=mail-wr1-x42a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9t-0005FB-C0; Thu, 10 Mar 2022 07:44:46 -0500 Received: by mail-wr1-x42a.google.com with SMTP id e24so7741714wrc.10; Thu, 10 Mar 2022 04:44:44 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xTGQ7M7ENCkwdO0I0QDKcDyvsgi5YVkLnkk13pgEIBU=; b=WfLCU/mw4ndJOWTq8w9GAz3u8poNeDILAB6ZbuT2aU/uOBGFOAmBeXT7cSnxlBbFv2 Qr7+CP3EN8ICyJu/UqtmmLlGNV5aWQFS+2SbprSWcUmWqdNIkGpSLUI2aK3ZFe2tgE4q pehzeZwZV3LcsTpWBUkK0wvx8daTUqbtEdvFSdRnmM5bfgWcejHgH9zZqIuwIe7sW3KJ i4kg8EKWJjGbM+Nuqd7vcHnQwl+xvroJ/eXqGkF4t6TGiE4J1AdvK7UWmMLFfV/QXG9J VCugZd1RvSE9l0QagMQB/1Ann34ZWfkDH3zl1I1UPQrmTXf+QwFrpe+nwfwrE8JJiVYG QVQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=xTGQ7M7ENCkwdO0I0QDKcDyvsgi5YVkLnkk13pgEIBU=; b=uqz+uz2BLw0SsmDa1OjxyV5f9MSYbfVXSOLCCuo+wK2YX5G5Q/gy6EJNRqwsp6ruOq UjIEYPWmvdywujhTo3qRzkULdi3VV5BeRgm87ZNzdI+3MoK5uO5tspEWp/dUN5f/7SeI q1+9XiZD0hnaKD1e3thhIMUPQuOzDuhIx7eGosSYtlG0lV3PJ8MAQfsHDrq7HNNQ1ACp I2BrO3QZ6H7WKhJbjCDrvz+tkVIMX55rJZA5bS/4XV4mUGUgf3wKZchWVAHZxVDr8hyU XNnDW11J/CS6eEBRHL9d05rvzttN+ftr1DKGT1mxUgvKeQ1NucBQnutEXKDVuOWKdSAg FRgA== X-Gm-Message-State: AOAM533WHrrU8kYrn+qGaM+4FnxJwUl507ejNjDAlml7JkgX0Ciy1tcb aaU+FdA7HyPTiih3l6rHoVTztnc6Dv0= X-Google-Smtp-Source: ABdhPJyP8vjiq7p6KkC25x8m0CNcOWFoPk2cWpsV2L18GgTa8CtZptr94zJTuCxdHdd7C1NKDiwi9g== X-Received: by 2002:a5d:6da9:0:b0:202:293e:85ff with SMTP id u9-20020a5d6da9000000b00202293e85ffmr3558501wrs.159.1646916283762; Thu, 10 Mar 2022 04:44:43 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 22/35] /perf/function-call Date: Thu, 10 Mar 2022 13:44:00 +0100 Message-Id: <20220310124413.1102441-23-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42a (failed) 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=2a00:1450:4864:20::42a; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42a.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646920205761100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index 0b7b4d6ef8..c44287bcb0 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -686,7 +686,6 @@ static void perf_yield(void) g_test_message("Yield %u iterations: %f s", maxcycles, duration); } =20 -#if 0 static __attribute__((noinline)) void dummy(unsigned *i) { (*i)--; @@ -709,6 +708,7 @@ static void perf_baseline(void) g_test_message("Function call %u iterations: %f s", maxcycles, duratio= n); } =20 +#if 0 static __attribute__((noinline)) void perf_cost_func(void *opaque) { qemu_coroutine_yield(); @@ -771,8 +771,8 @@ int main(int argc, char **argv) g_test_add_func("/perf/lifecycle/noalloc", perf_lifecycle_noalloc); g_test_add_func("/perf/nesting", perf_nesting); g_test_add_func("/perf/yield", perf_yield); -#if 0 g_test_add_func("/perf/function-call", perf_baseline); +#if 0 g_test_add_func("/perf/cost", perf_cost); #endif } --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646920442491540.8578384635955; Thu, 10 Mar 2022 05:54:02 -0800 (PST) Received: from localhost ([::1]:59928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSJEv-0005vv-Hg for importer@patchew.org; Thu, 10 Mar 2022 08:54:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9w-00070W-4v; Thu, 10 Mar 2022 07:44:48 -0500 Received: from [2a00:1450:4864:20::42e] (port=43708 helo=mail-wr1-x42e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9u-0005Fm-Kj; Thu, 10 Mar 2022 07:44:47 -0500 Received: by mail-wr1-x42e.google.com with SMTP id e24so7741802wrc.10; Thu, 10 Mar 2022 04:44:45 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gGeLsc1tiwY5zvvykmKyG+fpxXYhOiE3qnbOz5EEzZU=; b=lS51fVdlamqPf8gCxarVVLNw/JJw4Tv21egUAtQRxHBRumlwkP3CnZQMeUuAu5np3C QlCuaeCKLfO88WDhKfg1ANz6BVSzvaKHFHtITsWeFKNZX9NY2xzAvY/I1vr6zBuPOoA3 oeqZ1XUvSr5aYkA1sYDXVEnaJD4qZNvFXsuTaYBXE7jwwLbux4U8fdf0WBU2ghftnC8g NERZeM53vXwaDjQldittxGhePIry3aPKopb/OgKMt0zZPU1P2FDc7IOO0cg+ieVnZhlS l7Q+egiE5gZEcjBaIUO3SswhNJ0/JCt21npOj//a5+y9R94wcaWR0wdSUUFxkORlgSkz MEFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=gGeLsc1tiwY5zvvykmKyG+fpxXYhOiE3qnbOz5EEzZU=; b=2MbwnoBCd+wnzggv6Cj3jYpvdTd1Apd6/awbY0/ryvFQb9xis1wxS6jcYwch8GcPpG zrCbY36SJUma6j9f7eXcZxbLgyzsp5BcbnWZR2phrs+wxMKdi61xqrz27r4Ukt/vyry4 GYMnbM80zCX6VNRYIXThtibEMXjxIqXrwmHSzP/q2OXxUFcqilBEhfzZVPJyZj1OhmDg 5odNE75VpCi5QSN+47IgNwt5FSeYgGEchDsdVbo7eNA0sXMtPNJFQxrmD58Kjc1s9RhZ qBhlYyHAirDrZkVk/hBwodFPRCBplOtyqy3Eg+a/LWPQn4kgecjDbnLZBCMAxPO98eqn Be5Q== X-Gm-Message-State: AOAM532VnRTH63Af9q5MPOkLh/EnY0hQGBOB/xh5NO5+mKS6Vwsi+lWc O5bPww1r8FxGJlQk+LPaMyYqGcSVn8U= X-Google-Smtp-Source: ABdhPJz326tMO7tWs8jU4G/ZCps+GNyKSz0k89un2m0kRXiTaonc/UnsyDFxrKYT6+XJdSrq4/XZ+A== X-Received: by 2002:a05:6000:1786:b0:1f0:36a5:e573 with SMTP id e6-20020a056000178600b001f036a5e573mr3440820wrg.428.1646916285089; Thu, 10 Mar 2022 04:44:45 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 23/35] /perf/cost Date: Thu, 10 Mar 2022 13:44:01 +0100 Message-Id: <20220310124413.1102441-24-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42e (failed) 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=2a00:1450:4864:20::42e; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42e.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646920443251100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index c44287bcb0..080ee76dde 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -708,10 +708,25 @@ static void perf_baseline(void) g_test_message("Function call %u iterations: %f s", maxcycles, duratio= n); } =20 -#if 0 -static __attribute__((noinline)) void perf_cost_func(void *opaque) +CO_DECLARE_FRAME(perf_cost_func); +static CoroutineAction co__perf_cost_func(void *_frame) { - qemu_coroutine_yield(); + struct FRAME__verify_entered_step_2 *_f =3D _frame; + +switch(_f->_step) +{ +case 0: + _f->_step =3D 1; + return qemu_coroutine_yield(); +case 1: + break; +} +return stack_free(&_f->common); +} + +static CoroutineAction perf_cost_func(void *opaque) +{ + return CO_INIT_FRAME(perf_cost_func); } =20 static void perf_cost(void) @@ -737,7 +752,6 @@ static void perf_cost(void) duration, ops, (unsigned long)(1000000000.0 * duration / maxcycles)); } -#endif =20 int main(int argc, char **argv) { @@ -772,9 +786,7 @@ int main(int argc, char **argv) g_test_add_func("/perf/nesting", perf_nesting); g_test_add_func("/perf/yield", perf_yield); g_test_add_func("/perf/function-call", perf_baseline); -#if 0 g_test_add_func("/perf/cost", perf_cost); -#endif } return g_test_run(); } --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646920586819314.829096118434; Thu, 10 Mar 2022 05:56:26 -0800 (PST) Received: from localhost ([::1]:34000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSJHF-0007wr-Ih for importer@patchew.org; Thu, 10 Mar 2022 08:56:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9x-00071b-6E; Thu, 10 Mar 2022 07:44:49 -0500 Received: from [2a00:1450:4864:20::436] (port=33647 helo=mail-wr1-x436.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9v-0005Fy-HN; Thu, 10 Mar 2022 07:44:48 -0500 Received: by mail-wr1-x436.google.com with SMTP id j17so7850672wrc.0; Thu, 10 Mar 2022 04:44:46 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9Of5BOTiqOzJQASVLoGU30+VhnG3k9PQZ8CPGdOhqNg=; b=quB7285k6+YKR2ICfRdRAQsX45BCt1BAtfFNJqm5GgtEe549f7Vbr6mAMri14PvGGv FFTPnVC2qCRs7YUa5QmApAOoO+MT0NPoMlcYueXE53UfRkteh9Dw1iKlQjf4gUDHUguo Q/aTOAbcd4MHYMiRvB6cOHz0AaNwQ3uBcre4HS9cXO7ZIt7APetrq9ZtbOon6i7yVyRx sMYMevJMRRc3hbzBqEc2fnTJLVu18h1SmwhuSDhfAik6ztkD6fJtZ1d8XWNA6+bDChno POV3EdxccCjjTGOTjuNAA8KOn7khOMTiM7qMygk7nNqM2D9S5F/oJJE1WkWMApO3BNVi P06w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=9Of5BOTiqOzJQASVLoGU30+VhnG3k9PQZ8CPGdOhqNg=; b=k/7+7GDjxNBylU/mzLaAZosMdc9rzdGm8N5uMfVulko5lDMBTzDYfnFRmP0dIz4Jni 0CI4rHLqsryb6mm4/kfOeqqdtBS/IyvmtVclL0QkblYxf/x8ZoeORAJODsMwi9e54L41 sLUZnGswjhwmwMJ4cyv3wl1u25bUcbmn9b0gtw6jTj/qYUWK1fNMm4PZySapzNuXeyv1 3IyZU8fbAjazN11Xg6Wb15paku08GFUcm3EZ3EOugujNDsRKAIJboveTJ45QX8s+wxZe r8XPpx21isnsJb7XDpeKCiqCYnAbJfm+4BAu0pLk99Ggb9jJ2gaMhzjUeGB4Y8mNz789 6PTA== X-Gm-Message-State: AOAM532REHEw3FshHmGuv89Ld45vWcDPT4uQnlzIRl8H+ys6Rwdu4j1q i2Gkh7WDHcfmsGczwjbfgfcNyvblcE4= X-Google-Smtp-Source: ABdhPJxPyzhDE7ydmGek6CXlfM7FN1BYLPY/HC4gfnKs1LVMQcUb7VyPkEdQNbxowAXAFze4V+udlA== X-Received: by 2002:adf:f389:0:b0:1ef:5f0f:cb83 with SMTP id m9-20020adff389000000b001ef5f0fcb83mr3396300wro.26.1646916285940; Thu, 10 Mar 2022 04:44:45 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 24/35] /basic/no-dangling-access Date: Thu, 10 Mar 2022 13:44:02 +0100 Message-Id: <20220310124413.1102441-25-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::436 (failed) 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=2a00:1450:4864:20::436; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x436.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646920588425100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index 080ee76dde..0fe9226b86 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -201,16 +201,32 @@ static void test_yield(void) g_assert_cmpint(i, =3D=3D, 5); /* coroutine must yield 5 times */ } =20 -#if 0 -static void coroutine_fn c2_fn(void *opaque) +CO_DECLARE_FRAME(c2_fn); +static CoroutineAction co__c2_fn(void *_frame) { - qemu_coroutine_yield(); + struct FRAME__verify_entered_step_2 *_f =3D _frame; + +switch(_f->_step) +{ +case 0: + _f->_step =3D 1; + return qemu_coroutine_yield(); +case 1: + break; +} +return stack_free(&_f->common); } =20 -static void coroutine_fn c1_fn(void *opaque) +static CoroutineAction c2_fn(void *opaque) +{ + return CO_INIT_FRAME(c2_fn); +} + +static CoroutineAction c1_fn(void *opaque) { Coroutine *c2 =3D opaque; qemu_coroutine_enter(c2); + return COROUTINE_CONTINUE; } =20 static void test_no_dangling_access(void) @@ -233,6 +249,7 @@ static void test_no_dangling_access(void) *c1 =3D tmp; } =20 +#if 0 static bool locked; static int done; =20 @@ -757,7 +774,6 @@ int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); =20 -#if 0 /* This test assumes there is a freelist and marks freed coroutine mem= ory * with a sentinel value. If there is no freelist this would legitima= tely * crash, so skip it. @@ -765,7 +781,6 @@ int main(int argc, char **argv) if (CONFIG_COROUTINE_POOL) { g_test_add_func("/basic/no-dangling-access", test_no_dangling_acce= ss); } -#endif =20 g_test_add_func("/basic/lifecycle", test_lifecycle); g_test_add_func("/basic/yield", test_yield); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646917575533527.5577378543582; Thu, 10 Mar 2022 05:06:15 -0800 (PST) Received: from localhost ([::1]:42842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIUg-0001hr-PX for importer@patchew.org; Thu, 10 Mar 2022 08:06:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41664) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9y-00072t-CP; Thu, 10 Mar 2022 07:44:50 -0500 Received: from [2a00:1450:4864:20::429] (port=37520 helo=mail-wr1-x429.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9w-0005GE-FJ; Thu, 10 Mar 2022 07:44:50 -0500 Received: by mail-wr1-x429.google.com with SMTP id q14so7788906wrc.4; Thu, 10 Mar 2022 04:44:47 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Xf/ySd1tCWK85nEqkcIPE9vKNo3doFLcngkawPWCtQU=; b=f5NudKZxYfHEermi1OWmK4w7ssfU28WVWX32xgGVCQMswLRlMODemkgXDq/rdm4odM 4ouxKsbbT5dqO6WRP8RDWLMuQn8lVD/165zeT4CvaThmpWs1yqa0l3mi47Y1sUrqJ5Iq CkhuosZBIeApqc0v/3t3vsCLseVXF2RM/xD12y4odcGOckTcumTOppkdhIjyXmbklBv0 P7ERY4VcbznrUAAjK6Pxvv+wAbv7A4EoL7k2CQku2Bl9LC3eKhkuwwKPB4sF+IICK5IT Y8A5YAmpZsbdW3BXvq49eIcE6U3Gq73gaasvEZNn1TBHeiFmoWMcp+glyffYyHGy6cDo seEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Xf/ySd1tCWK85nEqkcIPE9vKNo3doFLcngkawPWCtQU=; b=Vjp1CwlQSwIy2/vjO64/cmt3bSSA81zjZg8CtIbt3cwsnq+catNPN1spP3bL/0oCOG xYTXm4ig59shOQmwqyjVnYnkyDjs280+yxrYvOQOUTlIlnqE5PnIz/zLO+FKqO+ICPDB piPiBcLxh5eELeEum9vBD9062OsG9yL+X7V2QlfqgzMywnBwHMFh1ftbtlsBbzHLwdXC i5BQVit63AZoc6f3JQn+fcEL0TUB5fXZfokVDUgiV/QK5nm+Wv6gOAwyfRv2BcETJmkB PgXCMC1TjNXUylRdqAxM6hdNP0Zi3XojfYed7qOe3ciadTbynYbyD0QIxyjPSlB+lQ0L 9cSg== X-Gm-Message-State: AOAM531tP0Qq3xECe0pKlyCW0JayhBbyecVC1WTsuXxlIvwjmGp2WMFk j7foLxkYXDe7sLruFCOrAMTKLPWdXkM= X-Google-Smtp-Source: ABdhPJwlk5Okh4UhDMijuRK1yLjskWSjjkxRXp+VFAQnhCYEojff2FMStXdi6iy57tfu/8fH6O9pnw== X-Received: by 2002:a5d:4d4b:0:b0:1f1:d99e:1122 with SMTP id a11-20020a5d4d4b000000b001f1d99e1122mr3479177wru.604.1646916286843; Thu, 10 Mar 2022 04:44:46 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 25/35] /locking/co-mutex Date: Thu, 10 Mar 2022 13:44:03 +0100 Message-Id: <20220310124413.1102441-26-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::429 (failed) 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=2a00:1450:4864:20::429; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x429.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646917577623100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index 0fe9226b86..642ef36bc3 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -249,22 +249,41 @@ static void test_no_dangling_access(void) *c1 =3D tmp; } =20 -#if 0 static bool locked; static int done; =20 -static void coroutine_fn mutex_fn(void *opaque) +CO_DECLARE_FRAME(mutex_fn, CoMutex *m); +static CoroutineAction co__mutex_fn(void *_frame) { - CoMutex *m =3D opaque; - qemu_co_mutex_lock(m); + struct FRAME__mutex_fn *_f =3D _frame; + CO_ARG(m); +switch(_f->_step) { +case 0: +_f->_step =3D 1; + return qemu_co_mutex_lock(m); +case 1: assert(!locked); locked =3D true; - qemu_coroutine_yield(); +_f->_step =3D 2; + return qemu_coroutine_yield(); +case 2: locked =3D false; - qemu_co_mutex_unlock(m); +_f->_step =3D 3; + return qemu_co_mutex_unlock(m); +case 3: done++; + break; +} +return stack_free(&_f->common); } =20 +static CoroutineAction mutex_fn(void *opaque) +{ + CoMutex *m =3D opaque; + return CO_INIT_FRAME(mutex_fn, m); +} + +#if 0 static void coroutine_fn lockable_fn(void *opaque) { QemuCoLockable *x =3D opaque; @@ -276,6 +295,7 @@ static void coroutine_fn lockable_fn(void *opaque) qemu_co_lockable_unlock(x); done++; } +#endif =20 static void do_test_co_mutex(CoroutineEntry *entry, void *opaque) { @@ -307,6 +327,7 @@ static void test_co_mutex(void) do_test_co_mutex(mutex_fn, &m); } =20 +#if 0 static void test_co_mutex_lockable(void) { CoMutex m; @@ -789,8 +810,8 @@ int main(int argc, char **argv) g_test_add_func("/basic/entered", test_entered); g_test_add_func("/basic/in_coroutine", test_in_coroutine); g_test_add_func("/basic/order", test_order); -#if 0 g_test_add_func("/locking/co-mutex", test_co_mutex); +#if 0 g_test_add_func("/locking/co-mutex/lockable", test_co_mutex_lockable); g_test_add_func("/locking/co-rwlock/upgrade", test_co_rwlock_upgrade); g_test_add_func("/locking/co-rwlock/downgrade", test_co_rwlock_downgra= de); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646920649234364.91052892117034; Thu, 10 Mar 2022 05:57:29 -0800 (PST) Received: from localhost ([::1]:36148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSJIG-00017T-1X for importer@patchew.org; Thu, 10 Mar 2022 08:57:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSI9z-00075v-NJ; Thu, 10 Mar 2022 07:44:51 -0500 Received: from [2a00:1450:4864:20::430] (port=33642 helo=mail-wr1-x430.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9x-0005GW-Lx; Thu, 10 Mar 2022 07:44:51 -0500 Received: by mail-wr1-x430.google.com with SMTP id j17so7850801wrc.0; Thu, 10 Mar 2022 04:44:49 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nT+l8ptDt61ghJ2d9zhtYyUlzG0YgTu30zE7V3Dxlek=; b=QPaaKshCe/aFzxAcH+4LzUmA0tl/BsWlWTIgGzmaLPnePtQIZBB6XUpB/0OklOkORd BShy/3NL+NYYc0+GAxX5eOrHxtFxSo1pHBkdlxRGyXnkGq2foN2QJFL4XcixejC08S26 w6MRVLRsM20URa7FogBGiB9Z5NsrJ3P/+h3WGfUIeGYw1VPa8xI5Lm791dHCtzpkz9a1 lnXwiM/g7WeSWFyHNN4J/ph7Kmh1hfmXfpU1/trfJClJzshgRS8fL4BGl8W24vkKQFpW Tbd05dsnKjzYwO4/1cxdtlwkKN7CVyvCL10nRRbjGgsy8u5QuAnD0u2voP6CQcbjYatK M4eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=nT+l8ptDt61ghJ2d9zhtYyUlzG0YgTu30zE7V3Dxlek=; b=kLckmwk/HE0EDQoRHzFTrsKCiqrrLjQ5F3c198ynYMpCjW0MHJfseOERYZrtVTnpxE ADCB0/F2IXF1XlVXt8WvzH00FsIzPwruAzyVFK83rkiaf2wLBa6dMf86yBR3ZxtrJZiq 9QXGsEzs6SLaM6JqHzIviESsJ8Dupx+JLDgIZ0DHCoZ9/mAE1GNEiBdivl6QMVH0mptF 9wse55ESX8FnO8h05TrcO8G4ivzZmFuhyrPaXVipNuJm512zAPpsaxbHFKSqyFWR1YPo cwE61Bi4SUvuwTcYJkM9zT+9huxV3m4Sd03aqL0kPMV0fNLqqlBLcHw0FJAMVbWUocr3 +fBg== X-Gm-Message-State: AOAM530YqLklVs+VnM/WzjMH8SwlzJvmKsgvTl00kCdBV6O2TOuxKl2+ wipwII0khl33eztrBdSQes1zvYdc6HY= X-Google-Smtp-Source: ABdhPJwn+GBW+G2lfqkBpZE30U/PIKR0le91KvlfHqdf+ZJyurDrfKCJh59x9ojVDQLFN3arIxIleQ== X-Received: by 2002:adf:e44b:0:b0:1f0:250a:d3ef with SMTP id t11-20020adfe44b000000b001f0250ad3efmr3461052wrm.402.1646916288138; Thu, 10 Mar 2022 04:44:48 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 26/35] convert qemu_co_mutex_lock_slowpath to magic macros Date: Thu, 10 Mar 2022 13:44:04 +0100 Message-Id: <20220310124413.1102441-27-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::430 (failed) 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=2a00:1450:4864:20::430; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x430.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646920651323100001 Content-Type: text/plain; charset="utf-8" Replace the hand-written frame structure with one built with the CO_* macro= s, just to shake them a bit. The produced code is exactly the same (except for CO_INIT_FRAME using a statement expression to keep the "return" statement visible in the code). Signed-off-by: Paolo Bonzini --- util/qemu-coroutine-lock.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index 061a376aa4..51f7da8bda 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -198,21 +198,13 @@ static void coroutine_fn qemu_co_mutex_wake(CoMutex *= mutex, Coroutine *co) aio_co_wake(co); } =20 -struct FRAME__qemu_co_mutex_lock_slowpath { - CoroutineFrame common; - uint32_t _step; - AioContext *ctx; - CoMutex *mutex; - Coroutine *self; - CoWaitRecord w; -}; +CO_DECLARE_FRAME(qemu_co_mutex_lock_slowpath, AioContext *ctx, CoMutex *mu= tex, Coroutine *self, CoWaitRecord w); =20 static CoroutineAction co__qemu_co_mutex_lock_slowpath(void *_frame) { struct FRAME__qemu_co_mutex_lock_slowpath *_f =3D _frame; - AioContext *ctx =3D _f->ctx; - CoMutex *mutex =3D _f->mutex; - Coroutine *self; + CO_ARG(ctx, mutex); + CO_DECLARE(self); unsigned old_handoff; =20 switch(_f->_step) { @@ -244,11 +236,11 @@ case 0: { } =20 _f->_step =3D 1; -_f->self =3D self; +CO_SAVE(self); return qemu_coroutine_yield(); } case 1: -self =3D _f->self; +CO_LOAD(self); trace_qemu_co_mutex_lock_return(mutex, self); mutex->holder =3D self; self->locks_held++; @@ -260,12 +252,7 @@ return stack_free(&_f->common); =20 static CoroutineAction qemu_co_mutex_lock_slowpath(AioContext *ctx, CoMute= x *mutex) { - struct FRAME__qemu_co_mutex_lock_slowpath *f; - f =3D stack_alloc(co__qemu_co_mutex_lock_slowpath, sizeof(*f)); - f->ctx =3D ctx; - f->mutex =3D mutex; - f->_step =3D 0; - return co__qemu_co_mutex_lock_slowpath(f); + return CO_INIT_FRAME(qemu_co_mutex_lock_slowpath, ctx, mutex); } =20 CoroutineAction qemu_co_mutex_lock(CoMutex *mutex) --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646917543694841.3559569709381; Thu, 10 Mar 2022 05:05:43 -0800 (PST) Received: from localhost ([::1]:41274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIU8-0000el-1z for importer@patchew.org; Thu, 10 Mar 2022 08:05:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSIA0-00077K-9x; Thu, 10 Mar 2022 07:44:52 -0500 Received: from [2a00:1450:4864:20::433] (port=42871 helo=mail-wr1-x433.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9y-0005Gh-Je; Thu, 10 Mar 2022 07:44:51 -0500 Received: by mail-wr1-x433.google.com with SMTP id u10so7752295wra.9; Thu, 10 Mar 2022 04:44:49 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BXL2jinMbEzupMfdEPM3XNAu06eQUhqHpIIRQqS3zRU=; b=mWLBgw5M4sEElGVI6dlgGo/EmkHZ+och0JMPqlZXw/NR8+vbCNHBZ8RGu9VJ5Ri60j mD41k79Qj4tU37thFiDDMbl1tQSBuu6k1heKCtwSFsYkVmviJYMP/Ux+/EiNKYJTea1c q2m0nPV/jL/v/moPvtgEpDryfd3Iomi8FDdLZjqZI5KrTGxuLIS1B7hFf8ZwR81rm9Ep EYFeAJOb5q92ZydEavGMuvpQgI8kEn6d1BItdIq1SgOGY/y8arpCzlUohshrMWA+/QOC IZw0K5HEfME3mtPRSTMOABdEShZQbgp8DqYAF/SW2Op+OqGMC2CJJVJv6pJOQozoQbW7 H1OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=BXL2jinMbEzupMfdEPM3XNAu06eQUhqHpIIRQqS3zRU=; b=bjMduk0A4CvtuocG642FN+lRS/IV12Vl/ZxshxX8vqdXltOAbY2WCfB7An4DTsDAK8 IMMljXmJeYHL7UM7f8ixbgOeIV5XUY/k9eou6qAgeAXkAxLIodPS4orxbK/iXQhwZuzV 2QlqPZ0LXxBuMmpiuS29nN0GUFgGI0JVGQtDNr7oiUApPzNFxOU0JMn0Ft8r3i3Ojw5j Mp//g/O8zk7vL3CJ18/XV2ZImwcN0tFpqZyJFzqrW+2pGAGMeC1+U1EdcLBkrFl/y3D7 l/CvRNAGagY8YZgM7hkQ1TCQYbVKVbwpd4qhpv0M6QJTFc1kTHq8ePchHvaUl5GbrB5W FlLA== X-Gm-Message-State: AOAM533cgoPf5Rcif5ARMui3lKDJYAg5oQfxw66IdRAZMHBypEkimvXd nXxDq+ICEkMpG2la6x3ZLzPB6WcOmSw= X-Google-Smtp-Source: ABdhPJxqhG4plQ7gnYxUVm+UCZMWM6cP/f73FsGvCbHPYVJj3xOucoAVmc79RsXi+AoM2uELVEAZSg== X-Received: by 2002:a05:6000:1689:b0:203:71fb:3930 with SMTP id y9-20020a056000168900b0020371fb3930mr3366255wrd.122.1646916288972; Thu, 10 Mar 2022 04:44:48 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 27/35] /locking/co-mutex/lockable Date: Thu, 10 Mar 2022 13:44:05 +0100 Message-Id: <20220310124413.1102441-28-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::433 (failed) 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=2a00:1450:4864:20::433; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x433.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646917545577100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index 642ef36bc3..db6718db40 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -283,19 +283,36 @@ static CoroutineAction mutex_fn(void *opaque) return CO_INIT_FRAME(mutex_fn, m); } =20 -#if 0 -static void coroutine_fn lockable_fn(void *opaque) +CO_DECLARE_FRAME(lockable_fn, QemuCoLockable *x); +static CoroutineAction co__lockable_fn(void *_frame) { - QemuCoLockable *x =3D opaque; - qemu_co_lockable_lock(x); + struct FRAME__lockable_fn *_f =3D _frame; + CO_ARG(x); +switch(_f->_step) { +case 0: +_f->_step =3D 1; + return qemu_co_lockable_lock(x); +case 1: assert(!locked); locked =3D true; - qemu_coroutine_yield(); +_f->_step =3D 2; + return qemu_coroutine_yield(); +case 2: locked =3D false; - qemu_co_lockable_unlock(x); +_f->_step =3D 3; + return qemu_co_lockable_unlock(x); +case 3: done++; + break; +} +return stack_free(&_f->common); +} + +static CoroutineAction lockable_fn(void *opaque) +{ + QemuCoLockable *x =3D opaque; + return CO_INIT_FRAME(lockable_fn, x); } -#endif =20 static void do_test_co_mutex(CoroutineEntry *entry, void *opaque) { @@ -327,7 +344,6 @@ static void test_co_mutex(void) do_test_co_mutex(mutex_fn, &m); } =20 -#if 0 static void test_co_mutex_lockable(void) { CoMutex m; @@ -339,6 +355,7 @@ static void test_co_mutex_lockable(void) g_assert(QEMU_MAKE_CO_LOCKABLE(null_pointer) =3D=3D NULL); } =20 +#if 0 static CoRwlock rwlock; =20 /* Test that readers are properly sent back to the queue when upgrading, @@ -811,8 +828,8 @@ int main(int argc, char **argv) g_test_add_func("/basic/in_coroutine", test_in_coroutine); g_test_add_func("/basic/order", test_order); g_test_add_func("/locking/co-mutex", test_co_mutex); -#if 0 g_test_add_func("/locking/co-mutex/lockable", test_co_mutex_lockable); +#if 0 g_test_add_func("/locking/co-rwlock/upgrade", test_co_rwlock_upgrade); g_test_add_func("/locking/co-rwlock/downgrade", test_co_rwlock_downgra= de); #endif --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646920759541584.4493802161721; Thu, 10 Mar 2022 05:59:19 -0800 (PST) Received: from localhost ([::1]:38326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSJK2-0002wz-IZ for importer@patchew.org; Thu, 10 Mar 2022 08:59:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSIA1-000792-2O; Thu, 10 Mar 2022 07:44:53 -0500 Received: from [2a00:1450:4864:20::42e] (port=36532 helo=mail-wr1-x42e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSI9z-0005Gy-Lx; Thu, 10 Mar 2022 07:44:52 -0500 Received: by mail-wr1-x42e.google.com with SMTP id r10so7800494wrp.3; Thu, 10 Mar 2022 04:44:50 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CoYUWeJfp1u68l+ilOCM3xBlf1E8aY0U6SOmZUzPt1o=; b=aeDa1KF6CLIPSOPbuY4rPaIirID3ooQKWTbqNU+ae6rSMfXifUi3fBqgONSHVXE6XH Aj5Qx5Nb3f+zOgWHHi5vV8kMiBeyiYBCbYsZFUrdv2I4GQwLGqywhTQCJjQiBM+d2v/b +MlXQ7eLvxAtyRNnTm7Uz3dQqff2DrG5wEjc0CsnVmQTUCNHt3or8o96xrrUj0bXklm9 HyXC0IV6G9eQ2/oKZlud5kg+0nlFdtOUEx+dxRnTtWYFtgPAziQ63LYFuRKRI5nEk710 H15rYh8qJ7pkrJNIe9y4RkBEst69fBAxNnKJGFA77IK+ouWmg853GKtZBAS3oBJvFVVS hr9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=CoYUWeJfp1u68l+ilOCM3xBlf1E8aY0U6SOmZUzPt1o=; b=D0TRpKiTETBelnVT4rVHnKjKxST0Zh9kBzG5+w7r29outKcOfXMMPNyA2zaNk2MtDQ U2InK+JYTWskwj8V71dOPAt7VeA8FT2O9Ik/ZFpyAYtjgEj43WEmZ/bVrIiS6A3+XLX/ k0VcbjQpu0adPUX6PXazwquq3NOeVtYvVrwNyWqYWB4urHFm7+mRBPoZJdgEwJq+IDWo Uczz331MhcD79zvEJd+13EAnS45013LNrW7rN53/d6ACTyBVXsgW/jZBe26jBa19K39P osCaVOP3/bI8Qj/YoBAS9zYYSfyU3KxZ9yUXGZckhrwWTHgUkWHaiwq+V5tl8wqXIPvy iRLQ== X-Gm-Message-State: AOAM533Z92DvspNUkX3QBVR172AJ+1SOkmVbHwdEo+5EzZLznB/E5KgV iR+Ks2LRN5wE2CJJHN25R1Qtbs8nzwM= X-Google-Smtp-Source: ABdhPJw06OOcNdfK1B6R1+mlXeo1f8dPFJj4g8cHZWwhZyqJNrbOeNmnagzzNOlDe289h/l32oBI5A== X-Received: by 2002:a05:6000:1d89:b0:1ed:b6d5:cbda with SMTP id bk9-20020a0560001d8900b001edb6d5cbdamr3378672wrb.514.1646916290007; Thu, 10 Mar 2022 04:44:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 28/35] qemu_co_rwlock_maybe_wake_one Date: Thu, 10 Mar 2022 13:44:06 +0100 Message-Id: <20220310124413.1102441-29-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42e (failed) 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=2a00:1450:4864:20::42e; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42e.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646920760989100001 Content-Type: text/plain; charset="utf-8" This is optimized a bit based on the assumption that qemu_co_mutex_unlock() never yields. In other words, qemu_co_mutex_unlock() and qemu_co_rwlock_maybe_wake_one() could be declared coroutine_only_fn instead of coroutine_fn. Signed-off-by: Paolo Bonzini --- util/qemu-coroutine-lock.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index 51f7da8bda..3b50e1dd5b 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -352,7 +352,6 @@ CoroutineAction qemu_co_mutex_unlock(CoMutex *mutex) return COROUTINE_CONTINUE; } =20 -#if 0 struct CoRwTicket { bool read; Coroutine *co; @@ -367,7 +366,7 @@ void qemu_co_rwlock_init(CoRwlock *lock) } =20 /* Releases the internal CoMutex. */ -static void qemu_co_rwlock_maybe_wake_one(CoRwlock *lock) +static CoroutineAction qemu_co_rwlock_maybe_wake_one(CoRwlock *lock) { CoRwTicket *tkt =3D QSIMPLEQ_FIRST(&lock->tickets); Coroutine *co =3D NULL; @@ -393,13 +392,17 @@ static void qemu_co_rwlock_maybe_wake_one(CoRwlock *l= ock) =20 if (co) { QSIMPLEQ_REMOVE_HEAD(&lock->tickets, next); - qemu_co_mutex_unlock(&lock->mutex); + int action =3D qemu_co_mutex_unlock(&lock->mutex); + assert(action =3D=3D COROUTINE_CONTINUE); aio_co_wake(co); } else { - qemu_co_mutex_unlock(&lock->mutex); + int action =3D qemu_co_mutex_unlock(&lock->mutex); + assert(action =3D=3D COROUTINE_CONTINUE); } + return COROUTINE_CONTINUE; } =20 +#if 0 void qemu_co_rwlock_rdlock(CoRwlock *lock) { Coroutine *self =3D qemu_coroutine_self(); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646918354197258.11466028361394; Thu, 10 Mar 2022 05:19:14 -0800 (PST) Received: from localhost ([::1]:34614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIhE-0000xH-QB for importer@patchew.org; Thu, 10 Mar 2022 08:19:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSIA2-0007Ac-0M; Thu, 10 Mar 2022 07:44:54 -0500 Received: from [2a00:1450:4864:20::433] (port=43714 helo=mail-wr1-x433.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSIA0-0005HC-F7; Thu, 10 Mar 2022 07:44:53 -0500 Received: by mail-wr1-x433.google.com with SMTP id e24so7742511wrc.10; Thu, 10 Mar 2022 04:44:51 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rIL44VOkxzwidSkVK2Nn32gV754faOsKItwpY0xf3aU=; b=eF3VEvCK1idjXjtTtWCelgwB3C5fNo8btjWHUQK7yStCVM/HXCxaj0FsZAwFTWmPFz FTK+WSPg2Sf1Xo6WpZtGG5Je2Km+H/6yHBNf8haRV6wLMdQ6Ufm3vqtE/iQ9KAyyXD2r GXNuD1Gi9g5PDNg7umbhXaWpF6RmHMP/+TQ4G2yk0CxwiOTa7gLAlHFNpjYQWi0EX0+R NULHRfTejXQxFGkIzF68P0MSxi7pBtKw4Ud3nEN+0eiDtFQowjz5C7QdtqZBHTZgHj4t 7KoLaPKbIF4TBno2DAKz3Jt//Ktfsiu8HtnK+hM/fqaxXsRprs5+1E78jBZtg8mqNOer hxpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=rIL44VOkxzwidSkVK2Nn32gV754faOsKItwpY0xf3aU=; b=bFG2UrJ6M91mWaoZ0X5L4euBYVQBwnhy/VY0wQqkIhjr5LrvJNKO6ElonDcnCjcNQp XwONjMCkzBftRKXgU7m0KKwhDEgCA4MynGNRNcQbil2DdqXf1ayqdmOP1PY7NLoefunU QTBEL8G0bkqrM4E0NHSLXDX7hn9DdiUZs4qK9magY5xNsomQMdf8jrwC3o8CPqtz6bJM ako8NLx+yDYqsl+OEpC2xONN1auGdD5FcSzt+UM5inEpcYW+XNpy6n9/SWJO2i5qEUbv Qyz1lCKTwpJFFHoX9Je9+NoDrKod1IrWMq5sX7njMZ519x5e3XRXERCjQiCU6FIFrmQd gwgg== X-Gm-Message-State: AOAM53147GEEHL5b4EwotskBUx3sYXHvj7nfEUSE1/hqwPD7WkOrCNYE 4W1kAh32Wq74q5uObT1ueN0uaWpFwBA= X-Google-Smtp-Source: ABdhPJyX0Z/LH33PHav4kq5fZzUn6pspPJnjk/c3+DyQaoEbkqeRl1yrmmx1otluxta0hmF8+oGU4g== X-Received: by 2002:adf:e5cf:0:b0:203:7a50:98bd with SMTP id a15-20020adfe5cf000000b002037a5098bdmr3439068wrn.416.1646916290847; Thu, 10 Mar 2022 04:44:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 29/35] qemu_co_rwlock_rdlock Date: Thu, 10 Mar 2022 13:44:07 +0100 Message-Id: <20220310124413.1102441-30-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::433 (failed) 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=2a00:1450:4864:20::433; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x433.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646918354927100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- util/qemu-coroutine-lock.c | 40 +++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index 3b50e1dd5b..e7eb446566 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -402,32 +402,54 @@ static CoroutineAction qemu_co_rwlock_maybe_wake_one(= CoRwlock *lock) return COROUTINE_CONTINUE; } =20 -#if 0 -void qemu_co_rwlock_rdlock(CoRwlock *lock) +CO_DECLARE_FRAME(qemu_co_rwlock_rdlock, CoRwlock *lock, Coroutine *self, C= oRwTicket my_ticket); +static CoroutineAction co__qemu_co_rwlock_rdlock(void *_frame) { + struct FRAME__qemu_co_rwlock_rdlock *_f =3D _frame; + CO_ARG(lock); Coroutine *self =3D qemu_coroutine_self(); =20 - qemu_co_mutex_lock(&lock->mutex); +switch(_f->_step) { +case 0: +_f->_step =3D 1; +CO_SAVE(self); + return qemu_co_mutex_lock(&lock->mutex); +case 1: +CO_LOAD(self); /* For fairness, wait if a writer is in line. */ if (lock->owners =3D=3D 0 || (lock->owners > 0 && QSIMPLEQ_EMPTY(&lock= ->tickets))) { lock->owners++; qemu_co_mutex_unlock(&lock->mutex); } else { - CoRwTicket my_ticket =3D { true, self }; + _f->my_ticket =3D (CoRwTicket){ true, self }; =20 - QSIMPLEQ_INSERT_TAIL(&lock->tickets, &my_ticket, next); + QSIMPLEQ_INSERT_TAIL(&lock->tickets, &_f->my_ticket, next); qemu_co_mutex_unlock(&lock->mutex); - qemu_coroutine_yield(); + +_f->_step =3D 2; + return qemu_coroutine_yield(); +case 2: assert(lock->owners >=3D 1); =20 /* Possibly wake another reader, which will wake the next in line.= */ - qemu_co_mutex_lock(&lock->mutex); +_f->_step =3D 3; + return qemu_co_mutex_lock(&lock->mutex); +case 3: +CO_LOAD(self); qemu_co_rwlock_maybe_wake_one(lock); } - - self->locks_held++; } =20 + self->locks_held++; +return stack_free(&_f->common); +} + +CoroutineAction qemu_co_rwlock_rdlock(CoRwlock *lock) +{ + return CO_INIT_FRAME(qemu_co_rwlock_rdlock, lock); +} + +#if 0 void qemu_co_rwlock_unlock(CoRwlock *lock) { Coroutine *self =3D qemu_coroutine_self(); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646921034683658.3621331105994; Thu, 10 Mar 2022 06:03:54 -0800 (PST) Received: from localhost ([::1]:40858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSJOS-0005Jl-Tp for importer@patchew.org; Thu, 10 Mar 2022 09:03:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSIA3-0007BH-1w; Thu, 10 Mar 2022 07:44:56 -0500 Received: from [2a00:1450:4864:20::42e] (port=39559 helo=mail-wr1-x42e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSIA1-0005HX-CI; Thu, 10 Mar 2022 07:44:54 -0500 Received: by mail-wr1-x42e.google.com with SMTP id h15so7758136wrc.6; Thu, 10 Mar 2022 04:44:52 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m7/i4QQ/tXgODsjwuJBS5kQ2OleKE7n7aRV1qWEFjdo=; b=EHzidgYzHZIxuuzy/14d2bpfR18xIQve1KVZdqH7gHCtFrqkGDx5FZBOgwevQJqGuP HtnC99ton+G+Xd855Gajtc2r4+OmNBE7a7kSH8sLObBWMcAAc3RXJmOy+68GBvOU0HJT AcfgpcWXJJfWD0OZTo7M81hNmSwQxTKJr042kq71G8qTHhmV31FxG9mntqk/a2XxsreR Mrbe2MfShP4Z0g+dXfjJf10IFUQvXvqsOyzuVf8byvwwZ4Fo0WR2gKsYlJBT/gjTNEfV iimHujRi9G0qJgu981f6WSDfAf3QIOMVxwTaxgO8Nxdd0ieHRQ+aKTlnWNyKhbtF/Cll govw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=m7/i4QQ/tXgODsjwuJBS5kQ2OleKE7n7aRV1qWEFjdo=; b=PRAofXXUYSu+b5agFlGZVS/qD07ioKpF0ExPBXZk3Czfs3withCLi1bAeNl3dHZ5IO BwqzhPs0dqAY2Q6FJlfdtvpUU4x6D4ppVU/SRJkmdLfwh5rtnpoXddPzMu0wwWlITXR8 Yw5buyrytTtOHB6Bk5VoaEYiVgXClizRh0O80k8kB6pp55yfkimH5bSYeCHCs9HGTxhH J5Hupm2AO8/RrtQYjVoFq3layLy6+1kVJdBZ9wygh/IV4sCxURXBIVBI1UXsEs3KU/Mq JjaDhkRerOhxWklN2YZ6DHWJRu49NtRvqH2FKSyop18dAdkR7B3oFs++zoFdsgoUnC7Z 1aTg== X-Gm-Message-State: AOAM533GLEDYEh1g+CaRrmFx/ztcs36E2FtliM4fIJz0O7B0wjV+pTDy b8Sd/koqyw9zkli64EoZqFiWJQUvQ0M= X-Google-Smtp-Source: ABdhPJz9/uSwZI9bd9Pv4LCf9RwJzsDsm/hLqbtREjvFl3IhKPNmw9oSQ6pxnR0vyIystbxxGG98yw== X-Received: by 2002:a05:6000:1786:b0:1f0:36a5:e573 with SMTP id e6-20020a056000178600b001f036a5e573mr3441167wrg.428.1646916291765; Thu, 10 Mar 2022 04:44:51 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 30/35] qemu_co_rwlock_unlock Date: Thu, 10 Mar 2022 13:44:08 +0100 Message-Id: <20220310124413.1102441-31-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42e (failed) 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=2a00:1450:4864:20::42e; envelope-from=paolo.bonzini@gmail.com; helo=mail-wr1-x42e.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646921035661100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- util/qemu-coroutine-lock.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index e7eb446566..c164cf6b15 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -449,15 +449,21 @@ CoroutineAction qemu_co_rwlock_rdlock(CoRwlock *lock) return CO_INIT_FRAME(qemu_co_rwlock_rdlock, lock); } =20 -#if 0 -void qemu_co_rwlock_unlock(CoRwlock *lock) +CO_DECLARE_FRAME(qemu_co_rwlock_unlock, CoRwlock *lock); +static CoroutineAction co__qemu_co_rwlock_unlock(void *_frame) { + struct FRAME__qemu_co_rwlock_unlock *_f =3D _frame; + CO_ARG(lock); Coroutine *self =3D qemu_coroutine_self(); =20 +switch(_f->_step) { +case 0: +_f->_step =3D 1; assert(qemu_in_coroutine()); self->locks_held--; =20 - qemu_co_mutex_lock(&lock->mutex); + return qemu_co_mutex_lock(&lock->mutex); +case 1: if (lock->owners > 0) { lock->owners--; } else { @@ -465,9 +471,20 @@ void qemu_co_rwlock_unlock(CoRwlock *lock) lock->owners =3D 0; } =20 - qemu_co_rwlock_maybe_wake_one(lock); +_f->_step =3D 2; + return qemu_co_rwlock_maybe_wake_one(lock); +case 2: + break; +} +return stack_free(&_f->common); } =20 +CoroutineAction qemu_co_rwlock_unlock(CoRwlock *lock) +{ + return CO_INIT_FRAME(qemu_co_rwlock_unlock, lock); +} + +#if 0 void qemu_co_rwlock_downgrade(CoRwlock *lock) { qemu_co_mutex_lock(&lock->mutex); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646918570720476.84584897256354; Thu, 10 Mar 2022 05:22:50 -0800 (PST) Received: from localhost ([::1]:42522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIkj-0006li-Dy for importer@patchew.org; Thu, 10 Mar 2022 08:22:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSIA4-0007Bl-Oe; Thu, 10 Mar 2022 07:44:57 -0500 Received: from [2a00:1450:4864:20::32f] (port=37753 helo=mail-wm1-x32f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSIA3-0005I6-9v; Thu, 10 Mar 2022 07:44:56 -0500 Received: by mail-wm1-x32f.google.com with SMTP id q7-20020a7bce87000000b00382255f4ca9so5372930wmj.2; Thu, 10 Mar 2022 04:44:54 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NtfLq8CDDAN+OsDz6ySOeMkfeiJ4VTMTdljzWdf/3D4=; b=Z/6fdqrQoT3cph0upoUUQ/sE7ernLtwaAp9tae9R/NY/ceVseZ0IzLHEPczEFxkbh8 nl4mn2V7UaSxWIhjC2MrS9cpoBf68Cb20mCuzMD2u6KE7rVzDCcdOMEnD5gpvtFckUTJ lUV54Wuj4zgXFt/hlYOiw0cKFLByiiruwF35orS8Mgirj2ZFn/YpCwkuoCtNF7iDRLng ayKGPRWsfQ0mm3KE3gVvErKwjHOCCAOc+lYCCaGQHRRf7bkKFCLn4Og0VOrhvu5eLUpQ D9CQ4AA5/nDYghJUt+m+NRagC9POKpqwSaIXmQYW1SCcAxYvjWPf5+YyrO9x05iqHDow mQTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=NtfLq8CDDAN+OsDz6ySOeMkfeiJ4VTMTdljzWdf/3D4=; b=wRx/3HuihhTj8sofYKhkK6burTrLK7bi+9ilz0n4fk8plRUCtLGMJlCyE1eexYvNyx SJZaclir70mHWUyIdZZIASAbBjtSOIUuFGMXu9D8M14ga1JMg1OOVe9Ai4NpR6imLHga lRhrEoHM9/pQmDQHAWxqH1hn3H8asXkpPEvzPHDv/2jqXpi7XTHLD6+F89fk4LBz8X4T pm4HO8VJic7D4SAbiKmvwjyOGkrVmON5SlVhFVjsoK/Ec2ThzNAbsDPjC2wttuhKNP7c QHeq4t+zCDWLNEY4NA6F/+2gK7SkYhWqIrTB4tRmmoepQmJqct+JR0gP45MvB6QKjQp9 Mxvg== X-Gm-Message-State: AOAM532V/JaX63b3sqFDhMdpcQ6hXtfTxeoCY1+SWUWF2+F67aqqiFo8 mOW11V+lFFJD8rTpO/6xoT8HOrhTt+U= X-Google-Smtp-Source: ABdhPJysoCyOTauiW3Nb0zShL8Uvt0IACYT4TwlCT3wmCWfqy6hrjWT0QNXqYVySfFEwRO8lnt0Jdg== X-Received: by 2002:a1c:e916:0:b0:37c:f44f:573 with SMTP id q22-20020a1ce916000000b0037cf44f0573mr11710627wmc.179.1646916293563; Thu, 10 Mar 2022 04:44:53 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 31/35] qemu_co_rwlock_downgrade Date: Thu, 10 Mar 2022 13:44:09 +0100 Message-Id: <20220310124413.1102441-32-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32f (failed) 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=2a00:1450:4864:20::32f; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32f.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646918572762100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- util/qemu-coroutine-lock.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index c164cf6b15..5a7b99cfaf 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -484,17 +484,35 @@ CoroutineAction qemu_co_rwlock_unlock(CoRwlock *lock) return CO_INIT_FRAME(qemu_co_rwlock_unlock, lock); } =20 -#if 0 -void qemu_co_rwlock_downgrade(CoRwlock *lock) +CO_DECLARE_FRAME(qemu_co_rwlock_downgrade, CoRwlock *lock); +static CoroutineAction co__qemu_co_rwlock_downgrade(void *_frame) { - qemu_co_mutex_lock(&lock->mutex); + struct FRAME__qemu_co_rwlock_downgrade *_f =3D _frame; + CO_ARG(lock); + +switch(_f->_step) { +case 0: +_f->_step =3D 1; + return qemu_co_mutex_lock(&lock->mutex); +case 1: assert(lock->owners =3D=3D -1); lock->owners =3D 1; =20 /* Possibly wake another reader, which will wake the next in line. */ - qemu_co_rwlock_maybe_wake_one(lock); +_f->_step =3D 2; + return qemu_co_rwlock_maybe_wake_one(lock); +case 2: + break; +} +return stack_free(&_f->common); } =20 +CoroutineAction qemu_co_rwlock_downgrade(CoRwlock *lock) +{ + return CO_INIT_FRAME(qemu_co_rwlock_downgrade, lock); +} + +#if 0 void qemu_co_rwlock_wrlock(CoRwlock *lock) { Coroutine *self =3D qemu_coroutine_self(); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646917790071754.7484962246853; Thu, 10 Mar 2022 05:09:50 -0800 (PST) Received: from localhost ([::1]:49844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIY9-0006uI-2c for importer@patchew.org; Thu, 10 Mar 2022 08:09:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSIA6-0007EH-By; Thu, 10 Mar 2022 07:44:58 -0500 Received: from [2a00:1450:4864:20::336] (port=45573 helo=mail-wm1-x336.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSIA4-0005Ia-Fx; Thu, 10 Mar 2022 07:44:57 -0500 Received: by mail-wm1-x336.google.com with SMTP id k29-20020a05600c1c9d00b003817fdc0f00so3287689wms.4; Thu, 10 Mar 2022 04:44:55 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r2jDEb+fQm79ZJXGhBcmAyaMICDBYPXvzMm0Xp2UO7o=; b=M2Qvm+uRj6PfwreH80nS5UJEnUF+iYaW2MLQLFT1rAXuV1/cActPRc+RhW4S2mn3CN 3DdTIeUPwzgXky0xT4FA455/bfvLhcCg/Aruw/a6zY0W7ksSwcQZfKthMJzAkA2kLg2S xIytQMKOkjJ7ag6T99mTgSjD/IlCtHxR8zJB6/Bi4OtzWXWVDFdMxj85xp6vSO77FHD/ w+OMzHqW2iowUEqhqT0oQ69Ddcw0I1NxjKb6MqlmCeLI7dgDihkZv7EUDJrTgoIGVapb 8A3xWhMNkSFNTEFYYv/WrmHJ4wqDB/LBJ+JeYmxXqKLEgSy2CmvcnQ5CoMbaTpo37ocz 4tZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=r2jDEb+fQm79ZJXGhBcmAyaMICDBYPXvzMm0Xp2UO7o=; b=ArVnIAg97OgX580lCP6Cew1IDCWCBrBzbpwi5fxURXQflh+X8tP8YQRM2KBo3rNfNh boZGXRa2OYmanw1vrcltxNadErom/XpVtynO08rgNFUM0hg2m+nH3SV+5CsUzHM4zHbs 1wgH3z3TgNQnNHtXl2fQ5lorDFn+k7WcyLS4zOaH4h6pq6tr63E46KlAXG2JBtN/UEES 16JUQpNjjtBRw7/Pb/2FHUd6V2H2joOuwviFCklKxs2bQGVP2+2oynUQuxklWyZLHNGI 2zZPK/iK6o4otsp9ML6G83N4bqtawr38677Y0Pkm9irY7eqC/qJ1dtNerFLwGTAkzTJH Fxeg== X-Gm-Message-State: AOAM532yyc888PBF8kWm1i9zKPch9f5StmmY21PC1aLixa0TG+ZCrFsV DOS49+feDGVge8m7S5IE0yRg5Xtwa4Q= X-Google-Smtp-Source: ABdhPJz/iqZ3ZxorO7rL/4gV8TpN86OYwwRP2TFUVyHkAxT9Yq+PzeTYSKkYnRRNPDnDJnE2X9t86g== X-Received: by 2002:a05:600c:3b21:b0:389:9738:be0f with SMTP id m33-20020a05600c3b2100b003899738be0fmr3348946wms.9.1646916294875; Thu, 10 Mar 2022 04:44:54 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 32/35] qemu_co_rwlock_wrlock Date: Thu, 10 Mar 2022 13:44:10 +0100 Message-Id: <20220310124413.1102441-33-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::336 (failed) 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=2a00:1450:4864:20::336; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646917792781100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- util/qemu-coroutine-lock.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index 5a7b99cfaf..c0541171d4 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -512,27 +512,47 @@ CoroutineAction qemu_co_rwlock_downgrade(CoRwlock *lo= ck) return CO_INIT_FRAME(qemu_co_rwlock_downgrade, lock); } =20 -#if 0 -void qemu_co_rwlock_wrlock(CoRwlock *lock) +CO_DECLARE_FRAME(qemu_co_rwlock_wrlock, CoRwlock *lock, Coroutine *self, C= oRwTicket my_ticket); +static CoroutineAction co__qemu_co_rwlock_wrlock(void *_frame) { + struct FRAME__qemu_co_rwlock_wrlock *_f =3D _frame; + CO_ARG(lock); Coroutine *self =3D qemu_coroutine_self(); =20 - qemu_co_mutex_lock(&lock->mutex); +switch(_f->_step) { +case 0: +_f->_step =3D 1; +CO_SAVE(self); + return qemu_co_mutex_lock(&lock->mutex); +case 1: +CO_LOAD(self); if (lock->owners =3D=3D 0) { lock->owners =3D -1; qemu_co_mutex_unlock(&lock->mutex); } else { - CoRwTicket my_ticket =3D { false, self }; + _f->my_ticket =3D (CoRwTicket){ false, self }; =20 - QSIMPLEQ_INSERT_TAIL(&lock->tickets, &my_ticket, next); + QSIMPLEQ_INSERT_TAIL(&lock->tickets, &_f->my_ticket, next); qemu_co_mutex_unlock(&lock->mutex); - qemu_coroutine_yield(); +_f->_step =3D 2; + return qemu_coroutine_yield(); +case 2: +CO_LOAD(self); assert(lock->owners =3D=3D -1); } - - self->locks_held++; + break; } =20 + self->locks_held++; +return stack_free(&_f->common); +} + +CoroutineAction qemu_co_rwlock_wrlock(CoRwlock *lock) +{ + return CO_INIT_FRAME(qemu_co_rwlock_wrlock, lock); +} + +#if 0 void qemu_co_rwlock_upgrade(CoRwlock *lock) { qemu_co_mutex_lock(&lock->mutex); --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646917929441838.1329670436003; Thu, 10 Mar 2022 05:12:09 -0800 (PST) Received: from localhost ([::1]:54618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIaO-000238-DV for importer@patchew.org; Thu, 10 Mar 2022 08:12:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSIA7-0007GU-Ap; Thu, 10 Mar 2022 07:45:00 -0500 Received: from [2a00:1450:4864:20::336] (port=41531 helo=mail-wm1-x336.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSIA5-0005Ig-GE; Thu, 10 Mar 2022 07:44:58 -0500 Received: by mail-wm1-x336.google.com with SMTP id 7-20020a05600c228700b00385fd860f49so3335618wmf.0; Thu, 10 Mar 2022 04:44:56 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VFGOgVAYDA+OTcd7yIQGvRjXavxhLP1/OZGLRQXwCrY=; b=hRYLTyv2P2Wnkn5i2teUGTeALemhG3UoMKIkntyfGN6OreJ/EWQga1T3GV8J57ajDo j4uSy77U7/RMIKmiYSvIAldw07GmM8gWMjlzebsKKW8qlUMDuQIBofbOfOpmgM+3RQOm TLOmw8a4XEhw60SEqkMMJS3ittRBUH8n0c61NacPUiospUq5pdTjeeeCtyGO89+nWouu eSQHBTU5E6YoLpNC5l64+ohdoMOhHh7jDx1pzzDMfxT+vT0TSy6QNbAnayZojUDokep7 m+/FGRzJ4A+VYBMSiJIbisJRlrp8GKsfXJ8cjnto4U1eqvJpqxSBD5XUKQLcGv8+wIm4 EeLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=VFGOgVAYDA+OTcd7yIQGvRjXavxhLP1/OZGLRQXwCrY=; b=gxcXpkUhoKg5HoeZUQ56kMaryR7qxQ8wWp7EImb+TnNvEuz7O+NVUIaKgcFq2q+2cW QcaYT+hpP5m8ZErBvnP8IaUMK4Owq+hKwIY5UcuIeLR3ru0wM9lRPIdjsocQaRfrDFvo yK9LZ+wXnqqLONVcSMprMSPp4OefJAIQVhtkBgpvKbGdtbwlcd2UoAUkYVANn8S/bmjW oR8Vu05aMBQYvWxH7IyePP6UkS8zUjfNjHnDlg+hRC5V6EH4EnYQLmFKS6Vlcx9hRHU9 aQIUgDNF9S/lg6NZX3vGZuD7+Uc4MKIRR0afcm665hJVCUYZPnKo0tqEclJHQKWDU7FQ 2t0A== X-Gm-Message-State: AOAM530WHiQJqPkOjWgFPUTCKFLm1nuZRidjydiYt8vnjUfA6whxvbnC xuAN4mmJE9aGROaDjqvhV+9sUqojvew= X-Google-Smtp-Source: ABdhPJyhV5aZupEog4llgI2EQTUlXV2qOb1YgKmV+wjrdStL3MyHUoZynxO8jJsb7PoyyN43hZW+vA== X-Received: by 2002:a05:600c:26c8:b0:389:a542:c20b with SMTP id 8-20020a05600c26c800b00389a542c20bmr11462325wmv.46.1646916295754; Thu, 10 Mar 2022 04:44:55 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 33/35] qemu_co_rwlock_upgrade Date: Thu, 10 Mar 2022 13:44:11 +0100 Message-Id: <20220310124413.1102441-34-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::336 (failed) 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=2a00:1450:4864:20::336; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646917931367100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- util/qemu-coroutine-lock.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/util/qemu-coroutine-lock.c b/util/qemu-coroutine-lock.c index c0541171d4..9674e8e3e3 100644 --- a/util/qemu-coroutine-lock.c +++ b/util/qemu-coroutine-lock.c @@ -552,23 +552,39 @@ CoroutineAction qemu_co_rwlock_wrlock(CoRwlock *lock) return CO_INIT_FRAME(qemu_co_rwlock_wrlock, lock); } =20 -#if 0 -void qemu_co_rwlock_upgrade(CoRwlock *lock) +CO_DECLARE_FRAME(qemu_co_rwlock_upgrade, CoRwlock *lock, CoRwTicket my_tic= ket); +static CoroutineAction co__qemu_co_rwlock_upgrade(void *_frame) { - qemu_co_mutex_lock(&lock->mutex); + struct FRAME__qemu_co_rwlock_upgrade *_f =3D _frame; + CO_ARG(lock); + +switch(_f->_step) { +case 0: +_f->_step =3D 1; + return qemu_co_mutex_lock(&lock->mutex); +case 1: assert(lock->owners > 0); /* For fairness, wait if a writer is in line. */ if (lock->owners =3D=3D 1 && QSIMPLEQ_EMPTY(&lock->tickets)) { lock->owners =3D -1; qemu_co_mutex_unlock(&lock->mutex); } else { - CoRwTicket my_ticket =3D { false, qemu_coroutine_self() }; + _f->my_ticket =3D (CoRwTicket){ false, qemu_coroutine_self() }; =20 lock->owners--; - QSIMPLEQ_INSERT_TAIL(&lock->tickets, &my_ticket, next); + QSIMPLEQ_INSERT_TAIL(&lock->tickets, &_f->my_ticket, next); qemu_co_rwlock_maybe_wake_one(lock); - qemu_coroutine_yield(); +_f->_step =3D 2; + return qemu_coroutine_yield(); +case 2: assert(lock->owners =3D=3D -1); } + break; +} +return stack_free(&_f->common); +} + +CoroutineAction qemu_co_rwlock_upgrade(CoRwlock *lock) +{ + return CO_INIT_FRAME(qemu_co_rwlock_upgrade, lock); } -#endif --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646918070499425.6459353103344; Thu, 10 Mar 2022 05:14:30 -0800 (PST) Received: from localhost ([::1]:58578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIcf-0005Mm-F4 for importer@patchew.org; Thu, 10 Mar 2022 08:14:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSIA9-0007KA-KT; Thu, 10 Mar 2022 07:45:02 -0500 Received: from [2a00:1450:4864:20::32b] (port=46718 helo=mail-wm1-x32b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSIA7-0005JM-MA; Thu, 10 Mar 2022 07:45:01 -0500 Received: by mail-wm1-x32b.google.com with SMTP id p184-20020a1c29c1000000b0037f76d8b484so3295093wmp.5; Thu, 10 Mar 2022 04:44:58 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LwEBVC9gS4h6aKzCcykqoukS49LhIwPfJ5VWQl2biiU=; b=OshQE2fkLrrlyRIqFmhlGuIQen6+SoW9kOF3dFsIt0SrwtcP+bKTMuhKjebVQUoWGq YKWIXE5oD9iOYHVyJgN3/3yS1R5ZjdTRWbQRh47mGl3GCWmpMlNwL27MsJ83+HnKZaoq +cpm/W87hm5NpiWgBX0JdE1CRDIiSRM7VZW1ypb1eGGzzajT6xeTet5QQmSu7ZBc6TYZ 1Dvyl9JjMMCoaWXxdr7rG10ohmf34felfl+l6aKGmagttTAC1bj9kgAt2clUTxlefq+f 94x/0NrMlnrnHNmsbi21WggwWXw0Ga5T1l6WgiPKabcnmlO1iMYsy8Biezk9/j9KKMYZ qKaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=LwEBVC9gS4h6aKzCcykqoukS49LhIwPfJ5VWQl2biiU=; b=iHzYQwNkHAMnFqi9oUdGtiMlc1kZkt67+9ZKhYnTn1Ni+D9TeH3Z6C8mMNvS1vW25g M+eGLTjkZQhcCqOxLXeI8TGZkdVhxhmiqO0DM1ePe28EVP6+Pjb7I7OEq4znMS5iZvuJ /lV6+DaCiNFXKMm64nazSVADf9p4fC02SB0NgogC0aDQzwV/G3g0zFmiErHuHSuip/7W vbZPydOcC4QqVB5yE7U5IWNfaEVY0c0RJ3+wv4VXzipzwIcjxGIivCsit8d6+koIOyw4 ChBHeglg0714Fr1ShLT3meNL41rPjNn+y5vxEeH1kdzH6VjV9J7EfnRWyo+fAbN0C3OU /HZA== X-Gm-Message-State: AOAM530JXbkEZHmg1c7o5nencgVhAajG3IVnbQVOjkDNIP0BDiw7KAQL h0KBFkXfOC8fooveE/RL0FEB6yEAemA= X-Google-Smtp-Source: ABdhPJyzhl8I1pnuoZW8+fuTcsgpt1pXXF7Me+S6QtJhH+EEIxHR9b5mEnH00vHraDVAcTKyKm7l9w== X-Received: by 2002:a05:600c:1c02:b0:389:cf43:da63 with SMTP id j2-20020a05600c1c0200b00389cf43da63mr7188652wms.205.1646916298027; Thu, 10 Mar 2022 04:44:58 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 34/35] /locking/co-rwlock/upgrade Date: Thu, 10 Mar 2022 13:44:12 +0100 Message-Id: <20220310124413.1102441-35-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32b (failed) 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=2a00:1450:4864:20::32b; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x32b.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646918073527100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 68 ++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index db6718db40..39d0f31492 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -355,7 +355,6 @@ static void test_co_mutex_lockable(void) g_assert(QEMU_MAKE_CO_LOCKABLE(null_pointer) =3D=3D NULL); } =20 -#if 0 static CoRwlock rwlock; =20 /* Test that readers are properly sent back to the queue when upgrading, @@ -375,24 +374,66 @@ static CoRwlock rwlock; * | unlock | | */ =20 -static void coroutine_fn rwlock_yield_upgrade(void *opaque) +CO_DECLARE_FRAME(rwlock_yield_upgrade, bool *done); +static CoroutineAction co__rwlock_yield_upgrade(void *_frame) { - qemu_co_rwlock_rdlock(&rwlock); - qemu_coroutine_yield(); + struct FRAME__rwlock_yield_upgrade *_f =3D _frame; + CO_ARG(done); +switch(_f->_step) { +case 0: +_f->_step =3D 1; + return qemu_co_rwlock_rdlock(&rwlock); +case 1: +_f->_step =3D 2; + return qemu_coroutine_yield(); =20 - qemu_co_rwlock_upgrade(&rwlock); - qemu_co_rwlock_unlock(&rwlock); +case 2: +_f->_step =3D 3; + return qemu_co_rwlock_upgrade(&rwlock); +case 3: +_f->_step =3D 4; + return qemu_co_rwlock_unlock(&rwlock); =20 - *(bool *)opaque =3D true; +case 4: + *done =3D true; + break; +} +return stack_free(&_f->common); } =20 -static void coroutine_fn rwlock_wrlock_yield(void *opaque) +static CoroutineAction rwlock_yield_upgrade(void *opaque) { - qemu_co_rwlock_wrlock(&rwlock); - qemu_coroutine_yield(); + bool *done =3D opaque; + return CO_INIT_FRAME(rwlock_yield_upgrade, done); +} =20 - qemu_co_rwlock_unlock(&rwlock); - *(bool *)opaque =3D true; +CO_DECLARE_FRAME(rwlock_wrlock_yield, bool *done); +static CoroutineAction co__rwlock_wrlock_yield(void *_frame) +{ + struct FRAME__rwlock_wrlock_yield *_f =3D _frame; + CO_ARG(done); +switch(_f->_step) { +case 0: +_f->_step =3D 1; + return qemu_co_rwlock_wrlock(&rwlock); +case 1: +_f->_step =3D 2; + return qemu_coroutine_yield(); + +case 2: +_f->_step =3D 3; + return qemu_co_rwlock_unlock(&rwlock); +case 3: + *done =3D true; + break; +} +return stack_free(&_f->common); +} + +static CoroutineAction rwlock_wrlock_yield(void *opaque) +{ + bool *done =3D opaque; + return CO_INIT_FRAME(rwlock_wrlock_yield, done); } =20 static void test_co_rwlock_upgrade(void) @@ -417,6 +458,7 @@ static void test_co_rwlock_upgrade(void) g_assert(c2_done); } =20 +#if 0 static void coroutine_fn rwlock_rdlock_yield(void *opaque) { qemu_co_rwlock_rdlock(&rwlock); @@ -829,8 +871,8 @@ int main(int argc, char **argv) g_test_add_func("/basic/order", test_order); g_test_add_func("/locking/co-mutex", test_co_mutex); g_test_add_func("/locking/co-mutex/lockable", test_co_mutex_lockable); -#if 0 g_test_add_func("/locking/co-rwlock/upgrade", test_co_rwlock_upgrade); +#if 0 g_test_add_func("/locking/co-rwlock/downgrade", test_co_rwlock_downgra= de); #endif if (g_test_perf()) { --=20 2.35.1 From nobody Mon Feb 9 10:53:39 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1646918841579281.80108230758367; Thu, 10 Mar 2022 05:27:21 -0800 (PST) Received: from localhost ([::1]:49088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nSIp7-0002m9-JR for importer@patchew.org; Thu, 10 Mar 2022 08:27:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nSIAB-0007Ls-7k; Thu, 10 Mar 2022 07:45:03 -0500 Received: from [2a00:1450:4864:20::329] (port=40815 helo=mail-wm1-x329.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nSIA8-0005JX-KH; Thu, 10 Mar 2022 07:45:02 -0500 Received: by mail-wm1-x329.google.com with SMTP id i9-20020a1c3b09000000b00389d0a5c511so979572wma.5; Thu, 10 Mar 2022 04:44:59 -0800 (PST) Received: from avogadro.lan ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id r188-20020a1c2bc5000000b00387c81c32e7sm8063026wmr.8.2022.03.10.04.44.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Mar 2022 04:44:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AtYdT8RKivvEG07Jq6tvA5wlDPXFZUyMGRT+nhiso34=; b=gzcNsYE+RBd5MyAIS5jS/+y4OySY7mNgQkm+9y/7w0wLCGo94BwquhgOkBStTvjQdL UN/zEQaYA67DX5JwOoRxsrmYOftmOluhOQyxLNdtklHMdtGKpvAYSKd3WRQl7dO5yjtD hzYpo+uWzgJABn2/RpAUSYdx0tyi2ugXeCLF6OLQtagh6vwZkxcR3N7Gg6ZUecBlGcqw smDj23b9iagt6GE/jyjqG1wVdOWkSFMmFjAV54+j3qNlJdtUX0uzJ9x7qYglXko9y039 8KlYB/8tdFMQ2LWsQixxNm69PSpkaIKBzJRGZyJJWYVl/jt56jTmMZimobv44RnlQEwh veAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=AtYdT8RKivvEG07Jq6tvA5wlDPXFZUyMGRT+nhiso34=; b=wG7tGZT4bhNjEjLb91+WWZvSTGYrwIve4jICw/pwk0SVEj7gcjn1cjjI+np8M7W1lw kjBMFipltstL0nHTljFvu9qcxwWMf9YEgzsyGOE8ndYr6iw1oSFqxN2YfAP2lH1oElJC PIc/Gaz0jGHjUMDJFb4eDsj/6mJ8u4cQMLsE8tIS9rN1tamL8xi+Yf7mYx+mcHwE/4gq LbAbN4L8+5pa1YpBGM76CyGq9qpLlITc1j4QCkjws8FCmm4vOVUZ5wvzSP7t1GjqIihT Ebqru+NBF84j+IOliXZ1klwpO2kDTt0V9ejEyrsmkmVa8HPsgmwlnYlRVAsZksJGGP4b u82Q== X-Gm-Message-State: AOAM533DtxPIylDjIsUqwHNBq8BUO2yCHe1sfc87CYCQ2yqSDAi/cJ7m KD2iQPsV+0KUlTVIj7E2CjcHmTHbFUs= X-Google-Smtp-Source: ABdhPJxAIHfpt27WvFbaq2ppZ5FNusxMYCQ4BLM3x/Zr2q/z+ciZkwpnkG7yXmgU5+nuxSwUMj112Q== X-Received: by 2002:a7b:c5d5:0:b0:37b:fda9:a5e2 with SMTP id n21-20020a7bc5d5000000b0037bfda9a5e2mr3401470wmk.62.1646916298914; Thu, 10 Mar 2022 04:44:58 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 35/35] /locking/co-rwlock/downgrade Date: Thu, 10 Mar 2022 13:44:13 +0100 Message-Id: <20220310124413.1102441-36-pbonzini@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310124413.1102441-1-pbonzini@redhat.com> References: <20220310124413.1102441-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::329 (failed) 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=2a00:1450:4864:20::329; envelope-from=paolo.bonzini@gmail.com; helo=mail-wm1-x329.google.com X-Spam_score_int: 0 X-Spam_score: -0.1 X-Spam_bar: / X-Spam_report: (-0.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: hreitz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org, sguelton@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1646918860871100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- tests/unit/test-coroutine.c | 123 ++++++++++++++++++++++++++++-------- 1 file changed, 98 insertions(+), 25 deletions(-) diff --git a/tests/unit/test-coroutine.c b/tests/unit/test-coroutine.c index 39d0f31492..174ea8d579 100644 --- a/tests/unit/test-coroutine.c +++ b/tests/unit/test-coroutine.c @@ -458,41 +458,117 @@ static void test_co_rwlock_upgrade(void) g_assert(c2_done); } =20 -#if 0 -static void coroutine_fn rwlock_rdlock_yield(void *opaque) +CO_DECLARE_FRAME(rwlock_rdlock_yield, bool *done); +static CoroutineAction co__rwlock_rdlock_yield(void *_frame) { - qemu_co_rwlock_rdlock(&rwlock); - qemu_coroutine_yield(); + struct FRAME__rwlock_rdlock_yield *_f =3D _frame; + CO_ARG(done); +switch(_f->_step) { +case 0: +_f->_step =3D 1; + return qemu_co_rwlock_rdlock(&rwlock); +case 1: +_f->_step =3D 2; + return qemu_coroutine_yield(); =20 - qemu_co_rwlock_unlock(&rwlock); - qemu_coroutine_yield(); - - *(bool *)opaque =3D true; +case 2: +_f->_step =3D 3; + return qemu_co_rwlock_unlock(&rwlock); +case 3: +_f->_step =3D 4; + return qemu_coroutine_yield(); +case 4: + *done =3D true; + break; +} +return stack_free(&_f->common); } =20 -static void coroutine_fn rwlock_wrlock_downgrade(void *opaque) +static CoroutineAction rwlock_rdlock_yield(void *opaque) { - qemu_co_rwlock_wrlock(&rwlock); - - qemu_co_rwlock_downgrade(&rwlock); - qemu_co_rwlock_unlock(&rwlock); - *(bool *)opaque =3D true; + bool *done =3D opaque; + return CO_INIT_FRAME(rwlock_rdlock_yield, done); } =20 -static void coroutine_fn rwlock_rdlock(void *opaque) +CO_DECLARE_FRAME(rwlock_wrlock_downgrade, bool *done); +static CoroutineAction co__rwlock_wrlock_downgrade(void *_frame) { - qemu_co_rwlock_rdlock(&rwlock); + struct FRAME__rwlock_wrlock_downgrade *_f =3D _frame; + CO_ARG(done); +switch(_f->_step) { +case 0: +_f->_step =3D 1; + return qemu_co_rwlock_wrlock(&rwlock); =20 - qemu_co_rwlock_unlock(&rwlock); - *(bool *)opaque =3D true; +case 1: +_f->_step =3D 2; + return qemu_co_rwlock_downgrade(&rwlock); +case 2: +_f->_step =3D 3; + return qemu_co_rwlock_unlock(&rwlock); +case 3: + *done =3D true; + break; +} +return stack_free(&_f->common); } =20 -static void coroutine_fn rwlock_wrlock(void *opaque) +static CoroutineAction rwlock_wrlock_downgrade(void *opaque) { - qemu_co_rwlock_wrlock(&rwlock); + bool *done =3D opaque; + return CO_INIT_FRAME(rwlock_wrlock_downgrade, done); +} =20 - qemu_co_rwlock_unlock(&rwlock); - *(bool *)opaque =3D true; +CO_DECLARE_FRAME(rwlock_rdlock, bool *done); +static CoroutineAction co__rwlock_rdlock(void *_frame) +{ + struct FRAME__rwlock_rdlock *_f =3D _frame; + CO_ARG(done); +switch(_f->_step) { +case 0: +_f->_step =3D 1; + return qemu_co_rwlock_rdlock(&rwlock); + +case 1: +_f->_step =3D 2; + return qemu_co_rwlock_unlock(&rwlock); +case 2: + *done =3D true; + break; +} +return stack_free(&_f->common); +} + +static CoroutineAction rwlock_rdlock(void *opaque) +{ + bool *done =3D opaque; + return CO_INIT_FRAME(rwlock_rdlock, done); +} + +CO_DECLARE_FRAME(rwlock_wrlock, bool *done); +static CoroutineAction co__rwlock_wrlock(void *_frame) +{ + struct FRAME__rwlock_wrlock *_f =3D _frame; + CO_ARG(done); +switch(_f->_step) { +case 0: +_f->_step =3D 1; + return qemu_co_rwlock_wrlock(&rwlock); + +case 1: +_f->_step =3D 2; + return qemu_co_rwlock_unlock(&rwlock); +case 2: + *done =3D true; + break; +} +return stack_free(&_f->common); +} + +static CoroutineAction rwlock_wrlock(void *opaque) +{ + bool *done =3D opaque; + return CO_INIT_FRAME(rwlock_wrlock, done); } =20 /* @@ -556,7 +632,6 @@ static void test_co_rwlock_downgrade(void) =20 g_assert(c1_done); } -#endif =20 /* * Check that creation, enter, and return work @@ -872,9 +947,7 @@ int main(int argc, char **argv) g_test_add_func("/locking/co-mutex", test_co_mutex); g_test_add_func("/locking/co-mutex/lockable", test_co_mutex_lockable); g_test_add_func("/locking/co-rwlock/upgrade", test_co_rwlock_upgrade); -#if 0 g_test_add_func("/locking/co-rwlock/downgrade", test_co_rwlock_downgra= de); -#endif if (g_test_perf()) { g_test_add_func("/perf/lifecycle", perf_lifecycle); g_test_add_func("/perf/lifecycle/noalloc", perf_lifecycle_noalloc); --=20 2.35.1