From patchwork Wed Jul 20 03:57:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umesh Deshpande X-Patchwork-Id: 105576 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 9BAE6B6F7A for ; Wed, 20 Jul 2011 14:00:21 +1000 (EST) Received: from localhost ([::1]:58863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjNxI-0007ja-K9 for incoming@patchwork.ozlabs.org; Wed, 20 Jul 2011 00:00:16 -0400 Received: from eggs.gnu.org ([140.186.70.92]:52121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjNuY-0007ie-HR for qemu-devel@nongnu.org; Tue, 19 Jul 2011 23:57:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QjNuW-00019y-9N for qemu-devel@nongnu.org; Tue, 19 Jul 2011 23:57:25 -0400 Received: from mx4-phx2.redhat.com ([209.132.183.25]:37072) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjNuV-00019l-Pd for qemu-devel@nongnu.org; Tue, 19 Jul 2011 23:57:24 -0400 Received: from mail01.corp.redhat.com (zmail01.collab.prod.int.phx2.redhat.com [10.5.5.41]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p6K3vMan004386; Tue, 19 Jul 2011 23:57:22 -0400 Date: Tue, 19 Jul 2011 23:57:22 -0400 (EDT) From: Umesh Deshpande To: kvm@vger.kernel.org, qemu-devel@nongnu.org Message-ID: <2134256325.1447254.1311134242326.JavaMail.root@zmail01.collab.prod.int.phx2.redhat.com> In-Reply-To: <1252685407.1446272.1311128340387.JavaMail.root@zmail01.collab.prod.int.phx2.redhat.com> MIME-Version: 1.0 X-Originating-IP: [10.5.5.72] X-Mailer: Zimbra 6.0.9_GA_2686 (ZimbraWebClient - FF3.0 (Linux)/6.0.9_GA_2686) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.25 Subject: [Qemu-devel] [RFC 2/4] A separate thread for the VM migration 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 This patch implements a migration clock, whose implementation is similar to the existing rt_clock. This allows the migration timer to run in parallel to other timers in the rt_clock. In the next patch, this clock is used to create a new timer from the migration thread that calls the VM migration routine on the source side. Signed-off-by: Umesh Deshpande --- qemu-timer.c | 29 +++++++++++++++++++++++++++-- qemu-timer.h | 3 +++ 2 files changed, 30 insertions(+), 2 deletions(-) -- diff --git a/qemu-timer.c b/qemu-timer.c index 72066c7..91e356f 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -144,6 +144,7 @@ void cpu_disable_ticks(void) #define QEMU_CLOCK_REALTIME 0 #define QEMU_CLOCK_VIRTUAL 1 #define QEMU_CLOCK_HOST 2 +#define QEMU_CLOCK_MIGRATE 3 struct QEMUClock { int type; @@ -364,9 +365,10 @@ next: } } -#define QEMU_NUM_CLOCKS 3 +#define QEMU_NUM_CLOCKS 4 QEMUClock *rt_clock; +QEMUClock *migration_clock; QEMUClock *vm_clock; QEMUClock *host_clock; @@ -561,12 +563,31 @@ int qemu_timer_pending(QEMUTimer *ts) return 0; } +int64_t qemu_timer_difference(QEMUTimer *ts, QEMUClock *clock) +{ + int64_t expire_time, current_time; + QEMUTimer *t; + + current_time = qemu_get_clock_ms(clock); + for (t = active_timers[clock->type]; t != NULL; t = t->next) { + if (t == ts) { + expire_time = ts->expire_time / SCALE_MS; + if (current_time >= expire_time) { + return 0; + } else { + return expire_time - current_time; + } + } + } + return 0; +} + int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time) { return qemu_timer_expired_ns(timer_head, current_time * timer_head->scale); } -static void qemu_run_timers(QEMUClock *clock) +void qemu_run_timers(QEMUClock *clock) { QEMUTimer **ptimer_head, *ts; int64_t current_time; @@ -595,6 +616,9 @@ int64_t qemu_get_clock_ns(QEMUClock *clock) switch(clock->type) { case QEMU_CLOCK_REALTIME: return get_clock(); + + case QEMU_CLOCK_MIGRATE: + return get_clock(); default: case QEMU_CLOCK_VIRTUAL: if (use_icount) { @@ -610,6 +634,7 @@ int64_t qemu_get_clock_ns(QEMUClock *clock) void init_clocks(void) { rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME); + migration_clock = qemu_new_clock(QEMU_CLOCK_MIGRATE); vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL); host_clock = qemu_new_clock(QEMU_CLOCK_HOST); diff --git a/qemu-timer.h b/qemu-timer.h index 06cbe20..014b70b 100644 --- a/qemu-timer.h +++ b/qemu-timer.h @@ -23,6 +23,7 @@ typedef void QEMUTimerCB(void *opaque); machine is stopped. The real time clock has a frequency of 1000 Hz. */ extern QEMUClock *rt_clock; +extern QEMUClock *migration_clock; /* The virtual clock is only run during the emulation. It is stopped when the virtual machine is stopped. Virtual timers use a high @@ -45,7 +46,9 @@ QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale, void qemu_free_timer(QEMUTimer *ts); void qemu_del_timer(QEMUTimer *ts); void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time); +void qemu_run_timers(QEMUClock *clock); int qemu_timer_pending(QEMUTimer *ts); +int64_t qemu_timer_difference(QEMUTimer *ts, QEMUClock *); int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time); void qemu_run_all_timers(void);