From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KxhmH-0000ER-Di for qemu-devel@nongnu.org; Wed, 05 Nov 2008 07:46:29 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KxhmG-0000EB-Qa for qemu-devel@nongnu.org; Wed, 05 Nov 2008 07:46:29 -0500 Received: from [199.232.76.173] (port=45479 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KxhmG-0000E6-OA for qemu-devel@nongnu.org; Wed, 05 Nov 2008 07:46:28 -0500 Received: from mx2.redhat.com ([66.187.237.31]:60153) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KxhmG-000051-Hs for qemu-devel@nongnu.org; Wed, 05 Nov 2008 07:46:28 -0500 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id mA5CkRwf027148 for ; Wed, 5 Nov 2008 07:46:27 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id mA5CkQe0014188 for ; Wed, 5 Nov 2008 07:46:27 -0500 Received: from localhost.localdomain (vpn-12-67.rdu.redhat.com [10.11.12.67]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id mA5CkP8N006396 for ; Wed, 5 Nov 2008 07:46:26 -0500 Message-ID: <491195B5.6080206@redhat.com> Date: Wed, 05 Nov 2008 14:46:45 +0200 From: Dor Laor MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 3/3] Fix time drift problem under high load when RTC is in use. References: <20081029152236.14831.15193.stgit@dhcp-1-237.local> <20081029152252.14831.7543.stgit@dhcp-1-237.local> In-Reply-To: <20081029152252.14831.7543.stgit@dhcp-1-237.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Reply-To: dlaor@redhat.com, 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 Gleb Natapov wrote: > Count the number of interrupts that was lost due to interrupt coalescing > and re-inject them back when possible. This fixes time drift problem when > RTC is used as a time source. > > Signed-off-by: Gleb Natapov > --- > > hw/mc146818rtc.c | 11 +++++++++-- > 1 files changed, 9 insertions(+), 2 deletions(-) > > diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c > index 30bb044..505e117 100644 > --- a/hw/mc146818rtc.c > +++ b/hw/mc146818rtc.c > @@ -66,6 +66,7 @@ struct RTCState { > int64_t next_periodic_time; > /* second update */ > int64_t next_second_time; > + uint32_t irq_coalesced; > QEMUTimer *second_timer; > QEMUTimer *second_timer2; > }; > @@ -101,7 +102,8 @@ static void rtc_periodic_timer(void *opaque) > > rtc_timer_update(s, s->next_periodic_time); > s->cmos_data[RTC_REG_C] |= 0xc0; > - qemu_irq_raise(s->irq); > + if(!qemu_irq_raise(s->irq)) > + s->irq_coalesced++; > } > > static void cmos_ioport_write(void *opaque, uint32_t addr, uint32_t data) > @@ -360,7 +362,12 @@ static uint32_t cmos_ioport_read(void *opaque, uint32_t addr) > case RTC_REG_C: > ret = s->cmos_data[s->cmos_index]; > qemu_irq_lower(s->irq); > - s->cmos_data[RTC_REG_C] = 0x00; > + if(!s->irq_coalesced) { > + s->cmos_data[RTC_REG_C] = 0x00; > + } else { > + if(qemu_irq_raise(s->irq)) > + s->irq_coalesced--; > + } > break; > default: > ret = s->cmos_data[s->cmos_index]; > > > The rtc needs to recalculate the irq_coalesced counter if the frequency was changed, similarly to the pit patch.