From patchwork Wed Mar 16 14:16:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8601081 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 55B6D9F6E1 for ; Wed, 16 Mar 2016 14:23:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AF6D32034B for ; Wed, 16 Mar 2016 14:23:14 +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 1FDD3202AE for ; Wed, 16 Mar 2016 14:23:09 +0000 (UTC) Received: from localhost ([::1]:56651 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agCLs-0005YU-G1 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 16 Mar 2016 10:23:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agCGJ-0003DR-2d for qemu-devel@nongnu.org; Wed, 16 Mar 2016 10:17:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agCGI-00065d-1N for qemu-devel@nongnu.org; Wed, 16 Mar 2016 10:17:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45419) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agCGH-00065T-Sh for qemu-devel@nongnu.org; Wed, 16 Mar 2016 10:17:21 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 9BD097001F for ; Wed, 16 Mar 2016 14:17:21 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2GEGwc5001673; Wed, 16 Mar 2016 10:17:20 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 16 Mar 2016 15:16:53 +0100 Message-Id: <1458137817-15383-13-git-send-email-pbonzini@redhat.com> In-Reply-To: <1458137817-15383-1-git-send-email-pbonzini@redhat.com> References: <1458137817-15383-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: famz@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v2 12/16] aio: introduce aio_context_in_iothread 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 This will be used by bdrv_drain (and indirectly by the synchronous I/O helpers), to choose between aio_poll or QemuEvent. Reviewed-by: Fam Zheng Signed-off-by: Paolo Bonzini --- include/block/aio.h | 7 +++++++ iothread.c | 9 +++++++++ stubs/Makefile.objs | 1 + stubs/iothread.c | 8 ++++++++ 4 files changed, 25 insertions(+) create mode 100644 stubs/iothread.c diff --git a/include/block/aio.h b/include/block/aio.h index e086e3b..9434665 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -435,6 +435,13 @@ static inline bool aio_node_check(AioContext *ctx, bool is_external) } /** + * @ctx: the aio context + * + * Return whether we are running in the I/O thread that manages @ctx. + */ +bool aio_context_in_iothread(AioContext *ctx); + +/** * aio_context_setup: * @ctx: the aio context * diff --git a/iothread.c b/iothread.c index f183d38..8d40bb0 100644 --- a/iothread.c +++ b/iothread.c @@ -20,6 +20,7 @@ #include "qmp-commands.h" #include "qemu/error-report.h" #include "qemu/rcu.h" +#include "qemu/main-loop.h" typedef ObjectClass IOThreadClass; @@ -28,6 +29,13 @@ typedef ObjectClass IOThreadClass; #define IOTHREAD_CLASS(klass) \ OBJECT_CLASS_CHECK(IOThreadClass, klass, TYPE_IOTHREAD) +static __thread IOThread *my_iothread; + +bool aio_context_in_iothread(AioContext *ctx) +{ + return ctx == (my_iothread ? my_iothread->ctx : qemu_get_aio_context()); +} + static void *iothread_run(void *opaque) { IOThread *iothread = opaque; @@ -35,6 +43,7 @@ static void *iothread_run(void *opaque) rcu_register_thread(); + my_iothread = iothread; qemu_mutex_lock(&iothread->init_done_lock); iothread->thread_id = qemu_get_thread_id(); qemu_cond_signal(&iothread->init_done_cond); diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index e922de9..187cee1 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -13,6 +13,7 @@ stub-obj-y += gdbstub.o stub-obj-y += get-fd.o stub-obj-y += get-next-serial.o stub-obj-y += get-vm-name.o +stub-obj-y += iothread.o stub-obj-y += iothread-lock.o stub-obj-y += is-daemonized.o stub-obj-y += machine-init-done.o diff --git a/stubs/iothread.c b/stubs/iothread.c new file mode 100644 index 0000000..6c02323 --- /dev/null +++ b/stubs/iothread.c @@ -0,0 +1,8 @@ +#include "qemu/osdep.h" +#include "block/aio.h" +#include "qemu/main-loop.h" + +bool aio_context_in_iothread(AioContext *ctx) +{ + return ctx == qemu_get_aio_context(); +}