qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: edgar.iglesias@gmail.com
Subject: [Qemu-devel] [PATCH 4/4] inline qemu_icount_delta
Date: Mon, 21 Feb 2011 09:51:26 +0100	[thread overview]
Message-ID: <1298278286-9158-5-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1298278286-9158-1-git-send-email-pbonzini@redhat.com>

In order to improve accuracy with -icount N, we inline qemu_icount_delta
into qemu_calculate_timeout.

This way, we can still avoid that virtual time gets too far ahead of
real time when using low speeds.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-timer.c |   26 +++++++++++---------------
 1 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index 163ec69..5cc7e60 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -110,18 +110,6 @@ static int64_t cpu_get_clock(void)
     }
 }
 
-static int64_t qemu_icount_delta(void)
-{
-    if (use_icount == 1) {
-        /* When not using an adaptive execution frequency
-           we tend to get badly out of sync with real time,
-           so just delay for a reasonable amount of time.  */
-        return 0;
-    } else {
-        return cpu_get_icount() - cpu_get_clock();
-    }
-}
-
 /* enable cpu_get_ticks() */
 void cpu_enable_ticks(void)
 {
@@ -618,6 +606,7 @@ static int64_t cpu_clock_last_read;
 
 int qemu_calculate_timeout(void)
 {
+    int64_t cur_time, cur_icount;
     int64_t delta;
 
     /* When using icount, vm_clock timers are handled outside of the alarm
@@ -628,10 +617,17 @@ int qemu_calculate_timeout(void)
         return 5000;
     }
 
-    delta = qemu_icount_delta();
-    if (delta > 0) {
+    cur_time = cpu_get_clock();
+    cur_icount = cpu_get_icount();
+    if (cur_icount > cur_time) {
         /* Virtual time is ahead of real time, wait for it to sync.  Time
-           spent waiting for I/O will not be counted.  */
+           spent waiting for I/O will not be counted.  Be careful to avoid
+           overflow.  */
+        if (cur_icount > cur_time + INT32_MAX) {
+            delta = INT32_MAX;
+        } else {
+            delta = cur_icount - cur_time;
+        }
         cpu_clock_last_read = -1;
     } else {
         /* Wait until the next virtual time event, and account the wait
-- 
1.7.3.5

  parent reply	other threads:[~2011-02-21  8:51 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-21  8:51 [Qemu-devel] [PATCH 0/4] Improve -icount, fix it with iothread Paolo Bonzini
2011-02-21  8:51 ` [Qemu-devel] [PATCH 1/4] do not use qemu_icount_delta in the !use_icount case Paolo Bonzini
2011-02-21  8:51 ` [Qemu-devel] [PATCH 2/4] qemu_next_deadline should not consider host-time timers Paolo Bonzini
2011-02-21  8:51 ` [Qemu-devel] [PATCH 3/4] rewrite accounting of wait time to the vm_clock Paolo Bonzini
2011-02-21  8:51 ` Paolo Bonzini [this message]
2011-02-23 10:18 ` [Qemu-devel] Re: [PATCH 0/4] Improve -icount, fix it with iothread Edgar E. Iglesias
2011-02-23 10:25   ` Paolo Bonzini
2011-02-23 11:08     ` Edgar E. Iglesias
2011-02-23 11:39       ` Jan Kiszka
2011-02-23 12:40         ` Edgar E. Iglesias
2011-02-23 12:45           ` Jan Kiszka
2011-02-25 19:33         ` Paolo Bonzini
2011-02-23 12:42       ` Paolo Bonzini
2011-02-23 16:27         ` Edgar E. Iglesias
2011-02-23 16:32           ` Paolo Bonzini

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=1298278286-9158-5-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=edgar.iglesias@gmail.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).