From patchwork Mon Oct 17 13:54:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 683008 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3syKsz2lLDz9s5g for ; Tue, 18 Oct 2016 01:12:55 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=OsbV+wJ3; dkim-atps=neutral Received: from localhost ([::1]:33336 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bw8eq-0001bB-7N for incoming@patchwork.ozlabs.org; Mon, 17 Oct 2016 10:12:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45506) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bw8Nt-0003HR-QR for qemu-devel@nongnu.org; Mon, 17 Oct 2016 09:55:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bw8Ns-0005LS-Ql for qemu-devel@nongnu.org; Mon, 17 Oct 2016 09:55:21 -0400 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]:33953) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bw8Ns-0005LM-Is; Mon, 17 Oct 2016 09:55:20 -0400 Received: by mail-lf0-x244.google.com with SMTP id x23so21102254lfi.1; Mon, 17 Oct 2016 06:55:20 -0700 (PDT) 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=V9stuLkU1/gNPxz3G9nVAbcXom5DcEr/1oQWHHvA2vo=; b=OsbV+wJ3sLCHcIWcT1WFzgW7RInRPAT/4OyMnZOWGvLucaN7SIL1PpVllUAjXUKlg/ yq++WbOUoUROyfTI1hgYg4+m9CCHcGG+jPQOeXSbeDQpfuz5Uo8f7p2eNRLjfgtVxfdt P+KRwvCi7//rpZQEmm0wpCBcsfF5Z6JBdyD9s64iLtJfbiXbLo3kostrpiNqbC8v79S/ NubMBLWCZfRnWi82qzIn6Ix1DON01mqkDDFpIvtnakCRA21r/i4CPnbQeD02UJmzGfhE jg0n3FknYjQII1C6Xehf0xdF/qZVXMvHs2PgS0xTYu0xagmFWu96p77E52mwux3tI0eD KYbg== 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=V9stuLkU1/gNPxz3G9nVAbcXom5DcEr/1oQWHHvA2vo=; b=bqw5lPZid5k0WBhKetu7hLIdJtcQXZJvAWxz+IkrhZF/4ZxF5L/2+BwawSxD3klqqO +jWVq+eFzwUbOpOe/Y3EZgPlaKZGR7jLUuXM0jCKiEnA3AQU03UKa8kresB+zj2+/Mk0 Ossx4qGLzy7K8Ar4v+f61SCF0TAEYsuI31uyfFoCIVXM4jFMtl5UwGC4meJSQ1N3P/tw TSQu+LEqqnjoBQ2D0HPAkcE/pdbCXuG6/EEsnyKwOd4ngsvpsePy0jguJkqd7gquE+wB +XoPMe/KpwV1aDcSu07GFFI7VbKk0e/Ag6DVczac7SfyktmclPyc9QdUhKwjA5aH5PW8 qGpQ== X-Gm-Message-State: AA6/9Rk0jLEfpsJAdPE3LVenH7uvD0EnL8y0t9FLxsN2n67DbbKB6CxqhcfQSnPxZh3vsQ== X-Received: by 10.28.10.146 with SMTP id 140mr8804036wmk.129.1476712519017; Mon, 17 Oct 2016 06:55:19 -0700 (PDT) Received: from donizetti.lan (94-39-170-54.adsl-ull.clienti.tiscali.it. [94.39.170.54]) by smtp.gmail.com with ESMTPSA id af4sm43814062wjc.17.2016.10.17.06.55.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Oct 2016 06:55:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 17 Oct 2016 15:54:21 +0200 Message-Id: <1476712470-11660-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476712470-11660-1-git-send-email-pbonzini@redhat.com> References: <1476712470-11660-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:4010:c07::244 Subject: [Qemu-devel] [PATCH 11/20] aio: introduce qemu_get_current_aio_context 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: kwolf@redhat.com, famz@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This will be used by BDRV_POLL_WHILE (and thus by bdrv_drain) to choose how to wait for I/O completion. Reviewed-by: Fam Zheng Signed-off-by: Paolo Bonzini --- v1->v2: adjust documentation according to Stefan's suggestion include/block/aio.h | 18 ++++++++++++++++++ iothread.c | 9 +++++++++ stubs/Makefile.objs | 1 + stubs/iothread.c | 8 ++++++++ 4 files changed, 36 insertions(+) create mode 100644 stubs/iothread.c diff --git a/include/block/aio.h b/include/block/aio.h index b9fe2cb..040b3b1 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -453,6 +453,24 @@ static inline bool aio_node_check(AioContext *ctx, bool is_external) } /** + * Return the AioContext whose event loop runs in the current thread. + * + * If called from an IOThread this will be the IOThread's AioContext. If + * called from another thread it will be the main loop AioContext. + */ +AioContext *qemu_get_current_aio_context(void); + +/** + * @ctx: the aio context + * + * Return whether we are running in the I/O thread that manages @ctx. + */ +static inline bool aio_context_in_iothread(AioContext *ctx) +{ + return ctx == qemu_get_current_aio_context(); +} + +/** * aio_context_setup: * @ctx: the aio context * diff --git a/iothread.c b/iothread.c index fbeb8de..62c8796 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; + +AioContext *qemu_get_current_aio_context(void) +{ + return 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 c5850e8..84b9d9e 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -17,6 +17,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..8cc9e28 --- /dev/null +++ b/stubs/iothread.c @@ -0,0 +1,8 @@ +#include "qemu/osdep.h" +#include "block/aio.h" +#include "qemu/main-loop.h" + +AioContext *qemu_get_current_aio_context(void) +{ + return qemu_get_aio_context(); +}