From patchwork Wed Oct 31 15:30:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 195955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6A98C2C0180 for ; Thu, 1 Nov 2012 04:30:56 +1100 (EST) Received: from localhost ([::1]:32971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTaIA-0000zR-38 for incoming@patchwork.ozlabs.org; Wed, 31 Oct 2012 11:33:18 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTaHi-0000Vb-0s for qemu-devel@nongnu.org; Wed, 31 Oct 2012 11:32:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTaHg-0005Ys-JH for qemu-devel@nongnu.org; Wed, 31 Oct 2012 11:32:49 -0400 Received: from mail-da0-f45.google.com ([209.85.210.45]:43195) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTaHg-0005YY-Di for qemu-devel@nongnu.org; Wed, 31 Oct 2012 11:32:48 -0400 Received: by mail-da0-f45.google.com with SMTP id n15so666869dad.4 for ; Wed, 31 Oct 2012 08:32:47 -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:x-mailer:in-reply-to :references; bh=6N5kI1VqMpQlzI6I6m9xKZUx2QnoTAFyOmGc6kiKFqQ=; b=MoTvekBtpuHcuzvcQ4VHLJ4I1KyCnDi2NohBXvTghKkHpyZqHdhfLyLRaQ/zWRoTge LFCBbzzjz3xKA3zT+YYyBaHfosw2Tq8PR/ftQ1QI3NC9+6yzewt2hquGp32JJ9gIGp0+ +/2De2FfrfbF6vf43fnqQdPlOh6fbLOn8D4/cYlvp5LuWQjb5R+kOo5oR0HN1mhANo1i Wdiyf+mNOwVCFa4R0Lbmxp4+3NFTIBZenXX1jC6Qyo33v4On2UtQHsiq9ZHfUUh/yxXS kIbmcdXREVqUaGzlkVAIPZikZTL7/HYo0hFAxJ9gQXvXW8UvIB24RRXhv2d1Ft3/oytu 9NbQ== Received: by 10.66.90.65 with SMTP id bu1mr103130539pab.31.1351697567370; Wed, 31 Oct 2012 08:32:47 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id sz6sm2445230pbc.52.2012.10.31.08.32.44 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 31 Oct 2012 08:32:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 31 Oct 2012 16:30:42 +0100 Message-Id: <1351697456-16107-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1351697456-16107-1-git-send-email-pbonzini@redhat.com> References: <1351697456-16107-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.45 Cc: aliguori@us.ibm.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v2 25/39] aio: add aio_notify 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org With this change async.c does not rely anymore on any service from main-loop.c, i.e. it is completely self-contained. Reviewed-by: Anthony Liguori Signed-off-by: Paolo Bonzini --- async.c | 30 ++++++++++++++++++++++++++---- qemu-aio.h | 18 ++++++++++++++++++ 2 file modificati, 44 inserzioni(+), 4 rimozioni(-) diff --git a/async.c b/async.c index 4ffdd98..564526f 100644 --- a/async.c +++ b/async.c @@ -30,6 +30,7 @@ /* bottom halves (can be seen as timers which expire ASAP) */ struct QEMUBH { + AioContext *ctx; QEMUBHFunc *cb; void *opaque; QEMUBH *next; @@ -42,6 +43,7 @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque) { QEMUBH *bh; bh = g_malloc0(sizeof(QEMUBH)); + bh->ctx = ctx; bh->cb = cb; bh->opaque = opaque; bh->next = ctx->first_bh; @@ -101,8 +103,7 @@ void qemu_bh_schedule(QEMUBH *bh) return; bh->scheduled = 1; bh->idle = 0; - /* stop the currently executing CPU to execute the BH ASAP */ - qemu_notify_event(); + aio_notify(bh->ctx); } void qemu_bh_cancel(QEMUBH *bh) @@ -177,11 +178,20 @@ aio_ctx_dispatch(GSource *source, return true; } +static void +aio_ctx_finalize(GSource *source) +{ + AioContext *ctx = (AioContext *) source; + + aio_set_event_notifier(ctx, &ctx->notifier, NULL, NULL); + event_notifier_cleanup(&ctx->notifier); +} + static GSourceFuncs aio_source_funcs = { aio_ctx_prepare, aio_ctx_check, aio_ctx_dispatch, - NULL + aio_ctx_finalize }; GSource *aio_get_g_source(AioContext *ctx) @@ -190,9 +200,21 @@ GSource *aio_get_g_source(AioContext *ctx) return &ctx->source; } +void aio_notify(AioContext *ctx) +{ + event_notifier_set(&ctx->notifier); +} + AioContext *aio_context_new(void) { - return (AioContext *) g_source_new(&aio_source_funcs, sizeof(AioContext)); + AioContext *ctx; + ctx = (AioContext *) g_source_new(&aio_source_funcs, sizeof(AioContext)); + event_notifier_init(&ctx->notifier, false); + aio_set_event_notifier(ctx, &ctx->notifier, + (EventNotifierHandler *) + event_notifier_test_and_clear, NULL); + + return ctx; } void aio_context_ref(AioContext *ctx) diff --git a/qemu-aio.h b/qemu-aio.h index aedf66c..2354617 100644 --- a/qemu-aio.h +++ b/qemu-aio.h @@ -62,6 +62,9 @@ typedef struct AioContext { * no callbacks are removed while we're walking and dispatching callbacks. */ int walking_bh; + + /* Used for aio_notify. */ + EventNotifier notifier; } AioContext; /* Returns 1 if there are still outstanding AIO requests; 0 otherwise */ @@ -102,6 +105,21 @@ void aio_context_unref(AioContext *ctx); QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque); /** + * aio_notify: Force processing of pending events. + * + * Similar to signaling a condition variable, aio_notify forces + * aio_wait to exit, so that the next call will re-examine pending events. + * The caller of aio_notify will usually call aio_wait again very soon, + * or go through another iteration of the GLib main loop. Hence, aio_notify + * also has the side effect of recalculating the sets of file descriptors + * that the main loop waits for. + * + * Calling aio_notify is rarely necessary, because for example scheduling + * a bottom half calls it already. + */ +void aio_notify(AioContext *ctx); + +/** * aio_bh_poll: Poll bottom halves for an AioContext. * * These are internal functions used by the QEMU main loop.