qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/3] Fix time drift problem under high load when PIT is in use.
Date: Wed, 29 Oct 2008 17:22:47 +0200	[thread overview]
Message-ID: <20081029152247.14831.41835.stgit@dhcp-1-237.local> (raw)
In-Reply-To: <20081029152236.14831.15193.stgit@dhcp-1-237.local>

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 <gleb@redhat.com>
---

 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);
     }
 }

  parent reply	other threads:[~2008-10-29 15:22 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-29 15:22 [Qemu-devel] [RESEND][PATCH 0/3] Fix guest time drift under heavy load Gleb Natapov
2008-10-29 15:22 ` [Qemu-devel] [PATCH 1/3] Change qemu_set_irq() to return status information Gleb Natapov
2008-10-29 15:22 ` Gleb Natapov [this message]
2008-10-29 15:22 ` [Qemu-devel] [PATCH 3/3] Fix time drift problem under high load when RTC is in use Gleb Natapov
2008-11-05 12:46   ` Dor Laor
2008-10-31 19:17 ` [Qemu-devel] [RESEND][PATCH 0/3] Fix guest time drift under heavy load Anthony Liguori
2008-11-02 13:04   ` Gleb Natapov
2008-11-05 12:45     ` Dor Laor
2008-11-05 15:48       ` andrzej zaborowski
2008-11-05 16:33         ` Anthony Liguori
2008-11-06  7:16         ` Gleb Natapov
2008-11-06  9:37           ` andrzej zaborowski
2008-11-06 10:08             ` Gleb Natapov
2008-11-06 13:21               ` andrzej zaborowski
2008-11-06 14:18                 ` Gleb Natapov
2008-11-06 14:35                   ` andrzej zaborowski
2008-11-06 15:04                     ` Gleb Natapov
2008-11-06 15:41                       ` Anthony Liguori
2008-11-07 23:18                       ` andrzej zaborowski
2008-11-08  8:23                         ` Gleb Natapov
2008-11-06 13:44               ` Paul Brook
2008-11-05 17:43       ` Gleb Natapov
2008-11-06 17:28       ` David S. Ahern
2008-11-05 16:43     ` Anthony Liguori
2008-11-06  3:55       ` Jamie Lokier
2008-11-06  8:12       ` Gleb Natapov
2008-11-06 14:10         ` Anthony Liguori
2008-11-06 14:24           ` Paul Brook
2008-11-06 14:40             ` Anthony Liguori
2008-11-06 14:51               ` Gleb Natapov
2008-11-06 15:37                 ` Anthony Liguori
2008-11-08  8:36                   ` Gleb Natapov
2008-11-08 22:14                     ` Dor Laor
2008-11-09  7:40                     ` Gleb Natapov
2008-11-09 16:38                       ` Anthony Liguori
2008-11-09 21:00                         ` Avi Kivity
2008-11-09 16:36                     ` Anthony Liguori
2008-11-10 14:37                       ` Gleb Natapov
2008-11-10 15:24                         ` Anthony Liguori
2008-11-10 15:29                           ` Gleb Natapov
2008-11-10 15:46                             ` Anthony Liguori
2008-11-10 15:51                               ` Gleb Natapov
2008-11-11 14:43                               ` Gleb Natapov
2008-11-11 17:26                                 ` Anthony Liguori
2008-11-11 20:17                                 ` Anthony Liguori
2008-11-12 11:42                                   ` Gleb Natapov
2008-11-12 11:54                                     ` Glauber Costa
2008-11-12 12:38                                       ` Dor Laor
2008-11-06  3:41     ` Jamie Lokier
  -- strict thread matches above, loose matches on Subject: below --
2008-06-29 14:02 [Qemu-devel] [PATCH " Gleb Natapov
2008-06-29 14:02 ` [Qemu-devel] [PATCH 2/3] Fix time drift problem under high load when PIT is in use Gleb Natapov
2008-06-23 10:49 [Qemu-devel] [PATCH 0/3] Fix guest time drift under heavy load Gleb Natapov
2008-06-23 10:49 ` [Qemu-devel] [PATCH 2/3] Fix time drift problem under high load when PIT is in use Gleb Natapov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081029152247.14831.41835.stgit@dhcp-1-237.local \
    --to=gleb@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).