qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 4/4] inline qemu_icount_delta


From: Paolo Bonzini
Subject: [Qemu-devel] [PATCH 4/4] inline qemu_icount_delta
Date: Mon, 21 Feb 2011 09:51:26 +0100

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]