From patchwork Tue Sep 27 16:31:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 116645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0C78FB6F70 for ; Wed, 28 Sep 2011 03:38:49 +1000 (EST) Received: from localhost ([::1]:37159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8aaR-0002Tt-3u for incoming@patchwork.ozlabs.org; Tue, 27 Sep 2011 12:32:51 -0400 Received: from eggs.gnu.org ([140.186.70.92]:42391) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8aZt-0001B1-A0 for qemu-devel@nongnu.org; Tue, 27 Sep 2011 12:32:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R8aZq-0002Rq-6M for qemu-devel@nongnu.org; Tue, 27 Sep 2011 12:32:17 -0400 Received: from mail-bw0-f45.google.com ([209.85.214.45]:60225) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8aZp-0002Pr-Nm for qemu-devel@nongnu.org; Tue, 27 Sep 2011 12:32:13 -0400 Received: by mail-bw0-f45.google.com with SMTP id zv15so7356448bkb.4 for ; Tue, 27 Sep 2011 09:32:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=Ob/sfbL+GWgXzGEiPvB8UmCrJsPX9vWCwkC+71qigs0=; b=B/+haF0A+MtqYhnKT0st4A8pD36WKvOQfSxcalpM3mkt7kfDH5zyjOhkyNsoYbvE0h Fqna9uhMuOmTPZiGQwAkgTRwoyVsLlk7QsieT/B+eSGhs9t0uag3rRdy2FEKkJZy1WvJ g4bdSsMCxJ9jtCL/w+9eLd9me3srTAhAdT8vc= Received: by 10.204.135.154 with SMTP id n26mr5425418bkt.157.1317141133306; Tue, 27 Sep 2011 09:32:13 -0700 (PDT) Received: from localhost.localdomain (93-34-218-143.ip51.fastwebnet.it. [93.34.218.143]) by mx.google.com with ESMTPS id d1sm25178167bku.1.2011.09.27.09.32.11 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 27 Sep 2011 09:32:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 27 Sep 2011 18:31:46 +0200 Message-Id: <1317141111-27701-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1317141111-27701-1-git-send-email-pbonzini@redhat.com> References: <1317141111-27701-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.214.45 Subject: [Qemu-devel] [PATCH 07/12] qemu-timer: move more stuff out of qemu-timer.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Paolo Bonzini --- qemu-timer.c | 35 ++++------------------------------- qemu-timer.h | 2 ++ savevm.c | 25 +++++++++++++++++++++++++ vl.c | 1 + 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/qemu-timer.c b/qemu-timer.c index 7fa81e1..58926dd 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -266,11 +266,8 @@ static QEMUClock *qemu_new_clock(int type) clock = g_malloc0(sizeof(QEMUClock)); clock->type = type; clock->enabled = 1; + clock->last = INT64_MIN; notifier_list_init(&clock->reset_notifiers); - /* required to detect & report backward jumps */ - if (type == QEMU_CLOCK_HOST) { - clock->last = get_clock_realtime(); - } return clock; } @@ -344,7 +341,7 @@ void qemu_del_timer(QEMUTimer *ts) /* modify the current timer so that it will be fired when current_time >= expire_time. The corresponding callback will be called. */ -static void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) +void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) { QEMUTimer **pt, *t; @@ -378,8 +375,6 @@ static void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time) } } -/* modify the current timer so that it will be fired when current_time - >= expire_time. The corresponding callback will be called. */ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time) { qemu_mod_timer_ns(ts, expire_time * ts->scale); @@ -464,33 +459,11 @@ void init_clocks(void) rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME); vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL); host_clock = qemu_new_clock(QEMU_CLOCK_HOST); - - rtc_clock = host_clock; } -/* save a timer */ -void qemu_put_timer(QEMUFile *f, QEMUTimer *ts) +uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts) { - uint64_t expire_time; - - if (qemu_timer_pending(ts)) { - expire_time = ts->expire_time; - } else { - expire_time = -1; - } - qemu_put_be64(f, expire_time); -} - -void qemu_get_timer(QEMUFile *f, QEMUTimer *ts) -{ - uint64_t expire_time; - - expire_time = qemu_get_be64(f); - if (expire_time != -1) { - qemu_mod_timer_ns(ts, expire_time); - } else { - qemu_del_timer(ts); - } + return qemu_timer_pending(ts) ? ts->expire_time : -1; } void qemu_run_all_timers(void) diff --git a/qemu-timer.h b/qemu-timer.h index b4ea201..9f4ffed 100644 --- a/qemu-timer.h +++ b/qemu-timer.h @@ -52,9 +52,11 @@ QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, QEMUTimerCB *cb, void *opaque); void qemu_free_timer(QEMUTimer *ts); void qemu_del_timer(QEMUTimer *ts); +void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time); void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time); int qemu_timer_pending(QEMUTimer *ts); int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time); +uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts); void qemu_run_all_timers(void); int qemu_alarm_pending(void); diff --git a/savevm.c b/savevm.c index 46f2447..eb0ccfd 100644 --- a/savevm.c +++ b/savevm.c @@ -81,6 +81,7 @@ #include "migration.h" #include "qemu_socket.h" #include "qemu-queue.h" +#include "qemu-timer.h" #include "cpus.h" #define SELF_ANNOUNCE_ROUNDS 5 @@ -674,6 +675,30 @@ uint64_t qemu_get_be64(QEMUFile *f) return v; } + +/* timer */ + +void qemu_put_timer(QEMUFile *f, QEMUTimer *ts) +{ + uint64_t expire_time; + + expire_time = qemu_timer_expire_time_ns(ts); + qemu_put_be64(f, expire_time); +} + +void qemu_get_timer(QEMUFile *f, QEMUTimer *ts) +{ + uint64_t expire_time; + + expire_time = qemu_get_be64(f); + if (expire_time != -1) { + qemu_mod_timer_ns(ts, expire_time); + } else { + qemu_del_timer(ts); + } +} + + /* bool */ static int get_bool(QEMUFile *f, void *pv, size_t size) diff --git a/vl.c b/vl.c index 8ae6468..19e7169 100644 --- a/vl.c +++ b/vl.c @@ -2322,6 +2322,7 @@ int main(int argc, char **argv, char **envp) runstate_init(); init_clocks(); + rtc_clock = host_clock; qemu_cache_utils_init(envp);