Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J9rPW-0005ys-1D for qemu-devel@nongnu.org; Tue, 01 Jan 2008 19:24:42 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J9rPV-0005yS-51 for qemu-devel@nongnu.org; Tue, 01 Jan 2008 19:24:41 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J9rPV-0005yO-1A for qemu-devel@nongnu.org; Tue, 01 Jan 2008 19:24:41 -0500 Received: from 0xc2c0b63d.fbbft3nxf1.bf-dhcp.tele.dk ([194.192.182.61] helo=smtp.hotelhot.dk) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1J9rPU-0006k3-Jt for qemu-devel@nongnu.org; Tue, 01 Jan 2008 19:24:40 -0500 Received: from smtp.hotelhot.dk (localhost [127.0.0.1]) by smtp.hotelhot.dk (Postfix) with ESMTP id 8A08514263 for ; Wed, 2 Jan 2008 01:24:34 +0100 (CET) Received: from kalibalik.dk (dylle.kalibalik.dk [192.168.0.251]) by smtp.hotelhot.dk (Postfix) with SMTP id 7858E14254 for ; Wed, 2 Jan 2008 01:24:33 +0100 (CET) From: Anders Date: Wed, 02 Jan 2008 01:24:33 +0100 Message-ID: <87prwlrs5a.fsf@dylle.kalibalik.dk> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Subject: [Qemu-devel] [PATCH] Rearm timer more often Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --=-=-= The timer must be rearmed if a new timeout is added at the start of the timeout list (or the new timeout will be expired too late.) However, as the rearming always happens after servicing expired timers, do not rearm in that case. Also, move the setting of the dirty flag outside conditional in host_alarm_handler(), to make sure it is always done. This broke kvm. Cheers, Anders. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=qemu-more-rearm.diff diff --git a/vl.c b/vl.c index 129166d..a7d9021 100644 --- a/vl.c +++ b/vl.c @@ -822,7 +822,7 @@ struct qemu_alarm_timer { }; #define ALARM_FLAG_DYNTICKS 0x1 -#define ALARM_FLAG_MODIFIED 0x2 +#define ALARM_FLAG_EXPIRED 0x2 static inline int alarm_has_dynticks(struct qemu_alarm_timer *t) { @@ -834,11 +834,6 @@ 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); } @@ -1001,8 +996,6 @@ 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]; @@ -1041,6 +1034,12 @@ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time) ts->expire_time = expire_time; ts->next = *pt; *pt = ts; + + /* Rearm if necessary */ + if ((alarm_timer->flags & ALARM_FLAG_EXPIRED) == 0 + && pt == &active_timers[ts->clock->type]) { + qemu_rearm_alarm_timer(alarm_timer); + } } int qemu_timer_pending(QEMUTimer *ts) @@ -1193,8 +1192,9 @@ static void host_alarm_handler(int host_signum) #endif CPUState *env = next_cpu; + alarm_timer->flags |= ALARM_FLAG_EXPIRED; + 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 @@ -7396,7 +7396,10 @@ 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); + if (alarm_timer->flags & ALARM_FLAG_EXPIRED) { + alarm_timer->flags &= ~(ALARM_FLAG_EXPIRED); + qemu_rearm_alarm_timer(alarm_timer); + } /* Check bottom-halves last in case any of the earlier events triggered them. */ --=-=-=--