From patchwork Tue Feb 9 11:46:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8261501 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4FA7A9F38B for ; Tue, 9 Feb 2016 12:36:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B17E420260 for ; Tue, 9 Feb 2016 12:36:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 072872025A for ; Tue, 9 Feb 2016 12:36:04 +0000 (UTC) Received: from localhost ([::1]:54716 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aT6r3-00077D-Rw for patchwork-qemu-devel@patchwork.kernel.org; Tue, 09 Feb 2016 06:53:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aT6kP-000687-QL for qemu-devel@nongnu.org; Tue, 09 Feb 2016 06:46:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aT6kO-0005Ex-MF for qemu-devel@nongnu.org; Tue, 09 Feb 2016 06:46:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47520) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aT6kO-0005Et-HO for qemu-devel@nongnu.org; Tue, 09 Feb 2016 06:46:20 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 271FDC0C2349 for ; Tue, 9 Feb 2016 11:46:20 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-47.ams2.redhat.com [10.36.112.47]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u19BkELk002965; Tue, 9 Feb 2016 06:46:18 -0500 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 9 Feb 2016 12:46:00 +0100 Message-Id: <1455018374-4706-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1455018374-4706-1-git-send-email-pbonzini@redhat.com> References: <1455018374-4706-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: stefanha@redhat.com Subject: [Qemu-devel] [PATCH 02/16] aio: do not really acquire/release the main AIO context X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The main AIO context is used in many places that are not aware of AioContexts at all. bdrv_drain will soon do a release/acquire itself, which for the main AIO context would break because code calls bdrv_drain on it without acquiring anything. Very soon, bdrv will be ready for removal of aio_context_acquire from non-block-layer code. The idea is that the AioContext will be acquired by bdrv_*, and no one will care of what's running in the main I/O thread or in the dataplane thread. Even if there are two concurrent instances of the I/O thread, locks protect the data structures; this evolves naturally to the multiqueue case where there are multiple I/O threads touching the same BlockDriverState. When this happens, aio_context_acquire/release can go away, replaced by fine-grained locks, and this hack will also go away with it. Signed-off-by: Paolo Bonzini --- async.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/async.c b/async.c index d4dd2cc..d083564 100644 --- a/async.c +++ b/async.c @@ -369,10 +369,18 @@ void aio_context_unref(AioContext *ctx) void aio_context_acquire(AioContext *ctx) { - rfifolock_lock(&ctx->lock); + if (ctx == qemu_get_aio_context()) { + assert(qemu_mutex_iothread_locked()); + } else { + rfifolock_lock(&ctx->lock); + } } void aio_context_release(AioContext *ctx) { - rfifolock_unlock(&ctx->lock); + if (ctx == qemu_get_aio_context()) { + assert(qemu_mutex_iothread_locked()); + } else { + rfifolock_unlock(&ctx->lock); + } }