From patchwork Fri Jul 29 20:57:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umesh Deshpande X-Patchwork-Id: 107455 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 6720DB6F62 for ; Sat, 30 Jul 2011 06:57:56 +1000 (EST) Received: from localhost ([::1]:58621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qmu7w-0005DE-Hi for incoming@patchwork.ozlabs.org; Fri, 29 Jul 2011 16:57:48 -0400 Received: from eggs.gnu.org ([140.186.70.92]:37423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qmu7k-00054V-Hu for qemu-devel@nongnu.org; Fri, 29 Jul 2011 16:57:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qmu7i-0004qo-EC for qemu-devel@nongnu.org; Fri, 29 Jul 2011 16:57:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1085) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qmu7i-0004qS-79 for qemu-devel@nongnu.org; Fri, 29 Jul 2011 16:57:34 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6TKvWRn016427 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 29 Jul 2011 16:57:33 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p6TKvW22003504; Fri, 29 Jul 2011 16:57:32 -0400 Received: from umeshhome.stny.rr.com (vpn-8-21.rdu.redhat.com [10.11.8.21]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p6TKvUlT005141; Fri, 29 Jul 2011 16:57:31 -0400 From: Umesh Deshpande To: kvm@vger.kernel.org, qemu-devel@nongnu.org Date: Fri, 29 Jul 2011 16:57:25 -0400 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, mtosatti@redhat.com, Umesh Deshpande , Juan Quintela Subject: [Qemu-devel] [RFC PATCH v2 2/3] fine grained qemu_mutex locking for 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 In the migration thread, qemu_mutex is released during the most time consuming part. i.e. during is_dup_page which identifies the uniform data pages and during the put_buffer. qemu_mutex is also released while blocking on select to wait for the descriptor to become ready for writes. Signed-off-by: Umesh Deshpande --- arch_init.c | 14 +++++++++++--- migration.c | 11 +++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/arch_init.c b/arch_init.c index 484b39d..cd545bc 100644 --- a/arch_init.c +++ b/arch_init.c @@ -110,7 +110,7 @@ static int is_dup_page(uint8_t *page, uint8_t ch) static RAMBlock *last_block; static ram_addr_t last_offset; -static int ram_save_block(QEMUFile *f) +static int ram_save_block(QEMUFile *f, int stage) { RAMBlock *block = last_block; ram_addr_t offset = last_offset; @@ -131,6 +131,10 @@ static int ram_save_block(QEMUFile *f) current_addr + TARGET_PAGE_SIZE, MIGRATION_DIRTY_FLAG); + if (stage != 3) { + qemu_mutex_unlock_iothread(); + } + p = block->host + offset; if (is_dup_page(p, *p)) { @@ -153,6 +157,10 @@ static int ram_save_block(QEMUFile *f) bytes_sent = TARGET_PAGE_SIZE; } + if (stage != 3) { + qemu_mutex_lock_iothread(); + } + break; } @@ -301,7 +309,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) while (!qemu_file_rate_limit(f)) { int bytes_sent; - bytes_sent = ram_save_block(f); + bytes_sent = ram_save_block(f, stage); bytes_transferred += bytes_sent; if (bytes_sent == 0) { /* no more blocks */ break; @@ -322,7 +330,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) int bytes_sent; /* flush all remaining blocks regardless of rate limiting */ - while ((bytes_sent = ram_save_block(f)) != 0) { + while ((bytes_sent = ram_save_block(f, stage)) != 0) { bytes_transferred += bytes_sent; } cpu_physical_memory_set_dirty_tracking(0); diff --git a/migration.c b/migration.c index bf86067..992fef5 100644 --- a/migration.c +++ b/migration.c @@ -375,15 +375,19 @@ void migrate_fd_begin(void *arg) if (ret < 0) { DPRINTF("failed, %d\n", ret); migrate_fd_error(s); - goto out; + qemu_mutex_unlock_iothread(); + return; } expire_time = qemu_get_clock_ms(rt_clock) + 100; migrate_fd_put_ready(s); + qemu_mutex_unlock_iothread(); while (s->state == MIG_STATE_ACTIVE) { if (migrate_fd_check_expire()) { + qemu_mutex_lock_iothread(); buffered_rate_tick(s->file); + qemu_mutex_unlock_iothread(); } if (s->state != MIG_STATE_ACTIVE) { @@ -392,12 +396,11 @@ void migrate_fd_begin(void *arg) if (s->callback) { migrate_fd_wait_for_unfreeze(s); + qemu_mutex_lock_iothread(); s->callback(s); + qemu_mutex_unlock_iothread(); } } - -out: - qemu_mutex_unlock_iothread(); }