[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH 07/14] qemu-timer: move more stuff out of qemu-t
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [RFC PATCH 07/14] qemu-timer: move more stuff out of qemu-timer.c |
Date: |
Fri, 16 Sep 2011 17:09:03 +0200 |
Signed-off-by: Paolo Bonzini <address@hidden>
---
qemu-timer.c | 37 +++++--------------------------------
qemu-timer.h | 3 ++-
savevm.c | 25 +++++++++++++++++++++++++
vl.c | 2 +-
4 files changed, 33 insertions(+), 34 deletions(-)
diff --git a/qemu-timer.c b/qemu-timer.c
index 0c7cfd2..3438c1c 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -266,11 +266,8 @@ static QEMUClock *qemu_new_clock(int type)
clock = g_malloc0(sizeof(QEMUClock));
clock->type = type;
clock->enabled = 1;
+ clock->last = INT64_MIN;
notifier_list_init(&clock->reset_notifiers);
- /* required to detect & report backward jumps */
- if (type == QEMU_CLOCK_HOST) {
- clock->last = get_clock_realtime();
- }
return clock;
}
@@ -344,7 +341,7 @@ 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. */
-static void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time)
+void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time)
{
QEMUTimer **pt, *t;
@@ -378,8 +375,6 @@ static void qemu_mod_timer_ns(QEMUTimer *ts, int64_t
expire_time)
}
}
-/* 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(QEMUTimer *ts, int64_t expire_time)
{
qemu_mod_timer_ns(ts, expire_time * ts->scale);
@@ -459,38 +454,16 @@ void qemu_unregister_clock_reset_notifier(QEMUClock
*clock, Notifier *notifier)
notifier_list_remove(&clock->reset_notifiers, notifier);
}
-void init_clocks(void)
+static void __attribute__((constructor)) init_clocks(void)
{
rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME);
vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL);
host_clock = qemu_new_clock(QEMU_CLOCK_HOST);
-
- rtc_clock = host_clock;
}
-/* save a timer */
-void qemu_put_timer(QEMUFile *f, QEMUTimer *ts)
+uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts)
{
- uint64_t expire_time;
-
- if (qemu_timer_pending(ts)) {
- expire_time = ts->expire_time;
- } else {
- expire_time = -1;
- }
- qemu_put_be64(f, expire_time);
-}
-
-void qemu_get_timer(QEMUFile *f, QEMUTimer *ts)
-{
- uint64_t expire_time;
-
- expire_time = qemu_get_be64(f);
- if (expire_time != -1) {
- qemu_mod_timer_ns(ts, expire_time);
- } else {
- qemu_del_timer(ts);
- }
+ return qemu_timer_pending(ts) ? ts->expire_time : -1;
}
void qemu_run_all_timers(void)
diff --git a/qemu-timer.h b/qemu-timer.h
index ce576b9..19f1d0f 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -52,15 +52,16 @@ QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale,
QEMUTimerCB *cb, void *opaque);
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);
int qemu_timer_pending(QEMUTimer *ts);
int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time);
+uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts);
void qemu_run_all_timers(void);
int qemu_alarm_pending(void);
void configure_alarms(char const *opt);
int qemu_calculate_timeout(void);
-void init_clocks(void);
int init_timer_alarm(void);
void quit_timers(void);
diff --git a/savevm.c b/savevm.c
index 1feaa70..1edcbd4 100644
--- a/savevm.c
+++ b/savevm.c
@@ -81,6 +81,7 @@
#include "migration.h"
#include "qemu_socket.h"
#include "qemu-queue.h"
+#include "qemu-timer.h"
#include "cpus.h"
#define SELF_ANNOUNCE_ROUNDS 5
@@ -674,6 +675,30 @@ uint64_t qemu_get_be64(QEMUFile *f)
return v;
}
+
+/* timer */
+
+void qemu_put_timer(QEMUFile *f, QEMUTimer *ts)
+{
+ uint64_t expire_time;
+
+ expire_time = qemu_timer_expire_time_ns(ts);
+ qemu_put_be64(f, expire_time);
+}
+
+void qemu_get_timer(QEMUFile *f, QEMUTimer *ts)
+{
+ uint64_t expire_time;
+
+ expire_time = qemu_get_be64(f);
+ if (expire_time != -1) {
+ qemu_mod_timer_ns(ts, expire_time);
+ } else {
+ qemu_del_timer(ts);
+ }
+}
+
+
/* bool */
static int get_bool(QEMUFile *f, void *pv, size_t size)
diff --git a/vl.c b/vl.c
index b773d2f..56a3db2 100644
--- a/vl.c
+++ b/vl.c
@@ -2202,7 +2202,7 @@ int main(int argc, char **argv, char **envp)
g_mem_set_vtable(&mem_trace);
g_thread_init(NULL);
- init_clocks();
+ rtc_clock = host_clock;
qemu_cache_utils_init(envp);
--
1.7.6
- [Qemu-devel] [RFC PATCH 00/14] allow tools to use the QEMU main loop, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 01/14] remove unused function, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 02/14] qemu-timer: remove active_timers array, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 04/14] qemu-timer: more clock functions, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 05/14] qemu-timer: move icount to cpus.c, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 06/14] qemu-timer: do not refer to vm_running, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 08/14] create main-loop.h, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 10/14] Revert to a hand-made select loop, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 07/14] qemu-timer: move more stuff out of qemu-timer.c,
Paolo Bonzini <=
- [Qemu-devel] [RFC PATCH 12/14] makefile: extract tools-obj-y, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 11/14] simplify main loop functions, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 03/14] qemu-timer: move common code to qemu_rearm_alarm_timer, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 09/14] create main-loop.c, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 14/14] qemu-nbd: use common main loop, Paolo Bonzini, 2011/09/16
- [Qemu-devel] [RFC PATCH 13/14] link the main loop and its dependencies into the tools, Paolo Bonzini, 2011/09/16