From patchwork Tue Sep 29 06:32:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 523796 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id DCBA8140273 for ; Tue, 29 Sep 2015 21:33:21 +1000 (AEST) Received: from localhost ([::1]:49916 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zgt9r-0002BQ-MX for incoming@patchwork.ozlabs.org; Tue, 29 Sep 2015 07:33:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgoTI-0005he-Hr for qemu-devel@nongnu.org; Tue, 29 Sep 2015 02:33:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZgoTH-0003AT-Gp for qemu-devel@nongnu.org; Tue, 29 Sep 2015 02:33:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51168) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgoTH-0003AM-9g for qemu-devel@nongnu.org; Tue, 29 Sep 2015 02:33:03 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 079BAC0B64BB for ; Tue, 29 Sep 2015 06:33:03 +0000 (UTC) Received: from localhost (ovpn-113-55.phx2.redhat.com [10.3.113.55]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8T6X1Lm026376; Tue, 29 Sep 2015 02:33:02 -0400 From: Amit Shah To: Juan Quintela Date: Tue, 29 Sep 2015 12:02:23 +0530 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Amit Shah , qemu list , "Dr. David Alan Gilbert" Subject: [Qemu-devel] [migration PULL 8/9] Move dirty page search state into separate structure 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 From: "Dr. David Alan Gilbert" Pull the search state for one iteration of the dirty page search into a structure. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Amit Shah Message-Id: <1443018431-11170-2-git-send-email-dgilbert@redhat.com> Reviewed-by: Amit Shah Signed-off-by: Amit Shah --- migration/ram.c | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 7df9157..d79d79d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -227,6 +227,17 @@ static uint64_t migration_dirty_pages; static uint32_t last_version; static bool ram_bulk_stage; +/* used by the search for pages to send */ +struct PageSearchStatus { + /* Current block being searched */ + RAMBlock *block; + /* Current offset to search from */ + ram_addr_t offset; + /* Set once we wrap around */ + bool complete_round; +}; +typedef struct PageSearchStatus PageSearchStatus; + struct CompressParam { bool start; bool done; @@ -531,7 +542,6 @@ static void migration_bitmap_sync_range(ram_addr_t start, ram_addr_t length) cpu_physical_memory_sync_dirty_bitmap(bitmap, start, length); } - /* Fix me: there are too many global variables used in migration process. */ static int64_t start_time; static int64_t bytes_xfer_prev; @@ -923,26 +933,30 @@ static int ram_save_compressed_page(QEMUFile *f, RAMBlock *block, static int ram_find_and_save_block(QEMUFile *f, bool last_stage, uint64_t *bytes_transferred) { - RAMBlock *block = last_seen_block; - ram_addr_t offset = last_offset; - bool complete_round = false; + PageSearchStatus pss; int pages = 0; - if (!block) - block = QLIST_FIRST_RCU(&ram_list.blocks); + pss.block = last_seen_block; + pss.offset = last_offset; + pss.complete_round = false; + + if (!pss.block) { + pss.block = QLIST_FIRST_RCU(&ram_list.blocks); + } while (true) { - offset = migration_bitmap_find_and_reset_dirty(block, offset); - if (complete_round && block == last_seen_block && - offset >= last_offset) { + pss.offset = migration_bitmap_find_and_reset_dirty(pss.block, + pss.offset); + if (pss.complete_round && pss.block == last_seen_block && + pss.offset >= last_offset) { break; } - if (offset >= block->used_length) { - offset = 0; - block = QLIST_NEXT_RCU(block, next); - if (!block) { - block = QLIST_FIRST_RCU(&ram_list.blocks); - complete_round = true; + if (pss.offset >= pss.block->used_length) { + pss.offset = 0; + pss.block = QLIST_NEXT_RCU(pss.block, next); + if (!pss.block) { + pss.block = QLIST_FIRST_RCU(&ram_list.blocks); + pss.complete_round = true; ram_bulk_stage = false; if (migrate_use_xbzrle()) { /* If xbzrle is on, stop using the data compression at this @@ -954,23 +968,24 @@ static int ram_find_and_save_block(QEMUFile *f, bool last_stage, } } else { if (compression_switch && migrate_use_compression()) { - pages = ram_save_compressed_page(f, block, offset, last_stage, + pages = ram_save_compressed_page(f, pss.block, pss.offset, + last_stage, bytes_transferred); } else { - pages = ram_save_page(f, block, offset, last_stage, + pages = ram_save_page(f, pss.block, pss.offset, last_stage, bytes_transferred); } /* if page is unmodified, continue to the next */ if (pages > 0) { - last_sent_block = block; + last_sent_block = pss.block; break; } } } - last_seen_block = block; - last_offset = offset; + last_seen_block = pss.block; + last_offset = pss.offset; return pages; }