From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=33319 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PrRUZ-0007Ly-6W for qemu-devel@nongnu.org; Mon, 21 Feb 2011 03:51:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PrRUX-0001Xg-1m for qemu-devel@nongnu.org; Mon, 21 Feb 2011 03:51:38 -0500 Received: from mail-wy0-f173.google.com ([74.125.82.173]:52350) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PrRUW-0001Wp-OL for qemu-devel@nongnu.org; Mon, 21 Feb 2011 03:51:37 -0500 Received: by mail-wy0-f173.google.com with SMTP id 29so1155761wyb.4 for ; Mon, 21 Feb 2011 00:51:36 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 21 Feb 2011 09:51:26 +0100 Message-Id: <1298278286-9158-5-git-send-email-pbonzini@redhat.com> In-Reply-To: <1298278286-9158-1-git-send-email-pbonzini@redhat.com> References: <1298278286-9158-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 4/4] inline qemu_icount_delta List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: edgar.iglesias@gmail.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 --- 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