From patchwork Thu Feb 3 13:48:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 81653 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EB50BB70E3 for ; Fri, 4 Feb 2011 00:55:15 +1100 (EST) Received: from localhost ([127.0.0.1]:37244 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkzeS-0006NP-V9 for incoming@patchwork.ozlabs.org; Thu, 03 Feb 2011 08:55:13 -0500 Received: from [140.186.70.92] (port=41168 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkzYh-0003oU-Vy for qemu-devel@nongnu.org; Thu, 03 Feb 2011 08:51:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PkzYe-0004Da-90 for qemu-devel@nongnu.org; Thu, 03 Feb 2011 08:49:13 -0500 Received: from mail-yi0-f45.google.com ([209.85.218.45]:47521) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PkzYe-0004DT-6c for qemu-devel@nongnu.org; Thu, 03 Feb 2011 08:49:12 -0500 Received: by yie21 with SMTP id 21so533816yie.4 for ; Thu, 03 Feb 2011 05:49:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:cc:subject:date:message-id :x-mailer:in-reply-to:references; bh=g1REiqUNWQBt/TjAmk5JlG3l2vzc+bQhDsBsJNTbYLc=; b=YJwVLi7gPf+1HiW3tTagy2O46qIDmk8O4YjNdvE15pmV4k+13mBPJz2RwmARY/frEz uuHlK8eGaaDp4oHQT/DabuqliYDhYkcbf5qUvqtwyLiNLaS3pqNS6cys95hLSyarMLwu sss8JHC5COUgxWVITYw25WZWXizuT/scJx+ko= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=BUowzpmcednObz2AC3OZOkFUEHVBqN8jkxsH7HEnwENj/2CI6xlBiRHRhEAGxGLolE KC+qVEAf4eABvs4/t9Bp4Jgahtx31uFUY86bzzTRap8vPP39ksZPrmRzc+vqOD4MviSO o6hHHczKnlCXZgZdtQBGs3FyycE05fnIRiy9A= Received: by 10.150.229.16 with SMTP id b16mr5773312ybh.226.1296740951699; Thu, 03 Feb 2011 05:49:11 -0800 (PST) Received: from localhost.localdomain (93-34-149-100.ip50.fastwebnet.it [93.34.149.100]) by mx.google.com with ESMTPS id u3sm315000yba.16.2011.02.03.05.49.10 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 03 Feb 2011 05:49:11 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 3 Feb 2011 14:48:59 +0100 Message-Id: <1296740941-24296-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.3.5 In-Reply-To: <1296740941-24296-1-git-send-email-pbonzini@redhat.com> References: <1296740941-24296-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.218.45 Cc: aurelien@aurel32.net Subject: [Qemu-devel] [PATCH v2 1/3] use nanoseconds everywhere for timeout computation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Suggested by Aurelien Jarno. Signed-off-by: Paolo Bonzini --- qemu-timer.c | 30 +++++++++++++++--------------- 1 files changed, 15 insertions(+), 15 deletions(-) diff --git a/qemu-timer.c b/qemu-timer.c index db1ec49..60283a8 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -197,8 +197,8 @@ static void qemu_rearm_alarm_timer(struct qemu_alarm_timer *t) t->rearm(t); } -/* TODO: MIN_TIMER_REARM_US should be optimized */ -#define MIN_TIMER_REARM_US 250 +/* TODO: MIN_TIMER_REARM_NS should be optimized */ +#define MIN_TIMER_REARM_NS 250000 #ifdef _WIN32 @@ -698,11 +698,11 @@ int64_t qemu_next_deadline(void) if (active_timers[QEMU_CLOCK_VIRTUAL]) { delta = active_timers[QEMU_CLOCK_VIRTUAL]->expire_time - - qemu_get_clock(vm_clock); + qemu_get_clock_ns(vm_clock); } if (active_timers[QEMU_CLOCK_HOST]) { int64_t hdelta = active_timers[QEMU_CLOCK_HOST]->expire_time - - qemu_get_clock(host_clock); + qemu_get_clock_ns(host_clock); if (hdelta < delta) delta = hdelta; } @@ -727,17 +727,17 @@ static uint64_t qemu_next_deadline_dyntick(void) if (use_icount) delta = INT32_MAX; else - delta = (qemu_next_deadline() + 999) / 1000; + delta = qemu_next_deadline(); if (active_timers[QEMU_CLOCK_REALTIME]) { - rtdelta = (active_timers[QEMU_CLOCK_REALTIME]->expire_time - - qemu_get_clock(rt_clock))*1000; + rtdelta = (active_timers[QEMU_CLOCK_REALTIME]->expire_time * 1000000 - + qemu_get_clock_ns(rt_clock)); if (rtdelta < delta) delta = rtdelta; } - if (delta < MIN_TIMER_REARM_US) - delta = MIN_TIMER_REARM_US; + if (delta < MIN_TIMER_REARM_NS) + delta = MIN_TIMER_REARM_NS; return delta; } @@ -887,8 +887,8 @@ static void dynticks_rearm_timer(struct qemu_alarm_timer *t) { timer_t host_timer = (timer_t)(long)t->priv; struct itimerspec timeout; - int64_t nearest_delta_us = INT64_MAX; - int64_t current_us; + int64_t nearest_delta_ns = INT64_MAX; + int64_t current_ns; assert(alarm_has_dynticks(t)); if (!active_timers[QEMU_CLOCK_REALTIME] && @@ -896,7 +896,7 @@ static void dynticks_rearm_timer(struct qemu_alarm_timer *t) !active_timers[QEMU_CLOCK_HOST]) return; - nearest_delta_us = qemu_next_deadline_dyntick(); + nearest_delta_ns = qemu_next_deadline_dyntick(); /* check whether a timer is already running */ if (timer_gettime(host_timer, &timeout)) { @@ -904,14 +904,14 @@ static void dynticks_rearm_timer(struct qemu_alarm_timer *t) fprintf(stderr, "Internal timer error: aborting\n"); exit(1); } - current_us = timeout.it_value.tv_sec * 1000000 + timeout.it_value.tv_nsec/1000; - if (current_us && current_us <= nearest_delta_us) + current_ns = timeout.it_value.tv_sec * 1000000000LL + timeout.it_value.tv_nsec; + if (current_ns && current_ns <= nearest_delta_ns) return; timeout.it_interval.tv_sec = 0; timeout.it_interval.tv_nsec = 0; /* 0 for one-shot timer */ - timeout.it_value.tv_sec = nearest_delta_us / 1000000; - timeout.it_value.tv_nsec = (nearest_delta_us % 1000000) * 1000; + timeout.it_value.tv_sec = nearest_delta_ns / 1000000000; + timeout.it_value.tv_nsec = nearest_delta_ns % 1000000000; if (timer_settime(host_timer, 0 /* RELATIVE */, &timeout, NULL)) { perror("settime"); fprintf(stderr, "Internal timer error: aborting\n");