diff mbox

[02/19] add qemu_icount_round

Message ID 1261382970-23251-3-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Dec. 21, 2009, 8:09 a.m. UTC
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 vl.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/vl.c b/vl.c
index e38cea7..97410ad 100644
--- a/vl.c
+++ b/vl.c
@@ -920,6 +920,11 @@  static void configure_icount(const char *option)
                    qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10);
 }
 
+static int64_t qemu_icount_round(int64_t count)
+{
+    return (count + (1 << icount_time_shift) - 1) >> icount_time_shift;
+}
+
 static struct qemu_alarm_timer alarm_timers[] = {
 #ifndef _WIN32
 #ifdef __linux__
@@ -4031,9 +4036,7 @@  static int qemu_cpu_exec(CPUState *env)
         qemu_icount -= (env->icount_decr.u16.low + env->icount_extra);
         env->icount_decr.u16.low = 0;
         env->icount_extra = 0;
-        count = qemu_next_deadline();
-        count = (count + (1 << icount_time_shift) - 1)
-                >> icount_time_shift;
+        count = qemu_icount_round (qemu_next_deadline());
         qemu_icount += count;
         decr = (count > 0xffff) ? 0xffff : count;
         count -= decr;
@@ -4141,9 +4144,7 @@  static int qemu_calculate_timeout(void)
             if (add > 10000000)
                 add = 10000000;
             delta += add;
-            add = (add + (1 << icount_time_shift) - 1)
-                  >> icount_time_shift;
-            qemu_icount += add;
+            qemu_icount += qemu_icount_round (add);
             timeout = delta / 1000000;
             if (timeout < 0)
                 timeout = 0;