From patchwork Tue Dec 11 12:47:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 205225 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 C30E32C0089 for ; Wed, 12 Dec 2012 00:46:42 +1100 (EST) Received: from localhost ([::1]:58824 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiQAS-0007Rm-MU for incoming@patchwork.ozlabs.org; Tue, 11 Dec 2012 08:46:40 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiPFZ-0006ud-Cz for qemu-devel@nongnu.org; Tue, 11 Dec 2012 07:48:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TiPFW-0004WX-Up for qemu-devel@nongnu.org; Tue, 11 Dec 2012 07:47:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52156) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TiPFW-0004WP-N8 for qemu-devel@nongnu.org; Tue, 11 Dec 2012 07:47:50 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBBCloGD025629 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 11 Dec 2012 07:47:50 -0500 Received: from trasno.mitica (ovpn-113-46.phx2.redhat.com [10.3.113.46]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qBBClCVv027513; Tue, 11 Dec 2012 07:47:49 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Tue, 11 Dec 2012 13:47:07 +0100 Message-Id: <1355230031-28233-32-git-send-email-quintela@redhat.com> In-Reply-To: <1355230031-28233-1-git-send-email-quintela@redhat.com> References: <1355230031-28233-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 31/35] ram: refactor ram_save_block() return value 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 It could only return 0 if we only found dirty xbzrle pages that hadn't changed (i.e. they were written with the same content). We don't care about that case, it is the same than nothing dirty. So now the return of the function is how much have it written, nothing else. Adjust callers. And we also made ram_save_iterate() return the number of transferred bytes, not the number of transferred pages. Signed-off-by: Juan Quintela --- arch_init.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/arch_init.c b/arch_init.c index 3e82588..723529a 100644 --- a/arch_init.c +++ b/arch_init.c @@ -422,9 +422,8 @@ static void migration_bitmap_sync(void) /* * ram_save_block: Writes a page of memory to the stream f * - * Returns: 0: if the page hasn't changed - * -1: if there are no more dirty pages - * n: the amount of bytes written in other case + * Returns: The number of bytes written. + * 0 means no dirty pages */ static int ram_save_block(QEMUFile *f, bool last_stage) @@ -432,7 +431,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage) RAMBlock *block = last_seen_block; ram_addr_t offset = last_offset; bool complete_round = false; - int bytes_sent = -1; + int bytes_sent = 0; MemoryRegion *mr; ram_addr_t current_addr; @@ -460,6 +459,8 @@ static int ram_save_block(QEMUFile *f, bool last_stage) p = memory_region_get_ram_ptr(mr) + offset; + /* In doubt sent page as normal */ + bytes_sent = -1; if (is_dup_page(p)) { acct_info.dup_pages++; bytes_sent = save_block_hdr(f, block, offset, cont, @@ -475,7 +476,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage) } } - /* either we didn't send yet (we may have had XBZRLE overflow) */ + /* XBZRLE overflow or normal page */ if (bytes_sent == -1) { bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_PAGE); qemu_put_buffer(f, p, TARGET_PAGE_SIZE); @@ -484,7 +485,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage) } /* if page is unmodified, continue to the next */ - if (bytes_sent != 0) { + if (bytes_sent > 0) { last_sent_block = block; break; } @@ -631,6 +632,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) int ret; int i; int64_t t0; + int total_sent = 0; qemu_mutex_lock_ramlist(); @@ -645,10 +647,10 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) bytes_sent = ram_save_block(f, false); /* no more blocks to sent */ - if (bytes_sent < 0) { + if (bytes_sent == 0) { break; } - bytes_transferred += bytes_sent; + total_sent += bytes_sent; acct_info.iterations++; /* we want to check in the 1st loop, just in case it was the 1st time and we had to sync the dirty bitmap. @@ -667,13 +669,16 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } if (ret < 0) { + bytes_transferred += total_sent; return ret; } qemu_mutex_unlock_ramlist(); qemu_put_be64(f, RAM_SAVE_FLAG_EOS); + total_sent += 8; + bytes_transferred += total_sent; - return i; + return total_sent; } static int ram_save_complete(QEMUFile *f, void *opaque) @@ -690,7 +695,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque) bytes_sent = ram_save_block(f, true); /* no more blocks to sent */ - if (bytes_sent < 0) { + if (bytes_sent == 0) { break; } bytes_transferred += bytes_sent;