From patchwork Mon Feb 8 16:15:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8251931 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 865959F1C1 for ; Mon, 8 Feb 2016 16:24:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB466203A4 for ; Mon, 8 Feb 2016 16:24:07 +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 052EC20389 for ; Mon, 8 Feb 2016 16:24:07 +0000 (UTC) Received: from localhost ([::1]:46290 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSobe-00033I-Dh for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 Feb 2016 11:24:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoTS-0006S5-4f for qemu-devel@nongnu.org; Mon, 08 Feb 2016 11:15:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSoTQ-0002UL-Ic for qemu-devel@nongnu.org; Mon, 08 Feb 2016 11:15:38 -0500 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:35450) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoTQ-0002U9-27 for qemu-devel@nongnu.org; Mon, 08 Feb 2016 11:15:36 -0500 Received: by mail-wm0-x243.google.com with SMTP id g62so16196832wme.2 for ; Mon, 08 Feb 2016 08:15:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=KRcoij6hlzqlc3GfEeVnm/R2GCxPedSM1FxZmvjB0Hw=; b=ZVhE9nA0nlRLryZX+bvMliG7gmyiwuntfy69sRjSeVnlLdWQjp2IBaU6e72y79MdUE ctuG6L69wXK9bJPJkahXu76dhybf4EmXh5F2Le7PJl3W7gBc6eImE3fXS8IzTo1Fht/W 74boxqTO36tyIIKz72T1KXeHEqbE5n3L10e+e9P9WcHLLo2HmM2KUsH3n36M0KejmXdu l5rDeYvNI+faMJ89uPorzsm2vK0owLC2T4tRCUK65Kq0rdXsn6VNAFIF7w3CK6aOQ+vT oViYUoZYDDArle53BcTlxa9ZBBcKEZnH9yMexa+st4UHs82kLGYmD84TZOcCrahJ0Bsn S5gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=KRcoij6hlzqlc3GfEeVnm/R2GCxPedSM1FxZmvjB0Hw=; b=nKoy9d7jlg0XuoLcPJl6KTyX/cXd6HXRo0PzPClx/iz4WGpZA443gHXnkiEJ2xy73q Akr3P/mzfQ0J88RkvYJG7MS1nePIgXanDzOwa9UWGOgju8e4CAN2RGBVDnhdeTCRVCSx GKJvB0bF1PVKMENgum0U8AI3vrxDuvYNYcw4U1Ovx7BqQl3BDPWf+Rfe7ysLF9BCEsMu s59fzksIEjvs8cK+MtY/etxreaH3twG0gMn6VCilGfSCJ+ES/Za6WEuxp8YOFFQ6DCTC Nuo+MmSgvLmS+FCaLNS/mnUB2HkPY9+m7MR9aRZIWimp3m9AfikzDy0vAn97n1QJprQb tzNg== X-Gm-Message-State: AG10YOSdGvJxSUfWhI21OIJcgdDkD/loGKdn/F5NhMfO3eGm+siBQSt6LOzunkX+a3ukiA== X-Received: by 10.194.114.164 with SMTP id jh4mr28395943wjb.153.1454948135619; Mon, 08 Feb 2016 08:15:35 -0800 (PST) Received: from donizetti.lan (94-39-141-130.adsl-ull.clienti.tiscali.it. [94.39.141.130]) by smtp.gmail.com with ESMTPSA id v2sm13305429wmd.24.2016.02.08.08.15.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Feb 2016 08:15:34 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 8 Feb 2016 17:15:06 +0100 Message-Id: <1454948107-11844-16-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454948107-11844-1-git-send-email-pbonzini@redhat.com> References: <1454948107-11844-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Cc: stefanha@redhat.com Subject: [Qemu-devel] [PATCH 15/16] aio: document locking 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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 Signed-off-by: Paolo Bonzini --- docs/multiple-iothreads.txt | 5 ++--- include/block/aio.h | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/docs/multiple-iothreads.txt b/docs/multiple-iothreads.txt index c5d38e9..8ec3777 100644 --- a/docs/multiple-iothreads.txt +++ b/docs/multiple-iothreads.txt @@ -84,9 +84,8 @@ How to synchronize with an IOThread AioContext is not thread-safe so some rules must be followed when using file descriptors, event notifiers, timers, or BHs across threads: -1. AioContext functions can be called safely from file descriptor, event -notifier, timer, or BH callbacks invoked by the AioContext. No locking is -necessary. +1. AioContext functions can always be called safely. They handle their +own locking internally. 2. Other threads wishing to access the AioContext must take the QEMU global mutex *as well as* call aio_context_acquire()/aio_context_release() for diff --git a/include/block/aio.h b/include/block/aio.h index fb0ff21..cea92b0 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -50,18 +50,12 @@ typedef void IOHandler(void *opaque); struct AioContext { GSource source; - /* Protects all fields from multi-threaded access */ + /* Used by AioContext users to protect from multi-threaded access. */ QemuRecMutex lock; - /* The list of registered AIO handlers */ + /* The list of registered AIO handlers. Protected by ctx->list_lock. */ QLIST_HEAD(, AioHandler) aio_handlers; - /* This is a simple lock used to protect the aio_handlers list. - * Specifically, it's used to ensure that no callbacks are removed while - * we're walking and dispatching callbacks. - */ - int walking_handlers; - /* Used to avoid unnecessary event_notifier_set calls in aio_notify; * accessed with atomic primitives. If this field is 0, everything * (file descriptors, bottom halves, timers) will be re-evaluated @@ -87,9 +81,9 @@ struct AioContext { */ uint32_t notify_me; - /* A lock to protect between bh's adders and deleter, and to ensure - * that no callbacks are removed while we're walking and dispatching - * them. + /* A lock to protect between QEMUBH and AioHandler adders and deleter, + * and to ensure that no callbacks are removed while we're walking and + * dispatching them. */ QemuLockCnt list_lock; @@ -111,10 +105,14 @@ struct AioContext { bool notified; EventNotifier notifier; - /* Thread pool for performing work and receiving completion callbacks */ + /* Thread pool for performing work and receiving completion callbacks. + * Has its own locking. + */ struct ThreadPool *thread_pool; - /* TimerLists for calling timers - one per clock type */ + /* TimerLists for calling timers - one per clock type. Has its own + * locking. + */ QEMUTimerListGroup tlg; int external_disable_cnt; @@ -162,9 +160,11 @@ void aio_context_unref(AioContext *ctx); * automatically takes care of calling aio_context_acquire and * aio_context_release. * - * Access to timers and BHs from a thread that has not acquired AioContext - * is possible. Access to callbacks for now must be done while the AioContext - * is owned by the thread (FIXME). + * Note that this is separate from bdrv_drained_begin/bdrv_drained_end. A + * thread still has to call those to avoid being interrupted by the guest. + * + * Bottom halves, timers and callbacks can be created or removed without + * acquiring the AioContext. */ void aio_context_acquire(AioContext *ctx);