From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2U9q-0004X6-Qy for qemu-devel@nongnu.org; Mon, 16 May 2016 21:50:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b2U9m-0007gz-HV for qemu-devel@nongnu.org; Mon, 16 May 2016 21:50:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60021) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b2U9m-0007gs-BT for qemu-devel@nongnu.org; Mon, 16 May 2016 21:50:46 -0400 Date: Tue, 17 May 2016 09:50:44 +0800 From: Fam Zheng Message-ID: <20160517015044.GA21731@ad.usersys.redhat.com> References: <1463047636-124524-1-git-send-email-arei.gonglei@huawei.com> <1463047636-124524-4-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1463047636-124524-4-git-send-email-arei.gonglei@huawei.com> Subject: Re: [Qemu-devel] [PATCH v3 3/3] memory: drop some wrappers that waste cpu cycle List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gonglei Cc: qemu-devel@nongnu.org, pbonzini@redhat.com, peter.huangpeng@huawei.com On Thu, 05/12 18:07, Gonglei wrote: > For better performance, we can use RAMblock > directly stored in memory_region at present. > > Signed-off-by: Gonglei > --- > exec.c | 33 ++------------------------------- > hw/misc/ivshmem.c | 8 +++++--- > hw/virtio/vhost-user.c | 13 ++++++++----- > include/exec/ram_addr.h | 4 +--- > memory.c | 2 +- > 5 files changed, 17 insertions(+), 43 deletions(-) > > diff --git a/exec.c b/exec.c > index 117c9a8..f8de928 100644 > --- a/exec.c > +++ b/exec.c > @@ -1812,38 +1812,9 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) > } > #endif /* !_WIN32 */ > > -int qemu_get_ram_fd(ram_addr_t addr) > +void *qemu_get_ram_block_host_ptr(RAMBlock *ram_block) > { > - RAMBlock *block; > - int fd; > - > - rcu_read_lock(); > - block = qemu_get_ram_block(addr); > - fd = block->fd; > - rcu_read_unlock(); > - return fd; > -} > - > -void qemu_set_ram_fd(ram_addr_t addr, int fd) > -{ > - RAMBlock *block; > - > - rcu_read_lock(); > - block = qemu_get_ram_block(addr); > - block->fd = fd; > - rcu_read_unlock(); > -} > - > -void *qemu_get_ram_block_host_ptr(ram_addr_t addr) > -{ > - RAMBlock *block; > - void *ptr; > - > - rcu_read_lock(); > - block = qemu_get_ram_block(addr); > - ptr = ramblock_ptr(block, 0); > - rcu_read_unlock(); > - return ptr; > + return ramblock_ptr(ram_block, 0); > } > > /* Return a host pointer to ram allocated with qemu_ram_alloc. > diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c > index e40f23b..1e930fa 100644 > --- a/hw/misc/ivshmem.c > +++ b/hw/misc/ivshmem.c > @@ -533,7 +533,9 @@ static void process_msg_shmem(IVShmemState *s, int fd, Error **errp) > } > memory_region_init_ram_ptr(&s->server_bar2, OBJECT(s), > "ivshmem.bar2", size, ptr); > - qemu_set_ram_fd(memory_region_get_ram_addr(&s->server_bar2), fd); > + assert(s->server_bar2.ram_block); > + s->server_bar2.ram_block->fd = fd; > + > s->ivshmem_bar2 = &s->server_bar2; > } > > @@ -939,8 +941,8 @@ static void ivshmem_exit(PCIDevice *dev) > error_report("Failed to munmap shared memory %s", > strerror(errno)); > } > - > - fd = qemu_get_ram_fd(memory_region_get_ram_addr(s->ivshmem_bar2)); Maybe this is okay but personally I think it is cleaner to add a qemu_{set,get}_ramblock_fd pair. Fam