Commit d5d08334d4f18e98a4a47a6a747ddb540e1106e7

Authored by balrog
1 parent 6d1f1778

Rearm timers in qemu_mod_timer when needed (Anders Melchiorsen).


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3890 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 14 additions and 12 deletions
... ... @@ -822,7 +822,7 @@ struct qemu_alarm_timer {
822 822 };
823 823  
824 824 #define ALARM_FLAG_DYNTICKS 0x1
825   -#define ALARM_FLAG_MODIFIED 0x2
  825 +#define ALARM_FLAG_EXPIRED 0x2
826 826  
827 827 static inline int alarm_has_dynticks(struct qemu_alarm_timer *t)
828 828 {
... ... @@ -834,11 +834,6 @@ static void qemu_rearm_alarm_timer(struct qemu_alarm_timer *t)
834 834 if (!alarm_has_dynticks(t))
835 835 return;
836 836  
837   - if (!(t->flags & ALARM_FLAG_MODIFIED))
838   - return;
839   -
840   - t->flags &= ~(ALARM_FLAG_MODIFIED);
841   -
842 837 t->rearm(t);
843 838 }
844 839  
... ... @@ -1001,8 +996,6 @@ void qemu_del_timer(QEMUTimer *ts)
1001 996 {
1002 997 QEMUTimer **pt, *t;
1003 998  
1004   - alarm_timer->flags |= ALARM_FLAG_MODIFIED;
1005   -
1006 999 /* NOTE: this code must be signal safe because
1007 1000 qemu_timer_expired() can be called from a signal. */
1008 1001 pt = &active_timers[ts->clock->type];
... ... @@ -1041,6 +1034,11 @@ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
1041 1034 ts->expire_time = expire_time;
1042 1035 ts->next = *pt;
1043 1036 *pt = ts;
  1037 +
  1038 + /* Rearm if necessary */
  1039 + if ((alarm_timer->flags & ALARM_FLAG_EXPIRED) == 0 &&
  1040 + pt == &active_timers[ts->clock->type])
  1041 + qemu_rearm_alarm_timer(alarm_timer);
1044 1042 }
1045 1043  
1046 1044 int qemu_timer_pending(QEMUTimer *ts)
... ... @@ -1193,8 +1191,9 @@ static void host_alarm_handler(int host_signum)
1193 1191 #endif
1194 1192 CPUState *env = next_cpu;
1195 1193  
  1194 + alarm_timer->flags |= ALARM_FLAG_EXPIRED;
  1195 +
1196 1196 if (env) {
1197   - alarm_timer->flags |= ALARM_FLAG_MODIFIED;
1198 1197 /* stop the currently executing cpu because a timer occured */
1199 1198 cpu_interrupt(env, CPU_INTERRUPT_EXIT);
1200 1199 #ifdef USE_KQEMU
... ... @@ -1379,7 +1378,7 @@ static void dynticks_rearm_timer(struct qemu_alarm_timer *t)
1379 1378  
1380 1379 if (!active_timers[QEMU_TIMER_REALTIME] &&
1381 1380 !active_timers[QEMU_TIMER_VIRTUAL])
1382   - return;
  1381 + return;
1383 1382  
1384 1383 nearest_delta_us = qemu_next_deadline();
1385 1384  
... ... @@ -1506,7 +1505,7 @@ static void win32_rearm_timer(struct qemu_alarm_timer *t)
1506 1505  
1507 1506 if (!active_timers[QEMU_TIMER_REALTIME] &&
1508 1507 !active_timers[QEMU_TIMER_VIRTUAL])
1509   - return;
  1508 + return;
1510 1509  
1511 1510 nearest_delta_us = qemu_next_deadline();
1512 1511 nearest_delta_us /= 1000;
... ... @@ -7396,7 +7395,10 @@ void main_loop_wait(int timeout)
7396 7395 qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME],
7397 7396 qemu_get_clock(rt_clock));
7398 7397  
7399   - qemu_rearm_alarm_timer(alarm_timer);
  7398 + if (alarm_timer->flags & ALARM_FLAG_EXPIRED) {
  7399 + alarm_timer->flags &= ~(ALARM_FLAG_EXPIRED);
  7400 + qemu_rearm_alarm_timer(alarm_timer);
  7401 + }
7400 7402  
7401 7403 /* Check bottom-halves last in case any of the earlier events triggered
7402 7404 them. */
... ...