From patchwork Tue Jan 15 11:18:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 212130 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2F7D92C00A0 for ; Tue, 15 Jan 2013 22:58:19 +1100 (EST) Received: from localhost ([::1]:37784 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tv4YH-0005Ub-81 for incoming@patchwork.ozlabs.org; Tue, 15 Jan 2013 06:19:33 -0500 Received: from eggs.gnu.org ([208.118.235.92]:58208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tv4XR-0003xV-DS for qemu-devel@nongnu.org; Tue, 15 Jan 2013 06:18:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tv4XQ-0001AV-5O for qemu-devel@nongnu.org; Tue, 15 Jan 2013 06:18:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57453) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tv4XP-0001AN-Uj for qemu-devel@nongnu.org; Tue, 15 Jan 2013 06:18:40 -0500 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 r0FBId1V014534 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 15 Jan 2013 06:18:39 -0500 Received: from trasno.mitica (ovpn-113-25.phx2.redhat.com [10.3.113.25]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0FBIMrA005333; Tue, 15 Jan 2013 06:18:38 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Tue, 15 Jan 2013 12:18:19 +0100 Message-Id: <1358248702-14278-12-git-send-email-quintela@redhat.com> In-Reply-To: <1358248702-14278-1-git-send-email-quintela@redhat.com> References: <1358248702-14278-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 11/14] migration: unfold rest of migrate_fd_put_ready() into thread 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 will allow us finer control in next patches. Signed-off-by: Juan Quintela --- migration.c | 95 ++++++++++++++++++++++++++----------------------------------- 1 file changed, 41 insertions(+), 54 deletions(-) diff --git a/migration.c b/migration.c index 651edd5..6d3aeed 100644 --- a/migration.c +++ b/migration.c @@ -662,54 +662,6 @@ static int64_t buffered_get_rate_limit(void *opaque) return s->xfer_limit; } -static bool migrate_fd_put_ready(MigrationState *s, uint64_t max_size) -{ - int ret; - uint64_t pending_size; - bool last_round = false; - - qemu_mutex_lock_iothread(); - DPRINTF("iterate\n"); - pending_size = qemu_savevm_state_pending(s->file, max_size); - DPRINTF("pending size %lu max %lu\n", pending_size, max_size); - if (pending_size >= max_size) { - ret = qemu_savevm_state_iterate(s->file); - if (ret < 0) { - migrate_fd_error(s); - } - } else { - int old_vm_running = runstate_is_running(); - int64_t start_time, end_time; - - DPRINTF("done iterating\n"); - start_time = qemu_get_clock_ms(rt_clock); - qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); - if (old_vm_running) { - vm_stop(RUN_STATE_FINISH_MIGRATE); - } else { - vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); - } - - if (qemu_savevm_state_complete(s->file) < 0) { - migrate_fd_error(s); - } else { - migrate_fd_completed(s); - } - end_time = qemu_get_clock_ms(rt_clock); - s->total_time = end_time - s->total_time; - s->downtime = end_time - start_time; - if (s->state != MIG_STATE_COMPLETED) { - if (old_vm_running) { - vm_start(); - } - } - last_round = true; - } - qemu_mutex_unlock_iothread(); - - return last_round; -} - static void *buffered_file_thread(void *opaque) { MigrationState *s = opaque; @@ -730,6 +682,7 @@ static void *buffered_file_thread(void *opaque) while (true) { int64_t current_time = qemu_get_clock_ms(rt_clock); + uint64_t pending_size; qemu_mutex_lock_iothread(); if (s->state != MIG_STATE_ACTIVE) { @@ -741,6 +694,46 @@ static void *buffered_file_thread(void *opaque) qemu_mutex_unlock_iothread(); break; } + if (s->bytes_xfer < s->xfer_limit) { + DPRINTF("iterate\n"); + pending_size = qemu_savevm_state_pending(s->file, max_size); + DPRINTF("pending size %lu max %lu\n", pending_size, max_size); + if (pending_size >= max_size) { + ret = qemu_savevm_state_iterate(s->file); + if (ret < 0) { + qemu_mutex_unlock_iothread(); + break; + } + } else { + int old_vm_running = runstate_is_running(); + int64_t start_time, end_time; + + DPRINTF("done iterating\n"); + start_time = qemu_get_clock_ms(rt_clock); + qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER); + if (old_vm_running) { + vm_stop(RUN_STATE_FINISH_MIGRATE); + } else { + vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); + } + ret = qemu_savevm_state_complete(s->file); + if (ret < 0) { + qemu_mutex_unlock_iothread(); + break; + } else { + migrate_fd_completed(s); + } + end_time = qemu_get_clock_ms(rt_clock); + s->total_time = end_time - s->total_time; + s->downtime = end_time - start_time; + if (s->state != MIG_STATE_COMPLETED) { + if (old_vm_running) { + vm_start(); + } + } + last_round = true; + } + } qemu_mutex_unlock_iothread(); if (current_time >= initial_time + BUFFER_DELAY) { uint64_t transferred_bytes = s->bytes_xfer; @@ -763,12 +756,6 @@ static void *buffered_file_thread(void *opaque) if (ret < 0) { break; } - - DPRINTF("file is ready\n"); - if (s->bytes_xfer < s->xfer_limit) { - DPRINTF("notifying client\n"); - last_round = migrate_fd_put_ready(s, max_size); - } } out: