[Top][All Lists]
[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
- [Qemu-devel] [PATCH 0/4] Improve -icount, fix it with iothread, Paolo Bonzini, 2011/02/21
- [Qemu-devel] [PATCH 1/4] do not use qemu_icount_delta in the !use_icount case, Paolo Bonzini, 2011/02/21
- [Qemu-devel] [PATCH 3/4] rewrite accounting of wait time to the vm_clock, Paolo Bonzini, 2011/02/21
- [Qemu-devel] [PATCH 4/4] inline qemu_icount_delta,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 2/4] qemu_next_deadline should not consider host-time timers, Paolo Bonzini, 2011/02/21
- [Qemu-devel] Re: [PATCH 0/4] Improve -icount, fix it with iothread, Edgar E. Iglesias, 2011/02/23
- [Qemu-devel] Re: [PATCH 0/4] Improve -icount, fix it with iothread, Paolo Bonzini, 2011/02/23
- [Qemu-devel] Re: [PATCH 0/4] Improve -icount, fix it with iothread, Edgar E. Iglesias, 2011/02/23
- [Qemu-devel] Re: [PATCH 0/4] Improve -icount, fix it with iothread, Jan Kiszka, 2011/02/23
- [Qemu-devel] Re: [PATCH 0/4] Improve -icount, fix it with iothread, Edgar E. Iglesias, 2011/02/23
- [Qemu-devel] Re: [PATCH 0/4] Improve -icount, fix it with iothread, Jan Kiszka, 2011/02/23
- [Qemu-devel] Re: [PATCH 0/4] Improve -icount, fix it with iothread, Paolo Bonzini, 2011/02/25
- [Qemu-devel] Re: [PATCH 0/4] Improve -icount, fix it with iothread, Paolo Bonzini, 2011/02/23
- [Qemu-devel] Re: [PATCH 0/4] Improve -icount, fix it with iothread, Edgar E. Iglesias, 2011/02/23