From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KD3yD-0006kw-DO for qemu-devel@nongnu.org; Sun, 29 Jun 2008 16:58:01 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KD3yB-0006hS-By for qemu-devel@nongnu.org; Sun, 29 Jun 2008 16:58:00 -0400 Received: from [199.232.76.173] (port=42207 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KD3yA-0006gm-Jb for qemu-devel@nongnu.org; Sun, 29 Jun 2008 16:57:58 -0400 Received: from il.qumranet.com ([212.179.150.194]:20692) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KD3yA-00014o-2I for qemu-devel@nongnu.org; Sun, 29 Jun 2008 16:57:58 -0400 From: Dor Laor In-Reply-To: <20080629135917.5447.7163.stgit@gleb-debian.qumranet.com.qumranet.com> References: <20080629135455.5447.90849.stgit@gleb-debian.qumranet.com.qumranet.com> <20080629135917.5447.7163.stgit@gleb-debian.qumranet.com.qumranet.com> Content-Type: text/plain; charset=UTF-8 Date: Sun, 29 Jun 2008 23:56:22 +0300 Message-Id: <1214772982.782.97.camel@localhost.localdomain> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] Re: [PATCH 2/3] Fix time drift problem under high load when PIT is in use. Reply-To: dor.laor@qumranet.com, qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gleb Natapov Cc: qemu-devel , kvm@vger.kernel.org On Sun, 2008-06-29 at 16:59 +0300, Gleb Natapov wrote: > Count the number of interrupts that was lost due to interrupt coalescin= g > and re-inject them back when possible. This fixes time drift problem wh= en > pit is used as a time source. >=20 > Signed-off-by: Gleb Natapov > --- >=20 > hw/i8254.c | 20 +++++++++++++++++++- > 1 files changed, 19 insertions(+), 1 deletions(-) >=20 > diff --git a/hw/i8254.c b/hw/i8254.c > index 4813b03..c4f0f46 100644 > --- a/hw/i8254.c > +++ b/hw/i8254.c > @@ -61,6 +61,8 @@ static PITState pit_state; > =20 > static void pit_irq_timer_update(PITChannelState *s, int64_t current_t= ime); > =20 > +static uint32_t pit_irq_coalesced; The pit has 3 channels, it should be a channel field. Also every time the pit frequency changes the above field should be compensated with * (new_freq/old_freq).=20 For example, if the guest was running with 1000hz clock and the pit_irq_coalesced value is 100 currently, a frequency change to 100hz should reduce =EF=BB=BFpit_irq_coalesced to 10. Except that, its high time we stop drifting :) > + > static int pit_get_count(PITChannelState *s) > { > uint64_t d; > @@ -369,12 +371,28 @@ static void pit_irq_timer_update(PITChannelState = *s, int64_t current_time) > return; > expire_time =3D pit_get_next_transition_time(s, current_time); > irq_level =3D pit_get_out1(s, current_time); > - qemu_set_irq(s->irq, irq_level); > + if(irq_level) { > + if(!qemu_irq_raise(s->irq)) > + pit_irq_coalesced++; > + } else { > + qemu_irq_lower(s->irq); > + if(pit_irq_coalesced > 0) { > + if(qemu_irq_raise(s->irq)) > + pit_irq_coalesced--; > + qemu_irq_lower(s->irq); > + } > + } > + > #ifdef DEBUG_PIT > printf("irq_level=3D%d next_delay=3D%f\n", > irq_level, > (double)(expire_time - current_time) / ticks_per_sec); > #endif > + if(pit_irq_coalesced && expire_time !=3D -1) { > + uint32_t div =3D ((pit_irq_coalesced >> 10) & 0x7f) + 2; > + expire_time -=3D ((expire_time - current_time) / div); > + } > + > s->next_transition_time =3D expire_time; > if (expire_time !=3D -1) > qemu_mod_timer(s->irq_timer, expire_time); >=20 > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html