[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 2/3] Fix time drift problem under high load when
From: |
Gleb Natapov |
Subject: |
[Qemu-devel] [PATCH v2 2/3] Fix time drift problem under high load when PIT is in use. |
Date: |
Tue, 08 Jul 2008 14:15:41 +0300 |
User-agent: |
StGIT/0.14.2 |
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
pit is used as a time source.
Signed-off-by: Gleb Natapov <address@hidden>
---
hw/i8254.c | 23 ++++++++++++++++++++++-
1 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/hw/i8254.c b/hw/i8254.c
index 4813b03..1a43ffc 100644
--- a/hw/i8254.c
+++ b/hw/i8254.c
@@ -49,6 +49,7 @@ typedef struct PITChannelState {
int64_t count_load_time;
/* irq handling */
int64_t next_transition_time;
+ uint32_t irq_coalesced;
QEMUTimer *irq_timer;
qemu_irq irq;
} PITChannelState;
@@ -228,6 +229,9 @@ static inline void pit_load_count(PITChannelState *s, int
val)
{
if (val == 0)
val = 0x10000;
+ /* recalculate how much IRQs to inject based on new timer value */
+ if(s->irq_coalesced)
+ s->irq_coalesced = (s->irq_coalesced * s->count) / val;
s->count_load_time = qemu_get_clock(vm_clock);
s->count = val;
pit_irq_timer_update(s, s->count_load_time);
@@ -369,12 +373,28 @@ static void pit_irq_timer_update(PITChannelState *s,
int64_t current_time)
return;
expire_time = pit_get_next_transition_time(s, current_time);
irq_level = pit_get_out1(s, current_time);
- qemu_set_irq(s->irq, irq_level);
+ if(irq_level) {
+ if(!qemu_irq_raise(s->irq))
+ s->irq_coalesced++;
+ } else {
+ qemu_irq_lower(s->irq);
+ if(s->irq_coalesced > 0) {
+ if(qemu_irq_raise(s->irq))
+ s->irq_coalesced--;
+ qemu_irq_lower(s->irq);
+ }
+ }
+
#ifdef DEBUG_PIT
printf("irq_level=%d next_delay=%f\n",
irq_level,
(double)(expire_time - current_time) / ticks_per_sec);
#endif
+ if(s->irq_coalesced && expire_time != -1) {
+ uint32_t div = ((s->irq_coalesced >> 10) & 0x7f) + 2;
+ expire_time -= ((expire_time - current_time) / div);
+ }
+
s->next_transition_time = expire_time;
if (expire_time != -1)
qemu_mod_timer(s->irq_timer, expire_time);
@@ -459,6 +479,7 @@ static void pit_reset(void *opaque)
s = &pit->channels[i];
s->mode = 3;
s->gate = (i != 2);
+ s->irq_coalesced = 0;
pit_load_count(s, 0);
}
}