Patchwork [06/19] more alarm timer cleanup

login
register
mail settings
Submitter Paolo Bonzini
Date Dec. 21, 2009, 8:09 a.m.
Message ID <1261382970-23251-7-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/41530/
State New
Headers show

Comments

Paolo Bonzini - Dec. 21, 2009, 8:09 a.m.
The timer_alarm_pending variable is related to the alarm timer but not
placed in the struct.  Also, in qemu_mod_timer the wrong flag was being
tested: the timer is rearmed in the alarm timer "bottom half", so the
right flag to test there is the "pending" flag.

Finally, I hoisted the NULL checks from alarm_has_dynticks to
host_alarm_handler.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 vl.c |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)

Patch

diff --git a/vl.c b/vl.c
index efffaf1..1af2f81 100644
--- a/vl.c
+++ b/vl.c
@@ -253,7 +253,6 @@  uint64_t node_cpumask[MAX_NODES];
 
 static CPUState *cur_cpu;
 static CPUState *next_cpu;
-static int timer_alarm_pending = 1;
 /* Conversion factor from emulated instructions to virtual clock ticks.  */
 static int icount_time_shift;
 /* Arbitrarily pick 1MIPS as the minimum allowable speed.  */
@@ -784,12 +783,13 @@  struct qemu_alarm_timer {
     void (*rearm)(struct qemu_alarm_timer *t);
     void *priv;
 
-    unsigned int expired;
+    char expired;
+    char pending;
 };
 
 static inline int alarm_has_dynticks(struct qemu_alarm_timer *t)
 {
-    return t && t->rearm;
+    return !!t->rearm;
 }
 
 static void qemu_rearm_alarm_timer(struct qemu_alarm_timer *t)
@@ -1084,7 +1084,7 @@  void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
 
     /* Rearm if necessary  */
     if (pt == &active_timers[ts->clock->type]) {
-        if (!alarm_timer->expired) {
+        if (!alarm_timer->pending) {
             qemu_rearm_alarm_timer(alarm_timer);
         }
         /* Interrupt execution to force deadline recalculation.  */
@@ -1202,6 +1202,10 @@  static void CALLBACK host_alarm_handler(UINT uTimerID, UINT uMsg,
 static void host_alarm_handler(int host_signum)
 #endif
 {
+    struct qemu_alarm_timer *t = alarm_timer;
+    if (!t)
+	return;
+
 #if 0
 #define DISP_FREQ 1000
     {
@@ -1231,7 +1235,7 @@  static void host_alarm_handler(int host_signum)
         last_clock = ti;
     }
 #endif
-    if (alarm_has_dynticks(alarm_timer) ||
+    if (alarm_has_dynticks(t) ||
         (!use_icount &&
             qemu_timer_expired(active_timers[QEMU_CLOCK_VIRTUAL],
                                qemu_get_clock(vm_clock))) ||
@@ -1240,7 +1244,7 @@  static void host_alarm_handler(int host_signum)
         qemu_timer_expired(active_timers[QEMU_CLOCK_HOST],
                            qemu_get_clock(host_clock))) {
         qemu_event_increment();
-        if (alarm_timer) alarm_timer->expired = 1;
+        t->expired = alarm_has_dynticks(t);
 
 #ifndef CONFIG_IOTHREAD
         if (next_cpu) {
@@ -1248,7 +1252,7 @@  static void host_alarm_handler(int host_signum)
             cpu_exit(next_cpu);
         }
 #endif
-        timer_alarm_pending = 1;
+        t->pending = 1;
         qemu_notify_event();
     }
 }
@@ -1628,6 +1632,8 @@  static int init_timer_alarm(void)
         goto fail;
     }
 
+    /* first event is at time 0 */
+    t->pending = 1;
     alarm_timer = t;
 
     return 0;
@@ -1638,8 +1644,9 @@  fail:
 
 static void quit_timers(void)
 {
-    alarm_timer->stop(alarm_timer);
+    struct qemu_alarm_timer *t = alarm_timer;
     alarm_timer = NULL;
+    t->stop(t);
 }
 
 /***********************************************************/
@@ -3997,6 +4004,8 @@  void main_loop_wait(int timeout)
         qemu_rearm_alarm_timer(alarm_timer);
     }
 
+    alarm_timer->pending = 0;
+
     /* vm time timers */
     if (vm_running) {
         if (!cur_cpu || likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER)))
@@ -4066,10 +4075,8 @@  static void tcg_cpu_exec(void)
 
         if (!vm_running)
             break;
-        if (timer_alarm_pending) {
-            timer_alarm_pending = 0;
+        if (alarm_timer->pending)
             break;
-        }
         if (cpu_can_run(env))
             ret = qemu_cpu_exec(env);
         if (ret == EXCP_DEBUG) {