From patchwork Fri Feb 15 17:46:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 220790 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 540552C0080 for ; Sat, 16 Feb 2013 04:55:03 +1100 (EST) Received: from localhost ([::1]:60863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6PUz-0002bj-KX for incoming@patchwork.ozlabs.org; Fri, 15 Feb 2013 12:55:01 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6POU-0006Z9-Ht for qemu-devel@nongnu.org; Fri, 15 Feb 2013 12:48:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U6PO9-0004JK-UR for qemu-devel@nongnu.org; Fri, 15 Feb 2013 12:48:13 -0500 Received: from mail-ve0-f182.google.com ([209.85.128.182]:33102) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6PO9-0004J8-PT for qemu-devel@nongnu.org; Fri, 15 Feb 2013 12:47:57 -0500 Received: by mail-ve0-f182.google.com with SMTP id ox1so3337235veb.41 for ; Fri, 15 Feb 2013 09:47:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=TrazVQElhwqJW0DfApBwl2ZImvDaDkYpWix2ZWrGX9g=; b=TMiEZEXeJB1AwwVC24eXhJkKn/38NnCI7//Xea0/uv01oLHeadC01iTnDYqriOjQ+a /iRzVTPQeXkd+GC0FcigY5D7Tv2Utc3V8mOQ3g/fQpGyEwtmtVHtkoNBLt14k9SDEM6u TP9CQO45w+nOmm4eC3uAdYUoqRQ1WnwfevIWaXy7n3fIMKvC6rcmauznlfRJZVjLGUJa EnOg9YWiiFDTVjkPaFsl1J6HOT7e4cufu/auYDAODXZegUpWreiMDh9XdSHg+izZ51yk VmY9IJsHCv+QCiYhgpYci1tWUDGAhHzRxiI9Zdyuu/Eb+ozQgDgUHIYJBLzVFmScLAZS U+CA== X-Received: by 10.52.96.7 with SMTP id do7mr3663965vdb.115.1360950470481; Fri, 15 Feb 2013 09:47:50 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-179-137.ip50.fastwebnet.it. [93.34.179.137]) by mx.google.com with ESMTPS id yu12sm65402142vec.6.2013.02.15.09.47.48 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 15 Feb 2013 09:47:49 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 15 Feb 2013 18:46:45 +0100 Message-Id: <1360950433-17106-14-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1360950433-17106-1-git-send-email-pbonzini@redhat.com> References: <1360950433-17106-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.128.182 Cc: owasserm@redhat.com, chegu_vinod@hp.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH 13/41] migration: prepare to access s->state outside critical sections 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 Accessing s->state outside the big QEMU lock will simplify a bit the locking/unlocking of the iothread lock. Signed-off-by: Paolo Bonzini Reviewed-by: Orit Wasserman Reviewed-by: Juan Quintela --- migration.c | 21 ++++++++++++--------- 1 files changed, 12 insertions(+), 9 deletions(-) diff --git a/migration.c b/migration.c index b0b5578..a7f619b 100644 --- a/migration.c +++ b/migration.c @@ -281,14 +281,14 @@ static void migrate_fd_cleanup(MigrationState *s) void migrate_fd_error(MigrationState *s) { DPRINTF("setting error state\n"); - s->state = MIG_STATE_ERROR; + __sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE, MIG_STATE_ERROR); migrate_fd_cleanup(s); } static void migrate_fd_completed(MigrationState *s) { DPRINTF("setting completed state\n"); - s->state = MIG_STATE_COMPLETED; + __sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE, MIG_STATE_COMPLETED); migrate_fd_cleanup(s); } @@ -313,12 +313,9 @@ static ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data, static void migrate_fd_cancel(MigrationState *s) { - if (s->state != MIG_STATE_ACTIVE) - return; - DPRINTF("cancelling migration\n"); - s->state = MIG_STATE_CANCELLED; + __sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE, MIG_STATE_CANCELLED); migrate_fd_cleanup(s); } @@ -651,12 +648,14 @@ static void *buffered_file_thread(void *opaque) qemu_mutex_lock_iothread(); DPRINTF("beginning savevm\n"); qemu_savevm_state_begin(s->file, &s->params); + qemu_mutex_unlock_iothread(); while (s->state == MIG_STATE_ACTIVE) { int64_t current_time = qemu_get_clock_ms(rt_clock); uint64_t pending_size; if (s->bytes_xfer < s->xfer_limit) { + 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); @@ -672,8 +671,8 @@ static void *buffered_file_thread(void *opaque) qemu_savevm_state_complete(s->file); last_round = true; } + qemu_mutex_unlock_iothread(); } - qemu_mutex_unlock_iothread(); if (current_time >= initial_time + BUFFER_DELAY) { uint64_t transferred_bytes = s->bytes_xfer; uint64_t time_spent = current_time - initial_time; @@ -692,14 +691,18 @@ static void *buffered_file_thread(void *opaque) g_usleep((initial_time + BUFFER_DELAY - current_time)*1000); } buffered_flush(s); - qemu_mutex_lock_iothread(); if (qemu_file_get_error(s->file)) { + qemu_mutex_lock_iothread(); migrate_fd_error(s); + qemu_mutex_unlock_iothread(); } else if (last_round && s->buffer_size == 0) { + qemu_mutex_lock_iothread(); migrate_fd_completed(s); + qemu_mutex_unlock_iothread(); } } + qemu_mutex_lock_iothread(); if (s->state == MIG_STATE_COMPLETED) { int64_t end_time = qemu_get_clock_ms(rt_clock); s->total_time = end_time - s->total_time; @@ -711,8 +714,8 @@ static void *buffered_file_thread(void *opaque) vm_start(); } } - qemu_mutex_unlock_iothread(); + g_free(s->buffer); return NULL; }