[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/39] mc146818rtc: fix timer interrupt reinjection
From: |
Paolo Bonzini |
Subject: |
[PULL 02/39] mc146818rtc: fix timer interrupt reinjection |
Date: |
Thu, 24 Oct 2019 16:03:18 +0200 |
From: Marcelo Tosatti <address@hidden>
commit 369b41359af46bded5799c9ef8be2b641d92e043 broke timer interrupt
reinjection when there is no period change by the guest.
In that case, old_period is 0, which ends up zeroing irq_coalesced
(counter of reinjected interrupts).
The consequence is Windows 7 is unable to synchronize time via NTP.
Easily reproducible by playing a fullscreen video with cirrus and VNC.
Fix by not updating s->irq_coalesced when old_period is 0.
V2: reorganize code (Paolo Bonzini)
Signed-off-by: Marcelo Tosatti <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/timer/mc146818rtc.c | 53 +++++++++++++++++++++++++-------------------------
1 file changed, 27 insertions(+), 26 deletions(-)
diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index 6cb3787..0e7cf97 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -203,24 +203,28 @@ periodic_timer_update(RTCState *s, int64_t current_time,
uint32_t old_period)
period = rtc_periodic_clock_ticks(s);
- if (period) {
- /* compute 32 khz clock */
- cur_clock =
- muldiv64(current_time, RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND);
+ if (!period) {
+ s->irq_coalesced = 0;
+ timer_del(s->periodic_timer);
+ return;
+ }
- /*
- * if the periodic timer's update is due to period re-configuration,
- * we should count the clock since last interrupt.
- */
- if (old_period) {
- int64_t last_periodic_clock, next_periodic_clock;
-
- next_periodic_clock = muldiv64(s->next_periodic_time,
- RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND);
- last_periodic_clock = next_periodic_clock - old_period;
- lost_clock = cur_clock - last_periodic_clock;
- assert(lost_clock >= 0);
- }
+ /* compute 32 khz clock */
+ cur_clock =
+ muldiv64(current_time, RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND);
+
+ /*
+ * if the periodic timer's update is due to period re-configuration,
+ * we should count the clock since last interrupt.
+ */
+ if (old_period) {
+ int64_t last_periodic_clock, next_periodic_clock;
+
+ next_periodic_clock = muldiv64(s->next_periodic_time,
+ RTC_CLOCK_RATE, NANOSECONDS_PER_SECOND);
+ last_periodic_clock = next_periodic_clock - old_period;
+ lost_clock = cur_clock - last_periodic_clock;
+ assert(lost_clock >= 0);
/*
* s->irq_coalesced can change for two reasons:
@@ -251,22 +255,19 @@ periodic_timer_update(RTCState *s, int64_t current_time,
uint32_t old_period)
rtc_coalesced_timer_update(s);
}
} else {
- /*
+ /*
* no way to compensate the interrupt if LOST_TICK_POLICY_SLEW
* is not used, we should make the time progress anyway.
*/
lost_clock = MIN(lost_clock, period);
}
+ }
- assert(lost_clock >= 0 && lost_clock <= period);
+ assert(lost_clock >= 0 && lost_clock <= period);
- next_irq_clock = cur_clock + period - lost_clock;
- s->next_periodic_time = periodic_clock_to_ns(next_irq_clock) + 1;
- timer_mod(s->periodic_timer, s->next_periodic_time);
- } else {
- s->irq_coalesced = 0;
- timer_del(s->periodic_timer);
- }
+ next_irq_clock = cur_clock + period - lost_clock;
+ s->next_periodic_time = periodic_clock_to_ns(next_irq_clock) + 1;
+ timer_mod(s->periodic_timer, s->next_periodic_time);
}
static void rtc_periodic_timer(void *opaque)
--
1.8.3.1
- [PULL 00/39] Misc (mostly x86) patches for 2019-10-24, Paolo Bonzini, 2019/10/24
- [PULL 01/39] target/i386: log MCE guest and host addresses, Paolo Bonzini, 2019/10/24
- [PULL 06/39] memory-device: simplify Makefile.objs conditions, Paolo Bonzini, 2019/10/24
- [PULL 04/39] i386/kvm: add NoNonArchitecturalCoreSharing Hyper-V enlightenment, Paolo Bonzini, 2019/10/24
- [PULL 02/39] mc146818rtc: fix timer interrupt reinjection,
Paolo Bonzini <=
- [PULL 05/39] Do not use %m in common code to print error messages, Paolo Bonzini, 2019/10/24
- [PULL 03/39] Updated Bulgarian translation (19) - 4.1.0, Paolo Bonzini, 2019/10/24
- [PULL 08/39] hw/i386/pc: rename functions shared with non-PC machines, Paolo Bonzini, 2019/10/24
- [PULL 07/39] hw/virtio: Factorize virtio-mmio headers, Paolo Bonzini, 2019/10/24
- [PULL 10/39] hw/i386/pc: replace use of strtol with qemu_strtoui in x86_load_linux(), Paolo Bonzini, 2019/10/24
- [PULL 11/39] hw/i386/pc: avoid an assignment in if condition in x86_load_linux(), Paolo Bonzini, 2019/10/24
- [PULL 09/39] hw/i386/pc: fix code style issues on functions that will be moved out, Paolo Bonzini, 2019/10/24
- [PULL 17/39] hw/intc/apic: reject pic ints if isa_pic == NULL, Paolo Bonzini, 2019/10/24