From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45622) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V62lK-0006sg-C9 for qemu-devel@nongnu.org; Sun, 04 Aug 2013 14:10:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V62lE-00063h-LL for qemu-devel@nongnu.org; Sun, 04 Aug 2013 14:10:38 -0400 Received: from mail.avalus.com ([2001:41c8:10:1dd::10]:45300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V62lE-00063U-D9 for qemu-devel@nongnu.org; Sun, 04 Aug 2013 14:10:32 -0400 From: Alex Bligh Date: Sun, 4 Aug 2013 19:09:58 +0100 Message-Id: <1375639805-1943-10-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 09/16] aio / timers: Add a notify callback to QEMUTimerList 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 a notify pointer to QEMUTimerList so it knows what to notify on a timer change. Signed-off-by: Alex Bligh --- async.c | 7 ++++++- include/qemu/timer.h | 7 ++++++- qemu-timer.c | 24 ++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/async.c b/async.c index b3512ca..c80da2f 100644 --- a/async.c +++ b/async.c @@ -206,6 +206,11 @@ void aio_notify(AioContext *ctx) event_notifier_set(&ctx->notifier); } +static void aio_timerlist_notify(void *opaque) +{ + aio_notify((AioContext *)opaque); +} + AioContext *aio_context_new(void) { AioContext *ctx; @@ -216,7 +221,7 @@ AioContext *aio_context_new(void) aio_set_event_notifier(ctx, &ctx->notifier, (EventNotifierHandler *) event_notifier_test_and_clear, NULL); - timerlistgroup_init(ctx->tlg); + timerlistgroup_init(ctx->tlg, aio_timerlist_notify, ctx); return ctx; } diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 87e7b6e..970042d 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -21,6 +21,7 @@ typedef struct QEMUClock QEMUClock; typedef struct QEMUTimerList QEMUTimerList; typedef QEMUTimerList * QEMUTimerListGroup[QEMU_CLOCK_MAX]; typedef void QEMUTimerCB(void *opaque); +typedef void QEMUTimerListNotifyCB(void *opaque); extern QEMUTimerListGroup qemu_default_tlg; extern QEMUClock *QEMUClocks[QEMU_CLOCK_MAX]; @@ -70,8 +71,12 @@ int64_t timerlist_deadline(QEMUTimerList *tl); int64_t timerlist_deadline_ns(QEMUTimerList *tl); QEMUClock *timerlist_get_clock(QEMUTimerList *tl); bool timerlist_run_timers(QEMUTimerList *tl); +void timerlist_set_notify_cb(QEMUTimerList *tl, + QEMUTimerListNotifyCB *cb, void *opaque); +void timerlist_notify(QEMUTimerList *tl); -void timerlistgroup_init(QEMUTimerListGroup tlg); +void timerlistgroup_init(QEMUTimerListGroup tlg, + QEMUTimerListNotifyCB *cb, void *opaque); void timerlistgroup_deinit(QEMUTimerListGroup tlg); bool timerlistgroup_run_timers(QEMUTimerListGroup tlg); int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup tlg); diff --git a/qemu-timer.c b/qemu-timer.c index 1af3b65..4562c70 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -73,6 +73,8 @@ struct QEMUTimerList { QEMUClock *clock; QEMUTimer *active_timers; QLIST_ENTRY(QEMUTimerList) list; + QEMUTimerListNotifyCB *notify_cb; + void *notify_opaque; }; struct QEMUTimer { @@ -388,6 +390,22 @@ QEMUTimerList *qemu_clock_get_default_timerlist(QEMUClock *clock) return clock->default_timerlist; } +void timerlist_set_notify_cb(QEMUTimerList *tl, + QEMUTimerListNotifyCB *cb, void *opaque) +{ + tl->notify_cb = cb; + tl->notify_opaque = opaque; +} + +void timerlist_notify(QEMUTimerList *tl) +{ + if (tl->notify_cb) { + tl->notify_cb(tl->notify_opaque); + } else { + qemu_notify_event(); + } +} + /* Transition function to convert a nanosecond timeout to ms * This is used where a system does not support ppoll */ @@ -512,7 +530,7 @@ void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) /* Interrupt execution to force deadline recalculation. */ qemu_clock_warp(ts->tl->clock); if (use_icount) { - qemu_notify_event(); + timerlist_notify(ts->tl); } } } @@ -570,11 +588,13 @@ bool qemu_run_timers(QEMUClock *clock) return timerlist_run_timers(clock->default_timerlist); } -void timerlistgroup_init(QEMUTimerListGroup tlg) +void timerlistgroup_init(QEMUTimerListGroup tlg, + QEMUTimerListNotifyCB *cb, void *opaque) { QEMUClockType clock; for (clock = 0; clock < QEMU_CLOCK_MAX; clock++) { tlg[clock] = timerlist_new(clock); + timerlist_set_notify_cb(tlg[clock], cb, opaque); } } -- 1.7.9.5