From e93379b039030c68d85693a4bee2b76f814108d2 Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:39 +0100 Subject: aio / timers: Rename qemu_timer_* functions Rename four functions in preparation for new API. Rename qemu_timer_expired to timer_expired Rename qemu_timer_expire_time_ns to timer_expire_time_ns Rename qemu_timer_pending to timer_pending Rename qemu_timer_expired_ns to timer_expired_ns Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index b2d95e2..682c50f 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -80,7 +80,7 @@ struct qemu_alarm_timer { static struct qemu_alarm_timer *alarm_timer; -static bool qemu_timer_expired_ns(QEMUTimer *timer_head, int64_t current_time) +static bool timer_expired_ns(QEMUTimer *timer_head, int64_t current_time) { return timer_head && (timer_head->expire_time <= current_time); } @@ -301,7 +301,7 @@ void qemu_del_timer(QEMUTimer *ts) QEMUTimer **pt, *t; /* NOTE: this code must be signal safe because - qemu_timer_expired() can be called from a signal. */ + timer_expired() can be called from a signal. */ pt = &ts->clock->active_timers; for(;;) { t = *pt; @@ -325,11 +325,11 @@ void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) /* add the timer in the sorted list */ /* NOTE: this code must be signal safe because - qemu_timer_expired() can be called from a signal. */ + timer_expired() can be called from a signal. */ pt = &ts->clock->active_timers; for(;;) { t = *pt; - if (!qemu_timer_expired_ns(t, expire_time)) { + if (!timer_expired_ns(t, expire_time)) { break; } pt = &t->next; @@ -356,7 +356,7 @@ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time) qemu_mod_timer_ns(ts, expire_time * ts->scale); } -bool qemu_timer_pending(QEMUTimer *ts) +bool timer_pending(QEMUTimer *ts) { QEMUTimer *t; for (t = ts->clock->active_timers; t != NULL; t = t->next) { @@ -367,9 +367,9 @@ bool qemu_timer_pending(QEMUTimer *ts) return false; } -bool qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time) +bool timer_expired(QEMUTimer *timer_head, int64_t current_time) { - return qemu_timer_expired_ns(timer_head, current_time * timer_head->scale); + return timer_expired_ns(timer_head, current_time * timer_head->scale); } void qemu_run_timers(QEMUClock *clock) @@ -383,7 +383,7 @@ void qemu_run_timers(QEMUClock *clock) current_time = qemu_get_clock_ns(clock); for(;;) { ts = clock->active_timers; - if (!qemu_timer_expired_ns(ts, current_time)) { + if (!timer_expired_ns(ts, current_time)) { break; } /* remove timer from the list before calling the callback */ @@ -439,9 +439,9 @@ void init_clocks(void) } } -uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts) +uint64_t timer_expire_time_ns(QEMUTimer *ts) { - return qemu_timer_pending(ts) ? ts->expire_time : -1; + return timer_pending(ts) ? ts->expire_time : -1; } void qemu_run_all_timers(void) -- cgit v1.1 From 58ac56b9ad53b006396523639bb7d7043edc56bf Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:40 +0100 Subject: aio / timers: Rename qemu_new_clock and expose clock types Rename qemu_new_clock to qemu_clock_new. Expose clock types. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 682c50f..4117add 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -40,10 +40,6 @@ /***********************************************************/ /* timers */ -#define QEMU_CLOCK_REALTIME 0 -#define QEMU_CLOCK_VIRTUAL 1 -#define QEMU_CLOCK_HOST 2 - struct QEMUClock { QEMUTimer *active_timers; @@ -231,7 +227,7 @@ QEMUClock *rt_clock; QEMUClock *vm_clock; QEMUClock *host_clock; -static QEMUClock *qemu_new_clock(int type) +static QEMUClock *qemu_clock_new(int type) { QEMUClock *clock; @@ -433,9 +429,9 @@ void qemu_unregister_clock_reset_notifier(QEMUClock *clock, Notifier *notifier) void init_clocks(void) { if (!rt_clock) { - rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME); - vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL); - host_clock = qemu_new_clock(QEMU_CLOCK_HOST); + rt_clock = qemu_clock_new(QEMU_CLOCK_REALTIME); + vm_clock = qemu_clock_new(QEMU_CLOCK_VIRTUAL); + host_clock = qemu_clock_new(QEMU_CLOCK_HOST); } } -- cgit v1.1 From 02a03a9f12ec2fe68c9fed84fa8607a5326e2b65 Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:41 +0100 Subject: aio / timers: add qemu-timer.c utility functions Add utility functions to qemu-timer.c for nanosecond timing. Add qemu_clock_deadline_ns to calculate deadlines to nanosecond accuracy. Add utility function qemu_soonest_timeout to calculate soonest deadline. Add qemu_timeout_ns_to_ms to convert a timeout in nanoseconds back to milliseconds for when ppoll is not used. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 4117add..df8f12b 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -273,6 +273,56 @@ int64_t qemu_clock_deadline(QEMUClock *clock) return delta; } +/* + * As above, but return -1 for no deadline, and do not cap to 2^32 + * as we know the result is always positive. + */ + +int64_t qemu_clock_deadline_ns(QEMUClock *clock) +{ + int64_t delta; + + if (!clock->enabled || !clock->active_timers) { + return -1; + } + + delta = clock->active_timers->expire_time - qemu_get_clock_ns(clock); + + if (delta <= 0) { + return 0; + } + + return delta; +} + +/* Transition function to convert a nanosecond timeout to ms + * This is used where a system does not support ppoll + */ +int qemu_timeout_ns_to_ms(int64_t ns) +{ + int64_t ms; + if (ns < 0) { + return -1; + } + + if (!ns) { + return 0; + } + + /* Always round up, because it's better to wait too long than to wait too + * little and effectively busy-wait + */ + ms = (ns + SCALE_MS - 1) / SCALE_MS; + + /* To avoid overflow problems, limit this to 2^31, i.e. approx 25 days */ + if (ms > (int64_t) INT32_MAX) { + ms = INT32_MAX; + } + + return (int) ms; +} + + QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, QEMUTimerCB *cb, void *opaque) { -- cgit v1.1 From 043a7e1f8f66f3089ef0158aea00203e4591ba8d Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:42 +0100 Subject: aio / timers: Consistent treatment of disabled clocks for deadlines Make treatment of disabled clocks consistent in deadline calculation Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index df8f12b..be29adf 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -264,7 +264,7 @@ int64_t qemu_clock_deadline(QEMUClock *clock) /* To avoid problems with overflow limit this to 2^32. */ int64_t delta = INT32_MAX; - if (clock->active_timers) { + if (clock->enabled && clock->active_timers) { delta = clock->active_timers->expire_time - qemu_get_clock_ns(clock); } if (delta < 0) { -- cgit v1.1 From 4e0c6529fcb5ccbed5eb2c4f094264eb447d49ea Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:43 +0100 Subject: aio / timers: add ppoll support with qemu_poll_ns Add qemu_poll_ns which works like g_poll but takes a nanosecond timeout. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index be29adf..120d58f 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -37,6 +37,10 @@ #include #endif +#ifdef CONFIG_PPOLL +#include +#endif + /***********************************************************/ /* timers */ @@ -323,6 +327,26 @@ int qemu_timeout_ns_to_ms(int64_t ns) } +/* qemu implementation of g_poll which uses a nanosecond timeout but is + * otherwise identical to g_poll + */ +int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout) +{ +#ifdef CONFIG_PPOLL + if (timeout < 0) { + return ppoll((struct pollfd *)fds, nfds, NULL, NULL); + } else { + struct timespec ts; + ts.tv_sec = timeout / 1000000000LL; + ts.tv_nsec = timeout % 1000000000LL; + return ppoll((struct pollfd *)fds, nfds, &ts, NULL); + } +#else + return g_poll(fds, nfds, qemu_timeout_ns_to_ms(timeout)); +#endif +} + + QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, QEMUTimerCB *cb, void *opaque) { -- cgit v1.1 From cd758dd0acaaf1f76f9727d4409915f3293db07a Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:44 +0100 Subject: aio / timers: Add prctl(PR_SET_TIMERSLACK, 1, ...) to reduce timer slack Where supported, called prctl(PR_SET_TIMERSLACK, 1, ...) to set one nanosecond timer slack to increase precision of timer calls. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 120d58f..74f904b 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -41,6 +41,10 @@ #include #endif +#ifdef CONFIG_PRCTL_PR_SET_TIMERSLACK +#include +#endif + /***********************************************************/ /* timers */ @@ -507,6 +511,9 @@ void init_clocks(void) vm_clock = qemu_clock_new(QEMU_CLOCK_VIRTUAL); host_clock = qemu_clock_new(QEMU_CLOCK_HOST); } +#ifdef CONFIG_PRCTL_PR_SET_TIMERSLACK + prctl(PR_SET_TIMERSLACK, 1, 0, 0, 0); +#endif } uint64_t timer_expire_time_ns(QEMUTimer *ts) -- cgit v1.1 From f9a976b7408f061fc7fc48b14d16797ed6f8fd97 Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:45 +0100 Subject: aio / timers: Make qemu_run_timers and qemu_run_all_timers return progress 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 Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 74f904b..52a1947 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 -- cgit v1.1 From ff83c66eccf5b5f6b6530d504e3be41559250dcb Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:46 +0100 Subject: aio / timers: Split QEMUClock into QEMUClock and QEMUTimerList Split QEMUClock into QEMUClock and QEMUTimerList so that we can have more than one QEMUTimerList associated with the same clock. Introduce a main_loop_timerlist concept and make existing qemu_clock_* calls that actually should operate on a QEMUTimerList call the relevant QEMUTimerList implementations, using the clock's default timerlist. This vastly reduces the invasiveness of this change and means the API stays constant for existing users. Introduce a list of QEMUTimerLists associated with each clock so that reenabling the clock can cause all the notifiers to be called. Note the code to do the notifications is added in a later patch. Switch QEMUClockType to an enum. Remove global variables vm_clock, host_clock and rt_clock and add compatibility defines. Do not fix qemu_next_alarm_deadline as it's going to be deleted. Add qemu_clock_use_for_deadline to indicate whether a particular clock should be used for deadline calculations. When use_icount is true, vm_clock should not be used for deadline calculations as it does not contain a nanosecond count. Instead, icount timeouts come from the execution thread doing aio_notify or qemu_notify as appropriate. This function is used in the next patch. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 207 +++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 151 insertions(+), 56 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 52a1947..b045184 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -49,22 +49,29 @@ /* timers */ struct QEMUClock { - QEMUTimer *active_timers; + QEMUTimerList *main_loop_timerlist; + QLIST_HEAD(, QEMUTimerList) timerlists; NotifierList reset_notifiers; int64_t last; - int type; + QEMUClockType type; bool enabled; }; -struct QEMUTimer { - int64_t expire_time; /* in nanoseconds */ +QEMUClock *qemu_clocks[QEMU_CLOCK_MAX]; + +/* A QEMUTimerList is a list of timers attached to a clock. More + * than one QEMUTimerList can be attached to each clock, for instance + * used by different AioContexts / threads. Each clock also has + * a list of the QEMUTimerLists associated with it, in order that + * reenabling the clock can call all the notifiers. + */ + +struct QEMUTimerList { QEMUClock *clock; - QEMUTimerCB *cb; - void *opaque; - QEMUTimer *next; - int scale; + QEMUTimer *active_timers; + QLIST_ENTRY(QEMUTimerList) list; }; struct qemu_alarm_timer { @@ -93,21 +100,25 @@ static int64_t qemu_next_alarm_deadline(void) { int64_t delta = INT64_MAX; int64_t rtdelta; + int64_t hdelta; - if (!use_icount && vm_clock->enabled && vm_clock->active_timers) { - delta = vm_clock->active_timers->expire_time - - qemu_get_clock_ns(vm_clock); + if (!use_icount && vm_clock->enabled && + vm_clock->main_loop_timerlist->active_timers) { + delta = vm_clock->main_loop_timerlist->active_timers->expire_time - + qemu_get_clock_ns(vm_clock); } - if (host_clock->enabled && host_clock->active_timers) { - int64_t hdelta = host_clock->active_timers->expire_time - - qemu_get_clock_ns(host_clock); + if (host_clock->enabled && + host_clock->main_loop_timerlist->active_timers) { + hdelta = host_clock->main_loop_timerlist->active_timers->expire_time - + qemu_get_clock_ns(host_clock); if (hdelta < delta) { delta = hdelta; } } - if (rt_clock->enabled && rt_clock->active_timers) { - rtdelta = (rt_clock->active_timers->expire_time - - qemu_get_clock_ns(rt_clock)); + if (rt_clock->enabled && + rt_clock->main_loop_timerlist->active_timers) { + rtdelta = (rt_clock->main_loop_timerlist->active_timers->expire_time - + qemu_get_clock_ns(rt_clock)); if (rtdelta < delta) { delta = rtdelta; } @@ -231,11 +242,42 @@ next: } } -QEMUClock *rt_clock; -QEMUClock *vm_clock; -QEMUClock *host_clock; +static QEMUTimerList *timerlist_new_from_clock(QEMUClock *clock) +{ + QEMUTimerList *timer_list; + + /* Assert if we do not have a clock. If you see this + * assertion in means that the clocks have not been + * initialised before a timerlist is needed. This + * normally happens if an AioContext is used before + * init_clocks() is called within main(). + */ + assert(clock); + + timer_list = g_malloc0(sizeof(QEMUTimerList)); + timer_list->clock = clock; + QLIST_INSERT_HEAD(&clock->timerlists, timer_list, list); + return timer_list; +} + +QEMUTimerList *timerlist_new(QEMUClockType type) +{ + return timerlist_new_from_clock(qemu_clock_ptr(type)); +} -static QEMUClock *qemu_clock_new(int type) +void timerlist_free(QEMUTimerList *timer_list) +{ + assert(!timerlist_has_timers(timer_list)); + if (timer_list->clock) { + QLIST_REMOVE(timer_list, list); + if (timer_list->clock->main_loop_timerlist == timer_list) { + timer_list->clock->main_loop_timerlist = NULL; + } + } + g_free(timer_list); +} + +static QEMUClock *qemu_clock_new(QEMUClockType type) { QEMUClock *clock; @@ -243,10 +285,17 @@ static QEMUClock *qemu_clock_new(int type) clock->type = type; clock->enabled = true; clock->last = INT64_MIN; + QLIST_INIT(&clock->timerlists); notifier_list_init(&clock->reset_notifiers); + clock->main_loop_timerlist = timerlist_new_from_clock(clock); return clock; } +bool qemu_clock_use_for_deadline(QEMUClock *clock) +{ + return !(use_icount && (clock->type == QEMU_CLOCK_VIRTUAL)); +} + void qemu_clock_enable(QEMUClock *clock, bool enabled) { bool old = clock->enabled; @@ -256,24 +305,36 @@ void qemu_clock_enable(QEMUClock *clock, bool enabled) } } -int64_t qemu_clock_has_timers(QEMUClock *clock) +bool timerlist_has_timers(QEMUTimerList *timer_list) { - return !!clock->active_timers; + return !!timer_list->active_timers; } -int64_t qemu_clock_expired(QEMUClock *clock) +bool qemu_clock_has_timers(QEMUClock *clock) { - return (clock->active_timers && - clock->active_timers->expire_time < qemu_get_clock_ns(clock)); + return timerlist_has_timers(clock->main_loop_timerlist); } -int64_t qemu_clock_deadline(QEMUClock *clock) +bool timerlist_expired(QEMUTimerList *timer_list) +{ + return (timer_list->active_timers && + timer_list->active_timers->expire_time < + qemu_get_clock_ns(timer_list->clock)); +} + +bool qemu_clock_expired(QEMUClock *clock) +{ + return timerlist_expired(clock->main_loop_timerlist); +} + +int64_t timerlist_deadline(QEMUTimerList *timer_list) { /* To avoid problems with overflow limit this to 2^32. */ int64_t delta = INT32_MAX; - if (clock->enabled && clock->active_timers) { - delta = clock->active_timers->expire_time - qemu_get_clock_ns(clock); + if (timer_list->clock->enabled && timer_list->active_timers) { + delta = timer_list->active_timers->expire_time - + qemu_get_clock_ns(timer_list->clock); } if (delta < 0) { delta = 0; @@ -281,20 +342,26 @@ int64_t qemu_clock_deadline(QEMUClock *clock) return delta; } +int64_t qemu_clock_deadline(QEMUClock *clock) +{ + return timerlist_deadline(clock->main_loop_timerlist); +} + /* * As above, but return -1 for no deadline, and do not cap to 2^32 * as we know the result is always positive. */ -int64_t qemu_clock_deadline_ns(QEMUClock *clock) +int64_t timerlist_deadline_ns(QEMUTimerList *timer_list) { int64_t delta; - if (!clock->enabled || !clock->active_timers) { + if (!timer_list->clock->enabled || !timer_list->active_timers) { return -1; } - delta = clock->active_timers->expire_time - qemu_get_clock_ns(clock); + delta = timer_list->active_timers->expire_time - + qemu_get_clock_ns(timer_list->clock); if (delta <= 0) { return 0; @@ -303,6 +370,21 @@ int64_t qemu_clock_deadline_ns(QEMUClock *clock) return delta; } +int64_t qemu_clock_deadline_ns(QEMUClock *clock) +{ + return timerlist_deadline_ns(clock->main_loop_timerlist); +} + +QEMUClock *timerlist_get_clock(QEMUTimerList *timer_list) +{ + return timer_list->clock; +} + +QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClock *clock) +{ + return clock->main_loop_timerlist; +} + /* Transition function to convert a nanosecond timeout to ms * This is used where a system does not support ppoll */ @@ -351,17 +433,21 @@ int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout) } -QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, - QEMUTimerCB *cb, void *opaque) +void timer_init(QEMUTimer *ts, + QEMUTimerList *timer_list, int scale, + QEMUTimerCB *cb, void *opaque) { - QEMUTimer *ts; - - ts = g_malloc0(sizeof(QEMUTimer)); - ts->clock = clock; + ts->timer_list = timer_list; ts->cb = cb; ts->opaque = opaque; ts->scale = scale; - return ts; +} + +QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, + QEMUTimerCB *cb, void *opaque) +{ + return timer_new_tl(clock->main_loop_timerlist, + scale, cb, opaque); } void qemu_free_timer(QEMUTimer *ts) @@ -376,7 +462,7 @@ void qemu_del_timer(QEMUTimer *ts) /* NOTE: this code must be signal safe because timer_expired() can be called from a signal. */ - pt = &ts->clock->active_timers; + pt = &ts->timer_list->active_timers; for(;;) { t = *pt; if (!t) @@ -400,7 +486,7 @@ void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) /* add the timer in the sorted list */ /* NOTE: this code must be signal safe because timer_expired() can be called from a signal. */ - pt = &ts->clock->active_timers; + pt = &ts->timer_list->active_timers; for(;;) { t = *pt; if (!timer_expired_ns(t, expire_time)) { @@ -413,12 +499,12 @@ void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) *pt = ts; /* Rearm if necessary */ - if (pt == &ts->clock->active_timers) { + if (pt == &ts->timer_list->active_timers) { if (!alarm_timer->pending) { qemu_rearm_alarm_timer(alarm_timer); } /* Interrupt execution to force deadline recalculation. */ - qemu_clock_warp(ts->clock); + qemu_clock_warp(ts->timer_list->clock); if (use_icount) { qemu_notify_event(); } @@ -433,7 +519,7 @@ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time) bool timer_pending(QEMUTimer *ts) { QEMUTimer *t; - for (t = ts->clock->active_timers; t != NULL; t = t->next) { + for (t = ts->timer_list->active_timers; t != NULL; t = t->next) { if (t == ts) { return true; } @@ -446,23 +532,24 @@ bool timer_expired(QEMUTimer *timer_head, int64_t current_time) return timer_expired_ns(timer_head, current_time * timer_head->scale); } -bool qemu_run_timers(QEMUClock *clock) +bool timerlist_run_timers(QEMUTimerList *timer_list) { QEMUTimer *ts; int64_t current_time; bool progress = false; - if (!clock->enabled) + if (!timer_list->clock->enabled) { return progress; + } - current_time = qemu_get_clock_ns(clock); + current_time = qemu_get_clock_ns(timer_list->clock); for(;;) { - ts = clock->active_timers; + ts = timer_list->active_timers; if (!timer_expired_ns(ts, current_time)) { break; } /* remove timer from the list before calling the callback */ - clock->active_timers = ts->next; + timer_list->active_timers = ts->next; ts->next = NULL; /* run the callback (the timer list can be modified) */ @@ -472,6 +559,11 @@ bool qemu_run_timers(QEMUClock *clock) return progress; } +bool qemu_run_timers(QEMUClock *clock) +{ + return timerlist_run_timers(clock->main_loop_timerlist); +} + int64_t qemu_get_clock_ns(QEMUClock *clock) { int64_t now, last; @@ -509,11 +601,13 @@ void qemu_unregister_clock_reset_notifier(QEMUClock *clock, Notifier *notifier) void init_clocks(void) { - if (!rt_clock) { - rt_clock = qemu_clock_new(QEMU_CLOCK_REALTIME); - vm_clock = qemu_clock_new(QEMU_CLOCK_VIRTUAL); - host_clock = qemu_clock_new(QEMU_CLOCK_HOST); + QEMUClockType type; + for (type = 0; type < QEMU_CLOCK_MAX; type++) { + if (!qemu_clocks[type]) { + qemu_clocks[type] = qemu_clock_new(type); + } } + #ifdef CONFIG_PRCTL_PR_SET_TIMERSLACK prctl(PR_SET_TIMERSLACK, 1, 0, 0, 0); #endif @@ -530,9 +624,10 @@ bool qemu_run_all_timers(void) alarm_timer->pending = false; /* vm time timers */ - progress |= qemu_run_timers(vm_clock); - progress |= qemu_run_timers(rt_clock); - progress |= qemu_run_timers(host_clock); + QEMUClockType type; + for (type = 0; type < QEMU_CLOCK_MAX; type++) { + progress |= qemu_run_timers(qemu_clock_ptr(type)); + } /* rearm timer, if not periodic */ if (alarm_timer->expired) { -- cgit v1.1 From 754d6a544d044bddeef87e9a63b4f511f59f3c4e Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:48 +0100 Subject: aio / timers: Add QEMUTimerListGroup and helper functions 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 Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index b045184..c5e456e 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -59,6 +59,7 @@ struct QEMUClock { bool enabled; }; +QEMUTimerListGroup main_loop_tlg; QEMUClock *qemu_clocks[QEMU_CLOCK_MAX]; /* A QEMUTimerList is a list of timers attached to a clock. More @@ -564,6 +565,46 @@ bool qemu_run_timers(QEMUClock *clock) return timerlist_run_timers(clock->main_loop_timerlist); } +void timerlistgroup_init(QEMUTimerListGroup *tlg) +{ + QEMUClockType type; + for (type = 0; type < QEMU_CLOCK_MAX; type++) { + tlg->tl[type] = timerlist_new(type); + } +} + +void timerlistgroup_deinit(QEMUTimerListGroup *tlg) +{ + QEMUClockType type; + for (type = 0; type < QEMU_CLOCK_MAX; type++) { + timerlist_free(tlg->tl[type]); + } +} + +bool timerlistgroup_run_timers(QEMUTimerListGroup *tlg) +{ + QEMUClockType type; + bool progress = false; + for (type = 0; type < QEMU_CLOCK_MAX; type++) { + progress |= timerlist_run_timers(tlg->tl[type]); + } + return progress; +} + +int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg) +{ + int64_t deadline = -1; + QEMUClockType type; + for (type = 0; type < QEMU_CLOCK_MAX; type++) { + if (qemu_clock_use_for_deadline(tlg->tl[type]->clock)) { + deadline = qemu_soonest_timeout(deadline, + timerlist_deadline_ns( + tlg->tl[type])); + } + } + return deadline; +} + int64_t qemu_get_clock_ns(QEMUClock *clock) { int64_t now, last; @@ -605,6 +646,7 @@ void init_clocks(void) for (type = 0; type < QEMU_CLOCK_MAX; type++) { if (!qemu_clocks[type]) { qemu_clocks[type] = qemu_clock_new(type); + main_loop_tlg.tl[type] = qemu_clocks[type]->main_loop_timerlist; } } -- cgit v1.1 From d5541d86806acc2e1a3cf9e1402370ba884e9fe1 Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:50 +0100 Subject: aio / timers: Add a notify callback to QEMUTimerList Add a notify pointer to QEMUTimerList so it knows what to notify on a timer change. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index c5e456e..ffdc28a 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 qemu_alarm_timer { @@ -243,7 +245,9 @@ next: } } -static QEMUTimerList *timerlist_new_from_clock(QEMUClock *clock) +static QEMUTimerList *timerlist_new_from_clock(QEMUClock *clock, + QEMUTimerListNotifyCB *cb, + void *opaque) { QEMUTimerList *timer_list; @@ -257,13 +261,16 @@ static QEMUTimerList *timerlist_new_from_clock(QEMUClock *clock) timer_list = g_malloc0(sizeof(QEMUTimerList)); timer_list->clock = clock; + timer_list->notify_cb = cb; + timer_list->notify_opaque = opaque; QLIST_INSERT_HEAD(&clock->timerlists, timer_list, list); return timer_list; } -QEMUTimerList *timerlist_new(QEMUClockType type) +QEMUTimerList *timerlist_new(QEMUClockType type, + QEMUTimerListNotifyCB *cb, void *opaque) { - return timerlist_new_from_clock(qemu_clock_ptr(type)); + return timerlist_new_from_clock(qemu_clock_ptr(type), cb, opaque); } void timerlist_free(QEMUTimerList *timer_list) @@ -288,7 +295,7 @@ static QEMUClock *qemu_clock_new(QEMUClockType type) clock->last = INT64_MIN; QLIST_INIT(&clock->timerlists); notifier_list_init(&clock->reset_notifiers); - clock->main_loop_timerlist = timerlist_new_from_clock(clock); + clock->main_loop_timerlist = timerlist_new_from_clock(clock, NULL, NULL); return clock; } @@ -386,6 +393,15 @@ QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClock *clock) return clock->main_loop_timerlist; } +void timerlist_notify(QEMUTimerList *timer_list) +{ + if (timer_list->notify_cb) { + timer_list->notify_cb(timer_list->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 */ @@ -507,7 +523,7 @@ void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) /* Interrupt execution to force deadline recalculation. */ qemu_clock_warp(ts->timer_list->clock); if (use_icount) { - qemu_notify_event(); + timerlist_notify(ts->timer_list); } } } @@ -565,11 +581,12 @@ bool qemu_run_timers(QEMUClock *clock) return timerlist_run_timers(clock->main_loop_timerlist); } -void timerlistgroup_init(QEMUTimerListGroup *tlg) +void timerlistgroup_init(QEMUTimerListGroup *tlg, + QEMUTimerListNotifyCB *cb, void *opaque) { QEMUClockType type; for (type = 0; type < QEMU_CLOCK_MAX; type++) { - tlg->tl[type] = timerlist_new(type); + tlg->tl[type] = timerlist_new(type, cb, opaque); } } -- cgit v1.1 From b1bbfe72ec1ebf302d97f886cc646466c0abd679 Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:55 +0100 Subject: aio / timers: On timer modification, qemu_notify or aio_notify On qemu_mod_timer_ns, ensure qemu_notify or aio_notify is called to end the appropriate poll(), irrespective of use_icount value. On qemu_clock_enable, ensure qemu_notify or aio_notify is called for all QEMUTimerLists attached to the QEMUClock. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index ffdc28a..746ba8b 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -304,11 +304,20 @@ bool qemu_clock_use_for_deadline(QEMUClock *clock) return !(use_icount && (clock->type == QEMU_CLOCK_VIRTUAL)); } +void qemu_clock_notify(QEMUClock *clock) +{ + QEMUTimerList *timer_list; + QLIST_FOREACH(timer_list, &clock->timerlists, list) { + timerlist_notify(timer_list); + } +} + void qemu_clock_enable(QEMUClock *clock, bool enabled) { bool old = clock->enabled; clock->enabled = enabled; if (enabled && !old) { + qemu_clock_notify(clock); qemu_rearm_alarm_timer(alarm_timer); } } @@ -522,9 +531,7 @@ void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) } /* Interrupt execution to force deadline recalculation. */ qemu_clock_warp(ts->timer_list->clock); - if (use_icount) { - timerlist_notify(ts->timer_list); - } + timerlist_notify(ts->timer_list); } } -- cgit v1.1 From ac70aafc28bec4d1014082f0c6659a368c5a95bd Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:57 +0100 Subject: aio / timers: Use all timerlists in icount warp calculations Notify all timerlists derived from vm_clock in icount warp calculations. When calculating timer delay based on vm_clock deadline, use all timerlists. For compatibility, maintain an apparent bug where when using icount, if no vm_clock timer was set, qemu_clock_deadline would return INT32_MAX and always set an icount clock expiry about 2 seconds ahead. NB: thread safety - when different timerlists sit on different threads, this will need some locking. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 746ba8b..b56bfde 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -392,6 +392,22 @@ int64_t qemu_clock_deadline_ns(QEMUClock *clock) return timerlist_deadline_ns(clock->main_loop_timerlist); } +/* Calculate the soonest deadline across all timerlists attached + * to the clock. This is used for the icount timeout so we + * ignore whether or not the clock should be used in deadline + * calculations. + */ +int64_t qemu_clock_deadline_ns_all(QEMUClock *clock) +{ + int64_t deadline = -1; + QEMUTimerList *timer_list; + QLIST_FOREACH(timer_list, &clock->timerlists, list) { + deadline = qemu_soonest_timeout(deadline, + timerlist_deadline_ns(timer_list)); + } + return deadline; +} + QEMUClock *timerlist_get_clock(QEMUTimerList *timer_list) { return timer_list->clock; -- cgit v1.1 From 6d327171551a12b937c5718073b9848d0274c74d Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:59 +0100 Subject: aio / timers: Remove alarm timers Remove alarm timers from qemu-timers.c now we use g_poll / ppoll instead. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 500 +---------------------------------------------------------- 1 file changed, 1 insertion(+), 499 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index b56bfde..8ea8211 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -33,10 +33,6 @@ #include #endif -#ifdef _WIN32 -#include -#endif - #ifdef CONFIG_PPOLL #include #endif @@ -77,174 +73,11 @@ struct QEMUTimerList { void *notify_opaque; }; -struct qemu_alarm_timer { - char const *name; - int (*start)(struct qemu_alarm_timer *t); - void (*stop)(struct qemu_alarm_timer *t); - void (*rearm)(struct qemu_alarm_timer *t, int64_t nearest_delta_ns); -#if defined(__linux__) - timer_t timer; - int fd; -#elif defined(_WIN32) - HANDLE timer; -#endif - bool expired; - bool pending; -}; - -static struct qemu_alarm_timer *alarm_timer; - static bool timer_expired_ns(QEMUTimer *timer_head, int64_t current_time) { return timer_head && (timer_head->expire_time <= current_time); } -static int64_t qemu_next_alarm_deadline(void) -{ - int64_t delta = INT64_MAX; - int64_t rtdelta; - int64_t hdelta; - - if (!use_icount && vm_clock->enabled && - vm_clock->main_loop_timerlist->active_timers) { - delta = vm_clock->main_loop_timerlist->active_timers->expire_time - - qemu_get_clock_ns(vm_clock); - } - if (host_clock->enabled && - host_clock->main_loop_timerlist->active_timers) { - hdelta = host_clock->main_loop_timerlist->active_timers->expire_time - - qemu_get_clock_ns(host_clock); - if (hdelta < delta) { - delta = hdelta; - } - } - if (rt_clock->enabled && - rt_clock->main_loop_timerlist->active_timers) { - rtdelta = (rt_clock->main_loop_timerlist->active_timers->expire_time - - qemu_get_clock_ns(rt_clock)); - if (rtdelta < delta) { - delta = rtdelta; - } - } - - return delta; -} - -static void qemu_rearm_alarm_timer(struct qemu_alarm_timer *t) -{ - int64_t nearest_delta_ns = qemu_next_alarm_deadline(); - if (nearest_delta_ns < INT64_MAX) { - t->rearm(t, nearest_delta_ns); - } -} - -/* TODO: MIN_TIMER_REARM_NS should be optimized */ -#define MIN_TIMER_REARM_NS 250000 - -#ifdef _WIN32 - -static int mm_start_timer(struct qemu_alarm_timer *t); -static void mm_stop_timer(struct qemu_alarm_timer *t); -static void mm_rearm_timer(struct qemu_alarm_timer *t, int64_t delta); - -static int win32_start_timer(struct qemu_alarm_timer *t); -static void win32_stop_timer(struct qemu_alarm_timer *t); -static void win32_rearm_timer(struct qemu_alarm_timer *t, int64_t delta); - -#else - -static int unix_start_timer(struct qemu_alarm_timer *t); -static void unix_stop_timer(struct qemu_alarm_timer *t); -static void unix_rearm_timer(struct qemu_alarm_timer *t, int64_t delta); - -#ifdef __linux__ - -static int dynticks_start_timer(struct qemu_alarm_timer *t); -static void dynticks_stop_timer(struct qemu_alarm_timer *t); -static void dynticks_rearm_timer(struct qemu_alarm_timer *t, int64_t delta); - -#endif /* __linux__ */ - -#endif /* _WIN32 */ - -static struct qemu_alarm_timer alarm_timers[] = { -#ifndef _WIN32 -#ifdef __linux__ - {"dynticks", dynticks_start_timer, - dynticks_stop_timer, dynticks_rearm_timer}, -#endif - {"unix", unix_start_timer, unix_stop_timer, unix_rearm_timer}, -#else - {"mmtimer", mm_start_timer, mm_stop_timer, mm_rearm_timer}, - {"dynticks", win32_start_timer, win32_stop_timer, win32_rearm_timer}, -#endif - {NULL, } -}; - -static void show_available_alarms(void) -{ - int i; - - printf("Available alarm timers, in order of precedence:\n"); - for (i = 0; alarm_timers[i].name; i++) - printf("%s\n", alarm_timers[i].name); -} - -void configure_alarms(char const *opt) -{ - int i; - int cur = 0; - int count = ARRAY_SIZE(alarm_timers) - 1; - char *arg; - char *name; - struct qemu_alarm_timer tmp; - - if (is_help_option(opt)) { - show_available_alarms(); - exit(0); - } - - arg = g_strdup(opt); - - /* Reorder the array */ - name = strtok(arg, ","); - while (name) { - for (i = 0; i < count && alarm_timers[i].name; i++) { - if (!strcmp(alarm_timers[i].name, name)) - break; - } - - if (i == count) { - fprintf(stderr, "Unknown clock %s\n", name); - goto next; - } - - if (i < cur) - /* Ignore */ - goto next; - - /* Swap */ - tmp = alarm_timers[i]; - alarm_timers[i] = alarm_timers[cur]; - alarm_timers[cur] = tmp; - - cur++; -next: - name = strtok(NULL, ","); - } - - g_free(arg); - - if (cur) { - /* Disable remaining timers */ - for (i = cur; i < count; i++) - alarm_timers[i].name = NULL; - } else { - show_available_alarms(); - exit(1); - } -} - static QEMUTimerList *timerlist_new_from_clock(QEMUClock *clock, QEMUTimerListNotifyCB *cb, void *opaque) @@ -318,7 +151,6 @@ void qemu_clock_enable(QEMUClock *clock, bool enabled) clock->enabled = enabled; if (enabled && !old) { qemu_clock_notify(clock); - qemu_rearm_alarm_timer(alarm_timer); } } @@ -542,9 +374,6 @@ void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) /* Rearm if necessary */ if (pt == &ts->timer_list->active_timers) { - if (!alarm_timer->pending) { - qemu_rearm_alarm_timer(alarm_timer); - } /* Interrupt execution to force deadline recalculation. */ qemu_clock_warp(ts->timer_list->clock); timerlist_notify(ts->timer_list); @@ -703,338 +532,11 @@ uint64_t timer_expire_time_ns(QEMUTimer *ts) bool qemu_run_all_timers(void) { bool progress = false; - alarm_timer->pending = false; - - /* vm time timers */ QEMUClockType type; + for (type = 0; type < QEMU_CLOCK_MAX; type++) { progress |= qemu_run_timers(qemu_clock_ptr(type)); } - /* rearm timer, if not periodic */ - if (alarm_timer->expired) { - alarm_timer->expired = false; - qemu_rearm_alarm_timer(alarm_timer); - } - return progress; } - -#ifdef _WIN32 -static void CALLBACK host_alarm_handler(PVOID lpParam, BOOLEAN unused) -#else -static void host_alarm_handler(int host_signum) -#endif -{ - struct qemu_alarm_timer *t = alarm_timer; - if (!t) - return; - - t->expired = true; - t->pending = true; - qemu_notify_event(); -} - -#if defined(__linux__) - -#include "qemu/compatfd.h" - -static int dynticks_start_timer(struct qemu_alarm_timer *t) -{ - struct sigevent ev; - timer_t host_timer; - struct sigaction act; - - sigfillset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler = host_alarm_handler; - - sigaction(SIGALRM, &act, NULL); - - /* - * Initialize ev struct to 0 to avoid valgrind complaining - * about uninitialized data in timer_create call - */ - memset(&ev, 0, sizeof(ev)); - ev.sigev_value.sival_int = 0; - ev.sigev_notify = SIGEV_SIGNAL; -#ifdef CONFIG_SIGEV_THREAD_ID - if (qemu_signalfd_available()) { - ev.sigev_notify = SIGEV_THREAD_ID; - ev._sigev_un._tid = qemu_get_thread_id(); - } -#endif /* CONFIG_SIGEV_THREAD_ID */ - ev.sigev_signo = SIGALRM; - - if (timer_create(CLOCK_REALTIME, &ev, &host_timer)) { - perror("timer_create"); - return -1; - } - - t->timer = host_timer; - - return 0; -} - -static void dynticks_stop_timer(struct qemu_alarm_timer *t) -{ - timer_t host_timer = t->timer; - - timer_delete(host_timer); -} - -static void dynticks_rearm_timer(struct qemu_alarm_timer *t, - int64_t nearest_delta_ns) -{ - timer_t host_timer = t->timer; - struct itimerspec timeout; - int64_t current_ns; - - if (nearest_delta_ns < MIN_TIMER_REARM_NS) - nearest_delta_ns = MIN_TIMER_REARM_NS; - - /* check whether a timer is already running */ - if (timer_gettime(host_timer, &timeout)) { - perror("gettime"); - fprintf(stderr, "Internal timer error: aborting\n"); - exit(1); - } - current_ns = timeout.it_value.tv_sec * 1000000000LL + timeout.it_value.tv_nsec; - if (current_ns && current_ns <= nearest_delta_ns) - return; - - timeout.it_interval.tv_sec = 0; - timeout.it_interval.tv_nsec = 0; /* 0 for one-shot timer */ - timeout.it_value.tv_sec = nearest_delta_ns / 1000000000; - timeout.it_value.tv_nsec = nearest_delta_ns % 1000000000; - if (timer_settime(host_timer, 0 /* RELATIVE */, &timeout, NULL)) { - perror("settime"); - fprintf(stderr, "Internal timer error: aborting\n"); - exit(1); - } -} - -#endif /* defined(__linux__) */ - -#if !defined(_WIN32) - -static int unix_start_timer(struct qemu_alarm_timer *t) -{ - struct sigaction act; - - /* timer signal */ - sigfillset(&act.sa_mask); - act.sa_flags = 0; - act.sa_handler = host_alarm_handler; - - sigaction(SIGALRM, &act, NULL); - return 0; -} - -static void unix_rearm_timer(struct qemu_alarm_timer *t, - int64_t nearest_delta_ns) -{ - struct itimerval itv; - int err; - - if (nearest_delta_ns < MIN_TIMER_REARM_NS) - nearest_delta_ns = MIN_TIMER_REARM_NS; - - itv.it_interval.tv_sec = 0; - itv.it_interval.tv_usec = 0; /* 0 for one-shot timer */ - itv.it_value.tv_sec = nearest_delta_ns / 1000000000; - itv.it_value.tv_usec = (nearest_delta_ns % 1000000000) / 1000; - err = setitimer(ITIMER_REAL, &itv, NULL); - if (err) { - perror("setitimer"); - fprintf(stderr, "Internal timer error: aborting\n"); - exit(1); - } -} - -static void unix_stop_timer(struct qemu_alarm_timer *t) -{ - struct itimerval itv; - - memset(&itv, 0, sizeof(itv)); - setitimer(ITIMER_REAL, &itv, NULL); -} - -#endif /* !defined(_WIN32) */ - - -#ifdef _WIN32 - -static MMRESULT mm_timer; -static TIMECAPS mm_tc; - -static void CALLBACK mm_alarm_handler(UINT uTimerID, UINT uMsg, - DWORD_PTR dwUser, DWORD_PTR dw1, - DWORD_PTR dw2) -{ - struct qemu_alarm_timer *t = alarm_timer; - if (!t) { - return; - } - t->expired = true; - t->pending = true; - qemu_notify_event(); -} - -static int mm_start_timer(struct qemu_alarm_timer *t) -{ - timeGetDevCaps(&mm_tc, sizeof(mm_tc)); - return 0; -} - -static void mm_stop_timer(struct qemu_alarm_timer *t) -{ - if (mm_timer) { - timeKillEvent(mm_timer); - } -} - -static void mm_rearm_timer(struct qemu_alarm_timer *t, int64_t delta) -{ - int64_t nearest_delta_ms = delta / 1000000; - if (nearest_delta_ms < mm_tc.wPeriodMin) { - nearest_delta_ms = mm_tc.wPeriodMin; - } else if (nearest_delta_ms > mm_tc.wPeriodMax) { - nearest_delta_ms = mm_tc.wPeriodMax; - } - - if (mm_timer) { - timeKillEvent(mm_timer); - } - mm_timer = timeSetEvent((UINT)nearest_delta_ms, - mm_tc.wPeriodMin, - mm_alarm_handler, - (DWORD_PTR)t, - TIME_ONESHOT | TIME_CALLBACK_FUNCTION); - - if (!mm_timer) { - fprintf(stderr, "Failed to re-arm win32 alarm timer\n"); - timeEndPeriod(mm_tc.wPeriodMin); - exit(1); - } -} - -static int win32_start_timer(struct qemu_alarm_timer *t) -{ - HANDLE hTimer; - BOOLEAN success; - - /* If you call ChangeTimerQueueTimer on a one-shot timer (its period - is zero) that has already expired, the timer is not updated. Since - creating a new timer is relatively expensive, set a bogus one-hour - interval in the dynticks case. */ - success = CreateTimerQueueTimer(&hTimer, - NULL, - host_alarm_handler, - t, - 1, - 3600000, - WT_EXECUTEINTIMERTHREAD); - - if (!success) { - fprintf(stderr, "Failed to initialize win32 alarm timer: %ld\n", - GetLastError()); - return -1; - } - - t->timer = hTimer; - return 0; -} - -static void win32_stop_timer(struct qemu_alarm_timer *t) -{ - HANDLE hTimer = t->timer; - - if (hTimer) { - DeleteTimerQueueTimer(NULL, hTimer, NULL); - } -} - -static void win32_rearm_timer(struct qemu_alarm_timer *t, - int64_t nearest_delta_ns) -{ - HANDLE hTimer = t->timer; - int64_t nearest_delta_ms; - BOOLEAN success; - - nearest_delta_ms = nearest_delta_ns / 1000000; - if (nearest_delta_ms < 1) { - nearest_delta_ms = 1; - } - /* ULONG_MAX can be 32 bit */ - if (nearest_delta_ms > ULONG_MAX) { - nearest_delta_ms = ULONG_MAX; - } - success = ChangeTimerQueueTimer(NULL, - hTimer, - (unsigned long) nearest_delta_ms, - 3600000); - - if (!success) { - fprintf(stderr, "Failed to rearm win32 alarm timer: %ld\n", - GetLastError()); - exit(-1); - } - -} - -#endif /* _WIN32 */ - -static void quit_timers(void) -{ - struct qemu_alarm_timer *t = alarm_timer; - alarm_timer = NULL; - t->stop(t); -} - -#ifdef CONFIG_POSIX -static void reinit_timers(void) -{ - struct qemu_alarm_timer *t = alarm_timer; - t->stop(t); - if (t->start(t)) { - fprintf(stderr, "Internal timer error: aborting\n"); - exit(1); - } - qemu_rearm_alarm_timer(t); -} -#endif /* CONFIG_POSIX */ - -int init_timer_alarm(void) -{ - struct qemu_alarm_timer *t = NULL; - int i, err = -1; - - if (alarm_timer) { - return 0; - } - - for (i = 0; alarm_timers[i].name; i++) { - t = &alarm_timers[i]; - - err = t->start(t); - if (!err) - break; - } - - if (err) { - err = -ENOENT; - goto fail; - } - - atexit(quit_timers); -#ifdef CONFIG_POSIX - pthread_atfork(NULL, NULL, reinit_timers); -#endif - alarm_timer = t; - return 0; - -fail: - return err; -} - -- cgit v1.1 From 63111b69cce420886ba7bfb8e367bd6c6969c1b6 Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:03:00 +0100 Subject: aio / timers: Remove legacy qemu_clock_deadline & qemu_timerlist_deadline Remove qemu_clock_deadline and qemu_timerlist_deadline now we are using the ns functions throughout. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 8ea8211..b6f9304 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -176,26 +176,6 @@ bool qemu_clock_expired(QEMUClock *clock) return timerlist_expired(clock->main_loop_timerlist); } -int64_t timerlist_deadline(QEMUTimerList *timer_list) -{ - /* To avoid problems with overflow limit this to 2^32. */ - int64_t delta = INT32_MAX; - - if (timer_list->clock->enabled && timer_list->active_timers) { - delta = timer_list->active_timers->expire_time - - qemu_get_clock_ns(timer_list->clock); - } - if (delta < 0) { - delta = 0; - } - return delta; -} - -int64_t qemu_clock_deadline(QEMUClock *clock) -{ - return timerlist_deadline(clock->main_loop_timerlist); -} - /* * As above, but return -1 for no deadline, and do not cap to 2^32 * as we know the result is always positive. -- cgit v1.1 From 40daca54cd94678273c81dca8c0adefa297da5ea Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:03:02 +0100 Subject: aio / timers: Rearrange timer.h & make legacy functions call non-legacy Rearrange timer.h so it is in order by function type. Make legacy functions call non-legacy functions rather than vice-versa. Convert cpus.c to use new API. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 100 +++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 37 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index b6f9304..14794b8 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -132,25 +132,27 @@ static QEMUClock *qemu_clock_new(QEMUClockType type) return clock; } -bool qemu_clock_use_for_deadline(QEMUClock *clock) +bool qemu_clock_use_for_deadline(QEMUClockType type) { - return !(use_icount && (clock->type == QEMU_CLOCK_VIRTUAL)); + return !(use_icount && (type == QEMU_CLOCK_VIRTUAL)); } -void qemu_clock_notify(QEMUClock *clock) +void qemu_clock_notify(QEMUClockType type) { QEMUTimerList *timer_list; + QEMUClock *clock = qemu_clock_ptr(type); QLIST_FOREACH(timer_list, &clock->timerlists, list) { timerlist_notify(timer_list); } } -void qemu_clock_enable(QEMUClock *clock, bool enabled) +void qemu_clock_enable(QEMUClockType type, bool enabled) { + QEMUClock *clock = qemu_clock_ptr(type); bool old = clock->enabled; clock->enabled = enabled; if (enabled && !old) { - qemu_clock_notify(clock); + qemu_clock_notify(type); } } @@ -159,21 +161,23 @@ bool timerlist_has_timers(QEMUTimerList *timer_list) return !!timer_list->active_timers; } -bool qemu_clock_has_timers(QEMUClock *clock) +bool qemu_clock_has_timers(QEMUClockType type) { - return timerlist_has_timers(clock->main_loop_timerlist); + return timerlist_has_timers( + qemu_clock_ptr(type)->main_loop_timerlist); } bool timerlist_expired(QEMUTimerList *timer_list) { return (timer_list->active_timers && timer_list->active_timers->expire_time < - qemu_get_clock_ns(timer_list->clock)); + qemu_clock_get_ns(timer_list->clock->type)); } -bool qemu_clock_expired(QEMUClock *clock) +bool qemu_clock_expired(QEMUClockType type) { - return timerlist_expired(clock->main_loop_timerlist); + return timerlist_expired( + qemu_clock_ptr(type)->main_loop_timerlist); } /* @@ -190,7 +194,7 @@ int64_t timerlist_deadline_ns(QEMUTimerList *timer_list) } delta = timer_list->active_timers->expire_time - - qemu_get_clock_ns(timer_list->clock); + qemu_clock_get_ns(timer_list->clock->type); if (delta <= 0) { return 0; @@ -199,20 +203,16 @@ int64_t timerlist_deadline_ns(QEMUTimerList *timer_list) return delta; } -int64_t qemu_clock_deadline_ns(QEMUClock *clock) -{ - return timerlist_deadline_ns(clock->main_loop_timerlist); -} - /* Calculate the soonest deadline across all timerlists attached * to the clock. This is used for the icount timeout so we * ignore whether or not the clock should be used in deadline * calculations. */ -int64_t qemu_clock_deadline_ns_all(QEMUClock *clock) +int64_t qemu_clock_deadline_ns_all(QEMUClockType type) { int64_t deadline = -1; QEMUTimerList *timer_list; + QEMUClock *clock = qemu_clock_ptr(type); QLIST_FOREACH(timer_list, &clock->timerlists, list) { deadline = qemu_soonest_timeout(deadline, timerlist_deadline_ns(timer_list)); @@ -220,14 +220,14 @@ int64_t qemu_clock_deadline_ns_all(QEMUClock *clock) return deadline; } -QEMUClock *timerlist_get_clock(QEMUTimerList *timer_list) +QEMUClockType timerlist_get_clock(QEMUTimerList *timer_list) { - return timer_list->clock; + return timer_list->clock->type; } -QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClock *clock) +QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClockType type) { - return clock->main_loop_timerlist; + return qemu_clock_ptr(type)->main_loop_timerlist; } void timerlist_notify(QEMUTimerList *timer_list) @@ -304,13 +304,13 @@ QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, scale, cb, opaque); } -void qemu_free_timer(QEMUTimer *ts) +void timer_free(QEMUTimer *ts) { g_free(ts); } /* stop a timer, but do not dealloc it */ -void qemu_del_timer(QEMUTimer *ts) +void timer_del(QEMUTimer *ts) { QEMUTimer **pt, *t; @@ -331,11 +331,11 @@ void qemu_del_timer(QEMUTimer *ts) /* modify the current timer so that it will be fired when current_time >= expire_time. The corresponding callback will be called. */ -void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) +void timer_mod_ns(QEMUTimer *ts, int64_t expire_time) { QEMUTimer **pt, *t; - qemu_del_timer(ts); + timer_del(ts); /* add the timer in the sorted list */ /* NOTE: this code must be signal safe because @@ -355,14 +355,14 @@ void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) /* Rearm if necessary */ if (pt == &ts->timer_list->active_timers) { /* Interrupt execution to force deadline recalculation. */ - qemu_clock_warp(ts->timer_list->clock); + qemu_clock_warp(ts->timer_list->clock->type); timerlist_notify(ts->timer_list); } } -void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time) +void timer_mod(QEMUTimer *ts, int64_t expire_time) { - qemu_mod_timer_ns(ts, expire_time * ts->scale); + timer_mod_ns(ts, expire_time * ts->scale); } bool timer_pending(QEMUTimer *ts) @@ -391,7 +391,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) return progress; } - current_time = qemu_get_clock_ns(timer_list->clock); + current_time = qemu_clock_get_ns(timer_list->clock->type); for(;;) { ts = timer_list->active_timers; if (!timer_expired_ns(ts, current_time)) { @@ -408,9 +408,14 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) return progress; } +bool qemu_clock_run_timers(QEMUClockType type) +{ + return timerlist_run_timers(qemu_clock_ptr(type)->main_loop_timerlist); +} + bool qemu_run_timers(QEMUClock *clock) { - return timerlist_run_timers(clock->main_loop_timerlist); + return qemu_clock_run_timers(clock->type); } void timerlistgroup_init(QEMUTimerListGroup *tlg, @@ -445,7 +450,7 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg) int64_t deadline = -1; QEMUClockType type; for (type = 0; type < QEMU_CLOCK_MAX; type++) { - if (qemu_clock_use_for_deadline(tlg->tl[type]->clock)) { + if (qemu_clock_use_for_deadline(tlg->tl[type]->clock->type)) { deadline = qemu_soonest_timeout(deadline, timerlist_deadline_ns( tlg->tl[type])); @@ -454,11 +459,12 @@ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg) return deadline; } -int64_t qemu_get_clock_ns(QEMUClock *clock) +int64_t qemu_clock_get_ns(QEMUClockType type) { int64_t now, last; + QEMUClock *clock = qemu_clock_ptr(type); - switch(clock->type) { + switch (type) { case QEMU_CLOCK_REALTIME: return get_clock(); default: @@ -479,16 +485,36 @@ int64_t qemu_get_clock_ns(QEMUClock *clock) } } -void qemu_register_clock_reset_notifier(QEMUClock *clock, Notifier *notifier) +int64_t qemu_get_clock_ns(QEMUClock *clock) { + return qemu_clock_get_ns(clock->type); +} + +void qemu_clock_register_reset_notifier(QEMUClockType type, + Notifier *notifier) +{ + QEMUClock *clock = qemu_clock_ptr(type); notifier_list_add(&clock->reset_notifiers, notifier); } -void qemu_unregister_clock_reset_notifier(QEMUClock *clock, Notifier *notifier) +void qemu_clock_unregister_reset_notifier(QEMUClockType type, + Notifier *notifier) { notifier_remove(notifier); } +void qemu_register_clock_reset_notifier(QEMUClock *clock, + Notifier *notifier) +{ + qemu_clock_register_reset_notifier(clock->type, notifier); +} + +void qemu_unregister_clock_reset_notifier(QEMUClock *clock, + Notifier *notifier) +{ + qemu_clock_unregister_reset_notifier(clock->type, notifier); +} + void init_clocks(void) { QEMUClockType type; @@ -509,13 +535,13 @@ uint64_t timer_expire_time_ns(QEMUTimer *ts) return timer_pending(ts) ? ts->expire_time : -1; } -bool qemu_run_all_timers(void) +bool qemu_clock_run_all_timers(void) { bool progress = false; QEMUClockType type; for (type = 0; type < QEMU_CLOCK_MAX; type++) { - progress |= qemu_run_timers(qemu_clock_ptr(type)); + progress |= qemu_clock_run_timers(type); } return progress; -- cgit v1.1 From 7bf8fbde449600926370f744b2b3d9cc819ca74f Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:03:03 +0100 Subject: aio / timers: Remove main_loop_timerlist Now we have timerlistgroups implemented and main_loop_tlg, we no longer need the concept of a default timer list associated with each clock. Remove it and simplify initialisation of clocks and timer lists. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 63 ++++++++++++++++++++++++++---------------------------------- 1 file changed, 27 insertions(+), 36 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index 14794b8..ed1763f 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -45,7 +45,6 @@ /* timers */ struct QEMUClock { - QEMUTimerList *main_loop_timerlist; QLIST_HEAD(, QEMUTimerList) timerlists; NotifierList reset_notifiers; @@ -56,7 +55,7 @@ struct QEMUClock { }; QEMUTimerListGroup main_loop_tlg; -QEMUClock *qemu_clocks[QEMU_CLOCK_MAX]; +QEMUClock qemu_clocks[QEMU_CLOCK_MAX]; /* A QEMUTimerList is a list of timers attached to a clock. More * than one QEMUTimerList can be attached to each clock, for instance @@ -73,24 +72,30 @@ struct QEMUTimerList { void *notify_opaque; }; +/** + * qemu_clock_ptr: + * @type: type of clock + * + * Translate a clock type into a pointer to QEMUClock object. + * + * Returns: a pointer to the QEMUClock object + */ +QEMUClock *qemu_clock_ptr(QEMUClockType type) +{ + return &qemu_clocks[type]; +} + static bool timer_expired_ns(QEMUTimer *timer_head, int64_t current_time) { return timer_head && (timer_head->expire_time <= current_time); } -static QEMUTimerList *timerlist_new_from_clock(QEMUClock *clock, - QEMUTimerListNotifyCB *cb, - void *opaque) +QEMUTimerList *timerlist_new(QEMUClockType type, + QEMUTimerListNotifyCB *cb, + void *opaque) { QEMUTimerList *timer_list; - - /* Assert if we do not have a clock. If you see this - * assertion in means that the clocks have not been - * initialised before a timerlist is needed. This - * normally happens if an AioContext is used before - * init_clocks() is called within main(). - */ - assert(clock); + QEMUClock *clock = qemu_clock_ptr(type); timer_list = g_malloc0(sizeof(QEMUTimerList)); timer_list->clock = clock; @@ -100,36 +105,25 @@ static QEMUTimerList *timerlist_new_from_clock(QEMUClock *clock, return timer_list; } -QEMUTimerList *timerlist_new(QEMUClockType type, - QEMUTimerListNotifyCB *cb, void *opaque) -{ - return timerlist_new_from_clock(qemu_clock_ptr(type), cb, opaque); -} - void timerlist_free(QEMUTimerList *timer_list) { assert(!timerlist_has_timers(timer_list)); if (timer_list->clock) { QLIST_REMOVE(timer_list, list); - if (timer_list->clock->main_loop_timerlist == timer_list) { - timer_list->clock->main_loop_timerlist = NULL; - } } g_free(timer_list); } -static QEMUClock *qemu_clock_new(QEMUClockType type) +static void qemu_clock_init(QEMUClockType type) { - QEMUClock *clock; + QEMUClock *clock = qemu_clock_ptr(type); - clock = g_malloc0(sizeof(QEMUClock)); clock->type = type; clock->enabled = true; clock->last = INT64_MIN; QLIST_INIT(&clock->timerlists); notifier_list_init(&clock->reset_notifiers); - clock->main_loop_timerlist = timerlist_new_from_clock(clock, NULL, NULL); - return clock; + main_loop_tlg.tl[type] = timerlist_new(type, NULL, NULL); } bool qemu_clock_use_for_deadline(QEMUClockType type) @@ -164,7 +158,7 @@ bool timerlist_has_timers(QEMUTimerList *timer_list) bool qemu_clock_has_timers(QEMUClockType type) { return timerlist_has_timers( - qemu_clock_ptr(type)->main_loop_timerlist); + main_loop_tlg.tl[type]); } bool timerlist_expired(QEMUTimerList *timer_list) @@ -177,7 +171,7 @@ bool timerlist_expired(QEMUTimerList *timer_list) bool qemu_clock_expired(QEMUClockType type) { return timerlist_expired( - qemu_clock_ptr(type)->main_loop_timerlist); + main_loop_tlg.tl[type]); } /* @@ -227,7 +221,7 @@ QEMUClockType timerlist_get_clock(QEMUTimerList *timer_list) QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClockType type) { - return qemu_clock_ptr(type)->main_loop_timerlist; + return main_loop_tlg.tl[type]; } void timerlist_notify(QEMUTimerList *timer_list) @@ -300,7 +294,7 @@ void timer_init(QEMUTimer *ts, QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, QEMUTimerCB *cb, void *opaque) { - return timer_new_tl(clock->main_loop_timerlist, + return timer_new_tl(main_loop_tlg.tl[clock->type], scale, cb, opaque); } @@ -410,7 +404,7 @@ bool timerlist_run_timers(QEMUTimerList *timer_list) bool qemu_clock_run_timers(QEMUClockType type) { - return timerlist_run_timers(qemu_clock_ptr(type)->main_loop_timerlist); + return timerlist_run_timers(main_loop_tlg.tl[type]); } bool qemu_run_timers(QEMUClock *clock) @@ -519,10 +513,7 @@ void init_clocks(void) { QEMUClockType type; for (type = 0; type < QEMU_CLOCK_MAX; type++) { - if (!qemu_clocks[type]) { - qemu_clocks[type] = qemu_clock_new(type); - main_loop_tlg.tl[type] = qemu_clocks[type]->main_loop_timerlist; - } + qemu_clock_init(type); } #ifdef CONFIG_PRCTL_PR_SET_TIMERSLACK -- cgit v1.1 From b4049b74b97f30fe944c63b5f158ec9e87bd2593 Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:03:09 +0100 Subject: aio / timers: Remove legacy interface Remove the legacy interface from include/qemu/timers.h. Ensure struct QEMUClock is not exposed at all. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- qemu-timer.c | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) (limited to 'qemu-timer.c') diff --git a/qemu-timer.c b/qemu-timer.c index ed1763f..95ff47f 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -44,7 +44,7 @@ /***********************************************************/ /* timers */ -struct QEMUClock { +typedef struct QEMUClock { QLIST_HEAD(, QEMUTimerList) timerlists; NotifierList reset_notifiers; @@ -52,7 +52,7 @@ struct QEMUClock { QEMUClockType type; bool enabled; -}; +} QEMUClock; QEMUTimerListGroup main_loop_tlg; QEMUClock qemu_clocks[QEMU_CLOCK_MAX]; @@ -80,7 +80,7 @@ struct QEMUTimerList { * * Returns: a pointer to the QEMUClock object */ -QEMUClock *qemu_clock_ptr(QEMUClockType type) +static inline QEMUClock *qemu_clock_ptr(QEMUClockType type) { return &qemu_clocks[type]; } @@ -291,13 +291,6 @@ void timer_init(QEMUTimer *ts, ts->scale = scale; } -QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, - QEMUTimerCB *cb, void *opaque) -{ - return timer_new_tl(main_loop_tlg.tl[clock->type], - scale, cb, opaque); -} - void timer_free(QEMUTimer *ts) { g_free(ts); @@ -407,11 +400,6 @@ bool qemu_clock_run_timers(QEMUClockType type) return timerlist_run_timers(main_loop_tlg.tl[type]); } -bool qemu_run_timers(QEMUClock *clock) -{ - return qemu_clock_run_timers(clock->type); -} - void timerlistgroup_init(QEMUTimerListGroup *tlg, QEMUTimerListNotifyCB *cb, void *opaque) { @@ -479,11 +467,6 @@ int64_t qemu_clock_get_ns(QEMUClockType type) } } -int64_t qemu_get_clock_ns(QEMUClock *clock) -{ - return qemu_clock_get_ns(clock->type); -} - void qemu_clock_register_reset_notifier(QEMUClockType type, Notifier *notifier) { @@ -497,18 +480,6 @@ void qemu_clock_unregister_reset_notifier(QEMUClockType type, notifier_remove(notifier); } -void qemu_register_clock_reset_notifier(QEMUClock *clock, - Notifier *notifier) -{ - qemu_clock_register_reset_notifier(clock->type, notifier); -} - -void qemu_unregister_clock_reset_notifier(QEMUClock *clock, - Notifier *notifier) -{ - qemu_clock_unregister_reset_notifier(clock->type, notifier); -} - void init_clocks(void) { QEMUClockType type; -- cgit v1.1