From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V5LDw-0003OM-LD for qemu-devel@nongnu.org; Fri, 02 Aug 2013 15:41:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V5LDn-0002yx-NR for qemu-devel@nongnu.org; Fri, 02 Aug 2013 15:41:16 -0400 Received: from e37.co.us.ibm.com ([32.97.110.158]:56543) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V5LDn-0002xa-Gr for qemu-devel@nongnu.org; Fri, 02 Aug 2013 15:41:07 -0400 Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Aug 2013 13:41:03 -0600 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id DBEC9C40003 for ; Fri, 2 Aug 2013 13:35:37 -0600 (MDT) Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r72JexYB390622 for ; Fri, 2 Aug 2013 13:41:00 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r72JevCh024475 for ; Fri, 2 Aug 2013 13:40:59 -0600 Message-ID: <51FC0B48.8020405@linux.vnet.ibm.com> Date: Fri, 02 Aug 2013 15:40:56 -0400 From: "Michael R. Hines" MIME-Version: 1.0 References: <1374783499-2550-1-git-send-email-lilei@linux.vnet.ibm.com> <1374783499-2550-5-git-send-email-lilei@linux.vnet.ibm.com> In-Reply-To: <1374783499-2550-5-git-send-email-lilei@linux.vnet.ibm.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 04/12] arch_init: introduce ram_page_save() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Lei Li Cc: aarcange@redhat.com, aliguori@us.ibm.com, quintela@redhat.com, qemu-devel@nongnu.org, lagarcia@br.ibm.com, pbonzini@redhat.com, rcj@linux.vnet.ibm.com On 07/25/2013 04:18 PM, Lei Li wrote: > Signed-off-by: Lei Li > --- > arch_init.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 files changed, 58 insertions(+), 0 deletions(-) > > diff --git a/arch_init.c b/arch_init.c > index a8b91ee..a418071 100644 > --- a/arch_init.c > +++ b/arch_init.c > @@ -699,6 +699,64 @@ static uint64_t ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size) > return remaining_size; > } > > +/* This is the last block from where we have sent data for local migration */ > +static RAMBlock *last_block_local; > +static ram_addr_t last_offset_local; > + > +static int ram_page_save(QEMUFile *f) > +{ > + RAMBlock *block = last_block_local; > + ram_addr_t offset = last_offset_local; > + MemoryRegion *mr = block->mr; > + int bytes_sent = 0; > + > + if (!block) { > + block = QTAILQ_FIRST(&ram_list.blocks); > + } > + > + do { > + mr = block->mr; > + uint8_t *p; > + int cont = (block == last_block_local) ? RAM_SAVE_FLAG_CONTINUE : 0; > + > + p = memory_region_get_ram_ptr(mr) + offset; > + > + if (is_zero_page(p)) { > + qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_COMPRESS); > + if (!cont) { > + qemu_put_byte(f, strlen(block->idstr)); > + qemu_put_buffer(f, (uint8_t *)block->idstr, > + strlen(block->idstr)); > + } > + qemu_put_byte(f, *p); > + bytes_sent = 1; > + } else { > + qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_PAGE); > + if (!cont) { > + qemu_put_byte(f, strlen(block->idstr)); > + qemu_put_buffer(f, (uint8_t *)block->idstr, > + strlen(block->idstr)); > + } > + qemu_put_buffer(f, p, TARGET_PAGE_SIZE); > + bytes_sent = TARGET_PAGE_SIZE; > + } > + > + offset += TARGET_PAGE_SIZE; > + if (offset >= block->length) { > + offset = 0; > + block = QTAILQ_NEXT(block, next); > + if (!block) { > + block = QTAILQ_FIRST(&ram_list.blocks); > + } > + } > + } while (block != last_block_local || offset != last_offset_local); > + > + last_block_local = block; > + last_offset_local = offset; > + > + return bytes_sent; > +} > + > static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host) > { > int ret, rc = 0; Seems like there's a lot of duplicate code. We have new hooks to override the way memory is saved in arch_init.c See the QEMUFileOps......... save_page() / before_ram_iterate() / after_ram_iterate() You might need to introduce a new "load_page()" pointer in QEMUFileOps. Then all this code can be private to migration-local.c - Michael