From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wj9HN-0006h1-JG for qemu-devel@nongnu.org; Sat, 10 May 2014 11:33:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wj9HH-0007xu-Sd for qemu-devel@nongnu.org; Sat, 10 May 2014 11:33:37 -0400 Received: from mail-wg0-x22e.google.com ([2a00:1450:400c:c00::22e]:51504) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wj9HH-0007xq-Mn for qemu-devel@nongnu.org; Sat, 10 May 2014 11:33:31 -0400 Received: by mail-wg0-f46.google.com with SMTP id n12so5187409wgh.29 for ; Sat, 10 May 2014 08:33:30 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <536E46C3.1050502@redhat.com> Date: Sat, 10 May 2014 17:33:23 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1399719075-11517-1-git-send-email-pl@kamp.de> In-Reply-To: <1399719075-11517-1-git-send-email-pl@kamp.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] migration: cache memory region ram ptr List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Lieven , qemu-devel@nongnu.org Cc: dgilbert@redhat.com, quintela@redhat.com Il 10/05/2014 12:51, Peter Lieven ha scritto: > we currently look up the ram ptr for each single page. Cache > the pointer while we operate on the same block. Why don't you instead cache the result in the MemoryRegion, so that memory_region_get_ram_ptr becomes a simple, inline field access? Paolo > Signed-off-by: Peter Lieven > --- > arch_init.c | 23 ++++++++++++++++------- > 1 file changed, 16 insertions(+), 7 deletions(-) > > diff --git a/arch_init.c b/arch_init.c > index 582b716..ce338aa 100644 > --- a/arch_init.c > +++ b/arch_init.c > @@ -594,13 +594,19 @@ static int ram_save_block(QEMUFile *f, bool last_stage) > ram_bulk_stage = false; > } > } else { > + static uint8_t *ram_ptr; > int ret; > uint8_t *p; > bool send_async = true; > - int cont = (block == last_sent_block) ? > - RAM_SAVE_FLAG_CONTINUE : 0; > + int cont = 0; > > - p = memory_region_get_ram_ptr(mr) + offset; > + if (block != last_sent_block) { > + ram_ptr = memory_region_get_ram_ptr(mr); > + } else { > + cont = RAM_SAVE_FLAG_CONTINUE; > + } > + > + p = ram_ptr + offset; > > /* In doubt sent page as normal */ > bytes_sent = -1; > @@ -990,16 +996,17 @@ static inline void *host_from_stream_offset(QEMUFile *f, > int flags) > { > static RAMBlock *block = NULL; > + static uint8_t *ram_ptr; > char id[256]; > uint8_t len; > > if (flags & RAM_SAVE_FLAG_CONTINUE) { > - if (!block) { > + if (!block || !ram_ptr) { > fprintf(stderr, "Ack, bad migration stream!\n"); > return NULL; > } > > - return memory_region_get_ram_ptr(block->mr) + offset; > + return ram_ptr + offset; > } > > len = qemu_get_byte(f); > @@ -1007,8 +1014,10 @@ static inline void *host_from_stream_offset(QEMUFile *f, > id[len] = 0; > > QTAILQ_FOREACH(block, &ram_list.blocks, next) { > - if (!strncmp(id, block->idstr, sizeof(id))) > - return memory_region_get_ram_ptr(block->mr) + offset; > + if (!strncmp(id, block->idstr, sizeof(id))) { > + ram_ptr = memory_region_get_ram_ptr(block->mr); > + return ram_ptr + offset; > + } > } > > fprintf(stderr, "Can't find block %s!\n", id); >