From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38617) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2Tr3-0007of-7u for qemu-devel@nongnu.org; Thu, 25 Jul 2013 18:17:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2Tr1-0006TJ-Pm for qemu-devel@nongnu.org; Thu, 25 Jul 2013 18:17:49 -0400 Received: from mail.avalus.com ([2001:41c8:10:1dd::10]:40623) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2Tr1-0006Sp-Gl for qemu-devel@nongnu.org; Thu, 25 Jul 2013 18:17:47 -0400 From: Alex Bligh Date: Thu, 25 Jul 2013 23:16:43 +0100 Message-Id: <1374790608-7518-8-git-send-email-alex@alex.org.uk> In-Reply-To: <1374790608-7518-1-git-send-email-alex@alex.org.uk> References: <20130725093713.GG21033@stefanha-thinkpad.redhat.com> <1374790608-7518-1-git-send-email-alex@alex.org.uk> Subject: [Qemu-devel] [RFC] [PATCHv3 07/12] aio / timers: aio_ctx_prepare sets timeout from AioContext timers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Anthony Liguori , Alex Bligh , Stefan Hajnoczi , Paolo Bonzini , rth@twiddle.net Calculate the timeout in aio_ctx_prepare taking into account the timers attached to the AioContext. Alter aio_ctx_check similarly. Signed-off-by: Alex Bligh --- async.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/async.c b/async.c index 2968c68..a62c463 100644 --- a/async.c +++ b/async.c @@ -123,13 +123,14 @@ aio_ctx_prepare(GSource *source, gint *timeout) { AioContext *ctx = (AioContext *) source; QEMUBH *bh; + int deadline; for (bh = ctx->first_bh; bh; bh = bh->next) { if (!bh->deleted && bh->scheduled) { if (bh->idle) { /* idle bottom halves will be polled at least * every 10ms */ - *timeout = 10; + *timeout = qemu_soonest_timeout(*timeout, 10); } else { /* non-idle bottom halves will be executed * immediately */ @@ -139,6 +140,14 @@ aio_ctx_prepare(GSource *source, gint *timeout) } } + deadline = qemu_timeout_ns_to_ms(qemu_clock_deadline_ns(ctx->clock)); + if (deadline == 0) { + *timeout = 0; + return true; + } else { + *timeout = qemu_soonest_timeout(*timeout, deadline); + } + return false; } @@ -153,7 +162,7 @@ aio_ctx_check(GSource *source) return true; } } - return aio_pending(ctx); + return aio_pending(ctx) || (qemu_clock_deadline_ns(ctx->clock) >= 0); } static gboolean -- 1.7.9.5