From patchwork Sat Aug 10 10:06:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Bligh X-Patchwork-Id: 266193 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (unknown [IPv6:2001:4830:134:3::12]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BD0EC2C00D2 for ; Sat, 10 Aug 2013 20:07:40 +1000 (EST) Received: from localhost ([::1]:59511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V865C-0008TM-3H for incoming@patchwork.ozlabs.org; Sat, 10 Aug 2013 06:07:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V864X-0008Np-3x for qemu-devel@nongnu.org; Sat, 10 Aug 2013 06:06:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V864U-00059q-Kj for qemu-devel@nongnu.org; Sat, 10 Aug 2013 06:06:56 -0400 Received: from mail.avalus.com ([2001:41c8:10:1dd::10]:48416) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V864U-00059f-BO for qemu-devel@nongnu.org; Sat, 10 Aug 2013 06:06:54 -0400 Received: by mail.avalus.com (Postfix) with ESMTPSA id A7C23C561B2; Sat, 10 Aug 2013 11:06:53 +0100 (BST) From: Alex Bligh To: qemu-devel@nongnu.org Date: Sat, 10 Aug 2013 11:06:11 +0100 Message-Id: <1376129195-29872-8-git-send-email-alex@alex.org.uk> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1376129195-29872-1-git-send-email-alex@alex.org.uk> References: <1376129195-29872-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] [RFC] [PATCHv9 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