From patchwork Tue Sep 10 03:43:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jules Wang X-Patchwork-Id: 273885 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 44BA32C027A for ; Wed, 11 Sep 2013 00:29:44 +1000 (EST) Received: from localhost ([::1]:58334 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJOwo-0002SV-Bm for incoming@patchwork.ozlabs.org; Tue, 10 Sep 2013 10:29:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJFHC-0000RH-Qn for qemu-devel@nongnu.org; Tue, 10 Sep 2013 00:10:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJFH7-0002EL-K3 for qemu-devel@nongnu.org; Tue, 10 Sep 2013 00:10:06 -0400 Received: from [2001:250:208:1181:6e92:bfff:fe00:bcdb] (port=45357 helo=mail.cs2c.com.cn) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJFH7-0002Bd-1d for qemu-devel@nongnu.org; Tue, 10 Sep 2013 00:10:01 -0400 Received: from localhost.localdomain (cs2c.com.cn [127.0.0.1]) by mail.cs2c.com.cn (NSMail) with ESMTPA id 503BFB800EC; Tue, 10 Sep 2013 11:36:52 +0800 (CST) BANMAU_FRONT_USER_AUTHED: 1 BANMAU_FRONT_RESULT: 01 BANMAU_FRONT_SUSPICION_REASON: 0 X-Forward-For: 124.205.131.210 From: Jules Wang To: qemu-devel@nongnu.org Date: Tue, 10 Sep 2013 11:43:26 +0800 Message-Id: <1378784607-7398-4-git-send-email-junqing.wang@cs2c.com.cn> X-Mailer: git-send-email 1.8.0.1 In-Reply-To: <1378784607-7398-1-git-send-email-junqing.wang@cs2c.com.cn> References: <1378784607-7398-1-git-send-email-junqing.wang@cs2c.com.cn> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2001:250:208:1181:6e92:bfff:fe00:bcdb X-Mailman-Approved-At: Tue, 10 Sep 2013 10:27:12 -0400 Cc: quintela@redhat.com, owasserm@redhat.com, Jules Wang , stefanha@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH RFC 3/4] Curling: the sender 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 By leveraging live migration feature, the sender simply starts a new migration when the previous migration is completed. We need to handle the variables related to live migration very carefully. So the new migration does not restart from the very begin of the migration, instead, it continues the previous migration. Signed-off-by: Jules Wang --- arch_init.c | 18 +++++++++++++----- migration.c | 23 ++++++++++++++++++++++- savevm.c | 4 ++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/arch_init.c b/arch_init.c index e47e139..5d006f6 100644 --- a/arch_init.c +++ b/arch_init.c @@ -611,10 +611,14 @@ static int ram_save_setup(QEMUFile *f, void *opaque) { RAMBlock *block; int64_t ram_pages = last_ram_offset() >> TARGET_PAGE_BITS; + bool create = false; - migration_bitmap = bitmap_new(ram_pages); - bitmap_set(migration_bitmap, 0, ram_pages); - migration_dirty_pages = ram_pages; + if (!ft_enabled() || !migration_bitmap) { + migration_bitmap = bitmap_new(ram_pages); + bitmap_set(migration_bitmap, 0, ram_pages); + migration_dirty_pages = ram_pages; + create = true; + } mig_throttle_on = false; dirty_rate_high_cnt = 0; @@ -634,7 +638,9 @@ static int ram_save_setup(QEMUFile *f, void *opaque) qemu_mutex_lock_iothread(); qemu_mutex_lock_ramlist(); bytes_transferred = 0; - reset_ram_globals(); + if (!ft_enabled() || create) { + reset_ram_globals(); + } memory_global_dirty_log_start(); migration_bitmap_sync(); @@ -744,7 +750,9 @@ static int ram_save_complete(QEMUFile *f, void *opaque) } ram_control_after_iterate(f, RAM_CONTROL_FINISH); - migration_end(); + if (!ft_enabled()) { + migration_end(); + } qemu_mutex_unlock_ramlist(); qemu_put_be64(f, RAM_SAVE_FLAG_EOS); diff --git a/migration.c b/migration.c index 59c8f32..d8a9b2d 100644 --- a/migration.c +++ b/migration.c @@ -567,6 +567,7 @@ static void *migration_thread(void *opaque) int64_t max_size = 0; int64_t start_time = initial_time; bool old_vm_running = false; + int time_window = 100; DPRINTF("beginning savevm\n"); qemu_savevm_state_begin(s->file, &s->params); @@ -578,6 +579,8 @@ static void *migration_thread(void *opaque) while (s->state == MIG_STATE_ACTIVE) { int64_t current_time; + int64_t time_spent; + int64_t migration_start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); uint64_t pending_size; if (!qemu_file_rate_limit(s->file)) { @@ -607,10 +610,28 @@ static void *migration_thread(void *opaque) break; } - if (!qemu_file_get_error(s->file)) { + if (!qemu_file_get_error(s->file) && !ft_enabled()) { migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_COMPLETED); break; } + + if (ft_enabled()) { + if (old_vm_running) { + qemu_mutex_lock_iothread(); + vm_start(); + qemu_mutex_unlock_iothread(); + + current_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + time_spent = current_time - migration_start_time; + DPRINTF("this migration lasts for %" PRId64 "ms\n", + time_spent); + if (time_spent < time_window) { + g_usleep((time_window - time_spent)*1000); + initial_time += time_window - time_spent; + } + } + qemu_savevm_state_begin(s->file, &s->params); + } } } diff --git a/savevm.c b/savevm.c index c536aa4..6daf690 100644 --- a/savevm.c +++ b/savevm.c @@ -1824,6 +1824,7 @@ static void vmstate_save(QEMUFile *f, SaveStateEntry *se) #define QEMU_VM_SECTION_END 0x03 #define QEMU_VM_SECTION_FULL 0x04 #define QEMU_VM_SUBSECTION 0x05 +#define QEMU_VM_EOF_MAGIC 0xFeedCafe bool qemu_savevm_state_blocked(Error **errp) { @@ -1983,6 +1984,9 @@ void qemu_savevm_state_complete(QEMUFile *f) } qemu_put_byte(f, QEMU_VM_EOF); + if (ft_enabled()) { + qemu_put_be32(f, QEMU_VM_EOF_MAGIC); + } qemu_fflush(f); }