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 --- include/qemu/timer.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 9dd206c..a9afdb3 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -49,9 +49,9 @@ void qemu_free_timer(QEMUTimer *ts); void qemu_del_timer(QEMUTimer *ts); void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time); void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time); -bool qemu_timer_pending(QEMUTimer *ts); -bool qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time); -uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts); +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); -- 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 --- include/qemu/timer.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index a9afdb3..da43cbe 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -11,6 +11,10 @@ #define SCALE_US 1000 #define SCALE_NS 1 +#define QEMU_CLOCK_REALTIME 0 +#define QEMU_CLOCK_VIRTUAL 1 +#define QEMU_CLOCK_HOST 2 + typedef struct QEMUClock QEMUClock; typedef void QEMUTimerCB(void *opaque); -- 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 --- include/qemu/timer.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index da43cbe..e0a51a1 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -40,6 +40,29 @@ int64_t qemu_get_clock_ns(QEMUClock *clock); int64_t qemu_clock_has_timers(QEMUClock *clock); int64_t qemu_clock_expired(QEMUClock *clock); int64_t qemu_clock_deadline(QEMUClock *clock); + +/** + * qemu_clock_deadline_ns: + * @clock: the clock to operate on + * + * Calculate the timeout of the earliest expiring timer + * in nanoseconds, or -1 if no timer is set to expire. + * + * Returns: time until expiry in nanoseconds or -1 + */ +int64_t qemu_clock_deadline_ns(QEMUClock *clock); + +/** + * qemu_timeout_ns_to_ms: + * @ns: nanosecond timeout value + * + * Convert a nanosecond timeout value (or -1) to + * a millisecond value (or -1), always rounding up. + * + * Returns: millisecond timeout value + */ +int qemu_timeout_ns_to_ms(int64_t ns); + void qemu_clock_enable(QEMUClock *clock, bool enabled); void qemu_clock_warp(QEMUClock *clock); @@ -67,6 +90,25 @@ int64_t cpu_get_ticks(void); void cpu_enable_ticks(void); void cpu_disable_ticks(void); +/** + * qemu_soonest_timeout: + * @timeout1: first timeout in nanoseconds (or -1 for infinite) + * @timeout2: second timeout in nanoseconds (or -1 for infinite) + * + * Calculates the soonest of two timeout values. -1 means infinite, which + * is later than any other value. + * + * Returns: soonest timeout value in nanoseconds (or -1 for infinite) + */ +static inline int64_t qemu_soonest_timeout(int64_t timeout1, int64_t timeout2) +{ + /* we can abuse the fact that -1 (which means infinite) is a maximal + * value when cast to unsigned. As this is disgusting, it's kept in + * one inline function. + */ + return ((uint64_t) timeout1 < (uint64_t) timeout2) ? timeout1 : timeout2; +} + static inline QEMUTimer *qemu_new_timer_ns(QEMUClock *clock, QEMUTimerCB *cb, void *opaque) { -- 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 --- include/qemu/timer.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index e0a51a1..e4a6479 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -63,6 +63,18 @@ int64_t qemu_clock_deadline_ns(QEMUClock *clock); */ int qemu_timeout_ns_to_ms(int64_t ns); +/** + * qemu_poll_ns: + * @fds: Array of file descriptors + * @nfds: number of file descriptors + * @timeout: timeout in nanoseconds + * + * Perform a poll like g_poll but with a timeout in nanoseconds. + * See g_poll documentation for further details. + * + * Returns: number of fds ready + */ +int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout); void qemu_clock_enable(QEMUClock *clock, bool enabled); void qemu_clock_warp(QEMUClock *clock); -- 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 --- include/qemu/timer.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index e4a6479..962eca8 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); -- 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 --- include/qemu/timer.h | 348 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 325 insertions(+), 23 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 962eca8..b4a7ba0 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -1,6 +1,7 @@ #ifndef QEMU_TIMER_H #define QEMU_TIMER_H +#include "qemu/typedefs.h" #include "qemu-common.h" #include "qemu/main-loop.h" #include "qemu/notify.h" @@ -11,34 +12,84 @@ #define SCALE_US 1000 #define SCALE_NS 1 -#define QEMU_CLOCK_REALTIME 0 -#define QEMU_CLOCK_VIRTUAL 1 -#define QEMU_CLOCK_HOST 2 +/** + * QEMUClockType: + * + * The following clock types are available: + * + * @QEMU_CLOCK_REALTIME: Real time clock + * + * The real time clock should be used only for stuff which does not + * change the virtual machine state, as it is run even if the virtual + * machine is stopped. The real time clock has a frequency of 1000 + * Hz. + * + * Formerly rt_clock + * + * @QEMU_CLOCK_VIRTUAL: virtual clock + * + * The virtual clock is only run during the emulation. It is stopped + * when the virtual machine is stopped. Virtual timers use a high + * precision clock, usually cpu cycles (use ticks_per_sec). + * + * Formerly vm_clock + * + * @QEMU_CLOCK_HOST: host clock + * + * The host clock should be use for device models that emulate accurate + * real time sources. It will continue to run when the virtual machine + * is suspended, and it will reflect system time changes the host may + * undergo (e.g. due to NTP). The host clock has the same precision as + * the virtual clock. + * + * Formerly host_clock + */ + +typedef enum { + QEMU_CLOCK_REALTIME = 0, + QEMU_CLOCK_VIRTUAL = 1, + QEMU_CLOCK_HOST = 2, + QEMU_CLOCK_MAX +} QEMUClockType; typedef struct QEMUClock QEMUClock; +typedef struct QEMUTimerList QEMUTimerList; typedef void QEMUTimerCB(void *opaque); -/* The real time clock should be used only for stuff which does not - change the virtual machine state, as it is run even if the virtual - machine is stopped. The real time clock has a frequency of 1000 - Hz. */ -extern QEMUClock *rt_clock; +struct QEMUTimer { + int64_t expire_time; /* in nanoseconds */ + QEMUTimerList *timer_list; + QEMUTimerCB *cb; + void *opaque; + QEMUTimer *next; + int scale; +}; + +extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX]; -/* The virtual clock is only run during the emulation. It is stopped - when the virtual machine is stopped. Virtual timers use a high - precision clock, usually cpu cycles (use ticks_per_sec). */ -extern QEMUClock *vm_clock; +/** + * qemu_clock_ptr: + * @type: type of clock + * + * Translate a clock type into a pointer to QEMUClock object. + * + * Returns: a pointer to the QEMUClock object + */ +static inline QEMUClock *qemu_clock_ptr(QEMUClockType type) +{ + return qemu_clocks[type]; +} -/* The host clock should be use for device models that emulate accurate - real time sources. It will continue to run when the virtual machine - is suspended, and it will reflect system time changes the host may - undergo (e.g. due to NTP). The host clock has the same precision as - the virtual clock. */ -extern QEMUClock *host_clock; +/* These three clocks are maintained here with separate variable + * names for compatibility only. + */ +#define rt_clock (qemu_clock_ptr(QEMU_CLOCK_REALTIME)) +#define vm_clock (qemu_clock_ptr(QEMU_CLOCK_VIRTUAL)) +#define host_clock (qemu_clock_ptr(QEMU_CLOCK_HOST)) int64_t qemu_get_clock_ns(QEMUClock *clock); -int64_t qemu_clock_has_timers(QEMUClock *clock); -int64_t qemu_clock_expired(QEMUClock *clock); +bool qemu_clock_has_timers(QEMUClock *clock); +bool qemu_clock_expired(QEMUClock *clock); int64_t qemu_clock_deadline(QEMUClock *clock); /** @@ -53,6 +104,121 @@ int64_t qemu_clock_deadline(QEMUClock *clock); int64_t qemu_clock_deadline_ns(QEMUClock *clock); /** + * qemu_clock_use_for_deadline: + * @clock: the clock to operate on + * + * Determine whether a clock should be used for deadline + * calculations. Some clocks, for instance vm_clock with + * use_icount set, do not count in nanoseconds. Such clocks + * are not used for deadline calculations, and are presumed + * to interrupt any poll using qemu_notify/aio_notify + * etc. + * + * Returns: true if the clock runs in nanoseconds and + * should be used for a deadline. + */ +bool qemu_clock_use_for_deadline(QEMUClock *clock); + +/** + * qemu_clock_get_main_loop_timerlist: + * @clock: the clock to operate on + * + * Return the default timer list assocatiated with a clock. + * + * Returns: the default timer list + */ +QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClock *clock); + +/** + * timerlist_new: + * @type: the clock type to associate with the timerlist + * + * Create a new timerlist associated with the clock of + * type @type. + * + * Returns: a pointer to the QEMUTimerList created + */ +QEMUTimerList *timerlist_new(QEMUClockType type); + +/** + * timerlist_free: + * @timer_list: the timer list to free + * + * Frees a timer_list. It must have no active timers. + */ +void timerlist_free(QEMUTimerList *timer_list); + +/** + * timerlist_has_timers: + * @timer_list: the timer list to operate on + * + * Determine whether a timer list has active timers + * + * Returns: true if the timer list has timers. + */ +bool timerlist_has_timers(QEMUTimerList *timer_list); + +/** + * timerlist_expired: + * @timer_list: the timer list to operate on + * + * Determine whether a timer list has any timers which + * are expired. + * + * Returns: true if the timer list has timers which + * have expired. + */ +bool timerlist_expired(QEMUTimerList *timer_list); + +/** + * timerlist_deadline: + * @timer_list: the timer list to operate on + * + * Determine the deadline for a timer_list. This is + * a legacy function which returns INT32_MAX if the + * timer list has no timers or if the earliest timer + * expires later than INT32_MAX nanoseconds away. + * + * Returns: the number of nanoseconds until the earliest + * timer expires or INT32_MAX in the situations listed + * above + */ +int64_t timerlist_deadline(QEMUTimerList *timer_list); + +/** + * timerlist_deadline_ns: + * @timer_list: the timer list to operate on + * + * Determine the deadline for a timer_list, i.e. + * the number of nanoseconds until the first timer + * expires. Return -1 if there are no timers. + * + * Returns: the number of nanoseconds until the earliest + * timer expires -1 if none + */ +int64_t timerlist_deadline_ns(QEMUTimerList *timer_list); + +/** + * timerlist_getclock: + * @timer_list: the timer list to operate on + * + * Determine the clock associated with a timer list. + * + * Returns: the clock associated with the timer list. + */ +QEMUClock *timerlist_get_clock(QEMUTimerList *timer_list); + +/** + * timerlist_run_timers: + * @timer_list: the timer list to use + * + * Call all expired timers associated with the timer list. + * + * Returns: true if any timer expired + */ +bool timerlist_run_timers(QEMUTimerList *timer_list); + +/** * qemu_timeout_ns_to_ms: * @ns: nanosecond timeout value * @@ -84,6 +250,50 @@ void qemu_unregister_clock_reset_notifier(QEMUClock *clock, QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, QEMUTimerCB *cb, void *opaque); + +/** + * timer_init: + * @ts: the timer to be initialised + * @timer_list: the timer list to attach the timer to + * @scale: the scale value for the tiemr + * @cb: the callback to be called when the timer expires + * @opaque: the opaque pointer to be passed to the callback + * + * Initialise a new timer and associate it with @timer_list. + * The caller is responsible for allocating the memory. + * + * You need not call an explicit deinit call. Simply make + * sure it is not on a list with timer_del. + */ +void timer_init(QEMUTimer *ts, + QEMUTimerList *timer_list, int scale, + QEMUTimerCB *cb, void *opaque); + +/** + * timer_new_tl: + * @timer_list: the timer list to attach the timer to + * @scale: the scale value for the tiemr + * @cb: the callback to be called when the timer expires + * @opaque: the opaque pointer to be passed to the callback + * + * Creeate a new timer and associate it with @timer_list. + * The memory is allocated by the function. + * + * This is not the preferred interface unless you know you + * are going to call timer_free. Use timer_init instead. + * + * Returns: a pointer to the timer + */ +static inline QEMUTimer *timer_new_tl(QEMUTimerList *timer_list, + int scale, + QEMUTimerCB *cb, + void *opaque) +{ + QEMUTimer *ts = g_malloc0(sizeof(QEMUTimer)); + timer_init(ts, timer_list, scale, cb, opaque); + return ts; +} + void qemu_free_timer(QEMUTimer *ts); void qemu_del_timer(QEMUTimer *ts); void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time); @@ -92,11 +302,61 @@ bool timer_pending(QEMUTimer *ts); bool timer_expired(QEMUTimer *timer_head, int64_t current_time); uint64_t timer_expire_time_ns(QEMUTimer *ts); +/* New format calling conventions for timers */ + +/** + * timer_free: + * @ts: the timer + * + * Free a timer (it must not be on the active list) + */ +static inline void timer_free(QEMUTimer *ts) +{ + qemu_free_timer(ts); +} + +/** + * timer_del: + * @ts: the timer + * + * Delete a timer from the active list. + */ +static inline void timer_del(QEMUTimer *ts) +{ + qemu_del_timer(ts); +} + +/** + * timer_mod_ns: + * @ts: the timer + * @expire_time: the expiry time in nanoseconds + * + * Modify a timer to expire at @expire_time + */ +static inline void timer_mod_ns(QEMUTimer *ts, int64_t expire_time) +{ + qemu_mod_timer_ns(ts, expire_time); +} + +/** + * timer_mod: + * @ts: the timer + * @expire_time: the expire time in the units associated with the timer + * + * Modify a timer to expiry at @expire_time, taking into + * account the scale associated with the timer. + */ +static inline void timer_mod(QEMUTimer *ts, int64_t expire_timer) +{ + qemu_mod_timer(ts, expire_timer); +} + /** * qemu_run_timers: * @clock: clock on which to operate * - * Run all the timers associated with a clock. + * Run all the timers associated with the default timer list + * of a clock. * * Returns: true if any timer ran. */ @@ -105,7 +365,8 @@ bool qemu_run_timers(QEMUClock *clock); /** * qemu_run_all_timers: * - * Run all the timers associated with every clock. + * Run all the timers associated with the default timer list + * of every clock. * * Returns: true if any timer ran. */ @@ -138,13 +399,54 @@ static inline int64_t qemu_soonest_timeout(int64_t timeout1, int64_t timeout2) return ((uint64_t) timeout1 < (uint64_t) timeout2) ? timeout1 : timeout2; } +/** + * qemu_new_timer_ns: + * @clock: the clock to associate with the timer + * @callback: the callback to call when the timer expires + * @opaque: the opaque pointer to pass to the callback + * + * Create a new timer with nanosecond scale on the default timer list + * associated with the clock. + * + * Returns: a pointer to the newly created timer + */ static inline QEMUTimer *qemu_new_timer_ns(QEMUClock *clock, QEMUTimerCB *cb, void *opaque) { return qemu_new_timer(clock, SCALE_NS, cb, opaque); } -static inline QEMUTimer *qemu_new_timer_ms(QEMUClock *clock, QEMUTimerCB *cb, +/** + * qemu_new_timer_us: + * @clock: the clock to associate with the timer + * @callback: the callback to call when the timer expires + * @opaque: the opaque pointer to pass to the callback + * + * Create a new timer with microsecond scale on the default timer list + * associated with the clock. + * + * Returns: a pointer to the newly created timer + */ +static inline QEMUTimer *qemu_new_timer_us(QEMUClock *clock, + QEMUTimerCB *cb, + void *opaque) +{ + return qemu_new_timer(clock, SCALE_US, cb, opaque); +} + +/** + * qemu_new_timer_ms: + * @clock: the clock to associate with the timer + * @callback: the callback to call when the timer expires + * @opaque: the opaque pointer to pass to the callback + * + * Create a new timer with millisecond scale on the default timer list + * associated with the clock. + * + * Returns: a pointer to the newly created timer + */ +static inline QEMUTimer *qemu_new_timer_ms(QEMUClock *clock, + QEMUTimerCB *cb, void *opaque) { return qemu_new_timer(clock, SCALE_MS, cb, opaque); -- cgit v1.1 From 6a1751b7aad6e38e9d1ae6bcea72fa28bf6cc5fb Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:47 +0100 Subject: aio / timers: Untangle include files include/qemu/timer.h has no need to include main-loop.h and doing so causes an issue for the next patch. Unfortunately various files assume including timers.h will pull in main-loop.h. Untangle this mess. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- include/qemu/timer.h | 1 - include/qemu/typedefs.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index b4a7ba0..d4b643f 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -3,7 +3,6 @@ #include "qemu/typedefs.h" #include "qemu-common.h" -#include "qemu/main-loop.h" #include "qemu/notify.h" /* timers */ diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index ac9f8d4..cae94ff 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -7,6 +7,8 @@ typedef struct QEMUTimer QEMUTimer; typedef struct QEMUFile QEMUFile; typedef struct QEMUBH QEMUBH; +typedef struct AioContext AioContext; + struct Monitor; typedef struct Monitor Monitor; typedef struct MigrationParams MigrationParams; -- 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 --- include/qemu/timer.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ include/qemu/typedefs.h | 1 + 2 files changed, 50 insertions(+) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index d4b643f..6f1ec76 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -53,6 +53,11 @@ typedef enum { typedef struct QEMUClock QEMUClock; typedef struct QEMUTimerList QEMUTimerList; + +struct QEMUTimerListGroup { + QEMUTimerList *tl[QEMU_CLOCK_MAX]; +}; + typedef void QEMUTimerCB(void *opaque); struct QEMUTimer { @@ -64,6 +69,7 @@ struct QEMUTimer { int scale; }; +extern QEMUTimerListGroup main_loop_tlg; extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX]; /** @@ -218,6 +224,49 @@ QEMUClock *timerlist_get_clock(QEMUTimerList *timer_list); bool timerlist_run_timers(QEMUTimerList *timer_list); /** + * timerlistgroup_init: + * @tlg: the timer list group + * + * Initialise a timer list group. This must already be + * allocated in memory and zeroed. + */ +void timerlistgroup_init(QEMUTimerListGroup *tlg); + +/** + * timerlistgroup_deinit: + * @tlg: the timer list group + * + * Deinitialise a timer list group. This must already be + * initialised. Note the memory is not freed. + */ +void timerlistgroup_deinit(QEMUTimerListGroup *tlg); + +/** + * timerlistgroup_run_timers: + * @tlg: the timer list group + * + * Run the timers associated with a timer list group. + * This will run timers on multiple clocks. + * + * Returns: true if any timer callback ran + */ +bool timerlistgroup_run_timers(QEMUTimerListGroup *tlg); + +/** + * timerlistgroup_deadline_ns + * @tlg: the timer list group + * + * Determine the deadline of the soonest timer to + * expire associated with any timer list linked to + * the timer list group. Only clocks suitable for + * deadline calculation are included. + * + * Returns: the deadline in nanoseconds or -1 if no + * timers are to expire. + */ +int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg); + +/** * qemu_timeout_ns_to_ms: * @ns: nanosecond timeout value * diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index cae94ff..3205540 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -4,6 +4,7 @@ /* A load of opaque types so that device init declarations don't have to pull in all the real definitions. */ typedef struct QEMUTimer QEMUTimer; +typedef struct QEMUTimerListGroup QEMUTimerListGroup; typedef struct QEMUFile QEMUFile; typedef struct QEMUBH QEMUBH; -- 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 --- include/qemu/timer.h | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 6f1ec76..cb7321c 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -59,6 +59,7 @@ struct QEMUTimerListGroup { }; typedef void QEMUTimerCB(void *opaque); +typedef void QEMUTimerListNotifyCB(void *opaque); struct QEMUTimer { int64_t expire_time; /* in nanoseconds */ @@ -137,13 +138,16 @@ QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClock *clock); /** * timerlist_new: * @type: the clock type to associate with the timerlist + * @cb: the callback to call on notification + * @opaque: the opaque pointer to pass to the callback * * Create a new timerlist associated with the clock of * type @type. * * Returns: a pointer to the QEMUTimerList created */ -QEMUTimerList *timerlist_new(QEMUClockType type); +QEMUTimerList *timerlist_new(QEMUClockType type, + QEMUTimerListNotifyCB *cb, void *opaque); /** * timerlist_free: @@ -224,13 +228,28 @@ QEMUClock *timerlist_get_clock(QEMUTimerList *timer_list); bool timerlist_run_timers(QEMUTimerList *timer_list); /** + * timerlist_notify: + * @timer_list: the timer list to use + * + * call the notifier callback associated with the timer list. + */ +void timerlist_notify(QEMUTimerList *timer_list); + +/** * timerlistgroup_init: * @tlg: the timer list group + * @cb: the callback to call when a notify is required + * @opaque: the opaque pointer to be passed to the callback. * * Initialise a timer list group. This must already be - * allocated in memory and zeroed. - */ -void timerlistgroup_init(QEMUTimerListGroup *tlg); + * allocated in memory and zeroed. The notifier callback is + * called whenever a clock in the timer list group is + * reenabled or whenever a timer associated with any timer + * list is modified. If @cb is specified as null, qemu_notify() + * is used instead. + */ +void timerlistgroup_init(QEMUTimerListGroup *tlg, + QEMUTimerListNotifyCB *cb, void *opaque); /** * timerlistgroup_deinit: -- 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 --- include/qemu/timer.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index cb7321c..3fa9fa7 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -136,6 +136,15 @@ bool qemu_clock_use_for_deadline(QEMUClock *clock); QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClock *clock); /** + * qemu_clock_nofify: + * @clock: the clock to operate on + * + * Call the notifier callback connected with the default timer + * list linked to the clock, or qemu_notify() if none. + */ +void qemu_clock_notify(QEMUClock *clock); + +/** * timerlist_new: * @type: the clock type to associate with the timerlist * @cb: the callback to call on notification -- cgit v1.1 From a3a726ae09cdf6d277ac88cd725cf50d5849db2c Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:56 +0100 Subject: aio / timers: Introduce new API timer_new and friends Introduce new API for creating timers - timer_new and _ns, _ms, _us derivatives. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- include/qemu/timer.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 3fa9fa7..2053244 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -370,6 +370,24 @@ static inline QEMUTimer *timer_new_tl(QEMUTimerList *timer_list, return ts; } +/** + * timer_new: + * @type: the clock type to use + * @scale: the scale value for the tiemr + * @cb: the callback to be called when the timer expires + * @opaque: the opaque pointer to be passed to the callback + * + * Creeate a new timer and associate it with the default + * timer list for the clock type @type. + * + * Returns: a pointer to the timer + */ +static inline QEMUTimer *timer_new(QEMUClockType type, int scale, + QEMUTimerCB *cb, void *opaque) +{ + return timer_new_tl(main_loop_tlg.tl[type], scale, cb, opaque); +} + void qemu_free_timer(QEMUTimer *ts); void qemu_del_timer(QEMUTimer *ts); void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time); @@ -493,6 +511,23 @@ static inline QEMUTimer *qemu_new_timer_ns(QEMUClock *clock, QEMUTimerCB *cb, } /** + * timer_new_ns: + * @clock: the clock to associate with the timer + * @callback: the callback to call when the timer expires + * @opaque: the opaque pointer to pass to the callback + * + * Create a new timer with nanosecond scale on the default timer list + * associated with the clock. + * + * Returns: a pointer to the newly created timer + */ +static inline QEMUTimer *timer_new_ns(QEMUClockType type, QEMUTimerCB *cb, + void *opaque) +{ + return timer_new(type, SCALE_NS, cb, opaque); +} + +/** * qemu_new_timer_us: * @clock: the clock to associate with the timer * @callback: the callback to call when the timer expires @@ -511,6 +546,23 @@ static inline QEMUTimer *qemu_new_timer_us(QEMUClock *clock, } /** + * timer_new_us: + * @clock: the clock to associate with the timer + * @callback: the callback to call when the timer expires + * @opaque: the opaque pointer to pass to the callback + * + * Create a new timer with microsecond scale on the default timer list + * associated with the clock. + * + * Returns: a pointer to the newly created timer + */ +static inline QEMUTimer *timer_new_us(QEMUClockType type, QEMUTimerCB *cb, + void *opaque) +{ + return timer_new(type, SCALE_US, cb, opaque); +} + +/** * qemu_new_timer_ms: * @clock: the clock to associate with the timer * @callback: the callback to call when the timer expires @@ -528,6 +580,23 @@ static inline QEMUTimer *qemu_new_timer_ms(QEMUClock *clock, return qemu_new_timer(clock, SCALE_MS, cb, opaque); } +/** + * timer_new_ms: + * @clock: the clock to associate with the timer + * @callback: the callback to call when the timer expires + * @opaque: the opaque pointer to pass to the callback + * + * Create a new timer with millisecond scale on the default timer list + * associated with the clock. + * + * Returns: a pointer to the newly created timer + */ +static inline QEMUTimer *timer_new_ms(QEMUClockType type, QEMUTimerCB *cb, + void *opaque) +{ + return timer_new(type, SCALE_MS, cb, opaque); +} + static inline int64_t qemu_get_clock_ms(QEMUClock *clock) { return qemu_get_clock_ns(clock) / SCALE_MS; -- 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 --- include/qemu/timer.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 2053244..1265ad2 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -103,6 +103,7 @@ int64_t qemu_clock_deadline(QEMUClock *clock); * @clock: the clock to operate on * * Calculate the timeout of the earliest expiring timer + * on the default timer list associated with the clock * in nanoseconds, or -1 if no timer is set to expire. * * Returns: time until expiry in nanoseconds or -1 @@ -126,6 +127,18 @@ int64_t qemu_clock_deadline_ns(QEMUClock *clock); bool qemu_clock_use_for_deadline(QEMUClock *clock); /** + * qemu_clock_use_for_deadline: + * @clock: the clock to operate on + * + * Calculate the deadline across all timer lists associated + * with a clock (as opposed to just the default one) + * in nanoseconds, or -1 if no timer is set to expire. + * + * Returns: time until expiry in nanoseconds or -1 + */ +int64_t qemu_clock_deadline_ns_all(QEMUClock *clock); + +/** * qemu_clock_get_main_loop_timerlist: * @clock: the clock to operate on * -- cgit v1.1 From 54904d2a9165bd34dee0f076826b308be2498fe0 Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:02:58 +0100 Subject: aio / timers: Add documentation and new format calls Add documentation for existing qemu timer calls. Add new format calls of the format timer_XXX rather than qemu_XXX_timer for consistency. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- include/qemu/timer.h | 206 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 184 insertions(+), 22 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 1265ad2..84b35c8 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -93,8 +93,52 @@ static inline QEMUClock *qemu_clock_ptr(QEMUClockType type) #define vm_clock (qemu_clock_ptr(QEMU_CLOCK_VIRTUAL)) #define host_clock (qemu_clock_ptr(QEMU_CLOCK_HOST)) +/** + * qemu_get_clock_ns: + * @clock: the clock to operate on + * + * Get the nanosecond value of a clock + * + * Returns: the clock value in nanoseconds + */ int64_t qemu_get_clock_ns(QEMUClock *clock); + +/** + * qemu_clock_get_ns; + * @type: the clock type + * + * Get the nanosecond value of a clock with + * type @type + * + * Returns: the clock value in nanoseconds + */ +static inline int64_t qemu_clock_get_ns(QEMUClockType type) +{ + return qemu_get_clock_ns(qemu_clock_ptr(type)); +} + +/** + * qemu_clock_has_timers: + * @clock: the clock to operate on + * + * Determines whether a clock's default timer list + * has timers attached + * + * Returns: true if the clock's default timer list + * has timers attached + */ bool qemu_clock_has_timers(QEMUClock *clock); + +/** + * qemu_clock_expired: + * @clock: the clock to operate on + * + * Determines whether a clock's default timer list + * has an expired clock. + * + * Returns: true if the clock's default timer list has + * an expired timer + */ bool qemu_clock_expired(QEMUClock *clock); int64_t qemu_clock_deadline(QEMUClock *clock); @@ -294,7 +338,7 @@ void timerlistgroup_deinit(QEMUTimerListGroup *tlg); bool timerlistgroup_run_timers(QEMUTimerListGroup *tlg); /** - * timerlistgroup_deadline_ns + * timerlistgroup_deadline_ns: * @tlg: the timer list group * * Determine the deadline of the soonest timer to @@ -330,13 +374,57 @@ int qemu_timeout_ns_to_ms(int64_t ns); * Returns: number of fds ready */ int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout); + +/** + * qemu_clock_enable: + * @clock: the clock to operate on + * @enabled: true to enable, false to disable + * + * Enable or disable a clock + */ void qemu_clock_enable(QEMUClock *clock, bool enabled); + +/** + * qemu_clock_warp: + * @clock: the clock to operate on + * + * Warp a clock to a new value + */ void qemu_clock_warp(QEMUClock *clock); +/** + * qemu_register_clock_reset_notifier: + * @clock: the clock to operate on + * @notifier: the notifier function + * + * Register a notifier function to call when the clock + * concerned is reset. + */ void qemu_register_clock_reset_notifier(QEMUClock *clock, Notifier *notifier); + +/** + * qemu_unregister_clock_reset_notifier: + * @clock: the clock to operate on + * @notifier: the notifier function + * + * Unregister a notifier function to call when the clock + * concerned is reset. + */ void qemu_unregister_clock_reset_notifier(QEMUClock *clock, Notifier *notifier); +/** + * qemu_new_timer: + * @clock: the clock to operate on + * @scale: the scale of the clock + * @cb: the callback function to call when the timer expires + * @opaque: an opaque pointer to pass to the callback + * + * Produce a new timer attached to clock @clock. This is a legacy + * function. Use timer_new instead. + * + * Returns: a pointer to the new timer allocated. + */ QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, QEMUTimerCB *cb, void *opaque); @@ -401,21 +489,21 @@ static inline QEMUTimer *timer_new(QEMUClockType type, int scale, return timer_new_tl(main_loop_tlg.tl[type], scale, cb, opaque); } +/** + * qemu_free_timer: + * @ts: the timer to operate on + * + * free the timer @ts. @ts must not be active. + * + * This is a legacy function. Use timer_free instead. + */ void qemu_free_timer(QEMUTimer *ts); -void qemu_del_timer(QEMUTimer *ts); -void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time); -void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time); -bool timer_pending(QEMUTimer *ts); -bool timer_expired(QEMUTimer *timer_head, int64_t current_time); -uint64_t timer_expire_time_ns(QEMUTimer *ts); - -/* New format calling conventions for timers */ /** * timer_free: - * @ts: the timer + * @ts: the timer to operate on * - * Free a timer (it must not be on the active list) + * free the timer @ts. @ts must not be active. */ static inline void timer_free(QEMUTimer *ts) { @@ -423,10 +511,22 @@ static inline void timer_free(QEMUTimer *ts) } /** + * qemu_del_timer: + * @ts: the timer to operate on + * + * Delete a timer. This makes it inactive. It does not free + * memory. + * + * This is a legacy function. Use timer_del instead. + */ +void qemu_del_timer(QEMUTimer *ts); + +/** * timer_del: - * @ts: the timer + * @ts: the timer to operate on * - * Delete a timer from the active list. + * Delete a timer. This makes it inactive. It does not free + * memory. */ static inline void timer_del(QEMUTimer *ts) { @@ -434,11 +534,24 @@ static inline void timer_del(QEMUTimer *ts) } /** + * qemu_mod_timer_ns: + * @ts: the timer to operate on + * @expire_time: the expiry time in nanoseconds + * + * Modify a timer such that the expiry time is @expire_time + * as measured in nanoseconds + * + * This is a legacy function. Use timer_mod_ns. + */ +void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time); + +/** * timer_mod_ns: - * @ts: the timer + * @ts: the timer to operate on * @expire_time: the expiry time in nanoseconds * - * Modify a timer to expire at @expire_time + * Modify a timer such that the expiry time is @expire_time + * as measured in nanoseconds */ static inline void timer_mod_ns(QEMUTimer *ts, int64_t expire_time) { @@ -446,19 +559,62 @@ static inline void timer_mod_ns(QEMUTimer *ts, int64_t expire_time) } /** + * qemu_mod_timer: + * @ts: the timer to operate on + * @expire_time: the expiry time + * + * Modify a timer such that the expiry time is @expire_time + * as measured in the timer's scale + * + * This is a legacy function. Use timer_mod. + */ +void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time); + +/** * timer_mod: - * @ts: the timer - * @expire_time: the expire time in the units associated with the timer + * @ts: the timer to operate on + * @expire_time: the expiry time in nanoseconds * - * Modify a timer to expiry at @expire_time, taking into - * account the scale associated with the timer. + * Modify a timer such that the expiry time is @expire_time + * as measured in the timer's scale */ -static inline void timer_mod(QEMUTimer *ts, int64_t expire_timer) +static inline void timer_mod(QEMUTimer *ts, int64_t expire_time) { - qemu_mod_timer(ts, expire_timer); + qemu_mod_timer(ts, expire_time); } /** + * timer_pending: + * @ts: the timer to operate on + * + * Determines whether a timer is pending (i.e. is on the + * active list of timers, whether or not it has not yet expired). + * + * Returns: true if the timer is pending + */ +bool timer_pending(QEMUTimer *ts); + +/** + * timer_expired: + * @ts: the timer to operate on + * + * Determines whether a timer has expired. + * + * Returns: true if the timer has expired + */ +bool timer_expired(QEMUTimer *timer_head, int64_t current_time); + +/** + * timer_expire_time_ns: + * @ts: the timer to operate on + * + * Determines the time until a timer expires + * + * Returns: the time (in nanoseonds) until a timer expires + */ +uint64_t timer_expire_time_ns(QEMUTimer *ts); + +/** * qemu_run_timers: * @clock: clock on which to operate * @@ -480,9 +636,15 @@ bool qemu_run_timers(QEMUClock *clock); bool qemu_run_all_timers(void); void configure_alarms(char const *opt); -void init_clocks(void); int init_timer_alarm(void); +/** + * initclocks: + * + * Initialise the clock & timer infrastructure + */ +void init_clocks(void); + int64_t cpu_get_ticks(void); void cpu_enable_ticks(void); void cpu_disable_ticks(void); -- 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 --- include/qemu/timer.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 84b35c8..d0fb7b6 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -635,9 +635,6 @@ bool qemu_run_timers(QEMUClock *clock); */ bool qemu_run_all_timers(void); -void configure_alarms(char const *opt); -int init_timer_alarm(void); - /** * initclocks: * -- 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 --- include/qemu/timer.h | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index d0fb7b6..21f4810 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -140,7 +140,6 @@ bool qemu_clock_has_timers(QEMUClock *clock); * an expired timer */ bool qemu_clock_expired(QEMUClock *clock); -int64_t qemu_clock_deadline(QEMUClock *clock); /** * qemu_clock_deadline_ns: @@ -246,21 +245,6 @@ bool timerlist_has_timers(QEMUTimerList *timer_list); bool timerlist_expired(QEMUTimerList *timer_list); /** - * timerlist_deadline: - * @timer_list: the timer list to operate on - * - * Determine the deadline for a timer_list. This is - * a legacy function which returns INT32_MAX if the - * timer list has no timers or if the earliest timer - * expires later than INT32_MAX nanoseconds away. - * - * Returns: the number of nanoseconds until the earliest - * timer expires or INT32_MAX in the situations listed - * above - */ -int64_t timerlist_deadline(QEMUTimerList *timer_list); - -/** * timerlist_deadline_ns: * @timer_list: the timer list to operate on * -- cgit v1.1 From 55a197dab4d26e6dcd2b539320b7daf68cf8c967 Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:03:01 +0100 Subject: aio / timers: Add qemu_clock_get_ms and qemu_clock_get_ms Add utility functions qemu_clock_get_ms and qemu_clock_get_us Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- include/qemu/timer.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 21f4810..5c30f91 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -118,6 +118,34 @@ static inline int64_t qemu_clock_get_ns(QEMUClockType type) } /** + * qemu_clock_get_ms; + * @type: the clock type + * + * Get the millisecond value of a clock with + * type @type + * + * Returns: the clock value in milliseconds + */ +static inline int64_t qemu_clock_get_ms(QEMUClockType type) +{ + return qemu_clock_get_ns(type) / SCALE_MS; +} + +/** + * qemu_clock_get_us; + * @type: the clock type + * + * Get the microsecond value of a clock with + * type @type + * + * Returns: the clock value in microseconds + */ +static inline int64_t qemu_clock_get_us(QEMUClockType type) +{ + return qemu_clock_get_ns(type) / SCALE_US; +} + +/** * qemu_clock_has_timers: * @clock: the clock to operate on * -- 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 --- include/qemu/timer.h | 614 ++++++++++++++++++++++++++++----------------------- 1 file changed, 341 insertions(+), 273 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 5c30f91..35556e7 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -23,16 +23,12 @@ * machine is stopped. The real time clock has a frequency of 1000 * Hz. * - * Formerly rt_clock - * * @QEMU_CLOCK_VIRTUAL: virtual clock * * The virtual clock is only run during the emulation. It is stopped * when the virtual machine is stopped. Virtual timers use a high * precision clock, usually cpu cycles (use ticks_per_sec). * - * Formerly vm_clock - * * @QEMU_CLOCK_HOST: host clock * * The host clock should be use for device models that emulate accurate @@ -40,8 +36,6 @@ * is suspended, and it will reflect system time changes the host may * undergo (e.g. due to NTP). The host clock has the same precision as * the virtual clock. - * - * Formerly host_clock */ typedef enum { @@ -73,6 +67,10 @@ struct QEMUTimer { extern QEMUTimerListGroup main_loop_tlg; extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX]; +/* + * QEMUClock & QEMUClockType + */ + /** * qemu_clock_ptr: * @type: type of clock @@ -86,23 +84,6 @@ static inline QEMUClock *qemu_clock_ptr(QEMUClockType type) return qemu_clocks[type]; } -/* These three clocks are maintained here with separate variable - * names for compatibility only. - */ -#define rt_clock (qemu_clock_ptr(QEMU_CLOCK_REALTIME)) -#define vm_clock (qemu_clock_ptr(QEMU_CLOCK_VIRTUAL)) -#define host_clock (qemu_clock_ptr(QEMU_CLOCK_HOST)) - -/** - * qemu_get_clock_ns: - * @clock: the clock to operate on - * - * Get the nanosecond value of a clock - * - * Returns: the clock value in nanoseconds - */ -int64_t qemu_get_clock_ns(QEMUClock *clock); - /** * qemu_clock_get_ns; * @type: the clock type @@ -112,10 +93,7 @@ int64_t qemu_get_clock_ns(QEMUClock *clock); * * Returns: the clock value in nanoseconds */ -static inline int64_t qemu_clock_get_ns(QEMUClockType type) -{ - return qemu_get_clock_ns(qemu_clock_ptr(type)); -} +int64_t qemu_clock_get_ns(QEMUClockType type); /** * qemu_clock_get_ms; @@ -147,7 +125,7 @@ static inline int64_t qemu_clock_get_us(QEMUClockType type) /** * qemu_clock_has_timers: - * @clock: the clock to operate on + * @type: the clock type * * Determines whether a clock's default timer list * has timers attached @@ -155,11 +133,11 @@ static inline int64_t qemu_clock_get_us(QEMUClockType type) * Returns: true if the clock's default timer list * has timers attached */ -bool qemu_clock_has_timers(QEMUClock *clock); +bool qemu_clock_has_timers(QEMUClockType type); /** * qemu_clock_expired: - * @clock: the clock to operate on + * @type: the clock type * * Determines whether a clock's default timer list * has an expired clock. @@ -167,23 +145,11 @@ bool qemu_clock_has_timers(QEMUClock *clock); * Returns: true if the clock's default timer list has * an expired timer */ -bool qemu_clock_expired(QEMUClock *clock); - -/** - * qemu_clock_deadline_ns: - * @clock: the clock to operate on - * - * Calculate the timeout of the earliest expiring timer - * on the default timer list associated with the clock - * in nanoseconds, or -1 if no timer is set to expire. - * - * Returns: time until expiry in nanoseconds or -1 - */ -int64_t qemu_clock_deadline_ns(QEMUClock *clock); +bool qemu_clock_expired(QEMUClockType type); /** * qemu_clock_use_for_deadline: - * @clock: the clock to operate on + * @type: the clock type * * Determine whether a clock should be used for deadline * calculations. Some clocks, for instance vm_clock with @@ -195,11 +161,11 @@ int64_t qemu_clock_deadline_ns(QEMUClock *clock); * Returns: true if the clock runs in nanoseconds and * should be used for a deadline. */ -bool qemu_clock_use_for_deadline(QEMUClock *clock); +bool qemu_clock_use_for_deadline(QEMUClockType type); /** - * qemu_clock_use_for_deadline: - * @clock: the clock to operate on + * qemu_clock_deadline_ns_all: + * @type: the clock type * * Calculate the deadline across all timer lists associated * with a clock (as opposed to just the default one) @@ -207,26 +173,90 @@ bool qemu_clock_use_for_deadline(QEMUClock *clock); * * Returns: time until expiry in nanoseconds or -1 */ -int64_t qemu_clock_deadline_ns_all(QEMUClock *clock); +int64_t qemu_clock_deadline_ns_all(QEMUClockType type); /** * qemu_clock_get_main_loop_timerlist: - * @clock: the clock to operate on + * @type: the clock type * * Return the default timer list assocatiated with a clock. * * Returns: the default timer list */ -QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClock *clock); +QEMUTimerList *qemu_clock_get_main_loop_timerlist(QEMUClockType type); /** * qemu_clock_nofify: - * @clock: the clock to operate on + * @type: the clock type * * Call the notifier callback connected with the default timer * list linked to the clock, or qemu_notify() if none. */ -void qemu_clock_notify(QEMUClock *clock); +void qemu_clock_notify(QEMUClockType type); + +/** + * qemu_clock_enable: + * @type: the clock type + * @enabled: true to enable, false to disable + * + * Enable or disable a clock + */ +void qemu_clock_enable(QEMUClockType type, bool enabled); + +/** + * qemu_clock_warp: + * @type: the clock type + * + * Warp a clock to a new value + */ +void qemu_clock_warp(QEMUClockType type); + +/** + * qemu_clock_register_reset_notifier: + * @type: the clock type + * @notifier: the notifier function + * + * Register a notifier function to call when the clock + * concerned is reset. + */ +void qemu_clock_register_reset_notifier(QEMUClockType type, + Notifier *notifier); + +/** + * qemu_clock_unregister_reset_notifier: + * @type: the clock type + * @notifier: the notifier function + * + * Unregister a notifier function to call when the clock + * concerned is reset. + */ +void qemu_clock_unregister_reset_notifier(QEMUClockType type, + Notifier *notifier); + +/** + * qemu_clock_run_timers: + * @type: clock on which to operate + * + * Run all the timers associated with the default timer list + * of a clock. + * + * Returns: true if any timer ran. + */ +bool qemu_clock_run_timers(QEMUClockType type); + +/** + * qemu_clock_run_all_timers: + * + * Run all the timers associated with the default timer list + * of every clock. + * + * Returns: true if any timer ran. + */ +bool qemu_clock_run_all_timers(void); + +/* + * QEMUTimerList + */ /** * timerlist_new: @@ -286,14 +316,15 @@ bool timerlist_expired(QEMUTimerList *timer_list); int64_t timerlist_deadline_ns(QEMUTimerList *timer_list); /** - * timerlist_getclock: + * timerlist_get_clock: * @timer_list: the timer list to operate on * - * Determine the clock associated with a timer list. + * Determine the clock type associated with a timer list. * - * Returns: the clock associated with the timer list. + * Returns: the clock type associated with the + * timer list. */ -QEMUClock *timerlist_get_clock(QEMUTimerList *timer_list); +QEMUClockType timerlist_get_clock(QEMUTimerList *timer_list); /** * timerlist_run_timers: @@ -313,6 +344,10 @@ bool timerlist_run_timers(QEMUTimerList *timer_list); */ void timerlist_notify(QEMUTimerList *timer_list); +/* + * QEMUTimerListGroup + */ + /** * timerlistgroup_init: * @tlg: the timer list group @@ -363,82 +398,9 @@ bool timerlistgroup_run_timers(QEMUTimerListGroup *tlg); */ int64_t timerlistgroup_deadline_ns(QEMUTimerListGroup *tlg); -/** - * qemu_timeout_ns_to_ms: - * @ns: nanosecond timeout value - * - * Convert a nanosecond timeout value (or -1) to - * a millisecond value (or -1), always rounding up. - * - * Returns: millisecond timeout value - */ -int qemu_timeout_ns_to_ms(int64_t ns); - -/** - * qemu_poll_ns: - * @fds: Array of file descriptors - * @nfds: number of file descriptors - * @timeout: timeout in nanoseconds - * - * Perform a poll like g_poll but with a timeout in nanoseconds. - * See g_poll documentation for further details. - * - * Returns: number of fds ready - */ -int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout); - -/** - * qemu_clock_enable: - * @clock: the clock to operate on - * @enabled: true to enable, false to disable - * - * Enable or disable a clock - */ -void qemu_clock_enable(QEMUClock *clock, bool enabled); - -/** - * qemu_clock_warp: - * @clock: the clock to operate on - * - * Warp a clock to a new value - */ -void qemu_clock_warp(QEMUClock *clock); - -/** - * qemu_register_clock_reset_notifier: - * @clock: the clock to operate on - * @notifier: the notifier function - * - * Register a notifier function to call when the clock - * concerned is reset. - */ -void qemu_register_clock_reset_notifier(QEMUClock *clock, Notifier *notifier); - -/** - * qemu_unregister_clock_reset_notifier: - * @clock: the clock to operate on - * @notifier: the notifier function - * - * Unregister a notifier function to call when the clock - * concerned is reset. - */ -void qemu_unregister_clock_reset_notifier(QEMUClock *clock, - Notifier *notifier); - -/** - * qemu_new_timer: - * @clock: the clock to operate on - * @scale: the scale of the clock - * @cb: the callback function to call when the timer expires - * @opaque: an opaque pointer to pass to the callback - * - * Produce a new timer attached to clock @clock. This is a legacy - * function. Use timer_new instead. - * - * Returns: a pointer to the new timer allocated. +/* + * QEMUTimer */ -QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, - QEMUTimerCB *cb, void *opaque); /** * timer_init: @@ -502,102 +464,94 @@ static inline QEMUTimer *timer_new(QEMUClockType type, int scale, } /** - * qemu_free_timer: - * @ts: the timer to operate on - * - * free the timer @ts. @ts must not be active. + * timer_new_ns: + * @clock: the clock to associate with the timer + * @callback: the callback to call when the timer expires + * @opaque: the opaque pointer to pass to the callback * - * This is a legacy function. Use timer_free instead. - */ -void qemu_free_timer(QEMUTimer *ts); - -/** - * timer_free: - * @ts: the timer to operate on + * Create a new timer with nanosecond scale on the default timer list + * associated with the clock. * - * free the timer @ts. @ts must not be active. + * Returns: a pointer to the newly created timer */ -static inline void timer_free(QEMUTimer *ts) +static inline QEMUTimer *timer_new_ns(QEMUClockType type, QEMUTimerCB *cb, + void *opaque) { - qemu_free_timer(ts); + return timer_new(type, SCALE_NS, cb, opaque); } /** - * qemu_del_timer: - * @ts: the timer to operate on + * timer_new_us: + * @clock: the clock to associate with the timer + * @callback: the callback to call when the timer expires + * @opaque: the opaque pointer to pass to the callback * - * Delete a timer. This makes it inactive. It does not free - * memory. + * Create a new timer with microsecond scale on the default timer list + * associated with the clock. * - * This is a legacy function. Use timer_del instead. + * Returns: a pointer to the newly created timer */ -void qemu_del_timer(QEMUTimer *ts); +static inline QEMUTimer *timer_new_us(QEMUClockType type, QEMUTimerCB *cb, + void *opaque) +{ + return timer_new(type, SCALE_US, cb, opaque); +} /** - * timer_del: - * @ts: the timer to operate on + * timer_new_ms: + * @clock: the clock to associate with the timer + * @callback: the callback to call when the timer expires + * @opaque: the opaque pointer to pass to the callback * - * Delete a timer. This makes it inactive. It does not free - * memory. + * Create a new timer with millisecond scale on the default timer list + * associated with the clock. + * + * Returns: a pointer to the newly created timer */ -static inline void timer_del(QEMUTimer *ts) +static inline QEMUTimer *timer_new_ms(QEMUClockType type, QEMUTimerCB *cb, + void *opaque) { - qemu_del_timer(ts); + return timer_new(type, SCALE_MS, cb, opaque); } /** - * qemu_mod_timer_ns: - * @ts: the timer to operate on - * @expire_time: the expiry time in nanoseconds - * - * Modify a timer such that the expiry time is @expire_time - * as measured in nanoseconds + * timer_free: + * @ts: the timer * - * This is a legacy function. Use timer_mod_ns. + * Free a timer (it must not be on the active list) */ -void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time); +void timer_free(QEMUTimer *ts); /** - * timer_mod_ns: - * @ts: the timer to operate on - * @expire_time: the expiry time in nanoseconds + * timer_del: + * @ts: the timer * - * Modify a timer such that the expiry time is @expire_time - * as measured in nanoseconds + * Delete a timer from the active list. */ -static inline void timer_mod_ns(QEMUTimer *ts, int64_t expire_time) -{ - qemu_mod_timer_ns(ts, expire_time); -} +void timer_del(QEMUTimer *ts); /** - * qemu_mod_timer: - * @ts: the timer to operate on - * @expire_time: the expiry time - * - * Modify a timer such that the expiry time is @expire_time - * as measured in the timer's scale + * timer_mod_ns: + * @ts: the timer + * @expire_time: the expiry time in nanoseconds * - * This is a legacy function. Use timer_mod. + * Modify a timer to expire at @expire_time */ -void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time); +void timer_mod_ns(QEMUTimer *ts, int64_t expire_time); /** * timer_mod: - * @ts: the timer to operate on - * @expire_time: the expiry time in nanoseconds + * @ts: the timer + * @expire_time: the expire time in the units associated with the timer * - * Modify a timer such that the expiry time is @expire_time - * as measured in the timer's scale + * Modify a timer to expiry at @expire_time, taking into + * account the scale associated with the timer. */ -static inline void timer_mod(QEMUTimer *ts, int64_t expire_time) -{ - qemu_mod_timer(ts, expire_time); -} +void timer_mod(QEMUTimer *ts, int64_t expire_timer); /** * timer_pending: - * @ts: the timer to operate on + * @ts: the timer * * Determines whether a timer is pending (i.e. is on the * active list of timers, whether or not it has not yet expired). @@ -608,7 +562,7 @@ bool timer_pending(QEMUTimer *ts); /** * timer_expired: - * @ts: the timer to operate on + * @ts: the timer * * Determines whether a timer has expired. * @@ -618,45 +572,57 @@ bool timer_expired(QEMUTimer *timer_head, int64_t current_time); /** * timer_expire_time_ns: - * @ts: the timer to operate on + * @ts: the timer * - * Determines the time until a timer expires + * Determine the expiry time of a timer * - * Returns: the time (in nanoseonds) until a timer expires + * Returns: the expiry time in nanoseconds */ uint64_t timer_expire_time_ns(QEMUTimer *ts); /** - * qemu_run_timers: - * @clock: clock on which to operate - * - * Run all the timers associated with the default timer list - * of a clock. + * timer_get: + * @f: the file + * @ts: the timer * - * Returns: true if any timer ran. + * Read a timer @ts from a file @f */ -bool qemu_run_timers(QEMUClock *clock); +void timer_get(QEMUFile *f, QEMUTimer *ts); /** - * qemu_run_all_timers: + * timer_put: + * @f: the file + * @ts: the timer + */ +void timer_put(QEMUFile *f, QEMUTimer *ts); + +/* + * General utility functions + */ + +/** + * qemu_timeout_ns_to_ms: + * @ns: nanosecond timeout value * - * Run all the timers associated with the default timer list - * of every clock. + * Convert a nanosecond timeout value (or -1) to + * a millisecond value (or -1), always rounding up. * - * Returns: true if any timer ran. + * Returns: millisecond timeout value */ -bool qemu_run_all_timers(void); +int qemu_timeout_ns_to_ms(int64_t ns); /** - * initclocks: + * qemu_poll_ns: + * @fds: Array of file descriptors + * @nfds: number of file descriptors + * @timeout: timeout in nanoseconds * - * Initialise the clock & timer infrastructure + * Perform a poll like g_poll but with a timeout in nanoseconds. + * See g_poll documentation for further details. + * + * Returns: number of fds ready */ -void init_clocks(void); - -int64_t cpu_get_ticks(void); -void cpu_enable_ticks(void); -void cpu_disable_ticks(void); +int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout); /** * qemu_soonest_timeout: @@ -678,59 +644,181 @@ static inline int64_t qemu_soonest_timeout(int64_t timeout1, int64_t timeout2) } /** - * qemu_new_timer_ns: - * @clock: the clock to associate with the timer - * @callback: the callback to call when the timer expires - * @opaque: the opaque pointer to pass to the callback + * initclocks: * - * Create a new timer with nanosecond scale on the default timer list - * associated with the clock. + * Initialise the clock & timer infrastructure + */ +void init_clocks(void); + +int64_t cpu_get_ticks(void); +void cpu_enable_ticks(void); +void cpu_disable_ticks(void); + +static inline int64_t get_ticks_per_sec(void) +{ + return 1000000000LL; +} + +/************************************************** + * LEGACY API SECTION * - * Returns: a pointer to the newly created timer + * All these calls will be deleted in due course */ -static inline QEMUTimer *qemu_new_timer_ns(QEMUClock *clock, QEMUTimerCB *cb, - void *opaque) + +/* These three clocks are maintained here with separate variable + * names for compatibility only. + */ +#define rt_clock (qemu_clock_ptr(QEMU_CLOCK_REALTIME)) +#define vm_clock (qemu_clock_ptr(QEMU_CLOCK_VIRTUAL)) +#define host_clock (qemu_clock_ptr(QEMU_CLOCK_HOST)) + +/** LEGACY + * qemu_get_clock_ns: + * @clock: the clock to operate on + * + * Get the nanosecond value of a clock + * + * Returns: the clock value in nanoseconds + */ +int64_t qemu_get_clock_ns(QEMUClock *clock); + +/** LEGACY + * qemu_get_clock_ms: + * @clock: the clock to operate on + * + * Get the millisecond value of a clock + * + * Returns: the clock value in milliseconds + */ +static inline int64_t qemu_get_clock_ms(QEMUClock *clock) { - return qemu_new_timer(clock, SCALE_NS, cb, opaque); + return qemu_get_clock_ns(clock) / SCALE_MS; } -/** - * timer_new_ns: - * @clock: the clock to associate with the timer - * @callback: the callback to call when the timer expires - * @opaque: the opaque pointer to pass to the callback +/** LEGACY + * qemu_register_clock_reset_notifier: + * @clock: the clock to operate on + * @notifier: the notifier function * - * Create a new timer with nanosecond scale on the default timer list - * associated with the clock. + * Register a notifier function to call when the clock + * concerned is reset. + */ +void qemu_register_clock_reset_notifier(QEMUClock *clock, + Notifier *notifier); + +/** LEGACY + * qemu_unregister_clock_reset_notifier: + * @clock: the clock to operate on + * @notifier: the notifier function * - * Returns: a pointer to the newly created timer + * Unregister a notifier function to call when the clock + * concerned is reset. */ -static inline QEMUTimer *timer_new_ns(QEMUClockType type, QEMUTimerCB *cb, - void *opaque) +void qemu_unregister_clock_reset_notifier(QEMUClock *clock, + Notifier *notifier); + +/** LEGACY + * qemu_new_timer: + * @clock: the clock to operate on + * @scale: the scale of the clock + * @cb: the callback function to call when the timer expires + * @opaque: an opaque pointer to pass to the callback + * + * Produce a new timer attached to clock @clock. This is a legacy + * function. Use timer_new instead. + * + * Returns: a pointer to the new timer allocated. + */ +QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, + QEMUTimerCB *cb, void *opaque); + +/** LEGACY + * qemu_free_timer: + * @ts: the timer to operate on + * + * free the timer @ts. @ts must not be active. + * + * This is a legacy function. Use timer_free instead. + */ +static inline void qemu_free_timer(QEMUTimer *ts) { - return timer_new(type, SCALE_NS, cb, opaque); + timer_free(ts); } -/** - * qemu_new_timer_us: +/** LEGACY + * qemu_del_timer: + * @ts: the timer to operate on + * + * Delete a timer. This makes it inactive. It does not free + * memory. + * + * This is a legacy function. Use timer_del instead. + */ +static inline void qemu_del_timer(QEMUTimer *ts) +{ + timer_del(ts); +} + +/** LEGACY + * qemu_mod_timer_ns: + * @ts: the timer to operate on + * @expire_time: the expiry time in nanoseconds + * + * Modify a timer such that the expiry time is @expire_time + * as measured in nanoseconds + * + * This is a legacy function. Use timer_mod_ns. + */ +static inline void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) +{ + timer_mod_ns(ts, expire_time); +} + +/** LEGACY + * qemu_mod_timer: + * @ts: the timer to operate on + * @expire_time: the expiry time + * + * Modify a timer such that the expiry time is @expire_time + * as measured in the timer's scale + * + * This is a legacy function. Use timer_mod. + */ +static inline void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time) +{ + timer_mod(ts, expire_time); +} + +/** LEGACY + * qemu_run_timers: + * @clock: clock on which to operate + * + * Run all the timers associated with the default timer list + * of a clock. + * + * Returns: true if any timer ran. + */ +bool qemu_run_timers(QEMUClock *clock); + +/** LEGACY + * qemu_new_timer_ns: * @clock: the clock to associate with the timer * @callback: the callback to call when the timer expires * @opaque: the opaque pointer to pass to the callback * - * Create a new timer with microsecond scale on the default timer list + * Create a new timer with nanosecond scale on the default timer list * associated with the clock. * * Returns: a pointer to the newly created timer */ -static inline QEMUTimer *qemu_new_timer_us(QEMUClock *clock, - QEMUTimerCB *cb, +static inline QEMUTimer *qemu_new_timer_ns(QEMUClock *clock, QEMUTimerCB *cb, void *opaque) { - return qemu_new_timer(clock, SCALE_US, cb, opaque); + return qemu_new_timer(clock, SCALE_NS, cb, opaque); } -/** - * timer_new_us: +/** LEGACY + * qemu_new_timer_us: * @clock: the clock to associate with the timer * @callback: the callback to call when the timer expires * @opaque: the opaque pointer to pass to the callback @@ -740,13 +828,14 @@ static inline QEMUTimer *qemu_new_timer_us(QEMUClock *clock, * * Returns: a pointer to the newly created timer */ -static inline QEMUTimer *timer_new_us(QEMUClockType type, QEMUTimerCB *cb, - void *opaque) +static inline QEMUTimer *qemu_new_timer_us(QEMUClock *clock, + QEMUTimerCB *cb, + void *opaque) { - return timer_new(type, SCALE_US, cb, opaque); + return qemu_new_timer(clock, SCALE_US, cb, opaque); } -/** +/** LEGACY * qemu_new_timer_ms: * @clock: the clock to associate with the timer * @callback: the callback to call when the timer expires @@ -764,32 +853,14 @@ static inline QEMUTimer *qemu_new_timer_ms(QEMUClock *clock, return qemu_new_timer(clock, SCALE_MS, cb, opaque); } -/** - * timer_new_ms: - * @clock: the clock to associate with the timer - * @callback: the callback to call when the timer expires - * @opaque: the opaque pointer to pass to the callback - * - * Create a new timer with millisecond scale on the default timer list - * associated with the clock. - * - * Returns: a pointer to the newly created timer +/**************************************************** + * END OF LEGACY API SECTION */ -static inline QEMUTimer *timer_new_ms(QEMUClockType type, QEMUTimerCB *cb, - void *opaque) -{ - return timer_new(type, SCALE_MS, cb, opaque); -} -static inline int64_t qemu_get_clock_ms(QEMUClock *clock) -{ - return qemu_get_clock_ns(clock) / SCALE_MS; -} -static inline int64_t get_ticks_per_sec(void) -{ - return 1000000000LL; -} +/* + * Low level clock functions + */ /* real time host monotonic timer */ static inline int64_t get_clock_realtime(void) @@ -834,9 +905,6 @@ static inline int64_t get_clock(void) } #endif -void qemu_get_timer(QEMUFile *f, QEMUTimer *ts); -void qemu_put_timer(QEMUFile *f, QEMUTimer *ts); - /* icount */ int64_t cpu_get_icount(void); int64_t cpu_get_clock(void); -- 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 --- include/qemu/timer.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 35556e7..705463a 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -65,7 +65,6 @@ struct QEMUTimer { }; extern QEMUTimerListGroup main_loop_tlg; -extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX]; /* * QEMUClock & QEMUClockType @@ -79,10 +78,7 @@ extern QEMUClock *qemu_clocks[QEMU_CLOCK_MAX]; * * Returns: a pointer to the QEMUClock object */ -static inline QEMUClock *qemu_clock_ptr(QEMUClockType type) -{ - return qemu_clocks[type]; -} +QEMUClock *qemu_clock_ptr(QEMUClockType type); /** * qemu_clock_get_ns; -- cgit v1.1 From bc72ad67543f5c5d39c005ff0ca72da37642a1fb Mon Sep 17 00:00:00 2001 From: Alex Bligh Date: Wed, 21 Aug 2013 16:03:08 +0100 Subject: aio / timers: Switch entire codebase to the new timer API This is an autogenerated patch using scripts/switch-timer-api. Switch the entire code base to using the new timer API. Note this patch may introduce some line length issues. Signed-off-by: Alex Bligh Signed-off-by: Stefan Hajnoczi --- include/qemu/ratelimit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/qemu') diff --git a/include/qemu/ratelimit.h b/include/qemu/ratelimit.h index d1610f1..d413a4a 100644 --- a/include/qemu/ratelimit.h +++ b/include/qemu/ratelimit.h @@ -23,7 +23,7 @@ typedef struct { static inline int64_t ratelimit_calculate_delay(RateLimit *limit, uint64_t n) { - int64_t now = qemu_get_clock_ns(rt_clock); + int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); if (limit->next_slice_time < now) { limit->next_slice_time = now + limit->slice_ns; -- 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 --- include/qemu/timer.h | 214 +-------------------------------------------------- 1 file changed, 2 insertions(+), 212 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 705463a..e4934dd 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -45,7 +45,6 @@ typedef enum { QEMU_CLOCK_MAX } QEMUClockType; -typedef struct QEMUClock QEMUClock; typedef struct QEMUTimerList QEMUTimerList; struct QEMUTimerListGroup { @@ -67,20 +66,10 @@ struct QEMUTimer { extern QEMUTimerListGroup main_loop_tlg; /* - * QEMUClock & QEMUClockType + * QEMUClockType */ -/** - * 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); - -/** +/* * qemu_clock_get_ns; * @type: the clock type * @@ -655,205 +644,6 @@ static inline int64_t get_ticks_per_sec(void) return 1000000000LL; } -/************************************************** - * LEGACY API SECTION - * - * All these calls will be deleted in due course - */ - -/* These three clocks are maintained here with separate variable - * names for compatibility only. - */ -#define rt_clock (qemu_clock_ptr(QEMU_CLOCK_REALTIME)) -#define vm_clock (qemu_clock_ptr(QEMU_CLOCK_VIRTUAL)) -#define host_clock (qemu_clock_ptr(QEMU_CLOCK_HOST)) - -/** LEGACY - * qemu_get_clock_ns: - * @clock: the clock to operate on - * - * Get the nanosecond value of a clock - * - * Returns: the clock value in nanoseconds - */ -int64_t qemu_get_clock_ns(QEMUClock *clock); - -/** LEGACY - * qemu_get_clock_ms: - * @clock: the clock to operate on - * - * Get the millisecond value of a clock - * - * Returns: the clock value in milliseconds - */ -static inline int64_t qemu_get_clock_ms(QEMUClock *clock) -{ - return qemu_get_clock_ns(clock) / SCALE_MS; -} - -/** LEGACY - * qemu_register_clock_reset_notifier: - * @clock: the clock to operate on - * @notifier: the notifier function - * - * Register a notifier function to call when the clock - * concerned is reset. - */ -void qemu_register_clock_reset_notifier(QEMUClock *clock, - Notifier *notifier); - -/** LEGACY - * qemu_unregister_clock_reset_notifier: - * @clock: the clock to operate on - * @notifier: the notifier function - * - * Unregister a notifier function to call when the clock - * concerned is reset. - */ -void qemu_unregister_clock_reset_notifier(QEMUClock *clock, - Notifier *notifier); - -/** LEGACY - * qemu_new_timer: - * @clock: the clock to operate on - * @scale: the scale of the clock - * @cb: the callback function to call when the timer expires - * @opaque: an opaque pointer to pass to the callback - * - * Produce a new timer attached to clock @clock. This is a legacy - * function. Use timer_new instead. - * - * Returns: a pointer to the new timer allocated. - */ -QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, - QEMUTimerCB *cb, void *opaque); - -/** LEGACY - * qemu_free_timer: - * @ts: the timer to operate on - * - * free the timer @ts. @ts must not be active. - * - * This is a legacy function. Use timer_free instead. - */ -static inline void qemu_free_timer(QEMUTimer *ts) -{ - timer_free(ts); -} - -/** LEGACY - * qemu_del_timer: - * @ts: the timer to operate on - * - * Delete a timer. This makes it inactive. It does not free - * memory. - * - * This is a legacy function. Use timer_del instead. - */ -static inline void qemu_del_timer(QEMUTimer *ts) -{ - timer_del(ts); -} - -/** LEGACY - * qemu_mod_timer_ns: - * @ts: the timer to operate on - * @expire_time: the expiry time in nanoseconds - * - * Modify a timer such that the expiry time is @expire_time - * as measured in nanoseconds - * - * This is a legacy function. Use timer_mod_ns. - */ -static inline void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) -{ - timer_mod_ns(ts, expire_time); -} - -/** LEGACY - * qemu_mod_timer: - * @ts: the timer to operate on - * @expire_time: the expiry time - * - * Modify a timer such that the expiry time is @expire_time - * as measured in the timer's scale - * - * This is a legacy function. Use timer_mod. - */ -static inline void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time) -{ - timer_mod(ts, expire_time); -} - -/** LEGACY - * qemu_run_timers: - * @clock: clock on which to operate - * - * Run all the timers associated with the default timer list - * of a clock. - * - * Returns: true if any timer ran. - */ -bool qemu_run_timers(QEMUClock *clock); - -/** LEGACY - * qemu_new_timer_ns: - * @clock: the clock to associate with the timer - * @callback: the callback to call when the timer expires - * @opaque: the opaque pointer to pass to the callback - * - * Create a new timer with nanosecond scale on the default timer list - * associated with the clock. - * - * Returns: a pointer to the newly created timer - */ -static inline QEMUTimer *qemu_new_timer_ns(QEMUClock *clock, QEMUTimerCB *cb, - void *opaque) -{ - return qemu_new_timer(clock, SCALE_NS, cb, opaque); -} - -/** LEGACY - * qemu_new_timer_us: - * @clock: the clock to associate with the timer - * @callback: the callback to call when the timer expires - * @opaque: the opaque pointer to pass to the callback - * - * Create a new timer with microsecond scale on the default timer list - * associated with the clock. - * - * Returns: a pointer to the newly created timer - */ -static inline QEMUTimer *qemu_new_timer_us(QEMUClock *clock, - QEMUTimerCB *cb, - void *opaque) -{ - return qemu_new_timer(clock, SCALE_US, cb, opaque); -} - -/** LEGACY - * qemu_new_timer_ms: - * @clock: the clock to associate with the timer - * @callback: the callback to call when the timer expires - * @opaque: the opaque pointer to pass to the callback - * - * Create a new timer with millisecond scale on the default timer list - * associated with the clock. - * - * Returns: a pointer to the newly created timer - */ -static inline QEMUTimer *qemu_new_timer_ms(QEMUClock *clock, - QEMUTimerCB *cb, - void *opaque) -{ - return qemu_new_timer(clock, SCALE_MS, cb, opaque); -} - -/**************************************************** - * END OF LEGACY API SECTION - */ - - /* * Low level clock functions */ -- cgit v1.1