Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lwivj-0004Io-Mc for qemu-devel@nongnu.org; Wed, 22 Apr 2009 16:20:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lwivi-0004Hu-Uv for qemu-devel@nongnu.org; Wed, 22 Apr 2009 16:20:27 -0400 Received: from [199.232.76.173] (port=52922 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lwivi-0004He-ER for qemu-devel@nongnu.org; Wed, 22 Apr 2009 16:20:26 -0400 Received: from savannah.gnu.org ([199.232.41.3]:39489 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lwivi-0008Ij-7F for qemu-devel@nongnu.org; Wed, 22 Apr 2009 16:20:26 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Lwivh-0007yC-9P for qemu-devel@nongnu.org; Wed, 22 Apr 2009 20:20:25 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1Lwivf-0007y7-Tv for qemu-devel@nongnu.org; Wed, 22 Apr 2009 20:20:24 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Wed, 22 Apr 2009 20:20:23 +0000 Subject: [Qemu-devel] [7231] Change RTC time drift IRQ re-injection (Gleb Natapov) List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 7231 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7231 Author: aliguori Date: 2009-04-22 20:20:22 +0000 (Wed, 22 Apr 2009) Log Message: ----------- Change RTC time drift IRQ re-injection (Gleb Natapov) Currently IRQ are reinjected as soon as they are acknowledged to the RTC, but Windows sometimes do acknowledgement in a loop with global interrupt disabled waiting for interrupt to be cleared and it does not mask RTC vector in PIC/APIC while doing this. In such situation interrupt injection always fails and RTC interrupt is never cleared. Instead of reinjecting coalesced IRQs on acknowledgement the patch below reinjects them by accelerating RTC clock a bit. This way RTC interrupt is not constantly raced after coalesced interrupt. Signed-off-by: Gleb Natapov Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/hw/mc146818rtc.c Modified: trunk/hw/mc146818rtc.c =================================================================== --- trunk/hw/mc146818rtc.c 2009-04-22 20:20:07 UTC (rev 7230) +++ trunk/hw/mc146818rtc.c 2009-04-22 20:20:22 UTC (rev 7231) @@ -73,6 +73,7 @@ #ifdef TARGET_I386 uint32_t irq_coalesced; uint32_t period; + QEMUTimer *coalesced_timer; #endif QEMUTimer *second_timer; QEMUTimer *second_timer2; @@ -93,6 +94,37 @@ static void rtc_set_time(RTCState *s); static void rtc_copy_date(RTCState *s); +#ifdef TARGET_I386 +static void rtc_coalesced_timer_update(RTCState *s) +{ + if (s->irq_coalesced == 0) { + qemu_del_timer(s->coalesced_timer); + } else { + /* divide each RTC interval to 2 - 8 smaller intervals */ + int c = MIN(s->irq_coalesced, 7) + 1; + int64_t next_clock = qemu_get_clock(vm_clock) + + muldiv64(s->period / c, ticks_per_sec, 32768); + qemu_mod_timer(s->coalesced_timer, next_clock); + } +} + +static void rtc_coalesced_timer(void *opaque) +{ + RTCState *s = opaque; + + if (s->irq_coalesced != 0) { + apic_reset_irq_delivered(); + s->cmos_data[RTC_REG_C] |= 0xc0; + rtc_irq_raise(s->irq); + if (apic_get_irq_delivered()) { + s->irq_coalesced--; + } + } + + rtc_coalesced_timer_update(s); +} +#endif + static void rtc_timer_update(RTCState *s, int64_t current_time) { int period_code, period; @@ -138,14 +170,18 @@ RTCState *s = opaque; rtc_timer_update(s, s->next_periodic_time); + if (s->cmos_data[RTC_REG_B] & REG_B_PIE) { + s->cmos_data[RTC_REG_C] |= 0xc0; #ifdef TARGET_I386 - if ((s->cmos_data[RTC_REG_C] & 0xc0) && rtc_td_hack) { - s->irq_coalesced++; - return; - } + if(rtc_td_hack) { + apic_reset_irq_delivered(); + rtc_irq_raise(s->irq); + if (!apic_get_irq_delivered()) { + s->irq_coalesced++; + rtc_coalesced_timer_update(s); + } + } else #endif - if (s->cmos_data[RTC_REG_B] & REG_B_PIE) { - s->cmos_data[RTC_REG_C] |= 0xc0; rtc_irq_raise(s->irq); } if (s->cmos_data[RTC_REG_B] & REG_B_SQWE) { @@ -415,15 +451,6 @@ case RTC_REG_C: ret = s->cmos_data[s->cmos_index]; qemu_irq_lower(s->irq); -#ifdef TARGET_I386 - if(s->irq_coalesced) { - apic_reset_irq_delivered(); - qemu_irq_raise(s->irq); - if (apic_get_irq_delivered()) - s->irq_coalesced--; - break; - } -#endif s->cmos_data[RTC_REG_C] = 0x00; break; default: @@ -536,6 +563,7 @@ s->irq_coalesced = qemu_get_be32(f); s->period = qemu_get_be32(f); + rtc_coalesced_timer_update(s); return 0; } #endif @@ -558,6 +586,10 @@ s->periodic_timer = qemu_new_timer(vm_clock, rtc_periodic_timer, s); +#ifdef TARGET_I386 + if (rtc_td_hack) + s->coalesced_timer = qemu_new_timer(vm_clock, rtc_coalesced_timer, s); +#endif s->second_timer = qemu_new_timer(vm_clock, rtc_update_second, s); s->second_timer2 = qemu_new_timer(vm_clock,