From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V62lH-0006oM-9X for qemu-devel@nongnu.org; Sun, 04 Aug 2013 14:10:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V62lD-00063B-Tg for qemu-devel@nongnu.org; Sun, 04 Aug 2013 14:10:35 -0400 Received: from mail.avalus.com ([2001:41c8:10:1dd::10]:36527) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V62lD-00062t-Ji for qemu-devel@nongnu.org; Sun, 04 Aug 2013 14:10:31 -0400 From: Alex Bligh Date: Sun, 4 Aug 2013 19:09:56 +0100 Message-Id: <1375639805-1943-8-git-send-email-alex@alex.org.uk> In-Reply-To: <1375639805-1943-1-git-send-email-alex@alex.org.uk> References: <714109BBB1F743A30290732C@nimrod.local> <1375639805-1943-1-git-send-email-alex@alex.org.uk> Subject: [Qemu-devel] [RFC] [PATCHv5 07/16] aio / timers: Add QEMUTimerListGroup and helper functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Anthony Liguori , Alex Bligh , liu ping fan , Stefan Hajnoczi , Paolo Bonzini , MORITA Kazutaka , rth@twiddle.net Add QEMUTimerListGroup and helper functions, to represent a QEMUTimerList associated with each clock. Add a default QEMUTimerListGroup representing the default timer lists which are not associated with any other object (e.g. an AioContext as added by future patches). Signed-off-by: Alex Bligh --- include/qemu/timer.h | 7 +++++++ qemu-timer.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 9f1ff95..87e7b6e 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -19,8 +19,10 @@ typedef enum { typedef struct QEMUClock QEMUClock; typedef struct QEMUTimerList QEMUTimerList; +typedef QEMUTimerList * QEMUTimerListGroup[QEMU_CLOCK_MAX]; typedef void QEMUTimerCB(void *opaque); +extern QEMUTimerListGroup qemu_default_tlg; extern QEMUClock *QEMUClocks[QEMU_CLOCK_MAX]; static inline QEMUClock *qemu_get_clock(QEMUClockType type) @@ -69,6 +71,11 @@ int64_t timerlist_deadline_ns(QEMUTimerList *tl); QEMUClock *timerlist_get_clock(QEMUTimerList *tl); bool timerlist_run_timers(QEMUTimerList *tl); +void timerlistgroup_init(QEMUTimerListGroup tlg); +void timerlistgroup_deinit(QEMUTimerListGroup tlg); +bool timerlistgroup_run_timers(QEMUTimerListGroup tlg); +int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup tlg); + int qemu_timeout_ns_to_ms(int64_t ns); int qemu_poll_ns(GPollFD *fds, uint nfds, int64_t timeout); void qemu_clock_enable(QEMUClock *clock, bool enabled); diff --git a/qemu-timer.c b/qemu-timer.c index 231953a..1af3b65 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -59,6 +59,7 @@ struct QEMUClock { bool enabled; }; +QEMUTimerListGroup qemu_default_tlg; QEMUClock *QEMUClocks[QEMU_CLOCK_MAX]; /* A QEMUTimerList is a list of timers attached to a clock. More @@ -569,6 +570,45 @@ bool qemu_run_timers(QEMUClock *clock) return timerlist_run_timers(clock->default_timerlist); } +void timerlistgroup_init(QEMUTimerListGroup tlg) +{ + QEMUClockType clock; + for (clock = 0; clock < QEMU_CLOCK_MAX; clock++) { + tlg[clock] = timerlist_new(clock); + } +} + +void timerlistgroup_deinit(QEMUTimerListGroup tlg) +{ + QEMUClockType clock; + for (clock = 0; clock < QEMU_CLOCK_MAX; clock++) { + timerlist_free(tlg[clock]); + } +} + +bool timerlistgroup_run_timers(QEMUTimerListGroup tlg) +{ + QEMUClockType clock; + bool progress = false; + for (clock = 0; clock < QEMU_CLOCK_MAX; clock++) { + progress |= timerlist_run_timers(tlg[clock]); + } + return progress; +} + +int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup tlg) +{ + int64_t deadline = -1; + QEMUClockType clock; + for (clock = 0; clock < QEMU_CLOCK_MAX; clock++) { + if (qemu_clock_use_for_deadline(tlg[clock]->clock)) { + deadline = qemu_soonest_timeout(deadline, + timerlist_deadline_ns(tlg[clock])); + } + } + return deadline; +} + int64_t qemu_get_clock_ns(QEMUClock *clock) { int64_t now, last; @@ -610,6 +650,7 @@ void init_clocks(void) for (type = 0; type < QEMU_CLOCK_MAX; type++) { if (!QEMUClocks[type]) { QEMUClocks[type] = qemu_new_clock(type); + qemu_default_tlg[type] = QEMUClocks[type]->default_timerlist; } } -- 1.7.9.5