From nobody Sun May 19 02:26:35 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1621861483; cv=none; d=zohomail.com; s=zohoarc; b=gjM5SkotrGKaZE0j/imsUBhKKQct6WZbNTqwU/RFkpwZGz/NdY39AoxN36itVJBDayOhFyN+7BYHmSJaqw583lVbyI5FGMIrlJJYLb7NVd9Kg/AbvH13LgH0ZxMxnsp1pfwfCSx3mzKJuzZ90y6vqIHdB5oG+XFf+TsWSSM2T2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621861483; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r4lIr8BTDrF1dGkThDE8cvCezt7DIcFxQLMJnW043xk=; b=QjHSTy4c5qNSHOWjRG4JeXPetlRke607bz8SOQ163AWgDvvJ1UyR+FxcqSahxtQvGMo51n10UNERW/A+K4XYxZ50GXd5tJHfB7zf1lH2HUiaspjjqWkeZWhuw78ySlzRH4ud72e8fNDSbecwv8CBrEPrI5KkvSWXiC4RgmqaUCU= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621861483280898.3675894171174; Mon, 24 May 2021 06:04:43 -0700 (PDT) Received: from localhost ([::1]:36024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llAG9-0005fm-MW for importer@patchew.org; Mon, 24 May 2021 09:04:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llADr-0002MR-QT for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60730) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llADk-0007fH-FU for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-151-9nUsbqipPIeLEGW3yOUymQ-1; Mon, 24 May 2021 09:02:07 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4B72100945E; Mon, 24 May 2021 13:02:05 +0000 (UTC) Received: from localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67AFF5D9F0; Mon, 24 May 2021 13:02:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621861330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r4lIr8BTDrF1dGkThDE8cvCezt7DIcFxQLMJnW043xk=; b=hvUliNEYxQYU+ZiCAcJELbIucf/05QYdaammuY9VSrt+EducASogy6GvdDWvMlrLoKzpa0 2TWU/NYLeHLueaIPz9kPJi+wlwvbvaYm9yvYTNH2oDvC2NtZJzL10u+yENGjh+dBXJT3wy evcWl24QHRtvJwboLiJlhMJnV/evzVU= X-MC-Unique: 9nUsbqipPIeLEGW3yOUymQ-1 From: Stefan Hajnoczi To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 1/8] multi-process: Initialize variables declared with g_auto* Date: Mon, 24 May 2021 14:01:43 +0100 Message-Id: <20210524130150.50998-2-stefanha@redhat.com> In-Reply-To: <20210524130150.50998-1-stefanha@redhat.com> References: <20210524130150.50998-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.371, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Elena Ufimtseva , Vladimir Sementsov-Ogievskiy , Jagannathan Raman , qemu-block@nongnu.org, John G Johnson , John Snow , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Stefan Hajnoczi , Zenghui Yu , Miroslav Rezanina Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Zenghui Yu Quote docs/devel/style.rst (section "Automatic memory deallocation"): * Variables declared with g_auto* MUST always be initialized, otherwise the cleanup function will use uninitialized stack memory Initialize @name properly to get rid of the compilation error (using gcc-7.3.0 on CentOS): ../hw/remote/proxy.c: In function 'pci_proxy_dev_realize': /usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: 'name' may be u= sed uninitialized in this function [-Werror=3Dmaybe-uninitialized] g_free (*pp); ^~~~~~~~~~~~ ../hw/remote/proxy.c:350:30: note: 'name' was declared here g_autofree char *name; ^~~~ Signed-off-by: Zenghui Yu Reviewed-by: Jagannathan Raman Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Miroslav Rezanina Message-id: 20210312112143.1369-1-yuzenghui@huawei.com Signed-off-by: Stefan Hajnoczi --- hw/remote/memory.c | 5 ++--- hw/remote/proxy.c | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/hw/remote/memory.c b/hw/remote/memory.c index 2d4174614a..472ed2a272 100644 --- a/hw/remote/memory.c +++ b/hw/remote/memory.c @@ -41,10 +41,9 @@ void remote_sysmem_reconfig(MPQemuMsg *msg, Error **errp) =20 remote_sysmem_reset(); =20 - for (region =3D 0; region < msg->num_fds; region++) { - g_autofree char *name; + for (region =3D 0; region < msg->num_fds; region++, suffix++) { + g_autofree char *name =3D g_strdup_printf("remote-mem-%u", suffix); subregion =3D g_new(MemoryRegion, 1); - name =3D g_strdup_printf("remote-mem-%u", suffix++); memory_region_init_ram_from_fd(subregion, NULL, name, sysmem_info->sizes[region], true, msg->fds[region], diff --git a/hw/remote/proxy.c b/hw/remote/proxy.c index 4fa4be079d..6dda705fc2 100644 --- a/hw/remote/proxy.c +++ b/hw/remote/proxy.c @@ -347,13 +347,12 @@ static void probe_pci_info(PCIDevice *dev, Error **er= rp) PCI_BASE_ADDRESS_SPACE_IO : PCI_BASE_ADDRESS_SPACE_MEMO= RY; =20 if (size) { - g_autofree char *name; + g_autofree char *name =3D g_strdup_printf("bar-region-%d", i); pdev->region[i].dev =3D pdev; pdev->region[i].present =3D true; if (type =3D=3D PCI_BASE_ADDRESS_SPACE_MEMORY) { pdev->region[i].memory =3D true; } - name =3D g_strdup_printf("bar-region-%d", i); memory_region_init_io(&pdev->region[i].mr, OBJECT(pdev), &proxy_mr_ops, &pdev->region[i], name, size); --=20 2.31.1 From nobody Sun May 19 02:26:35 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1621861624; cv=none; d=zohomail.com; s=zohoarc; b=DWCEclddLQiUv0NIgMfGmsp/Ui/PHx+bv0jKAI4rQd8tEsNzcettk/1MEN3s36h3e1b6Jri/haF91XpmpaJh3mxyQb57bx9oGWDm2R0CRChnzQVqGEVZ3QFw6coRTk5Wm2IMwoVGReja9o+nnuTdABuYF0rd4kGw6iO2MQNNVSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621861624; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=euWbwCjrkNwNyW160mPypQMGgxxibCb1PhvP4119mfk=; b=QfqB/VyWNGE9adNhrKJNKOcTMR4jGSHDqLh/PPNY/ombbdEhYke3IgDvtddXVwL6Pp3/LsWUcvf18b7G1EIRogAN/RuPb+kIsBiBnQdiY9IXyZcaXIlObYvnHZWV7F7fBxPrqHiqEktdtQKVUJtHtW4Mju4niK9LUKDOGp+N2OM= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621861624843343.7750171776196; Mon, 24 May 2021 06:07:04 -0700 (PDT) Received: from localhost ([::1]:43904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llAIS-0002ey-56 for importer@patchew.org; Mon, 24 May 2021 09:07:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llADv-0002WC-BO for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47695) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llADr-0007gm-GW for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:23 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-476-EjjnrvcSPxSbOyWrcR_M1w-1; Mon, 24 May 2021 09:02:11 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 97891A40E7; Mon, 24 May 2021 13:02:10 +0000 (UTC) Received: from localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id C2DF35C230; Mon, 24 May 2021 13:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621861338; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=euWbwCjrkNwNyW160mPypQMGgxxibCb1PhvP4119mfk=; b=Y2m6ShEGEVH/Hs9MTg3HrQ/rFnxjRlYBFCmsOgv36sr+cd5Z1fUXCzVktijFzPHsNI2hHc 9WIedJUGEjEPzett08c9lL+0/F0FM2kjrBEOb/2y22LrdhLNo7CNVowcKDd9ctuoe9lVkV h6NAlJxxDIzuSet2CcvxYzEuo2pHfcs= X-MC-Unique: EjjnrvcSPxSbOyWrcR_M1w-1 From: Stefan Hajnoczi To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 2/8] bitops.h: Improve find_xxx_bit() documentation Date: Mon, 24 May 2021 14:01:44 +0100 Message-Id: <20210524130150.50998-3-stefanha@redhat.com> In-Reply-To: <20210524130150.50998-1-stefanha@redhat.com> References: <20210524130150.50998-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.371, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Elena Ufimtseva , Vladimir Sementsov-Ogievskiy , Jagannathan Raman , qemu-block@nongnu.org, John G Johnson , John Snow , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 Document the following functions return the bitmap size if no matching bit is found: - find_first_bit - find_next_bit - find_last_bit - find_first_zero_bit - find_next_zero_bit Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi Message-id: 20210510200758.2623154-2-philmd@redhat.com Signed-off-by: Stefan Hajnoczi --- include/qemu/bitops.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index 3acbf3384c..a72f69fea8 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -140,7 +140,8 @@ static inline int test_bit(long nr, const unsigned long= *addr) * @addr: The address to start the search at * @size: The maximum size to search * - * Returns the bit number of the first set bit, or size. + * Returns the bit number of the last set bit, + * or @size if there is no set bit in the bitmap. */ unsigned long find_last_bit(const unsigned long *addr, unsigned long size); @@ -150,6 +151,9 @@ unsigned long find_last_bit(const unsigned long *addr, * @addr: The address to base the search on * @offset: The bitnumber to start searching at * @size: The bitmap size in bits + * + * Returns the bit number of the next set bit, + * or @size if there are no further set bits in the bitmap. */ unsigned long find_next_bit(const unsigned long *addr, unsigned long size, @@ -160,6 +164,9 @@ unsigned long find_next_bit(const unsigned long *addr, * @addr: The address to base the search on * @offset: The bitnumber to start searching at * @size: The bitmap size in bits + * + * Returns the bit number of the next cleared bit, + * or @size if there are no further clear bits in the bitmap. */ =20 unsigned long find_next_zero_bit(const unsigned long *addr, @@ -171,7 +178,8 @@ unsigned long find_next_zero_bit(const unsigned long *a= ddr, * @addr: The address to start the search at * @size: The maximum size to search * - * Returns the bit number of the first set bit. + * Returns the bit number of the first set bit, + * or @size if there is no set bit in the bitmap. */ static inline unsigned long find_first_bit(const unsigned long *addr, unsigned long size) @@ -194,7 +202,8 @@ static inline unsigned long find_first_bit(const unsign= ed long *addr, * @addr: The address to start the search at * @size: The maximum size to search * - * Returns the bit number of the first cleared bit. + * Returns the bit number of the first cleared bit, + * or @size if there is no clear bit in the bitmap. */ static inline unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) --=20 2.31.1 From nobody Sun May 19 02:26:35 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1621861624; cv=none; d=zohomail.com; s=zohoarc; b=nhMbRB+6+SfZwlR6/cqs4eQNWWm5jeON96zEyPfzyqbLO60dXW1zujvTwANvsJLtPgKbyQP8JyElnEhrvz+GKIIx+bhtO1ILuFVJ37xroJvPHiJTRXDQtpSVHxxGbHGaMXoGReFvuIGruDNyQ4Q+bKLCqzvXMYGaU/yjrLNxnfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621861624; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wYPMPPOffy3HWUKMw+T9hJJylIZYAqFjgkC+UJGihBk=; b=QACbPr8glflkBUvxUJuNmtcgLDSK/nn/09R5up4CZpzX1oMKijbEPh1VfByuNs4FkGgoHHevfJcHz8CgQ4qoH5KgeIAcO8/1gm/CbOjGZISReXlKSHkq2vL14RORaR+gFG0mHAVd3gnZL2Nk4qG9KmwJVJvaMT9fhnOy1t4kZjE= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621861624325521.3001480164702; Mon, 24 May 2021 06:07:04 -0700 (PDT) Received: from localhost ([::1]:43922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llAIR-0002fs-LD for importer@patchew.org; Mon, 24 May 2021 09:07:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llADv-0002WB-3D for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26390) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llADp-0007fl-OE for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:22 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-289-GjR_c1IGOfmfNkMirNwrng-1; Mon, 24 May 2021 09:02:13 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 45190107AD2F; Mon, 24 May 2021 13:02:12 +0000 (UTC) Received: from localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBF4D5D9F0; Mon, 24 May 2021 13:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621861335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wYPMPPOffy3HWUKMw+T9hJJylIZYAqFjgkC+UJGihBk=; b=WlDb/mhyf7xEGDkx7l/e1mvkbMsQifZGl6AgtCFwPQvBMv9XZInmJCJAiFc0dvsWsBuyr0 vM8YERsmNV7HQI7nCRGqz4gPRkVEZkMSNiJYgOiBLkYlo1Osb6/FMoOumvd4jwMnu4F5GY FRTtU93ljkX6Jv5HzPXU+hBJV7cczEI= X-MC-Unique: GjR_c1IGOfmfNkMirNwrng-1 From: Stefan Hajnoczi To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 3/8] coroutine-sleep: use a stack-allocated timer Date: Mon, 24 May 2021 14:01:45 +0100 Message-Id: <20210524130150.50998-4-stefanha@redhat.com> In-Reply-To: <20210524130150.50998-1-stefanha@redhat.com> References: <20210524130150.50998-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.371, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Elena Ufimtseva , Vladimir Sementsov-Ogievskiy , Jagannathan Raman , qemu-block@nongnu.org, John G Johnson , John Snow , Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini The lifetime of the timer is well-known (it cannot outlive qemu_co_sleep_ns_wakeable, because it's deleted by the time the coroutine resumes), so it is not necessary to place it on the heap. Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Paolo Bonzini Message-id: 20210517100548.28806-2-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi --- util/qemu-coroutine-sleep.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index 8c4dac4fd7..eec6e81f3f 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -21,7 +21,7 @@ static const char *qemu_co_sleep_ns__scheduled =3D "qemu_= co_sleep_ns"; =20 struct QemuCoSleepState { Coroutine *co; - QEMUTimer *ts; + QEMUTimer ts; QemuCoSleepState **user_state_pointer; }; =20 @@ -35,7 +35,7 @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) if (sleep_state->user_state_pointer) { *sleep_state->user_state_pointer =3D NULL; } - timer_del(sleep_state->ts); + timer_del(&sleep_state->ts); aio_co_wake(sleep_state->co); } =20 @@ -50,7 +50,6 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType= type, int64_t ns, AioContext *ctx =3D qemu_get_current_aio_context(); QemuCoSleepState state =3D { .co =3D qemu_coroutine_self(), - .ts =3D aio_timer_new(ctx, type, SCALE_NS, co_sleep_cb, &state), .user_state_pointer =3D sleep_state, }; =20 @@ -63,10 +62,11 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockTy= pe type, int64_t ns, abort(); } =20 + aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); if (sleep_state) { *sleep_state =3D &state; } - timer_mod(state.ts, qemu_clock_get_ns(type) + ns); + timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); if (sleep_state) { /* @@ -75,5 +75,4 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType= type, int64_t ns, */ assert(*sleep_state =3D=3D NULL); } - timer_free(state.ts); } --=20 2.31.1 From nobody Sun May 19 02:26:35 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1621861508; cv=none; d=zohomail.com; s=zohoarc; b=BYU8H1uczLGp2KywL9lMAGh2QfoPJMMhOc8gtoklE90YrYFsHdiJ7coSpJutPh/pp0JPPtwvD1O+Qy/C4kDSwB1Hq1s5mbLPxWqsXbiyXNCtdfapD0viKiFZNZgm1mjXfqgRk6TQ2r6GA7vqqZgafqxpjHTfXreHi94vwyhnZ1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621861508; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wueI4YIUFKoP/IMc9SYoE+f7CgGDrWwlSxzrNW4O1Mo=; b=D1mZ8Me1IukPXN3y3yW4pIFmYsY+iGpNzcUzIzd+JRQgbrXMbsbpsuu0nyopK5Tq61eM/FSppQm2bd2xpGSFK0Pch6h5tWliB5yD1OusAcjrTNUbH6qGk54p63GdPVT4ohwzdY6eu6RG62guqcNKyV8CsY5gr78fV0h/A4m7RsU= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621861508578276.9597170587523; Mon, 24 May 2021 06:05:08 -0700 (PDT) Received: from localhost ([::1]:37364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llAGZ-0006ZZ-Ra for importer@patchew.org; Mon, 24 May 2021 09:05:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llADw-0002cP-Qa for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22674) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llADt-0007iT-Ay for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:24 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-515-uj8ma0Q6O2iHFQp_wCxPwA-1; Mon, 24 May 2021 09:02:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 231BC1966323; Mon, 24 May 2021 13:02:17 +0000 (UTC) Received: from localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63FAF5D71D; Mon, 24 May 2021 13:02:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621861340; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wueI4YIUFKoP/IMc9SYoE+f7CgGDrWwlSxzrNW4O1Mo=; b=HWQ2BrTOEMdJfLfK74vXz/fjZhBx5+waqTFPkSDwrVnpvXTaxLNz2U6O5ihXdy5LnH9xXk /WQfU0G7n6y1f+JViEPtjLCx+HnFdXloKbeMMpLAUmGxZR/wwtH3j2S5G+TsNM7rpGHPmr Xx5Ad+7evg0QQWWTRAJFhV2OKBjNczA= X-MC-Unique: uj8ma0Q6O2iHFQp_wCxPwA-1 From: Stefan Hajnoczi To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 4/8] coroutine-sleep: disallow NULL QemuCoSleepState** argument Date: Mon, 24 May 2021 14:01:46 +0100 Message-Id: <20210524130150.50998-5-stefanha@redhat.com> In-Reply-To: <20210524130150.50998-1-stefanha@redhat.com> References: <20210524130150.50998-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.371, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Elena Ufimtseva , Vladimir Sementsov-Ogievskiy , Jagannathan Raman , qemu-block@nongnu.org, John G Johnson , John Snow , Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Simplify the code by removing conditionals. qemu_co_sleep_ns can simply point the argument to an on-stack temporary. Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Paolo Bonzini Message-id: 20210517100548.28806-3-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi --- include/qemu/coroutine.h | 5 +++-- util/qemu-coroutine-sleep.c | 18 +++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index ce5b9c6851..c5d7742989 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -295,7 +295,7 @@ typedef struct QemuCoSleepState QemuCoSleepState; =20 /** * Yield the coroutine for a given duration. During this yield, @sleep_sta= te - * (if not NULL) is set to an opaque pointer, which may be used for + * is set to an opaque pointer, which may be used for * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when = the * timer fires. Don't save the obtained value to other variables and don't= call * qemu_co_sleep_wake from another aio context. @@ -304,7 +304,8 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockTy= pe type, int64_t ns, QemuCoSleepState **sleep_state= ); static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64= _t ns) { - qemu_co_sleep_ns_wakeable(type, ns, NULL); + QemuCoSleepState *unused =3D NULL; + qemu_co_sleep_ns_wakeable(type, ns, &unused); } =20 /** diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index eec6e81f3f..3f6f637e81 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -32,9 +32,7 @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) qemu_co_sleep_ns__scheduled, NU= LL); =20 assert(scheduled =3D=3D qemu_co_sleep_ns__scheduled); - if (sleep_state->user_state_pointer) { - *sleep_state->user_state_pointer =3D NULL; - } + *sleep_state->user_state_pointer =3D NULL; timer_del(&sleep_state->ts); aio_co_wake(sleep_state->co); } @@ -63,16 +61,10 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockTy= pe type, int64_t ns, } =20 aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); - if (sleep_state) { - *sleep_state =3D &state; - } + *sleep_state =3D &state; timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); - if (sleep_state) { - /* - * Note that *sleep_state is cleared during qemu_co_sleep_wake - * before resuming this coroutine. - */ - assert(*sleep_state =3D=3D NULL); - } + + /* qemu_co_sleep_wake clears *sleep_state before resuming this corouti= ne. */ + assert(*sleep_state =3D=3D NULL); } --=20 2.31.1 From nobody Sun May 19 02:26:35 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1621861806; cv=none; d=zohomail.com; s=zohoarc; b=M4MpEMmkhTFd1Zd5M0ifq+f8MGdRP91DnQJXnpJh5pWy+/VQ73bQk9wo0DkAvuHQyTuExD01S9f+myW+IdHxJrt0fsnLUCHIh1TCbRXOcGsJnsYcJLDDkZ7OWrRHTnWb3B0Q0nlVcVIPjHTf6nOZTrpakLsxup9gWoHZKWOjkt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621861806; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9E7UAyaR663w41AQQhkHnIEll+V9IkybDFnciUlz7GY=; b=E/oGYn5NN3v3n/X/jLXr27ouc+OyH4ptJojfm2PW/qSpDOtAVsJE4ZSD1gg47sYm0qDJ9IiGGdb6oiNxQXe2lJy4vj8ujwi2AdUp0q2pw6/DnYHDpOBCgQ31R37zF3uV5iSQRyvirs3d3NWfREIotDE3JCYudtSOFC2DrXbRG0Y= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621861806782937.6478763628315; Mon, 24 May 2021 06:10:06 -0700 (PDT) Received: from localhost ([::1]:50910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llALM-0007Yc-Ug for importer@patchew.org; Mon, 24 May 2021 09:10:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llAEA-0002zQ-Rq for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42333) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llAE7-0007qT-1y for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:38 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-397-c_usiDmRO-eJXPTdgHnnbg-1; Mon, 24 May 2021 09:02:30 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2BEC01012D93; Mon, 24 May 2021 13:02:29 +0000 (UTC) Received: from localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 639CE6E52F; Mon, 24 May 2021 13:02:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621861354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9E7UAyaR663w41AQQhkHnIEll+V9IkybDFnciUlz7GY=; b=e1WZY3eP+Ym71g/4f2wZUkq97hLcw8yFjGMateHAV63XLBgTCzXFj7x9R7cC576qC6/14A npATuBNMoxl1ovkAkqdaG89yCEdWk+5LQimQXjN4QwNr1n74AqNIBFyZO7+/unu1ilKzaX ikarMKSfoF/8icnIif2OPVqdsIbsnkE= X-MC-Unique: c_usiDmRO-eJXPTdgHnnbg-1 From: Stefan Hajnoczi To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 5/8] coroutine-sleep: allow qemu_co_sleep_wake that wakes nothing Date: Mon, 24 May 2021 14:01:47 +0100 Message-Id: <20210524130150.50998-6-stefanha@redhat.com> In-Reply-To: <20210524130150.50998-1-stefanha@redhat.com> References: <20210524130150.50998-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.371, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Elena Ufimtseva , Vladimir Sementsov-Ogievskiy , Jagannathan Raman , qemu-block@nongnu.org, John G Johnson , John Snow , Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini All callers of qemu_co_sleep_wake are checking whether they are passing a NULL argument inside the pointer-to-pointer: do the check in qemu_co_sleep_wake itself. As a side effect, qemu_co_sleep_wake can be called more than once and it will only wake the coroutine once; after the first time, the argument will be set to NULL via *sleep_state->user_state_pointer. However, this would not be safe unless co_sleep_cb keeps using the QemuCoSleepState* directly, so make it go through the pointer-to-pointer instead. Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Paolo Bonzini Message-id: 20210517100548.28806-4-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi --- block/block-copy.c | 4 +--- block/nbd.c | 8 ++------ util/qemu-coroutine-sleep.c | 21 ++++++++++++--------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index 9b4af00614..f896dc56f2 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -674,9 +674,7 @@ out: =20 void block_copy_kick(BlockCopyCallState *call_state) { - if (call_state->sleep_state) { - qemu_co_sleep_wake(call_state->sleep_state); - } + qemu_co_sleep_wake(call_state->sleep_state); } =20 /* diff --git a/block/nbd.c b/block/nbd.c index 1d4668d42d..1c6315b168 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -289,9 +289,7 @@ static void coroutine_fn nbd_client_co_drain_begin(Bloc= kDriverState *bs) BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; =20 s->drained =3D true; - if (s->connection_co_sleep_ns_state) { - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); - } + qemu_co_sleep_wake(s->connection_co_sleep_ns_state); =20 nbd_co_establish_connection_cancel(bs, false); =20 @@ -330,9 +328,7 @@ static void nbd_teardown_connection(BlockDriverState *b= s) =20 s->state =3D NBD_CLIENT_QUIT; if (s->connection_co) { - if (s->connection_co_sleep_ns_state) { - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); - } + qemu_co_sleep_wake(s->connection_co_sleep_ns_state); nbd_co_establish_connection_cancel(bs, true); } if (qemu_in_coroutine()) { diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index 3f6f637e81..3ae2b5399a 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -27,19 +27,22 @@ struct QemuCoSleepState { =20 void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) { - /* Write of schedule protected by barrier write in aio_co_schedule */ - const char *scheduled =3D qatomic_cmpxchg(&sleep_state->co->scheduled, - qemu_co_sleep_ns__scheduled, NU= LL); + if (sleep_state) { + /* Write of schedule protected by barrier write in aio_co_schedule= */ + const char *scheduled =3D qatomic_cmpxchg(&sleep_state->co->schedu= led, + qemu_co_sleep_ns__schedule= d, NULL); =20 - assert(scheduled =3D=3D qemu_co_sleep_ns__scheduled); - *sleep_state->user_state_pointer =3D NULL; - timer_del(&sleep_state->ts); - aio_co_wake(sleep_state->co); + assert(scheduled =3D=3D qemu_co_sleep_ns__scheduled); + *sleep_state->user_state_pointer =3D NULL; + timer_del(&sleep_state->ts); + aio_co_wake(sleep_state->co); + } } =20 static void co_sleep_cb(void *opaque) { - qemu_co_sleep_wake(opaque); + QemuCoSleepState **sleep_state =3D opaque; + qemu_co_sleep_wake(*sleep_state); } =20 void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, @@ -60,7 +63,7 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType= type, int64_t ns, abort(); } =20 - aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, &state); + aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_stat= e); *sleep_state =3D &state; timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); --=20 2.31.1 From nobody Sun May 19 02:26:35 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1621861874; cv=none; d=zohomail.com; s=zohoarc; b=mO/Bozx/0QIKyF4ORL4vlTcTKhYRW6atM1xhdIV78h8yN7+t3CGpKYa6mJvvzUUBQypvjVWhB7yLvevg/n8+vUGtXGUMr1ezqXKuypX0YO3jVXfL8zaD8eYbO3sKrikrbHmMPvcf+EM2vbEV80/Zph/uQ6hkBYhGCrkgXP+wMdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621861874; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LrKtf93KEwf7fhVYkXwikVjc1emb9I2sov9Y+NqXs+k=; b=nzyO7JrZzjar//wPjqLFUkr2x1H2M0S8wr6vnd8v8lM+/yXQABk1QZft8IhHRRFfFTGUE2u6gLNa98um3FaHhiPrxBYsIUVd0TYneeiSunjJzEjylnwWEt3z8hcrENho3hbRTkTJXJMDOjED8QbHJUFR8ywvZv+eLhumnA0XgXQ= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621861874956496.09169134967715; Mon, 24 May 2021 06:11:14 -0700 (PDT) Received: from localhost ([::1]:52994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llAMU-0000bK-7g for importer@patchew.org; Mon, 24 May 2021 09:11:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51606) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llAEK-00037e-FH for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23423) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llAEE-0007uK-D1 for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-601-YUsTXNMTM9Gu6DCLusM2Vw-1; Mon, 24 May 2021 09:02:35 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2538E801817; Mon, 24 May 2021 13:02:34 +0000 (UTC) Received: from localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61BD536DE; Mon, 24 May 2021 13:02:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621861360; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LrKtf93KEwf7fhVYkXwikVjc1emb9I2sov9Y+NqXs+k=; b=D9Avr/W4w73SnBg0oJRXlxB9+QUjRr1AYjzPB36A+bdbk6W9Cpjp51e0+l4CVM6DktAUfO ebS0Lp6rt+3yHu6Lgm6YrS5nF8vNFSR+WSTAtOFoaSn7i68V/O3Orxw5fw5C6jdDcfIFyA kS/sG9yQhe+RGYp9V7xjcVCKovv/zFY= X-MC-Unique: YUsTXNMTM9Gu6DCLusM2Vw-1 From: Stefan Hajnoczi To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 6/8] coroutine-sleep: move timer out of QemuCoSleepState Date: Mon, 24 May 2021 14:01:48 +0100 Message-Id: <20210524130150.50998-7-stefanha@redhat.com> In-Reply-To: <20210524130150.50998-1-stefanha@redhat.com> References: <20210524130150.50998-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.371, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Elena Ufimtseva , Vladimir Sementsov-Ogievskiy , Jagannathan Raman , qemu-block@nongnu.org, John G Johnson , John Snow , Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini This simplification is enabled by the previous patch. Now aio_co_wake will only be called once, therefore we do not care about a spurious firing of the timer after a qemu_co_sleep_wake. Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Paolo Bonzini Message-id: 20210517100548.28806-5-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi --- util/qemu-coroutine-sleep.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index 3ae2b5399a..1d25019620 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -21,7 +21,6 @@ static const char *qemu_co_sleep_ns__scheduled =3D "qemu_= co_sleep_ns"; =20 struct QemuCoSleepState { Coroutine *co; - QEMUTimer ts; QemuCoSleepState **user_state_pointer; }; =20 @@ -34,7 +33,6 @@ void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) =20 assert(scheduled =3D=3D qemu_co_sleep_ns__scheduled); *sleep_state->user_state_pointer =3D NULL; - timer_del(&sleep_state->ts); aio_co_wake(sleep_state->co); } } @@ -49,6 +47,7 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType= type, int64_t ns, QemuCoSleepState **sleep_state) { AioContext *ctx =3D qemu_get_current_aio_context(); + QEMUTimer ts; QemuCoSleepState state =3D { .co =3D qemu_coroutine_self(), .user_state_pointer =3D sleep_state, @@ -63,10 +62,11 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockTy= pe type, int64_t ns, abort(); } =20 - aio_timer_init(ctx, &state.ts, type, SCALE_NS, co_sleep_cb, sleep_stat= e); + aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state); *sleep_state =3D &state; - timer_mod(&state.ts, qemu_clock_get_ns(type) + ns); + timer_mod(&ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); + timer_del(&ts); =20 /* qemu_co_sleep_wake clears *sleep_state before resuming this corouti= ne. */ assert(*sleep_state =3D=3D NULL); --=20 2.31.1 From nobody Sun May 19 02:26:35 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1621861948; cv=none; d=zohomail.com; s=zohoarc; b=AgC+F9UJINJ7QJoNUUYkwcenP/N5pBvZxXjAKagd8x1ha9zZOz+2zT5DMaNsXaQkV44psD26i1FGefk0h0jjoVCFyEA5E6AVDVTfc7GVZYShHTZnOT/aV+e04uuNQdov9y/cTiiYCE6msltUtgLIRF4xsIObVPOwwLK1M/zOj5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621861948; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uO4+E8RP2Ua5+4hVx4LGaMf6mX/r5La2/K1i3KqW4Xg=; b=jEumQ70oYhUrpZ2twNL+dfXvxy0nY04QhsW2spTvhHC8t2C11G00oY/R70dmxmRZRfHr6wQVHP53E2pbW97zVY21uW3WWPe+C+RRNGRufnZe9T8cCS+9WTyzF7Wtw+/QTqf0qzknFgyIM/5TCfP8PNpHXVIz30bMWSuPf59WKRg= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621861948486273.17692809322716; Mon, 24 May 2021 06:12:28 -0700 (PDT) Received: from localhost ([::1]:55080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llANf-00027E-Fe for importer@patchew.org; Mon, 24 May 2021 09:12:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llAEL-0003Bj-FA for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24192) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llAEE-0007uM-D4 for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-312-VbpXtGcaN4WV9jkdQ6DdfQ-1; Mon, 24 May 2021 09:02:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C5D8107ACF2; Mon, 24 May 2021 13:02:35 +0000 (UTC) Received: from localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21BE06EF42; Mon, 24 May 2021 13:02:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621861360; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uO4+E8RP2Ua5+4hVx4LGaMf6mX/r5La2/K1i3KqW4Xg=; b=hFOzfixFHarKyVtUrv8veRpN8lYI9mJBN4KCpRWJAl4uT8q4H/xmeEFr8gCJpEivA7ZSMX yYagcUEOUMp0naGyDOxQnEMxiA7k5B12rVrT+HMseg+pdpPwyudY0XCVPzYQI0CD6DcQbw heU4ayvjBqHUgFCVdfB1391JPxYpSk0= X-MC-Unique: VbpXtGcaN4WV9jkdQ6DdfQ-1 From: Stefan Hajnoczi To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 7/8] coroutine-sleep: replace QemuCoSleepState pointer with struct in the API Date: Mon, 24 May 2021 14:01:49 +0100 Message-Id: <20210524130150.50998-8-stefanha@redhat.com> In-Reply-To: <20210524130150.50998-1-stefanha@redhat.com> References: <20210524130150.50998-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.371, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Elena Ufimtseva , Vladimir Sementsov-Ogievskiy , Jagannathan Raman , qemu-block@nongnu.org, John G Johnson , John Snow , Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Right now, users of qemu_co_sleep_ns_wakeable are simply passing a pointer to QemuCoSleepState by reference to the function. But QemuCoSleepState really is just a Coroutine*; making the content of the struct public is just as efficient and lets us skip the user_state_pointer indirection. Since the usage is changed, take the occasion to rename the struct to QemuCoSleep. Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Paolo Bonzini Message-id: 20210517100548.28806-6-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi --- include/qemu/coroutine.h | 23 +++++++++++---------- block/block-copy.c | 8 ++++---- block/nbd.c | 10 ++++----- util/qemu-coroutine-sleep.c | 41 ++++++++++++++++--------------------- 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index c5d7742989..82c0671f80 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -291,21 +291,22 @@ void qemu_co_rwlock_wrlock(CoRwlock *lock); */ void qemu_co_rwlock_unlock(CoRwlock *lock); =20 -typedef struct QemuCoSleepState QemuCoSleepState; +typedef struct QemuCoSleep { + Coroutine *to_wake; +} QemuCoSleep; =20 /** - * Yield the coroutine for a given duration. During this yield, @sleep_sta= te - * is set to an opaque pointer, which may be used for - * qemu_co_sleep_wake(). Be careful, the pointer is set back to zero when = the - * timer fires. Don't save the obtained value to other variables and don't= call - * qemu_co_sleep_wake from another aio context. + * Yield the coroutine for a given duration. Initializes @w so that, + * during this yield, it can be passed to qemu_co_sleep_wake() to + * terminate the sleep. */ -void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, - QemuCoSleepState **sleep_state= ); +void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, + QEMUClockType type, int64_t ns= ); + static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64= _t ns) { - QemuCoSleepState *unused =3D NULL; - qemu_co_sleep_ns_wakeable(type, ns, &unused); + QemuCoSleep w =3D { 0 }; + qemu_co_sleep_ns_wakeable(&w, type, ns); } =20 /** @@ -314,7 +315,7 @@ static inline void coroutine_fn qemu_co_sleep_ns(QEMUCl= ockType type, int64_t ns) * qemu_co_sleep_ns() and should be checked to be non-NULL before calling * qemu_co_sleep_wake(). */ -void qemu_co_sleep_wake(QemuCoSleepState *sleep_state); +void qemu_co_sleep_wake(QemuCoSleep *w); =20 /** * Yield until a file descriptor becomes readable diff --git a/block/block-copy.c b/block/block-copy.c index f896dc56f2..c2e5090412 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -50,7 +50,7 @@ typedef struct BlockCopyCallState { /* State */ int ret; bool finished; - QemuCoSleepState *sleep_state; + QemuCoSleep sleep; bool cancelled; =20 /* OUT parameters */ @@ -625,8 +625,8 @@ block_copy_dirty_clusters(BlockCopyCallState *call_stat= e) if (ns > 0) { block_copy_task_end(task, -EAGAIN); g_free(task); - qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, ns, - &call_state->sleep_state); + qemu_co_sleep_ns_wakeable(&call_state->sleep, + QEMU_CLOCK_REALTIME, ns); continue; } } @@ -674,7 +674,7 @@ out: =20 void block_copy_kick(BlockCopyCallState *call_state) { - qemu_co_sleep_wake(call_state->sleep_state); + qemu_co_sleep_wake(&call_state->sleep); } =20 /* diff --git a/block/nbd.c b/block/nbd.c index 1c6315b168..616f9ae6c4 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -116,7 +116,7 @@ typedef struct BDRVNBDState { CoQueue free_sema; Coroutine *connection_co; Coroutine *teardown_co; - QemuCoSleepState *connection_co_sleep_ns_state; + QemuCoSleep reconnect_sleep; bool drained; bool wait_drained_end; int in_flight; @@ -289,7 +289,7 @@ static void coroutine_fn nbd_client_co_drain_begin(Bloc= kDriverState *bs) BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; =20 s->drained =3D true; - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); + qemu_co_sleep_wake(&s->reconnect_sleep); =20 nbd_co_establish_connection_cancel(bs, false); =20 @@ -328,7 +328,7 @@ static void nbd_teardown_connection(BlockDriverState *b= s) =20 s->state =3D NBD_CLIENT_QUIT; if (s->connection_co) { - qemu_co_sleep_wake(s->connection_co_sleep_ns_state); + qemu_co_sleep_wake(&s->reconnect_sleep); nbd_co_establish_connection_cancel(bs, true); } if (qemu_in_coroutine()) { @@ -685,8 +685,8 @@ static coroutine_fn void nbd_co_reconnect_loop(BDRVNBDS= tate *s) } bdrv_inc_in_flight(s->bs); } else { - qemu_co_sleep_ns_wakeable(QEMU_CLOCK_REALTIME, timeout, - &s->connection_co_sleep_ns_state); + qemu_co_sleep_ns_wakeable(&s->reconnect_sleep, + QEMU_CLOCK_REALTIME, timeout); if (s->drained) { continue; } diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index 1d25019620..89c3b758c5 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -19,42 +19,37 @@ =20 static const char *qemu_co_sleep_ns__scheduled =3D "qemu_co_sleep_ns"; =20 -struct QemuCoSleepState { +void qemu_co_sleep_wake(QemuCoSleep *w) +{ Coroutine *co; - QemuCoSleepState **user_state_pointer; -}; =20 -void qemu_co_sleep_wake(QemuCoSleepState *sleep_state) -{ - if (sleep_state) { + co =3D w->to_wake; + w->to_wake =3D NULL; + if (co) { /* Write of schedule protected by barrier write in aio_co_schedule= */ - const char *scheduled =3D qatomic_cmpxchg(&sleep_state->co->schedu= led, + const char *scheduled =3D qatomic_cmpxchg(&co->scheduled, qemu_co_sleep_ns__schedule= d, NULL); =20 assert(scheduled =3D=3D qemu_co_sleep_ns__scheduled); - *sleep_state->user_state_pointer =3D NULL; - aio_co_wake(sleep_state->co); + aio_co_wake(co); } } =20 static void co_sleep_cb(void *opaque) { - QemuCoSleepState **sleep_state =3D opaque; - qemu_co_sleep_wake(*sleep_state); + QemuCoSleep *w =3D opaque; + qemu_co_sleep_wake(w); } =20 -void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns, - QemuCoSleepState **sleep_state) +void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, + QEMUClockType type, int64_t ns) { + Coroutine *co =3D qemu_coroutine_self(); AioContext *ctx =3D qemu_get_current_aio_context(); QEMUTimer ts; - QemuCoSleepState state =3D { - .co =3D qemu_coroutine_self(), - .user_state_pointer =3D sleep_state, - }; =20 - const char *scheduled =3D qatomic_cmpxchg(&state.co->scheduled, NULL, - qemu_co_sleep_ns__scheduled); + const char *scheduled =3D qatomic_cmpxchg(&co->scheduled, NULL, + qemu_co_sleep_ns__scheduled); if (scheduled) { fprintf(stderr, "%s: Co-routine was already scheduled in '%s'\n", @@ -62,12 +57,12 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockTy= pe type, int64_t ns, abort(); } =20 - aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, sleep_state); - *sleep_state =3D &state; + w->to_wake =3D co; + aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w), timer_mod(&ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); timer_del(&ts); =20 - /* qemu_co_sleep_wake clears *sleep_state before resuming this corouti= ne. */ - assert(*sleep_state =3D=3D NULL); + /* w->to_wake is cleared before resuming this coroutine. */ + assert(w->to_wake =3D=3D NULL); } --=20 2.31.1 From nobody Sun May 19 02:26:35 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1621861699; cv=none; d=zohomail.com; s=zohoarc; b=Y+Z8zw66CP8KTa/5zKVj+9F6I/IT2Yh8pAGSEYi3Lf2RNLp8bwa+ym1IJIqFoy34bXRNwrI9wq5vPFo9+SoCc89vrTKs8BkcPlh50iVHFuyCkiPO9DOkM99ofRNbAocQwNVYJbrTrHJpbZWusaAtbMEEbWBJjnbpFv5h/sTeetw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621861699; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JrpIWLzkGWcUYwerLw6c+S6FjPBoS4ixy8WOaOcBcK4=; b=X7iO2b2eSNrQ/KMLG98oSQmKJaGohm4ft7K1uBOmrUMz0jvBtxA2c8u5YMH/z8rY9cKZ6UdgjtkKNgCUPda4uYSxxHpYAnO5T+T2mQKndmVodNFJFTstAipG4bmxHV9/O6In+Kl+LdYN6SOdeyeHhPJMTd+TVUvPAoZVjGluWRI= ARC-Authentication-Results: i=1; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1621861699065937.162789966499; Mon, 24 May 2021 06:08:19 -0700 (PDT) Received: from localhost ([::1]:48086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llAJe-0005Zc-CK for importer@patchew.org; Mon, 24 May 2021 09:08:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llAEK-00039J-TJ for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27955) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llAEI-0007wV-PJ for qemu-devel@nongnu.org; Mon, 24 May 2021 09:02:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-03Wvw-pCNLWBSoxcnfhOfw-1; Mon, 24 May 2021 09:02:41 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BEFEA40C1; Mon, 24 May 2021 13:02:40 +0000 (UTC) Received: from localhost (ovpn-113-244.ams2.redhat.com [10.36.113.244]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1B9C10190AA; Mon, 24 May 2021 13:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621861365; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JrpIWLzkGWcUYwerLw6c+S6FjPBoS4ixy8WOaOcBcK4=; b=Je+zOHmGbXcZGAZGJl1Ou30tBMWSb0U6h14n1ui/9nM6oF6PuM2w1Qa/smyKPe0ruPL+M8 xSTWds2nmdroWRnrCpQsV+/sTvJvk1QHZOsivt7Ge+R4gxPZyiy1u8YqFySfSnTwokVGYL 8X/PZnVQ2bV3FCoJrmoDh+O6/cgn92E= X-MC-Unique: 03Wvw-pCNLWBSoxcnfhOfw-1 From: Stefan Hajnoczi To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 8/8] coroutine-sleep: introduce qemu_co_sleep Date: Mon, 24 May 2021 14:01:50 +0100 Message-Id: <20210524130150.50998-9-stefanha@redhat.com> In-Reply-To: <20210524130150.50998-1-stefanha@redhat.com> References: <20210524130150.50998-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.371, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Elena Ufimtseva , Vladimir Sementsov-Ogievskiy , Jagannathan Raman , qemu-block@nongnu.org, John G Johnson , John Snow , Max Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Allow using QemuCoSleep to sleep forever until woken by qemu_co_sleep_wake. This makes the logic of qemu_co_sleep_ns_wakeable easy to understand. In the future we will introduce an API that can work even if the sleep and wake happen from different threads. For now, initializing w->to_wake after timer_mod is fine because the timer can only fire in the same AioContext. Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Paolo Bonzini Message-id: 20210517100548.28806-7-pbonzini@redhat.com Signed-off-by: Stefan Hajnoczi --- include/qemu/coroutine.h | 5 +++++ util/qemu-coroutine-sleep.c | 26 +++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index 82c0671f80..292e61aef0 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -303,6 +303,11 @@ typedef struct QemuCoSleep { void coroutine_fn 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); + static inline void coroutine_fn qemu_co_sleep_ns(QEMUClockType type, int64= _t ns) { QemuCoSleep w =3D { 0 }; diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c index 89c3b758c5..571ab521ff 100644 --- a/util/qemu-coroutine-sleep.c +++ b/util/qemu-coroutine-sleep.c @@ -41,12 +41,9 @@ static void co_sleep_cb(void *opaque) qemu_co_sleep_wake(w); } =20 -void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep *w, - QEMUClockType type, int64_t ns) +void coroutine_fn qemu_co_sleep(QemuCoSleep *w) { Coroutine *co =3D qemu_coroutine_self(); - AioContext *ctx =3D qemu_get_current_aio_context(); - QEMUTimer ts; =20 const char *scheduled =3D qatomic_cmpxchg(&co->scheduled, NULL, qemu_co_sleep_ns__scheduled); @@ -58,11 +55,26 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QemuCoSleep= *w, } =20 w->to_wake =3D co; - aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w), - timer_mod(&ts, qemu_clock_get_ns(type) + ns); qemu_coroutine_yield(); - timer_del(&ts); =20 /* w->to_wake is cleared before resuming this coroutine. */ assert(w->to_wake =3D=3D NULL); } + +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; + + aio_timer_init(ctx, &ts, type, SCALE_NS, co_sleep_cb, w); + timer_mod(&ts, qemu_clock_get_ns(type) + ns); + + /* + * 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); +} --=20 2.31.1