Patchwork [2/2] Unify alarm deadline computation

login
register
mail settings
Submitter Paolo Bonzini
Date Jan. 29, 2011, 11 a.m.
Message ID <1296298848-3080-2-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/80937/
State New
Headers show

Comments

Paolo Bonzini - Jan. 29, 2011, 11 a.m.
Now that qemu_next_deadline_dyntick uses the correct formula, we can
simplify the code in host_alarm_handler and eliminate useless duplication.

Also, qemu_next_deadline_dyntick is always used in signed arithmetic,
so change its type.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-timer.c |   28 +++++++++++-----------------
 roms/vgabios |    2 +-
 2 files changed, 12 insertions(+), 18 deletions(-)

Patch

diff --git a/qemu-timer.c b/qemu-timer.c
index 174fd0c..1842d7a 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -635,6 +635,8 @@  void qemu_run_all_timers(void)
     qemu_run_timers(host_clock);
 }
 
+static int64_t qemu_next_alarm_deadline(void);
+
 #ifdef _WIN32
 static void CALLBACK host_alarm_handler(UINT uTimerID, UINT uMsg,
                                         DWORD_PTR dwUser, DWORD_PTR dw1,
@@ -677,14 +679,7 @@  static void host_alarm_handler(int host_signum)
     }
 #endif
     if (alarm_has_dynticks(t) ||
-        (!use_icount &&
-            qemu_timer_expired(active_timers[QEMU_CLOCK_VIRTUAL],
-                               qemu_get_clock(vm_clock))) ||
-        qemu_timer_expired(active_timers[QEMU_CLOCK_REALTIME],
-                           qemu_get_clock(rt_clock)) ||
-        qemu_timer_expired(active_timers[QEMU_CLOCK_HOST],
-                           qemu_get_clock(host_clock))) {
-
+        qemu_next_alarm_deadline () <= 0) {
         t->expired = alarm_has_dynticks(t);
         t->pending = 1;
         qemu_notify_event();
@@ -715,11 +710,7 @@  int64_t qemu_next_deadline(void)
 
 #ifndef _WIN32
 
-#if defined(__linux__)
-
-#define RTC_FREQ 1024
-
-static uint64_t qemu_next_deadline_dyntick(void)
+static int64_t qemu_next_alarm_deadline(void)
 {
     int64_t delta;
     int64_t rtdelta;
@@ -743,12 +734,13 @@  static uint64_t qemu_next_deadline_dyntick(void)
             delta = rtdelta;
     }
 
-    if (delta < MIN_TIMER_REARM_US)
-        delta = MIN_TIMER_REARM_US;
-
     return delta;
 }
 
+#if defined(__linux__)
+
+#define RTC_FREQ 1024
+
 static void enable_sigio_timer(int fd)
 {
     struct sigaction act;
@@ -903,7 +895,9 @@  static void dynticks_rearm_timer(struct qemu_alarm_timer *t)
         !active_timers[QEMU_CLOCK_HOST])
         return;
 
-    nearest_delta_us = qemu_next_deadline_dyntick();
+    nearest_delta_us = qemu_next_alarm_deadline();
+    if (nearest_delta_us < MIN_TIMER_REARM_US)
+        nearest_delta_us = MIN_TIMER_REARM_US;
 
     /* check whether a timer is already running */
     if (timer_gettime(host_timer, &timeout)) {