From patchwork Fri Jul 26 18:37:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Bligh X-Patchwork-Id: 262269 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 938402C00BD for ; Sat, 27 Jul 2013 05:54:48 +1000 (EST) Received: from localhost ([::1]:37836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2mxN-00085E-8s for incoming@patchwork.ozlabs.org; Fri, 26 Jul 2013 14:41:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2mu7-0003B0-Jb for qemu-devel@nongnu.org; Fri, 26 Jul 2013 14:38:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2mu5-0004C5-Bq for qemu-devel@nongnu.org; Fri, 26 Jul 2013 14:38:15 -0400 Received: from mail.avalus.com ([2001:41c8:10:1dd::10]:59421) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2mu5-0004C0-4K for qemu-devel@nongnu.org; Fri, 26 Jul 2013 14:38:13 -0400 Received: by mail.avalus.com (Postfix) with ESMTPSA id 2105DC561B0; Fri, 26 Jul 2013 19:38:12 +0100 (BST) From: Alex Bligh To: qemu-devel@nongnu.org Date: Fri, 26 Jul 2013 19:37:37 +0100 Message-Id: <1374863862-32517-9-git-send-email-alex@alex.org.uk> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1374863862-32517-1-git-send-email-alex@alex.org.uk> References: <34B083D4DB6D2988A571E420@nimrod.local> <1374863862-32517-1-git-send-email-alex@alex.org.uk> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:41c8:10:1dd::10 Cc: Kevin Wolf , Anthony Liguori , Alex Bligh , Stefan Hajnoczi , Paolo Bonzini , rth@twiddle.net Subject: [Qemu-devel] [RFC] [PATCHv4 08/13] aio / timers: aio_ctx_prepare sets timeout from AioContext timers 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 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 d3ed868..2a907e1 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_timerlist_deadline_ns(ctx->tl)); + 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_timerlist_deadline_ns(ctx->tl) >= 0); } static gboolean