From patchwork Wed Aug 21 15:02:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Bligh X-Patchwork-Id: 268828 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 0186C2C00D7 for ; Thu, 22 Aug 2013 01:04:25 +1000 (EST) Received: from localhost ([::1]:54208 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VC9xP-000051-1s for incoming@patchwork.ozlabs.org; Wed, 21 Aug 2013 11:04:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35068) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VC9wc-0008PG-7t for qemu-devel@nongnu.org; Wed, 21 Aug 2013 11:03:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VC9wW-0004HX-9M for qemu-devel@nongnu.org; Wed, 21 Aug 2013 11:03:34 -0400 Received: from mail.avalus.com ([2001:41c8:10:1dd::10]:47484) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VC9wW-0004G9-0V for qemu-devel@nongnu.org; Wed, 21 Aug 2013 11:03:28 -0400 Received: by mail.avalus.com (Postfix) with ESMTPSA id 0AFBAC561B5; Wed, 21 Aug 2013 16:03:27 +0100 (BST) From: Alex Bligh To: qemu-devel@nongnu.org Date: Wed, 21 Aug 2013 16:02:45 +0100 Message-Id: <1377097389-27335-8-git-send-email-alex@alex.org.uk> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1377097389-27335-1-git-send-email-alex@alex.org.uk> References: <1377097389-27335-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 , Jan Kiszka , liu ping fan , Stefan Hajnoczi , Paolo Bonzini , MORITA Kazutaka , rth@twiddle.net Subject: [Qemu-devel] [PATCHv13 07/31] aio / timers: Make qemu_run_timers and qemu_run_all_timers return progress 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 Make qemu_run_timers and qemu_run_all_timers return progress so that aio_poll etc. can determine whether a timer has been run. Signed-off-by: Alex Bligh --- include/qemu/timer.h | 21 +++++++++++++++++++-- qemu-timer.c | 18 ++++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index fcc3ca0..fcb6a42 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -92,8 +92,25 @@ bool timer_pending(QEMUTimer *ts); bool timer_expired(QEMUTimer *timer_head, int64_t current_time); uint64_t timer_expire_time_ns(QEMUTimer *ts); -void qemu_run_timers(QEMUClock *clock); -void qemu_run_all_timers(void); +/** + * qemu_run_timers: + * @clock: clock on which to operate + * + * Run all the timers associated with a clock. + * + * Returns: true if any timer ran. + */ +bool qemu_run_timers(QEMUClock *clock); + +/** + * qemu_run_all_timers: + * + * Run all the timers associated with every clock. + * + * Returns: true if any timer ran. + */ +bool qemu_run_all_timers(void); + void configure_alarms(char const *opt); void init_clocks(void); int init_timer_alarm(void); diff --git a/qemu-timer.c b/qemu-timer.c index f224b62..4a10315 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -446,13 +446,14 @@ bool timer_expired(QEMUTimer *timer_head, int64_t current_time) return timer_expired_ns(timer_head, current_time * timer_head->scale); } -void qemu_run_timers(QEMUClock *clock) +bool qemu_run_timers(QEMUClock *clock) { QEMUTimer *ts; int64_t current_time; + bool progress = false; if (!clock->enabled) - return; + return progress; current_time = qemu_get_clock_ns(clock); for(;;) { @@ -466,7 +467,9 @@ void qemu_run_timers(QEMUClock *clock) /* run the callback (the timer list can be modified) */ ts->cb(ts->opaque); + progress = true; } + return progress; } int64_t qemu_get_clock_ns(QEMUClock *clock) @@ -521,20 +524,23 @@ uint64_t timer_expire_time_ns(QEMUTimer *ts) return timer_pending(ts) ? ts->expire_time : -1; } -void qemu_run_all_timers(void) +bool qemu_run_all_timers(void) { + bool progress = false; alarm_timer->pending = false; /* vm time timers */ - qemu_run_timers(vm_clock); - qemu_run_timers(rt_clock); - qemu_run_timers(host_clock); + progress |= qemu_run_timers(vm_clock); + progress |= qemu_run_timers(rt_clock); + progress |= qemu_run_timers(host_clock); /* rearm timer, if not periodic */ if (alarm_timer->expired) { alarm_timer->expired = false; qemu_rearm_alarm_timer(alarm_timer); } + + return progress; } #ifdef _WIN32