Skip to content

Commit

Permalink
Redundant timer rearm optimisation by Anders Melchiorsen.
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3823 c046a42c-6fe2-441c-8c8c-71466251a162
  • Loading branch information
balrog committed Dec 16, 2007
1 parent b01bcae commit b99dc0d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion vl.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ struct qemu_alarm_timer {
};

#define ALARM_FLAG_DYNTICKS 0x1
#define ALARM_FLAG_MODIFIED 0x2

static inline int alarm_has_dynticks(struct qemu_alarm_timer *t)
{
Expand All @@ -833,6 +834,11 @@ static void qemu_rearm_alarm_timer(struct qemu_alarm_timer *t)
if (!alarm_has_dynticks(t))
return;

if (!(t->flags & ALARM_FLAG_MODIFIED))
return;

t->flags &= ~(ALARM_FLAG_MODIFIED);

t->rearm(t);
}

Expand Down Expand Up @@ -995,6 +1001,8 @@ void qemu_del_timer(QEMUTimer *ts)
{
QEMUTimer **pt, *t;

alarm_timer->flags |= ALARM_FLAG_MODIFIED;

/* NOTE: this code must be signal safe because
qemu_timer_expired() can be called from a signal. */
pt = &active_timers[ts->clock->type];
Expand Down Expand Up @@ -1067,7 +1075,6 @@ static void qemu_run_timers(QEMUTimer **ptimer_head, int64_t current_time)
/* run the callback (the timer list can be modified) */
ts->cb(ts->opaque);
}
qemu_rearm_alarm_timer(alarm_timer);
}

int64_t qemu_get_clock(QEMUClock *clock)
Expand Down Expand Up @@ -1187,6 +1194,7 @@ static void host_alarm_handler(int host_signum)
CPUState *env = next_cpu;

if (env) {
alarm_timer->flags |= ALARM_FLAG_MODIFIED;
/* stop the currently executing cpu because a timer occured */
cpu_interrupt(env, CPU_INTERRUPT_EXIT);
#ifdef USE_KQEMU
Expand Down Expand Up @@ -7364,6 +7372,8 @@ void main_loop_wait(int timeout)
qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME],
qemu_get_clock(rt_clock));

qemu_rearm_alarm_timer(alarm_timer);

/* Check bottom-halves last in case any of the earlier events triggered
them. */
qemu_bh_poll();
Expand Down

0 comments on commit b99dc0d

Please sign in to comment.