From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391182118304.8046622678545; Fri, 2 Jun 2017 01:13:02 -0700 (PDT) Received: from localhost ([::1]:48423 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhhb-0002wa-NI for importer@patchew.org; Fri, 02 Jun 2017 04:12:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhg9-00019n-Qk for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhg8-0001xw-Pz for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40770) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhg8-0001xG-Ka for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:28 -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 mx1.redhat.com (Postfix) with ESMTPS id ABDEFC0587C3; Fri, 2 Jun 2017 08:11:27 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D6A560A99; Fri, 2 Jun 2017 08:11:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ABDEFC0587C3 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com ABDEFC0587C3 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:10:59 +0800 Message-Id: <20170602081120.3497-2-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 02 Jun 2017 08:11:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 01/22] docker: Run tests with current user X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We've used --add-current-user to create a user in the image, use it to run tests, because root has too much priviledge, and can surprise test cases. Signed-off-by: Fam Zheng Message-Id: <20170505032340.26467-2-famz@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Paolo Bonzini Signed-off-by: Fam Zheng --- tests/docker/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include index 03eda37..0ed8c3d 100644 --- a/tests/docker/Makefile.include +++ b/tests/docker/Makefile.include @@ -126,7 +126,7 @@ docker-run: docker-qemu-src " COPYING $(EXECUTABLE) to $(IMAGE)")) $(call quiet-command, \ $(SRC_PATH)/tests/docker/docker.py run \ - -t \ + $(if $(NOUSER),,-u $(shell id -u)) -t \ $(if $V,,--rm) \ $(if $(DEBUG),-i,--net=3Dnone) \ -e TARGET_LIST=3D$(TARGET_LIST) \ --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391325775412.7601732786411; Fri, 2 Jun 2017 01:15:25 -0700 (PDT) Received: from localhost ([::1]:48432 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhjw-0004zT-7n for importer@patchew.org; Fri, 02 Jun 2017 04:15:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgC-0001Bf-Ld for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgB-000214-Q6 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42358) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgB-000203-K1 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:31 -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 mx1.redhat.com (Postfix) with ESMTPS id A1AA080F94; Fri, 2 Jun 2017 08:11:30 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F97853CDE; Fri, 2 Jun 2017 08:11:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A1AA080F94 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A1AA080F94 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:00 +0800 Message-Id: <20170602081120.3497-3-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 02 Jun 2017 08:11:30 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 02/22] docker: Add bzip2 and hostname to fedora image X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It is used by qemu-iotests. Signed-off-by: Fam Zheng Message-Id: <20170505032340.26467-3-famz@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Paolo Bonzini Signed-off-by: Fam Zheng --- tests/docker/dockerfiles/fedora.docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker/dockerfiles/fedora.docker b/tests/docker/dockerfi= les/fedora.docker index c4f80ad..39f6b58 100644 --- a/tests/docker/dockerfiles/fedora.docker +++ b/tests/docker/dockerfiles/fedora.docker @@ -1,6 +1,6 @@ FROM fedora:latest ENV PACKAGES \ - ccache git tar PyYAML sparse flex bison python2 \ + ccache git tar PyYAML sparse flex bison python2 bzip2 hostname \ glib2-devel pixman-devel zlib-devel SDL-devel libfdt-devel \ gcc gcc-c++ clang make perl which bc findutils \ mingw32-pixman mingw32-glib2 mingw32-gmp mingw32-SDL mingw32-pkg-confi= g \ --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391327281265.10145804673994; Fri, 2 Jun 2017 01:15:27 -0700 (PDT) Received: from localhost ([::1]:48433 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhjv-00050H-UY for importer@patchew.org; Fri, 02 Jun 2017 04:15:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgJ-0001Nw-PO for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgF-00023h-18 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60246) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgE-000233-Rb for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:34 -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 mx1.redhat.com (Postfix) with ESMTPS id C9E9C37EEF; Fri, 2 Jun 2017 08:11:33 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B73660A99; Fri, 2 Jun 2017 08:11:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C9E9C37EEF Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C9E9C37EEF From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:01 +0800 Message-Id: <20170602081120.3497-4-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 02 Jun 2017 08:11:34 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 03/22] docker: Add libaio to fedora image X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Fam Zheng Message-Id: <20170505032340.26467-5-famz@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Paolo Bonzini Signed-off-by: Fam Zheng --- tests/docker/dockerfiles/fedora.docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker/dockerfiles/fedora.docker b/tests/docker/dockerfi= les/fedora.docker index 39f6b58..4eaa8ed 100644 --- a/tests/docker/dockerfiles/fedora.docker +++ b/tests/docker/dockerfiles/fedora.docker @@ -2,7 +2,7 @@ FROM fedora:latest ENV PACKAGES \ ccache git tar PyYAML sparse flex bison python2 bzip2 hostname \ glib2-devel pixman-devel zlib-devel SDL-devel libfdt-devel \ - gcc gcc-c++ clang make perl which bc findutils \ + gcc gcc-c++ clang make perl which bc findutils libaio-devel \ mingw32-pixman mingw32-glib2 mingw32-gmp mingw32-SDL mingw32-pkg-confi= g \ mingw32-gtk2 mingw32-gtk3 mingw32-gnutls mingw32-nettle mingw32-libtas= n1 \ mingw32-libjpeg-turbo mingw32-libpng mingw32-curl mingw32-libssh2 \ --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391483575812.9147092491853; Fri, 2 Jun 2017 01:18:03 -0700 (PDT) Received: from localhost ([::1]:48447 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhmT-0007EF-Vm for importer@patchew.org; Fri, 02 Jun 2017 04:18:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgJ-0001O6-W5 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgH-00025Y-4j for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58666) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgG-00024h-Ur for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:37 -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 mx1.redhat.com (Postfix) with ESMTPS id 01564C04B31E; Fri, 2 Jun 2017 08:11:36 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62E6E60A99; Fri, 2 Jun 2017 08:11:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 01564C04B31E Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 01564C04B31E From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:02 +0800 Message-Id: <20170602081120.3497-5-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 02 Jun 2017 08:11:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 04/22] docker: Add flex and bison to centos6 image X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Currently there are warnings about flex and bison being missing when building in the centos6 image: make[1]: flex: Command not found BISON dtc-parser.tab.c make[1]: bison: Command not found Add them. Reported-by: Thomas Huth Signed-off-by: Fam Zheng Message-Id: <20170524005206.31916-1-famz@redhat.com> Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Fam Zheng --- tests/docker/dockerfiles/centos6.docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/docker/dockerfiles/centos6.docker b/tests/docker/dockerf= iles/centos6.docker index 34e0d3b..17a4d24 100644 --- a/tests/docker/dockerfiles/centos6.docker +++ b/tests/docker/dockerfiles/centos6.docker @@ -1,7 +1,7 @@ FROM centos:6 RUN yum install -y epel-release ENV PACKAGES libfdt-devel ccache \ - tar git make gcc g++ \ + tar git make gcc g++ flex bison \ zlib-devel glib2-devel SDL-devel pixman-devel \ epel-release RUN yum install -y $PACKAGES --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391635138781.0118281447664; Fri, 2 Jun 2017 01:20:35 -0700 (PDT) Received: from localhost ([::1]:48463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhou-000125-Td for importer@patchew.org; Fri, 02 Jun 2017 04:20:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgK-0001Ou-9O for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgJ-00027Y-78 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60336) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgI-00026Y-TP for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:39 -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 mx1.redhat.com (Postfix) with ESMTPS id EA10A37EE1; Fri, 2 Jun 2017 08:11:37 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87B9C60BE3; Fri, 2 Jun 2017 08:11:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EA10A37EE1 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EA10A37EE1 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:03 +0800 Message-Id: <20170602081120.3497-6-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 02 Jun 2017 08:11:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 05/22] block: access copy_on_read with atomic ops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-2-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block.c | 6 ++++-- block/io.c | 8 ++++---- blockdev.c | 2 +- include/block/block_int.h | 11 ++++++----- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/block.c b/block.c index fa1d06d..af6366b 100644 --- a/block.c +++ b/block.c @@ -1300,7 +1300,9 @@ static int bdrv_open_common(BlockDriverState *bs, Blo= ckBackend *file, goto fail_opts; } =20 - assert(bs->copy_on_read =3D=3D 0); /* bdrv_new() and bdrv_close() make= it so */ + /* bdrv_new() and bdrv_close() make it so */ + assert(atomic_read(&bs->copy_on_read) =3D=3D 0); + if (bs->open_flags & BDRV_O_COPY_ON_READ) { if (!bs->read_only) { bdrv_enable_copy_on_read(bs); @@ -3063,7 +3065,7 @@ static void bdrv_close(BlockDriverState *bs) =20 g_free(bs->opaque); bs->opaque =3D NULL; - bs->copy_on_read =3D 0; + atomic_set(&bs->copy_on_read, 0); bs->backing_file[0] =3D '\0'; bs->backing_format[0] =3D '\0'; bs->total_sectors =3D 0; diff --git a/block/io.c b/block/io.c index ed31810..98c690f 100644 --- a/block/io.c +++ b/block/io.c @@ -130,13 +130,13 @@ void bdrv_refresh_limits(BlockDriverState *bs, Error = **errp) */ void bdrv_enable_copy_on_read(BlockDriverState *bs) { - bs->copy_on_read++; + atomic_inc(&bs->copy_on_read); } =20 void bdrv_disable_copy_on_read(BlockDriverState *bs) { - assert(bs->copy_on_read > 0); - bs->copy_on_read--; + int old =3D atomic_fetch_dec(&bs->copy_on_read); + assert(old >=3D 1); } =20 /* Check if any requests are in-flight (including throttled requests) */ @@ -1144,7 +1144,7 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child, bdrv_inc_in_flight(bs); =20 /* Don't do copy-on-read if we read data before write operation */ - if (bs->copy_on_read && !(flags & BDRV_REQ_NO_SERIALISING)) { + if (atomic_read(&bs->copy_on_read) && !(flags & BDRV_REQ_NO_SERIALISIN= G)) { flags |=3D BDRV_REQ_COPY_ON_READ; } =20 diff --git a/blockdev.c b/blockdev.c index 892d768..335fbcc 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1791,7 +1791,7 @@ static void external_snapshot_commit(BlkActionState *= common) /* We don't need (or want) to use the transactional * bdrv_reopen_multiple() across all the entries at once, because we * don't want to abort all of them if one of them fails the reopen */ - if (!state->old_bs->copy_on_read) { + if (!atomic_read(&state->old_bs->copy_on_read)) { bdrv_reopen(state->old_bs, state->old_bs->open_flags & ~BDRV_O_RDW= R, NULL); } diff --git a/include/block/block_int.h b/include/block/block_int.h index e5eb473..5f99cdb 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -595,11 +595,6 @@ struct BlockDriverState { =20 /* Protected by AioContext lock */ =20 - /* If true, copy read backing sectors into image. Can be >1 if more - * than one client has requested copy-on-read. - */ - int copy_on_read; - /* If we are reading a disk image, give its size in sectors. * Generally read-only; it is written to by load_vmstate and save_vmst= ate, * but the block layer is quiescent during those. @@ -633,6 +628,12 @@ struct BlockDriverState { =20 QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps; =20 + /* If true, copy read backing sectors into image. Can be >1 if more + * than one client has requested copy-on-read. Accessed with atomic + * ops. + */ + int copy_on_read; + /* do we need to tell the quest if we have a volatile write cache? */ int enable_write_cache; =20 --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391485014376.15804012825265; Fri, 2 Jun 2017 01:18:05 -0700 (PDT) Received: from localhost ([::1]:48448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhmV-0007Fn-KF for importer@patchew.org; Fri, 02 Jun 2017 04:18:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgM-0001SS-BT for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgL-00029g-6n for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15560) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgL-00028a-0y for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:41 -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 mx1.redhat.com (Postfix) with ESMTPS id 1392780479; Fri, 2 Jun 2017 08:11:40 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D6F260A99; Fri, 2 Jun 2017 08:11:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1392780479 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1392780479 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:04 +0800 Message-Id: <20170602081120.3497-7-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 02 Jun 2017 08:11:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 06/22] block: access quiesce_counter with atomic ops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Reviewed-by: Alberto Garcia Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-3-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/io.c | 4 ++-- include/block/block_int.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index 98c690f..70643df 100644 --- a/block/io.c +++ b/block/io.c @@ -241,7 +241,7 @@ void bdrv_drained_begin(BlockDriverState *bs) return; } =20 - if (!bs->quiesce_counter++) { + if (atomic_fetch_inc(&bs->quiesce_counter) =3D=3D 0) { aio_disable_external(bdrv_get_aio_context(bs)); bdrv_parent_drained_begin(bs); } @@ -252,7 +252,7 @@ void bdrv_drained_begin(BlockDriverState *bs) void bdrv_drained_end(BlockDriverState *bs) { assert(bs->quiesce_counter > 0); - if (--bs->quiesce_counter > 0) { + if (atomic_fetch_dec(&bs->quiesce_counter) > 1) { return; } =20 diff --git a/include/block/block_int.h b/include/block/block_int.h index 5f99cdb..9691db3 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -637,6 +637,7 @@ struct BlockDriverState { /* do we need to tell the quest if we have a volatile write cache? */ int enable_write_cache; =20 + /* Accessed with atomic ops. */ int quiesce_counter; }; =20 --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391216219744.1860011510537; Fri, 2 Jun 2017 01:13:36 -0700 (PDT) Received: from localhost ([::1]:48424 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhiA-0003Rk-M2 for importer@patchew.org; Fri, 02 Jun 2017 04:13:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgV-0001kc-Mv for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgQ-0002D1-Nk for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41086) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgQ-0002CU-HW for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:46 -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 mx1.redhat.com (Postfix) with ESMTPS id 8848FC0587C1; Fri, 2 Jun 2017 08:11:45 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id A089060A99; Fri, 2 Jun 2017 08:11:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8848FC0587C1 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8848FC0587C1 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:05 +0800 Message-Id: <20170602081120.3497-8-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 02 Jun 2017 08:11:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 07/22] block: access io_limits_disabled with atomic ops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Reviewed-by: Alberto Garcia Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-4-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/block-backend.c | 4 ++-- block/throttle-groups.c | 2 +- include/sysemu/block-backend.h | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index f3a6008..e50ec03 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1953,7 +1953,7 @@ static void blk_root_drained_begin(BdrvChild *child) /* Note that blk->root may not be accessible here yet if we are just * attaching to a BlockDriverState that is drained. Use child instead.= */ =20 - if (blk->public.io_limits_disabled++ =3D=3D 0) { + if (atomic_fetch_inc(&blk->public.io_limits_disabled) =3D=3D 0) { throttle_group_restart_blk(blk); } } @@ -1964,7 +1964,7 @@ static void blk_root_drained_end(BdrvChild *child) assert(blk->quiesce_counter); =20 assert(blk->public.io_limits_disabled); - --blk->public.io_limits_disabled; + atomic_dec(&blk->public.io_limits_disabled); =20 if (--blk->quiesce_counter =3D=3D 0) { if (blk->dev_ops && blk->dev_ops->drained_end) { diff --git a/block/throttle-groups.c b/block/throttle-groups.c index b73e7a8..69bfbd4 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -240,7 +240,7 @@ static bool throttle_group_schedule_timer(BlockBackend = *blk, bool is_write) ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); bool must_wait; =20 - if (blkp->io_limits_disabled) { + if (atomic_read(&blkp->io_limits_disabled)) { return false; } =20 diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 840ad61..24b63d6 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -80,7 +80,8 @@ typedef struct BlockBackendPublic { CoQueue throttled_reqs[2]; =20 /* Nonzero if the I/O limits are currently being ignored; generally - * it is zero. */ + * it is zero. Accessed with atomic operations. + */ unsigned int io_limits_disabled; =20 /* The following fields are protected by the ThrottleGroup lock. --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391218687356.79680618871885; Fri, 2 Jun 2017 01:13:38 -0700 (PDT) Received: from localhost ([::1]:48425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhiD-0003U0-4Z for importer@patchew.org; Fri, 02 Jun 2017 04:13:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgV-0001ka-M2 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgS-0002Ds-MQ for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56850) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgS-0002Dc-GD for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:48 -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 mx1.redhat.com (Postfix) with ESMTPS id 9116980C24; Fri, 2 Jun 2017 08:11:47 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13D9D60BEB; Fri, 2 Jun 2017 08:11:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9116980C24 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9116980C24 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:06 +0800 Message-Id: <20170602081120.3497-9-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 02 Jun 2017 08:11:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 08/22] block: access serialising_in_flight with atomic ops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-5-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/io.c | 6 +++--- include/block/block_int.h | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/block/io.c b/block/io.c index 70643df..d76202b 100644 --- a/block/io.c +++ b/block/io.c @@ -375,7 +375,7 @@ void bdrv_drain_all(void) static void tracked_request_end(BdrvTrackedRequest *req) { if (req->serialising) { - req->bs->serialising_in_flight--; + atomic_dec(&req->bs->serialising_in_flight); } =20 QLIST_REMOVE(req, list); @@ -414,7 +414,7 @@ static void mark_request_serialising(BdrvTrackedRequest= *req, uint64_t align) - overlap_offset; =20 if (!req->serialising) { - req->bs->serialising_in_flight++; + atomic_inc(&req->bs->serialising_in_flight); req->serialising =3D true; } =20 @@ -519,7 +519,7 @@ static bool coroutine_fn wait_serialising_requests(Bdrv= TrackedRequest *self) bool retry; bool waited =3D false; =20 - if (!bs->serialising_in_flight) { + if (!atomic_read(&bs->serialising_in_flight)) { return false; } =20 diff --git a/include/block/block_int.h b/include/block/block_int.h index 9691db3..e5f19eb 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -604,10 +604,6 @@ struct BlockDriverState { /* Callback before write request is processed */ NotifierWithReturnList before_write_notifiers; =20 - /* number of in-flight requests; overall and serialising */ - unsigned int in_flight; - unsigned int serialising_in_flight; - bool wakeup; =20 /* Offset after the highest byte written to */ @@ -634,6 +630,12 @@ struct BlockDriverState { */ int copy_on_read; =20 + /* number of in-flight requests; overall and serialising. + * Accessed with atomic ops. + */ + unsigned int in_flight; + unsigned int serialising_in_flight; + /* do we need to tell the quest if we have a volatile write cache? */ int enable_write_cache; =20 --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391753777690.3590418247921; Fri, 2 Jun 2017 01:22:33 -0700 (PDT) Received: from localhost ([::1]:48473 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhqq-0002qU-Ba for importer@patchew.org; Fri, 02 Jun 2017 04:22:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54533) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgV-0001kg-PF for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgU-0002Ez-Pd for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43092) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgU-0002EF-HU for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:50 -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 mx1.redhat.com (Postfix) with ESMTPS id 9571B80F95; Fri, 2 Jun 2017 08:11:49 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F12960A99; Fri, 2 Jun 2017 08:11:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9571B80F95 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9571B80F95 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:07 +0800 Message-Id: <20170602081120.3497-10-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 02 Jun 2017 08:11:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 09/22] block: access wakeup with atomic ops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-6-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/io.c | 3 ++- block/nfs.c | 4 +++- block/sheepdog.c | 3 ++- include/block/block.h | 5 +++-- include/block/block_int.h | 7 +++++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/block/io.c b/block/io.c index d76202b..4a59829 100644 --- a/block/io.c +++ b/block/io.c @@ -501,7 +501,8 @@ static void dummy_bh_cb(void *opaque) =20 void bdrv_wakeup(BlockDriverState *bs) { - if (bs->wakeup) { + /* The barrier (or an atomic op) is in the caller. */ + if (atomic_read(&bs->wakeup)) { aio_bh_schedule_oneshot(qemu_get_aio_context(), dummy_bh_cb, NULL); } } diff --git a/block/nfs.c b/block/nfs.c index 848b2c0..18c87d2 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -730,7 +730,9 @@ nfs_get_allocated_file_size_cb(int ret, struct nfs_cont= ext *nfs, void *data, if (task->ret < 0) { error_report("NFS Error: %s", nfs_get_error(nfs)); } - task->complete =3D 1; + + /* Set task->complete before reading bs->wakeup. */ + atomic_mb_set(&task->complete, 1); bdrv_wakeup(task->bs); } =20 diff --git a/block/sheepdog.c b/block/sheepdog.c index a18315a..5ebf5d9 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -698,7 +698,8 @@ out: =20 srco->co =3D NULL; srco->ret =3D ret; - srco->finished =3D true; + /* Set srco->finished before reading bs->wakeup. */ + atomic_mb_set(&srco->finished, true); if (srco->bs) { bdrv_wakeup(srco->bs); } diff --git a/include/block/block.h b/include/block/block.h index 9b355e9..a4f09df 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -402,7 +402,8 @@ void bdrv_drain_all(void); * block_job_defer_to_main_loop for how to do it). \ */ \ assert(!bs_->wakeup); \ - bs_->wakeup =3D true; \ + /* Set bs->wakeup before evaluating cond. */ \ + atomic_mb_set(&bs_->wakeup, true); \ while (busy_) { \ if ((cond)) { \ waited_ =3D busy_ =3D true; \ @@ -414,7 +415,7 @@ void bdrv_drain_all(void); waited_ |=3D busy_; \ } \ } \ - bs_->wakeup =3D false; \ + atomic_set(&bs_->wakeup, false); \ } \ waited_; }) =20 diff --git a/include/block/block_int.h b/include/block/block_int.h index e5f19eb..dd09e00 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -604,8 +604,6 @@ struct BlockDriverState { /* Callback before write request is processed */ NotifierWithReturnList before_write_notifiers; =20 - bool wakeup; - /* Offset after the highest byte written to */ uint64_t wr_highest_offset; =20 @@ -636,6 +634,11 @@ struct BlockDriverState { unsigned int in_flight; unsigned int serialising_in_flight; =20 + /* Internal to BDRV_POLL_WHILE and bdrv_wakeup. Accessed with atomic + * ops. + */ + bool wakeup; + /* do we need to tell the quest if we have a volatile write cache? */ int enable_write_cache; =20 --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391361725783.9165674414448; Fri, 2 Jun 2017 01:16:01 -0700 (PDT) Received: from localhost ([::1]:48439 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhkW-0005Zr-CJ for importer@patchew.org; Fri, 02 Jun 2017 04:16:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgY-0001mf-3v for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgX-0002GM-6S for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43342) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgX-0002Fq-00 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:53 -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 mx1.redhat.com (Postfix) with ESMTPS id 0A8693DBEB; Fri, 2 Jun 2017 08:11:52 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B40760A99; Fri, 2 Jun 2017 08:11:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0A8693DBEB Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0A8693DBEB From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:08 +0800 Message-Id: <20170602081120.3497-11-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 02 Jun 2017 08:11:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 10/22] block: access io_plugged with atomic ops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-7-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/io.c | 4 ++-- include/block/block_int.h | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/block/io.c b/block/io.c index 4a59829..bb1c9c5 100644 --- a/block/io.c +++ b/block/io.c @@ -2645,7 +2645,7 @@ void bdrv_io_plug(BlockDriverState *bs) bdrv_io_plug(child->bs); } =20 - if (bs->io_plugged++ =3D=3D 0) { + if (atomic_fetch_inc(&bs->io_plugged) =3D=3D 0) { BlockDriver *drv =3D bs->drv; if (drv && drv->bdrv_io_plug) { drv->bdrv_io_plug(bs); @@ -2658,7 +2658,7 @@ void bdrv_io_unplug(BlockDriverState *bs) BdrvChild *child; =20 assert(bs->io_plugged); - if (--bs->io_plugged =3D=3D 0) { + if (atomic_fetch_dec(&bs->io_plugged) =3D=3D 1) { BlockDriver *drv =3D bs->drv; if (drv && drv->bdrv_io_unplug) { drv->bdrv_io_unplug(bs); diff --git a/include/block/block_int.h b/include/block/block_int.h index dd09e00..d11417e 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -611,9 +611,6 @@ struct BlockDriverState { uint64_t write_threshold_offset; NotifierWithReturn write_threshold_notifier; =20 - /* counter for nested bdrv_io_plug */ - unsigned io_plugged; - QLIST_HEAD(, BdrvTrackedRequest) tracked_requests; CoQueue flush_queue; /* Serializing flush queue */ bool active_flush_req; /* Flush request in flight? */ @@ -639,6 +636,11 @@ struct BlockDriverState { */ bool wakeup; =20 + /* counter for nested bdrv_io_plug. + * Accessed with atomic ops. + */ + unsigned io_plugged; + /* do we need to tell the quest if we have a volatile write cache? */ int enable_write_cache; =20 --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391365360607.555166099373; Fri, 2 Jun 2017 01:16:05 -0700 (PDT) Received: from localhost ([::1]:48440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhkZ-0005cR-W6 for importer@patchew.org; Fri, 02 Jun 2017 04:16:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgb-0001qR-Ob for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhga-0002Jg-FH for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43414) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhga-0002Iw-6I for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:56 -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 mx1.redhat.com (Postfix) with ESMTPS id 3D2E380F93; Fri, 2 Jun 2017 08:11:55 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77F1F60A99; Fri, 2 Jun 2017 08:11:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3D2E380F93 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3D2E380F93 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:09 +0800 Message-Id: <20170602081120.3497-12-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 02 Jun 2017 08:11:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 11/22] throttle-groups: only start one coroutine from drained_begin X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Starting all waiting coroutines from bdrv_drain_all is unnecessary; throttle_group_co_io_limits_intercept calls schedule_next_request as soon as the coroutine restarts, which in turn will restart the next request if possible. If we only start the first request and let the coroutines dance from there the code is simpler and there is more reuse between throttle_group_config, throttle_group_restart_blk and timer_cb. The next patch will benefit from this. We also stop accessing from throttle_group_restart_blk the blkp->throttled_reqs CoQueues even when there was no attached throttling group. This worked but is not pretty. The only thing that can interrupt the dance is the QEMU_CLOCK_VIRTUAL timer when switching from one block device to the next, because the timer is set to "now + 1" but QEMU_CLOCK_VIRTUAL might not be running. Set that timer to point in the present ("now") rather than the future and things work. Reviewed-by: Alberto Garcia Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-8-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/throttle-groups.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 69bfbd4..85169ec 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -292,7 +292,7 @@ static void schedule_next_request(BlockBackend *blk, bo= ol is_write) } else { ThrottleTimers *tt =3D &blk_get_public(token)->throttle_timers; int64_t now =3D qemu_clock_get_ns(tt->clock_type); - timer_mod(tt->timers[is_write], now + 1); + timer_mod(tt->timers[is_write], now); tg->any_timer_armed[is_write] =3D true; } tg->tokens[is_write] =3D token; @@ -340,15 +340,32 @@ void coroutine_fn throttle_group_co_io_limits_interce= pt(BlockBackend *blk, qemu_mutex_unlock(&tg->lock); } =20 +static void throttle_group_restart_queue(BlockBackend *blk, bool is_write) +{ + BlockBackendPublic *blkp =3D blk_get_public(blk); + ThrottleGroup *tg =3D container_of(blkp->throttle_state, ThrottleGroup= , ts); + bool empty_queue; + + aio_context_acquire(blk_get_aio_context(blk)); + empty_queue =3D !qemu_co_enter_next(&blkp->throttled_reqs[is_write]); + aio_context_release(blk_get_aio_context(blk)); + + /* If the request queue was empty then we have to take care of + * scheduling the next one */ + if (empty_queue) { + qemu_mutex_lock(&tg->lock); + schedule_next_request(blk, is_write); + qemu_mutex_unlock(&tg->lock); + } +} + void throttle_group_restart_blk(BlockBackend *blk) { BlockBackendPublic *blkp =3D blk_get_public(blk); - int i; =20 - for (i =3D 0; i < 2; i++) { - while (qemu_co_enter_next(&blkp->throttled_reqs[i])) { - ; - } + if (blkp->throttle_state) { + throttle_group_restart_queue(blk, 0); + throttle_group_restart_queue(blk, 1); } } =20 @@ -376,8 +393,7 @@ void throttle_group_config(BlockBackend *blk, ThrottleC= onfig *cfg) throttle_config(ts, tt, cfg); qemu_mutex_unlock(&tg->lock); =20 - qemu_co_enter_next(&blkp->throttled_reqs[0]); - qemu_co_enter_next(&blkp->throttled_reqs[1]); + throttle_group_restart_blk(blk); } =20 /* Get the throttle configuration from a particular group. Similar to @@ -408,7 +424,6 @@ static void timer_cb(BlockBackend *blk, bool is_write) BlockBackendPublic *blkp =3D blk_get_public(blk); ThrottleState *ts =3D blkp->throttle_state; ThrottleGroup *tg =3D container_of(ts, ThrottleGroup, ts); - bool empty_queue; =20 /* The timer has just been fired, so we can update the flag */ qemu_mutex_lock(&tg->lock); @@ -416,17 +431,7 @@ static void timer_cb(BlockBackend *blk, bool is_write) qemu_mutex_unlock(&tg->lock); =20 /* Run the request that was waiting for this timer */ - aio_context_acquire(blk_get_aio_context(blk)); - empty_queue =3D !qemu_co_enter_next(&blkp->throttled_reqs[is_write]); - aio_context_release(blk_get_aio_context(blk)); - - /* If the request queue was empty then we have to take care of - * scheduling the next one */ - if (empty_queue) { - qemu_mutex_lock(&tg->lock); - schedule_next_request(blk, is_write); - qemu_mutex_unlock(&tg->lock); - } + throttle_group_restart_queue(blk, is_write); } =20 static void read_timer_cb(void *opaque) --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391525600219.48280707430968; Fri, 2 Jun 2017 01:18:45 -0700 (PDT) Received: from localhost ([::1]:48449 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhnA-0007lV-3r for importer@patchew.org; Fri, 02 Jun 2017 04:18:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgg-0001uY-Tx for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgc-0002Le-Gz for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43476) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgc-0002KX-7m for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:11:58 -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 mx1.redhat.com (Postfix) with ESMTPS id 430D2CED6; Fri, 2 Jun 2017 08:11:57 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5C685C662; Fri, 2 Jun 2017 08:11:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 430D2CED6 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 430D2CED6 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:10 +0800 Message-Id: <20170602081120.3497-13-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 02 Jun 2017 08:11:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 12/22] throttle-groups: do not use qemu_co_enter_next X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Prepare for removing this function; always restart throttled requests from coroutine context. This will matter when restarting throttled requests will have to acquire a CoMutex. Reviewed-by: Alberto Garcia Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-9-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/throttle-groups.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 85169ec..8bf1031 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -260,6 +260,20 @@ static bool throttle_group_schedule_timer(BlockBackend= *blk, bool is_write) return must_wait; } =20 +/* Start the next pending I/O request for a BlockBackend. Return whether + * any request was actually pending. + * + * @blk: the current BlockBackend + * @is_write: the type of operation (read/write) + */ +static bool coroutine_fn throttle_group_co_restart_queue(BlockBackend *blk, + bool is_write) +{ + BlockBackendPublic *blkp =3D blk_get_public(blk); + + return qemu_co_queue_next(&blkp->throttled_reqs[is_write]); +} + /* Look for the next pending I/O request and schedule it. * * This assumes that tg->lock is held. @@ -287,7 +301,7 @@ static void schedule_next_request(BlockBackend *blk, bo= ol is_write) if (!must_wait) { /* Give preference to requests from the current blk */ if (qemu_in_coroutine() && - qemu_co_queue_next(&blkp->throttled_reqs[is_write])) { + throttle_group_co_restart_queue(blk, is_write)) { token =3D blk; } else { ThrottleTimers *tt =3D &blk_get_public(token)->throttle_timers; @@ -340,15 +354,21 @@ void coroutine_fn throttle_group_co_io_limits_interce= pt(BlockBackend *blk, qemu_mutex_unlock(&tg->lock); } =20 -static void throttle_group_restart_queue(BlockBackend *blk, bool is_write) +typedef struct { + BlockBackend *blk; + bool is_write; +} RestartData; + +static void coroutine_fn throttle_group_restart_queue_entry(void *opaque) { + RestartData *data =3D opaque; + BlockBackend *blk =3D data->blk; + bool is_write =3D data->is_write; BlockBackendPublic *blkp =3D blk_get_public(blk); ThrottleGroup *tg =3D container_of(blkp->throttle_state, ThrottleGroup= , ts); bool empty_queue; =20 - aio_context_acquire(blk_get_aio_context(blk)); - empty_queue =3D !qemu_co_enter_next(&blkp->throttled_reqs[is_write]); - aio_context_release(blk_get_aio_context(blk)); + empty_queue =3D !throttle_group_co_restart_queue(blk, is_write); =20 /* If the request queue was empty then we have to take care of * scheduling the next one */ @@ -359,6 +379,18 @@ static void throttle_group_restart_queue(BlockBackend = *blk, bool is_write) } } =20 +static void throttle_group_restart_queue(BlockBackend *blk, bool is_write) +{ + Coroutine *co; + RestartData rd =3D { + .blk =3D blk, + .is_write =3D is_write + }; + + co =3D qemu_coroutine_create(throttle_group_restart_queue_entry, &rd); + aio_co_enter(blk_get_aio_context(blk), co); +} + void throttle_group_restart_blk(BlockBackend *blk) { BlockBackendPublic *blkp =3D blk_get_public(blk); --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391664923929.056604595763; Fri, 2 Jun 2017 01:21:04 -0700 (PDT) Received: from localhost ([::1]:48464 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhpO-0001TI-H3 for importer@patchew.org; Fri, 02 Jun 2017 04:21:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgg-0001uc-UX for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhge-0002MJ-LD for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59852) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhge-0002M4-Cn for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:00 -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 mx1.redhat.com (Postfix) with ESMTPS id 6EB2FC04B920; Fri, 2 Jun 2017 08:11:59 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0D5218863; Fri, 2 Jun 2017 08:11:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6EB2FC04B920 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6EB2FC04B920 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:11 +0800 Message-Id: <20170602081120.3497-14-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 02 Jun 2017 08:11:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 13/22] throttle-groups: protect throttled requests with a CoMutex X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Another possibility is to use tg->lock, which we're holding anyway in both schedule_next_request and throttle_group_co_io_limits_intercept. This would require open-coding the CoQueue however, so I've chosen this alternative. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-10-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/block-backend.c | 1 + block/throttle-groups.c | 12 ++++++++++-- include/sysemu/block-backend.h | 7 ++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index e50ec03..be2ddf1 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -216,6 +216,7 @@ BlockBackend *blk_new(uint64_t perm, uint64_t shared_pe= rm) blk->shared_perm =3D shared_perm; blk_set_enable_write_cache(blk, true); =20 + qemu_co_mutex_init(&blk->public.throttled_reqs_lock); qemu_co_queue_init(&blk->public.throttled_reqs[0]); qemu_co_queue_init(&blk->public.throttled_reqs[1]); =20 diff --git a/block/throttle-groups.c b/block/throttle-groups.c index 8bf1031..a181cb1 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -270,8 +270,13 @@ static bool coroutine_fn throttle_group_co_restart_que= ue(BlockBackend *blk, bool is_write) { BlockBackendPublic *blkp =3D blk_get_public(blk); + bool ret; =20 - return qemu_co_queue_next(&blkp->throttled_reqs[is_write]); + qemu_co_mutex_lock(&blkp->throttled_reqs_lock); + ret =3D qemu_co_queue_next(&blkp->throttled_reqs[is_write]); + qemu_co_mutex_unlock(&blkp->throttled_reqs_lock); + + return ret; } =20 /* Look for the next pending I/O request and schedule it. @@ -340,7 +345,10 @@ void coroutine_fn throttle_group_co_io_limits_intercep= t(BlockBackend *blk, if (must_wait || blkp->pending_reqs[is_write]) { blkp->pending_reqs[is_write]++; qemu_mutex_unlock(&tg->lock); - qemu_co_queue_wait(&blkp->throttled_reqs[is_write], NULL); + qemu_co_mutex_lock(&blkp->throttled_reqs_lock); + qemu_co_queue_wait(&blkp->throttled_reqs[is_write], + &blkp->throttled_reqs_lock); + qemu_co_mutex_unlock(&blkp->throttled_reqs_lock); qemu_mutex_lock(&tg->lock); blkp->pending_reqs[is_write]--; } diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 24b63d6..999eb23 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -72,11 +72,8 @@ typedef struct BlockDevOps { * fields that must be public. This is in particular for QLIST_ENTRY() and * friends so that BlockBackends can be kept in lists outside block-backen= d.c */ typedef struct BlockBackendPublic { - /* I/O throttling has its own locking, but also some fields are - * protected by the AioContext lock. - */ - - /* Protected by AioContext lock. */ + /* throttled_reqs_lock protects the CoQueues for throttled requests. = */ + CoMutex throttled_reqs_lock; CoQueue throttled_reqs[2]; =20 /* Nonzero if the I/O limits are currently being ignored; generally --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391529798707.4851478115205; Fri, 2 Jun 2017 01:18:49 -0700 (PDT) Received: from localhost ([::1]:48450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhnE-0007oR-4c for importer@patchew.org; Fri, 02 Jun 2017 04:18:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgl-0001z1-CW for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgj-0002QG-PX for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59956) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgj-0002Pw-Gl for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:05 -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 mx1.redhat.com (Postfix) with ESMTPS id 888DEC049D59; Fri, 2 Jun 2017 08:12:04 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 015AC87945; Fri, 2 Jun 2017 08:11:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 888DEC049D59 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 888DEC049D59 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:12 +0800 Message-Id: <20170602081120.3497-15-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 02 Jun 2017 08:12:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 14/22] util: add stats64 module X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini This module provides fast paths for 64-bit atomic operations on machines that only have 32-bit atomic access. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-11-pbonzini@redhat.com> [Include qemu/processor.h for cpu_relax(). - Fam] Signed-off-by: Fam Zheng --- include/qemu/stats64.h | 193 +++++++++++++++++++++++++++++++++++++++++++++= ++++ util/Makefile.objs | 1 + util/stats64.c | 137 +++++++++++++++++++++++++++++++++++ 3 files changed, 331 insertions(+) create mode 100644 include/qemu/stats64.h create mode 100644 util/stats64.c diff --git a/include/qemu/stats64.h b/include/qemu/stats64.h new file mode 100644 index 0000000..4a357b3 --- /dev/null +++ b/include/qemu/stats64.h @@ -0,0 +1,193 @@ +/* + * Atomic operations on 64-bit quantities. + * + * Copyright (C) 2017 Red Hat, Inc. + * + * Author: Paolo Bonzini + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_STATS64_H +#define QEMU_STATS64_H 1 + +#include "qemu/atomic.h" + +/* This provides atomic operations on 64-bit type, using a reader-writer + * spinlock on architectures that do not have 64-bit accesses. Even on + * those architectures, it tries hard not to take the lock. + */ + +typedef struct Stat64 { +#ifdef CONFIG_ATOMIC64 + uint64_t value; +#else + uint32_t low, high; + uint32_t lock; +#endif +} Stat64; + +#ifdef CONFIG_ATOMIC64 +static inline void stat64_init(Stat64 *s, uint64_t value) +{ + /* This is not guaranteed to be atomic! */ + *s =3D (Stat64) { value }; +} + +static inline uint64_t stat64_get(const Stat64 *s) +{ + return atomic_read__nocheck(&s->value); +} + +static inline void stat64_add(Stat64 *s, uint64_t value) +{ + atomic_add(&s->value, value); +} + +static inline void stat64_min(Stat64 *s, uint64_t value) +{ + uint64_t orig =3D atomic_read__nocheck(&s->value); + while (orig > value) { + orig =3D atomic_cmpxchg__nocheck(&s->value, orig, value); + } +} + +static inline void stat64_max(Stat64 *s, uint64_t value) +{ + uint64_t orig =3D atomic_read__nocheck(&s->value); + while (orig < value) { + orig =3D atomic_cmpxchg__nocheck(&s->value, orig, value); + } +} +#else +uint64_t stat64_get(const Stat64 *s); +bool stat64_min_slow(Stat64 *s, uint64_t value); +bool stat64_max_slow(Stat64 *s, uint64_t value); +bool stat64_add32_carry(Stat64 *s, uint32_t low, uint32_t high); + +static inline void stat64_init(Stat64 *s, uint64_t value) +{ + /* This is not guaranteed to be atomic! */ + *s =3D (Stat64) { .low =3D value, .high =3D value >> 32, .lock =3D 0 }; +} + +static inline void stat64_add(Stat64 *s, uint64_t value) +{ + uint32_t low, high; + high =3D value >> 32; + low =3D (uint32_t) value; + if (!low) { + if (high) { + atomic_add(&s->high, high); + } + return; + } + + for (;;) { + uint32_t orig =3D s->low; + uint32_t result =3D orig + low; + uint32_t old; + + if (result < low || high) { + /* If the high part is affected, take the lock. */ + if (stat64_add32_carry(s, low, high)) { + return; + } + continue; + } + + /* No carry, try with a 32-bit cmpxchg. The result is independent= of + * the high 32 bits, so it can race just fine with stat64_add32_ca= rry + * and even stat64_get! + */ + old =3D atomic_cmpxchg(&s->low, orig, result); + if (orig =3D=3D old) { + return; + } + } +} + +static inline void stat64_min(Stat64 *s, uint64_t value) +{ + uint32_t low, high; + uint32_t orig_low, orig_high; + + high =3D value >> 32; + low =3D (uint32_t) value; + do { + orig_high =3D atomic_read(&s->high); + if (orig_high < high) { + return; + } + + if (orig_high =3D=3D high) { + /* High 32 bits are equal. Read low after high, otherwise we + * can get a false positive (e.g. 0x1235,0x0000 changes to + * 0x1234,0x8000 and we read it as 0x1234,0x0000). Pairs with + * the write barrier in stat64_min_slow. + */ + smp_rmb(); + orig_low =3D atomic_read(&s->low); + if (orig_low <=3D low) { + return; + } + + /* See if we were lucky and a writer raced against us. The + * barrier is theoretically unnecessary, but if we remove it + * we may miss being lucky. + */ + smp_rmb(); + orig_high =3D atomic_read(&s->high); + if (orig_high < high) { + return; + } + } + + /* If the value changes in any way, we have to take the lock. */ + } while (!stat64_min_slow(s, value)); +} + +static inline void stat64_max(Stat64 *s, uint64_t value) +{ + uint32_t low, high; + uint32_t orig_low, orig_high; + + high =3D value >> 32; + low =3D (uint32_t) value; + do { + orig_high =3D atomic_read(&s->high); + if (orig_high > high) { + return; + } + + if (orig_high =3D=3D high) { + /* High 32 bits are equal. Read low after high, otherwise we + * can get a false positive (e.g. 0x1234,0x8000 changes to + * 0x1235,0x0000 and we read it as 0x1235,0x8000). Pairs with + * the write barrier in stat64_max_slow. + */ + smp_rmb(); + orig_low =3D atomic_read(&s->low); + if (orig_low >=3D low) { + return; + } + + /* See if we were lucky and a writer raced against us. The + * barrier is theoretically unnecessary, but if we remove it + * we may miss being lucky. + */ + smp_rmb(); + orig_high =3D atomic_read(&s->high); + if (orig_high > high) { + return; + } + } + + /* If the value changes in any way, we have to take the lock. */ + } while (!stat64_max_slow(s, value)); +} + +#endif + +#endif diff --git a/util/Makefile.objs b/util/Makefile.objs index c6205eb..8a333d3 100644 --- a/util/Makefile.objs +++ b/util/Makefile.objs @@ -42,4 +42,5 @@ util-obj-y +=3D log.o util-obj-y +=3D qdist.o util-obj-y +=3D qht.o util-obj-y +=3D range.o +util-obj-y +=3D stats64.o util-obj-y +=3D systemd.o diff --git a/util/stats64.c b/util/stats64.c new file mode 100644 index 0000000..9968fcc --- /dev/null +++ b/util/stats64.c @@ -0,0 +1,137 @@ +/* + * Atomic operations on 64-bit quantities. + * + * Copyright (C) 2017 Red Hat, Inc. + * + * Author: Paolo Bonzini + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/atomic.h" +#include "qemu/stats64.h" +#include "qemu/processor.h" + +#ifndef CONFIG_ATOMIC64 +static inline void stat64_rdlock(Stat64 *s) +{ + /* Keep out incoming writers to avoid them starving us. */ + atomic_add(&s->lock, 2); + + /* If there is a concurrent writer, wait for it. */ + while (atomic_read(&s->lock) & 1) { + cpu_relax(); + } +} + +static inline void stat64_rdunlock(Stat64 *s) +{ + atomic_sub(&s->lock, 2); +} + +static inline bool stat64_wrtrylock(Stat64 *s) +{ + return atomic_cmpxchg(&s->lock, 0, 1) =3D=3D 0; +} + +static inline void stat64_wrunlock(Stat64 *s) +{ + atomic_dec(&s->lock); +} + +uint64_t stat64_get(const Stat64 *s) +{ + uint32_t high, low; + + stat64_rdlock((Stat64 *)s); + + /* 64-bit writes always take the lock, so we can read in + * any order. + */ + high =3D atomic_read(&s->high); + low =3D atomic_read(&s->low); + stat64_rdunlock((Stat64 *)s); + + return ((uint64_t)high << 32) | low; +} + +bool stat64_add32_carry(Stat64 *s, uint32_t low, uint32_t high) +{ + uint32_t old; + + if (!stat64_wrtrylock(s)) { + cpu_relax(); + return false; + } + + /* 64-bit reads always take the lock, so they don't care about the + * order of our update. By updating s->low first, we can check + * whether we have to carry into s->high. + */ + old =3D atomic_fetch_add(&s->low, low); + high +=3D (old + low) < old; + atomic_add(&s->high, high); + stat64_wrunlock(s); + return true; +} + +bool stat64_min_slow(Stat64 *s, uint64_t value) +{ + uint32_t high, low; + uint64_t orig; + + if (!stat64_wrtrylock(s)) { + cpu_relax(); + return false; + } + + high =3D atomic_read(&s->high); + low =3D atomic_read(&s->low); + + orig =3D ((uint64_t)high << 32) | low; + if (orig < value) { + /* We have to set low before high, just like stat64_min reads + * high before low. The value may become higher temporarily, but + * stat64_get does not notice (it takes the lock) and the only ill + * effect on stat64_min is that the slow path may be triggered + * unnecessarily. + */ + atomic_set(&s->low, (uint32_t)value); + smp_wmb(); + atomic_set(&s->high, value >> 32); + } + stat64_wrunlock(s); + return true; +} + +bool stat64_max_slow(Stat64 *s, uint64_t value) +{ + uint32_t high, low; + uint64_t orig; + + if (!stat64_wrtrylock(s)) { + cpu_relax(); + return false; + } + + high =3D atomic_read(&s->high); + low =3D atomic_read(&s->low); + + orig =3D ((uint64_t)high << 32) | low; + if (orig > value) { + /* We have to set low before high, just like stat64_max reads + * high before low. The value may become lower temporarily, but + * stat64_get does not notice (it takes the lock) and the only ill + * effect on stat64_max is that the slow path may be triggered + * unnecessarily. + */ + atomic_set(&s->low, (uint32_t)value); + smp_wmb(); + atomic_set(&s->high, value >> 32); + } + stat64_wrunlock(s); + return true; +} +#endif --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391669039236.3899674834696; Fri, 2 Jun 2017 01:21:09 -0700 (PDT) Received: from localhost ([::1]:48466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhpT-0001Y8-7a for importer@patchew.org; Fri, 02 Jun 2017 04:21:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgm-00020H-QP for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgl-0002R6-RY for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60010) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgl-0002Qf-Kp for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:07 -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 mx1.redhat.com (Postfix) with ESMTPS id AB6A6C049D59; Fri, 2 Jun 2017 08:12:06 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F40687945; Fri, 2 Jun 2017 08:12:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AB6A6C049D59 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AB6A6C049D59 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:13 +0800 Message-Id: <20170602081120.3497-16-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 02 Jun 2017 08:12:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 15/22] block: use Stat64 for wr_highest_offset X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-12-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/io.c | 4 +--- block/qapi.c | 2 +- include/block/block_int.h | 7 ++++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/block/io.c b/block/io.c index bb1c9c5..bc69b4c 100644 --- a/block/io.c +++ b/block/io.c @@ -1405,9 +1405,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChil= d *child, ++bs->write_gen; bdrv_set_dirty(bs, start_sector, end_sector - start_sector); =20 - if (bs->wr_highest_offset < offset + bytes) { - bs->wr_highest_offset =3D offset + bytes; - } + stat64_max(&bs->wr_highest_offset, offset + bytes); =20 if (ret >=3D 0) { bs->total_sectors =3D MAX(bs->total_sectors, end_sector); diff --git a/block/qapi.c b/block/qapi.c index a40922e..14b60ae 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -441,7 +441,7 @@ static BlockStats *bdrv_query_bds_stats(const BlockDriv= erState *bs, s->node_name =3D g_strdup(bdrv_get_node_name(bs)); } =20 - s->stats->wr_highest_offset =3D bs->wr_highest_offset; + s->stats->wr_highest_offset =3D stat64_get(&bs->wr_highest_offset); =20 if (bs->file) { s->has_parent =3D true; diff --git a/include/block/block_int.h b/include/block/block_int.h index d11417e..8f36d1f 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -29,6 +29,7 @@ #include "qemu/option.h" #include "qemu/queue.h" #include "qemu/coroutine.h" +#include "qemu/stats64.h" #include "qemu/timer.h" #include "qapi-types.h" #include "qemu/hbitmap.h" @@ -604,9 +605,6 @@ struct BlockDriverState { /* Callback before write request is processed */ NotifierWithReturnList before_write_notifiers; =20 - /* Offset after the highest byte written to */ - uint64_t wr_highest_offset; - /* threshold limit for writes, in bytes. "High water mark". */ uint64_t write_threshold_offset; NotifierWithReturn write_threshold_notifier; @@ -619,6 +617,9 @@ struct BlockDriverState { =20 QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps; =20 + /* Offset after the highest byte written to */ + Stat64 wr_highest_offset; + /* If true, copy read backing sectors into image. Can be >1 if more * than one client has requested copy-on-read. Accessed with atomic * ops. --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391907408626.2964062329619; Fri, 2 Jun 2017 01:25:07 -0700 (PDT) Received: from localhost ([::1]:48484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhtK-000582-1V for importer@patchew.org; Fri, 02 Jun 2017 04:25:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgr-0002Di-RD for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgo-0002So-1n for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42542) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgn-0002SD-Ov for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:09 -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 mx1.redhat.com (Postfix) with ESMTPS id C8A9F80474; Fri, 2 Jun 2017 08:12:08 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 430D487945; Fri, 2 Jun 2017 08:12:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C8A9F80474 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C8A9F80474 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:14 +0800 Message-Id: <20170602081120.3497-17-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 02 Jun 2017 08:12:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 16/22] block: access write_gen with atomics X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-13-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block.c | 2 +- block/io.c | 6 +++--- include/block/block_int.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index af6366b..361005c 100644 --- a/block.c +++ b/block.c @@ -3424,7 +3424,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, E= rror **errp) ret =3D refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); bdrv_dirty_bitmap_truncate(bs); bdrv_parent_cb_resize(bs); - ++bs->write_gen; + atomic_inc(&bs->write_gen); } return ret; } diff --git a/block/io.c b/block/io.c index bc69b4c..036f5a4 100644 --- a/block/io.c +++ b/block/io.c @@ -1402,7 +1402,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChil= d *child, } bdrv_debug_event(bs, BLKDBG_PWRITEV_DONE); =20 - ++bs->write_gen; + atomic_inc(&bs->write_gen); bdrv_set_dirty(bs, start_sector, end_sector - start_sector); =20 stat64_max(&bs->wr_highest_offset, offset + bytes); @@ -2291,7 +2291,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) goto early_exit; } =20 - current_gen =3D bs->write_gen; + current_gen =3D atomic_read(&bs->write_gen); =20 /* Wait until any previous flushes are completed */ while (bs->active_flush_req) { @@ -2516,7 +2516,7 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *b= s, int64_t offset, } ret =3D 0; out: - ++bs->write_gen; + atomic_inc(&bs->write_gen); bdrv_set_dirty(bs, req.offset >> BDRV_SECTOR_BITS, req.bytes >> BDRV_SECTOR_BITS); tracked_request_end(&req); diff --git a/include/block/block_int.h b/include/block/block_int.h index 8f36d1f..8a9bc0b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -612,7 +612,6 @@ struct BlockDriverState { QLIST_HEAD(, BdrvTrackedRequest) tracked_requests; CoQueue flush_queue; /* Serializing flush queue */ bool active_flush_req; /* Flush request in flight? */ - unsigned int write_gen; /* Current data generation */ unsigned int flushed_gen; /* Flushed write generation */ =20 QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps; @@ -647,6 +646,7 @@ struct BlockDriverState { =20 /* Accessed with atomic ops. */ int quiesce_counter; + unsigned int write_gen; /* Current data generation */ }; =20 struct BlockBackendRootState { --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149639178764169.6450993206978; Fri, 2 Jun 2017 01:23:07 -0700 (PDT) Received: from localhost ([::1]:48475 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhrO-0003Mu-11 for importer@patchew.org; Fri, 02 Jun 2017 04:23:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgr-0002Dm-RQ for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgq-0002TR-9a for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51522) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgp-0002TB-W3 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:12 -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 mx1.redhat.com (Postfix) with ESMTPS id 06C658123A; Fri, 2 Jun 2017 08:12:11 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6860C60A99; Fri, 2 Jun 2017 08:12:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 06C658123A Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 06C658123A From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:15 +0800 Message-Id: <20170602081120.3497-18-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 02 Jun 2017 08:12:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 17/22] block: protect tracked_requests and flush_queue with reqs_lock X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-14-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block.c | 1 + block/io.c | 16 ++++++++++++++-- include/block/block_int.h | 14 +++++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index 361005c..a5cbd45 100644 --- a/block.c +++ b/block.c @@ -320,6 +320,7 @@ BlockDriverState *bdrv_new(void) QLIST_INIT(&bs->op_blockers[i]); } notifier_with_return_list_init(&bs->before_write_notifiers); + qemu_co_mutex_init(&bs->reqs_lock); bs->refcnt =3D 1; bs->aio_context =3D qemu_get_aio_context(); =20 diff --git a/block/io.c b/block/io.c index 036f5a4..91611ff 100644 --- a/block/io.c +++ b/block/io.c @@ -378,8 +378,10 @@ static void tracked_request_end(BdrvTrackedRequest *re= q) atomic_dec(&req->bs->serialising_in_flight); } =20 + qemu_co_mutex_lock(&req->bs->reqs_lock); QLIST_REMOVE(req, list); qemu_co_queue_restart_all(&req->wait_queue); + qemu_co_mutex_unlock(&req->bs->reqs_lock); } =20 /** @@ -404,7 +406,9 @@ static void tracked_request_begin(BdrvTrackedRequest *r= eq, =20 qemu_co_queue_init(&req->wait_queue); =20 + qemu_co_mutex_lock(&bs->reqs_lock); QLIST_INSERT_HEAD(&bs->tracked_requests, req, list); + qemu_co_mutex_unlock(&bs->reqs_lock); } =20 static void mark_request_serialising(BdrvTrackedRequest *req, uint64_t ali= gn) @@ -526,6 +530,7 @@ static bool coroutine_fn wait_serialising_requests(Bdrv= TrackedRequest *self) =20 do { retry =3D false; + qemu_co_mutex_lock(&bs->reqs_lock); QLIST_FOREACH(req, &bs->tracked_requests, list) { if (req =3D=3D self || (!req->serialising && !self->serialisin= g)) { continue; @@ -544,7 +549,7 @@ static bool coroutine_fn wait_serialising_requests(Bdrv= TrackedRequest *self) * (instead of producing a deadlock in the former case). */ if (!req->waiting_for) { self->waiting_for =3D req; - qemu_co_queue_wait(&req->wait_queue, NULL); + qemu_co_queue_wait(&req->wait_queue, &bs->reqs_lock); self->waiting_for =3D NULL; retry =3D true; waited =3D true; @@ -552,6 +557,7 @@ static bool coroutine_fn wait_serialising_requests(Bdrv= TrackedRequest *self) } } } + qemu_co_mutex_unlock(&bs->reqs_lock); } while (retry); =20 return waited; @@ -2291,14 +2297,17 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) goto early_exit; } =20 + qemu_co_mutex_lock(&bs->reqs_lock); current_gen =3D atomic_read(&bs->write_gen); =20 /* Wait until any previous flushes are completed */ while (bs->active_flush_req) { - qemu_co_queue_wait(&bs->flush_queue, NULL); + qemu_co_queue_wait(&bs->flush_queue, &bs->reqs_lock); } =20 + /* Flushes reach this point in nondecreasing current_gen order. */ bs->active_flush_req =3D true; + qemu_co_mutex_unlock(&bs->reqs_lock); =20 /* Write back all layers by calling one driver function */ if (bs->drv->bdrv_co_flush) { @@ -2370,9 +2379,12 @@ out: if (ret =3D=3D 0) { bs->flushed_gen =3D current_gen; } + + qemu_co_mutex_lock(&bs->reqs_lock); bs->active_flush_req =3D false; /* Return value is ignored - it's ok if wait queue is empty */ qemu_co_queue_next(&bs->flush_queue); + qemu_co_mutex_unlock(&bs->reqs_lock); =20 early_exit: bdrv_dec_in_flight(bs); diff --git a/include/block/block_int.h b/include/block/block_int.h index 8a9bc0b..31fb364 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -609,11 +609,6 @@ struct BlockDriverState { uint64_t write_threshold_offset; NotifierWithReturn write_threshold_notifier; =20 - QLIST_HEAD(, BdrvTrackedRequest) tracked_requests; - CoQueue flush_queue; /* Serializing flush queue */ - bool active_flush_req; /* Flush request in flight? */ - unsigned int flushed_gen; /* Flushed write generation */ - QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps; =20 /* Offset after the highest byte written to */ @@ -647,6 +642,15 @@ struct BlockDriverState { /* Accessed with atomic ops. */ int quiesce_counter; unsigned int write_gen; /* Current data generation */ + + /* Protected by reqs_lock. */ + CoMutex reqs_lock; + QLIST_HEAD(, BdrvTrackedRequest) tracked_requests; + CoQueue flush_queue; /* Serializing flush queue */ + bool active_flush_req; /* Flush request in flight? */ + + /* Only read/written by whoever has set active_flush_req to true. */ + unsigned int flushed_gen; /* Flushed write generation */ }; =20 struct BlockBackendRootState { --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391879911185.15431046244544; Fri, 2 Jun 2017 01:24:39 -0700 (PDT) Received: from localhost ([::1]:48482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhss-0004jH-6a for importer@patchew.org; Fri, 02 Jun 2017 04:24:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgu-0002Hb-BF for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgs-0002Uf-EQ for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51572) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgs-0002Tr-3v for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:14 -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 mx1.redhat.com (Postfix) with ESMTPS id 2702F81227; Fri, 2 Jun 2017 08:12:13 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DE8560A99; Fri, 2 Jun 2017 08:12:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2702F81227 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2702F81227 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:16 +0800 Message-Id: <20170602081120.3497-19-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 02 Jun 2017 08:12:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 18/22] block: introduce dirty_bitmap_mutex X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini It protects only the list of dirty bitmaps; in the next patch we will also protect their content. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-15-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/dirty-bitmap.c | 44 +++++++++++++++++++++++++++++++++++++++++++- block/mirror.c | 3 ++- blockdev.c | 44 +++++++------------------------------------- include/block/block_int.h | 5 +++++ migration/block.c | 6 ------ 5 files changed, 57 insertions(+), 45 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 519737c..fa78109 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -52,6 +52,17 @@ struct BdrvDirtyBitmapIter { BdrvDirtyBitmap *bitmap; }; =20 +static inline void bdrv_dirty_bitmaps_lock(BlockDriverState *bs) +{ + qemu_mutex_lock(&bs->dirty_bitmap_mutex); +} + +static inline void bdrv_dirty_bitmaps_unlock(BlockDriverState *bs) +{ + qemu_mutex_unlock(&bs->dirty_bitmap_mutex); +} + +/* Called with BQL or dirty_bitmap lock taken. */ BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, const char *= name) { BdrvDirtyBitmap *bm; @@ -65,6 +76,7 @@ BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState = *bs, const char *name) return NULL; } =20 +/* Called with BQL taken. */ void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap) { assert(!bdrv_dirty_bitmap_frozen(bitmap)); @@ -72,6 +84,7 @@ void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap) bitmap->name =3D NULL; } =20 +/* Called with BQL taken. */ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs, uint32_t granularity, const char *name, @@ -100,7 +113,9 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverSt= ate *bs, bitmap->size =3D bitmap_size; bitmap->name =3D g_strdup(name); bitmap->disabled =3D false; + bdrv_dirty_bitmaps_lock(bs); QLIST_INSERT_HEAD(&bs->dirty_bitmaps, bitmap, list); + bdrv_dirty_bitmaps_unlock(bs); return bitmap; } =20 @@ -164,16 +179,19 @@ const char *bdrv_dirty_bitmap_name(const BdrvDirtyBit= map *bitmap) return bitmap->name; } =20 +/* Called with BQL taken. */ bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap) { return bitmap->successor; } =20 +/* Called with BQL taken. */ bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap) { return !(bitmap->disabled || bitmap->successor); } =20 +/* Called with BQL taken. */ DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap) { if (bdrv_dirty_bitmap_frozen(bitmap)) { @@ -188,6 +206,7 @@ DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBit= map *bitmap) /** * Create a successor bitmap destined to replace this bitmap after an oper= ation. * Requires that the bitmap is not frozen and has no successor. + * Called with BQL taken. */ int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, Error **er= rp) @@ -220,6 +239,7 @@ int bdrv_dirty_bitmap_create_successor(BlockDriverState= *bs, /** * For a bitmap with a successor, yield our name to the successor, * delete the old bitmap, and return a handle to the new bitmap. + * Called with BQL taken. */ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, @@ -247,6 +267,7 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriver= State *bs, * In cases of failure where we can no longer safely delete the parent, * we may wish to re-join the parent and child/successor. * The merged parent will be un-frozen, but not explicitly re-enabled. + * Called with BQL taken. */ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *parent, @@ -271,25 +292,30 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDrive= rState *bs, =20 /** * Truncates _all_ bitmaps attached to a BDS. + * Called with BQL taken. */ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs) { BdrvDirtyBitmap *bitmap; uint64_t size =3D bdrv_nb_sectors(bs); =20 + bdrv_dirty_bitmaps_lock(bs); QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) { assert(!bdrv_dirty_bitmap_frozen(bitmap)); assert(!bitmap->active_iterators); hbitmap_truncate(bitmap->bitmap, size); bitmap->size =3D size; } + bdrv_dirty_bitmaps_unlock(bs); } =20 +/* Called with BQL taken. */ static void bdrv_do_release_matching_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, bool only_named) { BdrvDirtyBitmap *bm, *next; + bdrv_dirty_bitmaps_lock(bs); QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) { if ((!bitmap || bm =3D=3D bitmap) && (!only_named || bm->name)) { assert(!bm->active_iterators); @@ -301,15 +327,19 @@ static void bdrv_do_release_matching_dirty_bitmap(Blo= ckDriverState *bs, g_free(bm); =20 if (bitmap) { - return; + goto out; } } } if (bitmap) { abort(); } + +out: + bdrv_dirty_bitmaps_unlock(bs); } =20 +/* Called with BQL taken. */ void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitm= ap) { bdrv_do_release_matching_dirty_bitmap(bs, bitmap, false); @@ -318,18 +348,21 @@ void bdrv_release_dirty_bitmap(BlockDriverState *bs, = BdrvDirtyBitmap *bitmap) /** * Release all named dirty bitmaps attached to a BDS (for use in bdrv_clos= e()). * There must not be any frozen bitmaps attached. + * Called with BQL taken. */ void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs) { bdrv_do_release_matching_dirty_bitmap(bs, NULL, true); } =20 +/* Called with BQL taken. */ void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap) { assert(!bdrv_dirty_bitmap_frozen(bitmap)); bitmap->disabled =3D true; } =20 +/* Called with BQL taken. */ void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap) { assert(!bdrv_dirty_bitmap_frozen(bitmap)); @@ -342,6 +375,7 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDrive= rState *bs) BlockDirtyInfoList *list =3D NULL; BlockDirtyInfoList **plist =3D &list; =20 + bdrv_dirty_bitmaps_lock(bs); QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) { BlockDirtyInfo *info =3D g_new0(BlockDirtyInfo, 1); BlockDirtyInfoList *entry =3D g_new0(BlockDirtyInfoList, 1); @@ -354,6 +388,7 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDrive= rState *bs) *plist =3D entry; plist =3D &entry->next; } + bdrv_dirty_bitmaps_unlock(bs); =20 return list; } @@ -508,12 +543,19 @@ void bdrv_set_dirty(BlockDriverState *bs, int64_t cur= _sector, int64_t nr_sectors) { BdrvDirtyBitmap *bitmap; + + if (QLIST_EMPTY(&bs->dirty_bitmaps)) { + return; + } + + bdrv_dirty_bitmaps_lock(bs); QLIST_FOREACH(bitmap, &bs->dirty_bitmaps, list) { if (!bdrv_dirty_bitmap_enabled(bitmap)) { continue; } hbitmap_set(bitmap->bitmap, cur_sector, nr_sectors); } + bdrv_dirty_bitmaps_unlock(bs); } =20 /** diff --git a/block/mirror.c b/block/mirror.c index a2a9703..88ae882 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -506,6 +506,8 @@ static void mirror_exit(BlockJob *job, void *opaque) BlockDriverState *mirror_top_bs =3D s->mirror_top_bs; Error *local_err =3D NULL; =20 + bdrv_release_dirty_bitmap(src, s->dirty_bitmap); + /* Make sure that the source BDS doesn't go away before we called * block_job_completed(). */ bdrv_ref(src); @@ -904,7 +906,6 @@ immediate_exit: g_free(s->cow_bitmap); g_free(s->in_flight_bitmap); bdrv_dirty_iter_free(s->dbi); - bdrv_release_dirty_bitmap(bs, s->dirty_bitmap); =20 data =3D g_malloc(sizeof(*data)); data->ret =3D ret; diff --git a/blockdev.c b/blockdev.c index 335fbcc..6e7c8a6 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1362,12 +1362,10 @@ out_aio_context: static BdrvDirtyBitmap *block_dirty_bitmap_lookup(const char *node, const char *name, BlockDriverState **pbs, - AioContext **paio, Error **errp) { BlockDriverState *bs; BdrvDirtyBitmap *bitmap; - AioContext *aio_context; =20 if (!node) { error_setg(errp, "Node cannot be NULL"); @@ -1383,29 +1381,17 @@ static BdrvDirtyBitmap *block_dirty_bitmap_lookup(c= onst char *node, return NULL; } =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - bitmap =3D bdrv_find_dirty_bitmap(bs, name); if (!bitmap) { error_setg(errp, "Dirty bitmap '%s' not found", name); - goto fail; + return NULL; } =20 if (pbs) { *pbs =3D bs; } - if (paio) { - *paio =3D aio_context; - } else { - aio_context_release(aio_context); - } =20 return bitmap; - - fail: - aio_context_release(aio_context); - return NULL; } =20 /* New and old BlockDriverState structs for atomic group operations */ @@ -2021,7 +2007,6 @@ static void block_dirty_bitmap_clear_prepare(BlkActio= nState *common, state->bitmap =3D block_dirty_bitmap_lookup(action->node, action->name, &state->bs, - &state->aio_context, errp); if (!state->bitmap) { return; @@ -2729,7 +2714,6 @@ void qmp_block_dirty_bitmap_add(const char *node, con= st char *name, bool has_granularity, uint32_t granularity, Error **errp) { - AioContext *aio_context; BlockDriverState *bs; =20 if (!name || name[0] =3D=3D '\0') { @@ -2742,14 +2726,11 @@ void qmp_block_dirty_bitmap_add(const char *node, c= onst char *name, return; } =20 - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - if (has_granularity) { if (granularity < 512 || !is_power_of_2(granularity)) { error_setg(errp, "Granularity must be power of 2 " "and at least 512"); - goto out; + return; } } else { /* Default to cluster size, if available: */ @@ -2757,19 +2738,15 @@ void qmp_block_dirty_bitmap_add(const char *node, c= onst char *name, } =20 bdrv_create_dirty_bitmap(bs, granularity, name, errp); - - out: - aio_context_release(aio_context); } =20 void qmp_block_dirty_bitmap_remove(const char *node, const char *name, Error **errp) { - AioContext *aio_context; BlockDriverState *bs; BdrvDirtyBitmap *bitmap; =20 - bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, &aio_context, er= rp); + bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); if (!bitmap || !bs) { return; } @@ -2778,13 +2755,10 @@ void qmp_block_dirty_bitmap_remove(const char *node= , const char *name, error_setg(errp, "Bitmap '%s' is currently frozen and cannot be removed", name); - goto out; + return; } bdrv_dirty_bitmap_make_anon(bitmap); bdrv_release_dirty_bitmap(bs, bitmap); - - out: - aio_context_release(aio_context); } =20 /** @@ -2794,11 +2768,10 @@ void qmp_block_dirty_bitmap_remove(const char *node= , const char *name, void qmp_block_dirty_bitmap_clear(const char *node, const char *name, Error **errp) { - AioContext *aio_context; BdrvDirtyBitmap *bitmap; BlockDriverState *bs; =20 - bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, &aio_context, er= rp); + bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); if (!bitmap || !bs) { return; } @@ -2807,18 +2780,15 @@ void qmp_block_dirty_bitmap_clear(const char *node,= const char *name, error_setg(errp, "Bitmap '%s' is currently frozen and cannot be modified= ", name); - goto out; + return; } else if (!bdrv_dirty_bitmap_enabled(bitmap)) { error_setg(errp, "Bitmap '%s' is currently disabled and cannot be cleare= d", name); - goto out; + return; } =20 bdrv_clear_dirty_bitmap(bitmap, NULL); - - out: - aio_context_release(aio_context); } =20 void hmp_drive_del(Monitor *mon, const QDict *qdict) diff --git a/include/block/block_int.h b/include/block/block_int.h index 31fb364..c834b86 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -609,6 +609,11 @@ struct BlockDriverState { uint64_t write_threshold_offset; NotifierWithReturn write_threshold_notifier; =20 + /* Writing to the list requires the BQL _and_ the dirty_bitmap_mutex. + * Reading from the list can be done with either the BQL or the + * dirty_bitmap_mutex. Modifying a bitmap requires the AioContext + * lock. */ + QemuMutex dirty_bitmap_mutex; QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps; =20 /* Offset after the highest byte written to */ diff --git a/migration/block.c b/migration/block.c index 13f90d3..9e9f031 100644 --- a/migration/block.c +++ b/migration/block.c @@ -345,10 +345,8 @@ static int set_dirty_tracking(void) int ret; =20 QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { - aio_context_acquire(blk_get_aio_context(bmds->blk)); bmds->dirty_bitmap =3D bdrv_create_dirty_bitmap(blk_bs(bmds->blk), BLOCK_SIZE, NULL, NU= LL); - aio_context_release(blk_get_aio_context(bmds->blk)); if (!bmds->dirty_bitmap) { ret =3D -errno; goto fail; @@ -359,9 +357,7 @@ static int set_dirty_tracking(void) fail: QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { if (bmds->dirty_bitmap) { - aio_context_acquire(blk_get_aio_context(bmds->blk)); bdrv_release_dirty_bitmap(blk_bs(bmds->blk), bmds->dirty_bitma= p); - aio_context_release(blk_get_aio_context(bmds->blk)); } } return ret; @@ -374,9 +370,7 @@ static void unset_dirty_tracking(void) BlkMigDevState *bmds; =20 QSIMPLEQ_FOREACH(bmds, &block_mig_state.bmds_list, entry) { - aio_context_acquire(blk_get_aio_context(bmds->blk)); bdrv_release_dirty_bitmap(blk_bs(bmds->blk), bmds->dirty_bitmap); - aio_context_release(blk_get_aio_context(bmds->blk)); } } =20 --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391783214998.9933229412304; Fri, 2 Jun 2017 01:23:03 -0700 (PDT) Received: from localhost ([::1]:48474 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhrJ-0003II-Sc for importer@patchew.org; Fri, 02 Jun 2017 04:23:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54790) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgv-0002IH-1i for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgu-0002Vy-7H for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60190) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgu-0002VA-11 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:16 -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 mx1.redhat.com (Postfix) with ESMTPS id 1833DC049D59; Fri, 2 Jun 2017 08:12:15 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97AC960A99; Fri, 2 Jun 2017 08:12:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1833DC049D59 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1833DC049D59 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:17 +0800 Message-Id: <20170602081120.3497-20-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 02 Jun 2017 08:12:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 19/22] migration/block: reset dirty bitmap before reading X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Any data that is returned by read may be stale already, the bitmap has to be cleared before issuing the read. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-16-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- migration/block.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/block.c b/migration/block.c index 9e9f031..8fe484e 100644 --- a/migration/block.c +++ b/migration/block.c @@ -536,6 +536,8 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDev= State *bmds, } else { nr_sectors =3D BDRV_SECTORS_PER_DIRTY_CHUNK; } + bdrv_reset_dirty_bitmap(bmds->dirty_bitmap, sector, nr_sectors= ); + blk =3D g_new(BlkMigBlock, 1); blk->buf =3D g_malloc(BLOCK_SIZE); blk->bmds =3D bmds; @@ -568,7 +570,6 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDev= State *bmds, g_free(blk); } =20 - bdrv_reset_dirty_bitmap(bmds->dirty_bitmap, sector, nr_sectors= ); sector +=3D nr_sectors; bmds->cur_dirty =3D sector; =20 --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391991231152.4907750199642; Fri, 2 Jun 2017 01:26:31 -0700 (PDT) Received: from localhost ([::1]:48495 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhue-0006Kg-VU for importer@patchew.org; Fri, 02 Jun 2017 04:26:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhgy-0002UK-Dh for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgw-0002YN-G6 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53396) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgw-0002Wu-5t for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:18 -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 mx1.redhat.com (Postfix) with ESMTPS id 3CF16142A7D; Fri, 2 Jun 2017 08:12:17 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id A3FDD60A99; Fri, 2 Jun 2017 08:12:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3CF16142A7D Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3CF16142A7D From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:18 +0800 Message-Id: <20170602081120.3497-21-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 02 Jun 2017 08:12:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 20/22] block: protect modification of dirty bitmaps with a mutex X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-17-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/dirty-bitmap.c | 70 ++++++++++++++++++++++++++++++++++++++--= ---- block/mirror.c | 11 +++++-- include/block/block_int.h | 4 +-- include/block/dirty-bitmap.h | 25 +++++++++++----- migration/block.c | 10 ++++--- 5 files changed, 95 insertions(+), 25 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index fa78109..a04c6e4 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -37,6 +37,7 @@ * or enabled. A frozen bitmap can only abdicate() or reclaim(). */ struct BdrvDirtyBitmap { + QemuMutex *mutex; HBitmap *bitmap; /* Dirty sector bitmap implementation */ HBitmap *meta; /* Meta dirty bitmap */ BdrvDirtyBitmap *successor; /* Anonymous child; implies frozen status = */ @@ -62,6 +63,16 @@ static inline void bdrv_dirty_bitmaps_unlock(BlockDriver= State *bs) qemu_mutex_unlock(&bs->dirty_bitmap_mutex); } =20 +void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap) +{ + qemu_mutex_lock(bitmap->mutex); +} + +void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap) +{ + qemu_mutex_unlock(bitmap->mutex); +} + /* Called with BQL or dirty_bitmap lock taken. */ BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, const char *= name) { @@ -109,6 +120,7 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverSt= ate *bs, return NULL; } bitmap =3D g_new0(BdrvDirtyBitmap, 1); + bitmap->mutex =3D &bs->dirty_bitmap_mutex; bitmap->bitmap =3D hbitmap_alloc(bitmap_size, ctz32(sector_granularity= )); bitmap->size =3D bitmap_size; bitmap->name =3D g_strdup(name); @@ -134,20 +146,24 @@ void bdrv_create_meta_dirty_bitmap(BdrvDirtyBitmap *b= itmap, int chunk_size) { assert(!bitmap->meta); + qemu_mutex_lock(bitmap->mutex); bitmap->meta =3D hbitmap_create_meta(bitmap->bitmap, chunk_size * BITS_PER_BYTE); + qemu_mutex_unlock(bitmap->mutex); } =20 void bdrv_release_meta_dirty_bitmap(BdrvDirtyBitmap *bitmap) { assert(bitmap->meta); + qemu_mutex_lock(bitmap->mutex); hbitmap_free_meta(bitmap->bitmap); bitmap->meta =3D NULL; + qemu_mutex_unlock(bitmap->mutex); } =20 -int bdrv_dirty_bitmap_get_meta(BlockDriverState *bs, - BdrvDirtyBitmap *bitmap, int64_t sector, - int nb_sectors) +int bdrv_dirty_bitmap_get_meta_locked(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, int64_t sec= tor, + int nb_sectors) { uint64_t i; int sectors_per_bit =3D 1 << hbitmap_granularity(bitmap->meta); @@ -162,11 +178,26 @@ int bdrv_dirty_bitmap_get_meta(BlockDriverState *bs, return false; } =20 +int bdrv_dirty_bitmap_get_meta(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, int64_t sector, + int nb_sectors) +{ + bool dirty; + + qemu_mutex_lock(bitmap->mutex); + dirty =3D bdrv_dirty_bitmap_get_meta_locked(bs, bitmap, sector, nb_sec= tors); + qemu_mutex_unlock(bitmap->mutex); + + return dirty; +} + void bdrv_dirty_bitmap_reset_meta(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, int64_t sector, int nb_sectors) { + qemu_mutex_lock(bitmap->mutex); hbitmap_reset(bitmap->meta, sector, nb_sectors); + qemu_mutex_unlock(bitmap->mutex); } =20 int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap) @@ -393,8 +424,9 @@ BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDrive= rState *bs) return list; } =20 -int bdrv_get_dirty(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, - int64_t sector) +/* Called within bdrv_dirty_bitmap_lock..unlock */ +int bdrv_get_dirty_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, + int64_t sector) { if (bitmap) { return hbitmap_get(bitmap->bitmap, sector); @@ -467,23 +499,42 @@ int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *ite= r) return hbitmap_iter_next(&iter->hbi); } =20 -void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, - int64_t cur_sector, int64_t nr_sectors) +/* Called within bdrv_dirty_bitmap_lock..unlock */ +void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, + int64_t cur_sector, int64_t nr_sectors) { assert(bdrv_dirty_bitmap_enabled(bitmap)); hbitmap_set(bitmap->bitmap, cur_sector, nr_sectors); } =20 -void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, - int64_t cur_sector, int64_t nr_sectors) +void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, + int64_t cur_sector, int64_t nr_sectors) +{ + bdrv_dirty_bitmap_lock(bitmap); + bdrv_set_dirty_bitmap_locked(bitmap, cur_sector, nr_sectors); + bdrv_dirty_bitmap_unlock(bitmap); +} + +/* Called within bdrv_dirty_bitmap_lock..unlock */ +void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, + int64_t cur_sector, int64_t nr_sectors) { assert(bdrv_dirty_bitmap_enabled(bitmap)); hbitmap_reset(bitmap->bitmap, cur_sector, nr_sectors); } =20 +void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, + int64_t cur_sector, int64_t nr_sectors) +{ + bdrv_dirty_bitmap_lock(bitmap); + bdrv_reset_dirty_bitmap_locked(bitmap, cur_sector, nr_sectors); + bdrv_dirty_bitmap_unlock(bitmap); +} + void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out) { assert(bdrv_dirty_bitmap_enabled(bitmap)); + bdrv_dirty_bitmap_lock(bitmap); if (!out) { hbitmap_reset_all(bitmap->bitmap); } else { @@ -492,6 +543,7 @@ void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, H= Bitmap **out) hbitmap_granularity(backup)); *out =3D backup; } + bdrv_dirty_bitmap_unlock(bitmap); } =20 void bdrv_undo_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *in) diff --git a/block/mirror.c b/block/mirror.c index 88ae882..19afcc6 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -342,6 +342,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) int max_io_sectors =3D MAX((s->buf_size >> BDRV_SECTOR_BITS) / MAX_IN_= FLIGHT, MAX_IO_SECTORS); =20 + bdrv_dirty_bitmap_lock(s->dirty_bitmap); sector_num =3D bdrv_dirty_iter_next(s->dbi); if (sector_num < 0) { bdrv_set_dirty_iter(s->dbi, 0); @@ -349,6 +350,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) trace_mirror_restart_iter(s, bdrv_get_dirty_count(s->dirty_bitmap)= ); assert(sector_num >=3D 0); } + bdrv_dirty_bitmap_unlock(s->dirty_bitmap); =20 first_chunk =3D sector_num / sectors_per_chunk; while (test_bit(first_chunk, s->in_flight_bitmap)) { @@ -360,12 +362,13 @@ static uint64_t coroutine_fn mirror_iteration(MirrorB= lockJob *s) =20 /* Find the number of consective dirty chunks following the first dirty * one, and wait for in flight requests in them. */ + bdrv_dirty_bitmap_lock(s->dirty_bitmap); while (nb_chunks * sectors_per_chunk < (s->buf_size >> BDRV_SECTOR_BIT= S)) { int64_t next_dirty; int64_t next_sector =3D sector_num + nb_chunks * sectors_per_chunk; int64_t next_chunk =3D next_sector / sectors_per_chunk; if (next_sector >=3D end || - !bdrv_get_dirty(source, s->dirty_bitmap, next_sector)) { + !bdrv_get_dirty_locked(source, s->dirty_bitmap, next_sector)) { break; } if (test_bit(next_chunk, s->in_flight_bitmap)) { @@ -386,8 +389,10 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBl= ockJob *s) * calling bdrv_get_block_status_above could yield - if some blocks are * marked dirty in this window, we need to know. */ - bdrv_reset_dirty_bitmap(s->dirty_bitmap, sector_num, - nb_chunks * sectors_per_chunk); + bdrv_reset_dirty_bitmap_locked(s->dirty_bitmap, sector_num, + nb_chunks * sectors_per_chunk); + bdrv_dirty_bitmap_unlock(s->dirty_bitmap); + bitmap_set(s->in_flight_bitmap, sector_num / sectors_per_chunk, nb_chu= nks); while (nb_chunks > 0 && sector_num < end) { int64_t ret; diff --git a/include/block/block_int.h b/include/block/block_int.h index c834b86..15c656d 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -611,8 +611,8 @@ struct BlockDriverState { =20 /* Writing to the list requires the BQL _and_ the dirty_bitmap_mutex. * Reading from the list can be done with either the BQL or the - * dirty_bitmap_mutex. Modifying a bitmap requires the AioContext - * lock. */ + * dirty_bitmap_mutex. Modifying a bitmap only requires + * dirty_bitmap_mutex. */ QemuMutex dirty_bitmap_mutex; QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps; =20 diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 9dea14b..ad6558a 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -36,8 +36,6 @@ bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap); const char *bdrv_dirty_bitmap_name(const BdrvDirtyBitmap *bitmap); int64_t bdrv_dirty_bitmap_size(const BdrvDirtyBitmap *bitmap); DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap); -int bdrv_get_dirty(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, - int64_t sector); void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap, int64_t cur_sector, int64_t nr_sectors); void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, @@ -45,6 +43,9 @@ void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, int bdrv_dirty_bitmap_get_meta(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, int64_t sector, int nb_sectors); +int bdrv_dirty_bitmap_get_meta_locked(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, int64_t sec= tor, + int nb_sectors); void bdrv_dirty_bitmap_reset_meta(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, int64_t sector, int nb_sectors); @@ -52,11 +53,6 @@ BdrvDirtyBitmapIter *bdrv_dirty_meta_iter_new(BdrvDirtyB= itmap *bitmap); BdrvDirtyBitmapIter *bdrv_dirty_iter_new(BdrvDirtyBitmap *bitmap, uint64_t first_sector); void bdrv_dirty_iter_free(BdrvDirtyBitmapIter *iter); -int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter); -void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t sector_num); -int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); -int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap); -void bdrv_dirty_bitmap_truncate(BlockDriverState *bs); =20 uint64_t bdrv_dirty_bitmap_serialization_size(const BdrvDirtyBitmap *bitma= p, uint64_t start, uint64_t cou= nt); @@ -72,4 +68,19 @@ void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitma= p *bitmap, bool finish); void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap); =20 +/* Functions that require manual locking. */ +void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap); +void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap); +int bdrv_get_dirty_locked(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, + int64_t sector); +void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, + int64_t cur_sector, int64_t nr_sectors); +void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap, + int64_t cur_sector, int64_t nr_sectors= ); +int64_t bdrv_dirty_iter_next(BdrvDirtyBitmapIter *iter); +void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_t sector_num); +int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); +int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap); +void bdrv_dirty_bitmap_truncate(BlockDriverState *bs); + #endif diff --git a/migration/block.c b/migration/block.c index 8fe484e..d102c84 100644 --- a/migration/block.c +++ b/migration/block.c @@ -529,14 +529,15 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigD= evState *bmds, } else { blk_mig_unlock(); } - if (bdrv_get_dirty(bs, bmds->dirty_bitmap, sector)) { - + bdrv_dirty_bitmap_lock(bmds->dirty_bitmap); + if (bdrv_get_dirty_locked(bs, bmds->dirty_bitmap, sector)) { if (total_sectors - sector < BDRV_SECTORS_PER_DIRTY_CHUNK) { nr_sectors =3D total_sectors - sector; } else { nr_sectors =3D BDRV_SECTORS_PER_DIRTY_CHUNK; } - bdrv_reset_dirty_bitmap(bmds->dirty_bitmap, sector, nr_sectors= ); + bdrv_reset_dirty_bitmap_locked(bmds->dirty_bitmap, sector, nr_= sectors); + bdrv_dirty_bitmap_unlock(bmds->dirty_bitmap); =20 blk =3D g_new(BlkMigBlock, 1); blk->buf =3D g_malloc(BLOCK_SIZE); @@ -572,9 +573,10 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDe= vState *bmds, =20 sector +=3D nr_sectors; bmds->cur_dirty =3D sector; - break; } + + bdrv_dirty_bitmap_unlock(bmds->dirty_bitmap); sector +=3D BDRV_SECTORS_PER_DIRTY_CHUNK; bmds->cur_dirty =3D sector; } --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496391905538787.6374778640749; Fri, 2 Jun 2017 01:25:05 -0700 (PDT) Received: from localhost ([::1]:48483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhtI-00053C-1b for importer@patchew.org; Fri, 02 Jun 2017 04:25:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhh4-0002jF-CO for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhgy-0002Zx-Kr for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60362) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhgy-0002ZS-BI for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:20 -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 mx1.redhat.com (Postfix) with ESMTPS id 65408C04B920; Fri, 2 Jun 2017 08:12:19 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id C905918863; Fri, 2 Jun 2017 08:12:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 65408C04B920 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 65408C04B920 From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:19 +0800 Message-Id: <20170602081120.3497-22-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 02 Jun 2017 08:12:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 21/22] block: introduce block_account_one_io X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini This is the common code to account operations that produced actual I/O. Reviewed-by: Alberto Garcia Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-18-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/accounting.c | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/block/accounting.c b/block/accounting.c index 3f457c4..a279e0b 100644 --- a/block/accounting.c +++ b/block/accounting.c @@ -86,7 +86,8 @@ void block_acct_start(BlockAcctStats *stats, BlockAcctCoo= kie *cookie, cookie->type =3D type; } =20 -void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie) +static void block_account_one_io(BlockAcctStats *stats, BlockAcctCookie *c= ookie, + bool failed) { BlockAcctTimedStats *s; int64_t time_ns =3D qemu_clock_get_ns(clock_type); @@ -98,31 +99,14 @@ void block_acct_done(BlockAcctStats *stats, BlockAcctCo= okie *cookie) =20 assert(cookie->type < BLOCK_MAX_IOTYPE); =20 - stats->nr_bytes[cookie->type] +=3D cookie->bytes; - stats->nr_ops[cookie->type]++; - stats->total_time_ns[cookie->type] +=3D latency_ns; - stats->last_access_time_ns =3D time_ns; - - QSLIST_FOREACH(s, &stats->intervals, entries) { - timed_average_account(&s->latency[cookie->type], latency_ns); + if (failed) { + stats->failed_ops[cookie->type]++; + } else { + stats->nr_bytes[cookie->type] +=3D cookie->bytes; + stats->nr_ops[cookie->type]++; } -} - -void block_acct_failed(BlockAcctStats *stats, BlockAcctCookie *cookie) -{ - assert(cookie->type < BLOCK_MAX_IOTYPE); - - stats->failed_ops[cookie->type]++; - - if (stats->account_failed) { - BlockAcctTimedStats *s; - int64_t time_ns =3D qemu_clock_get_ns(clock_type); - int64_t latency_ns =3D time_ns - cookie->start_time_ns; - - if (qtest_enabled()) { - latency_ns =3D qtest_latency_ns; - } =20 + if (!failed || stats->account_failed) { stats->total_time_ns[cookie->type] +=3D latency_ns; stats->last_access_time_ns =3D time_ns; =20 @@ -132,15 +116,24 @@ void block_acct_failed(BlockAcctStats *stats, BlockAc= ctCookie *cookie) } } =20 +void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie) +{ + block_account_one_io(stats, cookie, false); +} + +void block_acct_failed(BlockAcctStats *stats, BlockAcctCookie *cookie) +{ + block_account_one_io(stats, cookie, true); +} + void block_acct_invalid(BlockAcctStats *stats, enum BlockAcctType type) { assert(type < BLOCK_MAX_IOTYPE); =20 - /* block_acct_done() and block_acct_failed() update - * total_time_ns[], but this one does not. The reason is that - * invalid requests are accounted during their submission, - * therefore there's no actual I/O involved. */ - + /* block_account_one_io() updates total_time_ns[], but this one does + * not. The reason is that invalid requests are accounted during their + * submission, therefore there's no actual I/O involved. + */ stats->invalid_ops[type]++; =20 if (stats->account_invalid) { --=20 2.9.4 From nobody Mon Feb 9 13:56:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496392087345942.4272904460292; Fri, 2 Jun 2017 01:28:07 -0700 (PDT) Received: from localhost ([::1]:48499 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhwD-0007hC-Ur for importer@patchew.org; Fri, 02 Jun 2017 04:28:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGhh3-0002iB-TN for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGhh2-0002c2-Lg for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51786) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dGhh2-0002bf-D0 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 04:12:24 -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 mx1.redhat.com (Postfix) with ESMTPS id 797B17F6AC; Fri, 2 Jun 2017 08:12:23 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-49.pek2.redhat.com [10.72.12.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE8C260A99; Fri, 2 Jun 2017 08:12:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 797B17F6AC Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 797B17F6AC From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 2 Jun 2017 16:11:20 +0800 Message-Id: <20170602081120.3497-23-famz@redhat.com> In-Reply-To: <20170602081120.3497-1-famz@redhat.com> References: <20170602081120.3497-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 02 Jun 2017 08:12:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 22/22] block: make accounting thread-safe X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini I'm not trying too hard yet. Later, with multiqueue support, this may cause mutex contention or cacheline bouncing. Reviewed-by: Alberto Garcia Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-Id: <20170525163225.29954-19-pbonzini@redhat.com> Signed-off-by: Fam Zheng --- block/accounting.c | 16 ++++++++++++++++ include/block/accounting.h | 8 ++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/block/accounting.c b/block/accounting.c index a279e0b..37ed66f 100644 --- a/block/accounting.c +++ b/block/accounting.c @@ -35,6 +35,7 @@ static const int qtest_latency_ns =3D NANOSECONDS_PER_SEC= OND / 1000; void block_acct_init(BlockAcctStats *stats, bool account_invalid, bool account_failed) { + qemu_mutex_init(&stats->lock); stats->account_invalid =3D account_invalid; stats->account_failed =3D account_failed; =20 @@ -49,6 +50,7 @@ void block_acct_cleanup(BlockAcctStats *stats) QSLIST_FOREACH_SAFE(s, &stats->intervals, entries, next) { g_free(s); } + qemu_mutex_destroy(&stats->lock); } =20 void block_acct_add_interval(BlockAcctStats *stats, unsigned interval_leng= th) @@ -58,12 +60,15 @@ void block_acct_add_interval(BlockAcctStats *stats, uns= igned interval_length) =20 s =3D g_new0(BlockAcctTimedStats, 1); s->interval_length =3D interval_length; + s->stats =3D stats; + qemu_mutex_lock(&stats->lock); QSLIST_INSERT_HEAD(&stats->intervals, s, entries); =20 for (i =3D 0; i < BLOCK_MAX_IOTYPE; i++) { timed_average_init(&s->latency[i], clock_type, (uint64_t) interval_length * NANOSECONDS_PER_SE= COND); } + qemu_mutex_unlock(&stats->lock); } =20 BlockAcctTimedStats *block_acct_interval_next(BlockAcctStats *stats, @@ -99,6 +104,8 @@ static void block_account_one_io(BlockAcctStats *stats, = BlockAcctCookie *cookie, =20 assert(cookie->type < BLOCK_MAX_IOTYPE); =20 + qemu_mutex_lock(&stats->lock); + if (failed) { stats->failed_ops[cookie->type]++; } else { @@ -114,6 +121,8 @@ static void block_account_one_io(BlockAcctStats *stats,= BlockAcctCookie *cookie, timed_average_account(&s->latency[cookie->type], latency_ns); } } + + qemu_mutex_unlock(&stats->lock); } =20 void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie) @@ -134,18 +143,23 @@ void block_acct_invalid(BlockAcctStats *stats, enum B= lockAcctType type) * not. The reason is that invalid requests are accounted during their * submission, therefore there's no actual I/O involved. */ + qemu_mutex_lock(&stats->lock); stats->invalid_ops[type]++; =20 if (stats->account_invalid) { stats->last_access_time_ns =3D qemu_clock_get_ns(clock_type); } + qemu_mutex_unlock(&stats->lock); } =20 void block_acct_merge_done(BlockAcctStats *stats, enum BlockAcctType type, int num_requests) { assert(type < BLOCK_MAX_IOTYPE); + + qemu_mutex_lock(&stats->lock); stats->merged[type] +=3D num_requests; + qemu_mutex_unlock(&stats->lock); } =20 int64_t block_acct_idle_time_ns(BlockAcctStats *stats) @@ -160,7 +174,9 @@ double block_acct_queue_depth(BlockAcctTimedStats *stat= s, =20 assert(type < BLOCK_MAX_IOTYPE); =20 + qemu_mutex_lock(&stats->stats->lock); sum =3D timed_average_sum(&stats->latency[type], &elapsed); + qemu_mutex_unlock(&stats->stats->lock); =20 return (double) sum / elapsed; } diff --git a/include/block/accounting.h b/include/block/accounting.h index 2089163..2687be7 100644 --- a/include/block/accounting.h +++ b/include/block/accounting.h @@ -26,8 +26,10 @@ #define BLOCK_ACCOUNTING_H =20 #include "qemu/timed-average.h" +#include "qemu/thread.h" =20 typedef struct BlockAcctTimedStats BlockAcctTimedStats; +typedef struct BlockAcctStats BlockAcctStats; =20 enum BlockAcctType { BLOCK_ACCT_READ, @@ -37,12 +39,14 @@ enum BlockAcctType { }; =20 struct BlockAcctTimedStats { + BlockAcctStats *stats; TimedAverage latency[BLOCK_MAX_IOTYPE]; unsigned interval_length; /* in seconds */ QSLIST_ENTRY(BlockAcctTimedStats) entries; }; =20 -typedef struct BlockAcctStats { +struct BlockAcctStats { + QemuMutex lock; uint64_t nr_bytes[BLOCK_MAX_IOTYPE]; uint64_t nr_ops[BLOCK_MAX_IOTYPE]; uint64_t invalid_ops[BLOCK_MAX_IOTYPE]; @@ -53,7 +57,7 @@ typedef struct BlockAcctStats { QSLIST_HEAD(, BlockAcctTimedStats) intervals; bool account_invalid; bool account_failed; -} BlockAcctStats; +}; =20 typedef struct BlockAcctCookie { int64_t bytes; --=20 2.9.4