Unify alarm deadline computation

This patch shows how using the correct formula for
qemu_next_deadline_dyntick can simplify the code of
host_alarm_handler and eliminate useless duplication.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Paolo Bonzini 2011-02-03 14:49:01 +01:00 committed by Anthony Liguori
parent 6ad0a1ed21
commit 4c3d45eb69

View File

@ -635,6 +635,8 @@ void qemu_run_all_timers(void)
qemu_run_timers(host_clock); qemu_run_timers(host_clock);
} }
static int64_t qemu_next_alarm_deadline(void);
#ifdef _WIN32 #ifdef _WIN32
static void CALLBACK host_alarm_handler(UINT uTimerID, UINT uMsg, static void CALLBACK host_alarm_handler(UINT uTimerID, UINT uMsg,
DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dwUser, DWORD_PTR dw1,
@ -677,14 +679,7 @@ static void host_alarm_handler(int host_signum)
} }
#endif #endif
if (alarm_has_dynticks(t) || if (alarm_has_dynticks(t) ||
(!use_icount && qemu_next_alarm_deadline () <= 0) {
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))) {
t->expired = alarm_has_dynticks(t); t->expired = alarm_has_dynticks(t);
t->pending = 1; t->pending = 1;
qemu_notify_event(); qemu_notify_event();
@ -715,11 +710,7 @@ int64_t qemu_next_deadline(void)
#ifndef _WIN32 #ifndef _WIN32
#if defined(__linux__) static int64_t qemu_next_alarm_deadline(void)
#define RTC_FREQ 1024
static uint64_t qemu_next_deadline_dyntick(void)
{ {
int64_t delta; int64_t delta;
int64_t rtdelta; int64_t rtdelta;
@ -743,12 +734,13 @@ static uint64_t qemu_next_deadline_dyntick(void)
delta = rtdelta; delta = rtdelta;
} }
if (delta < MIN_TIMER_REARM_NS)
delta = MIN_TIMER_REARM_NS;
return delta; return delta;
} }
#if defined(__linux__)
#define RTC_FREQ 1024
static void enable_sigio_timer(int fd) static void enable_sigio_timer(int fd)
{ {
struct sigaction act; struct sigaction act;
@ -903,7 +895,9 @@ static void dynticks_rearm_timer(struct qemu_alarm_timer *t)
!active_timers[QEMU_CLOCK_HOST]) !active_timers[QEMU_CLOCK_HOST])
return; return;
nearest_delta_ns = qemu_next_deadline_dyntick(); nearest_delta_ns = qemu_next_alarm_deadline();
if (nearest_delta_ns < MIN_TIMER_REARM_NS)
nearest_delta_ns = MIN_TIMER_REARM_NS;
/* check whether a timer is already running */ /* check whether a timer is already running */
if (timer_gettime(host_timer, &timeout)) { if (timer_gettime(host_timer, &timeout)) {