From patchwork Thu May 12 10:07:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 9078481 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 224869F372 for ; Thu, 12 May 2016 10:09:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5A6B720218 for ; Thu, 12 May 2016 10:09:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D1EAB201F5 for ; Thu, 12 May 2016 10:09:02 +0000 (UTC) Received: from localhost ([::1]:56707 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0nYE-0005fV-0g for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 May 2016 06:09:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0nX6-0003cX-Do for qemu-devel@nongnu.org; Thu, 12 May 2016 06:07:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b0nX2-0006Da-22 for qemu-devel@nongnu.org; Thu, 12 May 2016 06:07:51 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:16044) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b0nX1-0006CT-57 for qemu-devel@nongnu.org; Thu, 12 May 2016 06:07:47 -0400 Received: from 172.24.1.47 (EHLO szxeml433-hub.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DHA52135; Thu, 12 May 2016 18:07:30 +0800 (CST) Received: from localhost (10.177.18.62) by szxeml433-hub.china.huawei.com (10.82.67.210) with Microsoft SMTP Server id 14.3.235.1; Thu, 12 May 2016 18:07:21 +0800 From: Gonglei To: Date: Thu, 12 May 2016 18:07:16 +0800 Message-ID: <1463047636-124524-4-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 2.6.3.windows.1 In-Reply-To: <1463047636-124524-1-git-send-email-arei.gonglei@huawei.com> References: <1463047636-124524-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.18.62] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.573455E4.0155, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: f0bff93e0f6d976de234d6c5774dbe0a X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.65 Subject: [Qemu-devel] [PATCH v3 3/3] memory: drop some wrappers that waste cpu cycle X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, Gonglei , famz@redhat.com, peter.huangpeng@huawei.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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)); + assert(s->ivshmem_bar2->ram_block); + fd = s->ivshmem_bar2->ram_block->fd; close(fd); } diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 5914e85..5082e04 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -248,17 +248,18 @@ static int vhost_user_set_mem_table(struct vhost_dev *dev, for (i = 0; i < dev->mem->nregions; ++i) { struct vhost_memory_region *reg = dev->mem->regions + i; ram_addr_t ram_addr; + MemoryRegion *mr; assert((uintptr_t)reg->userspace_addr == reg->userspace_addr); - qemu_ram_addr_from_host((void *)(uintptr_t)reg->userspace_addr, + mr = qemu_ram_addr_from_host((void *)(uintptr_t)reg->userspace_addr, &ram_addr); - fd = qemu_get_ram_fd(ram_addr); + fd = mr->ram_block->fd; if (fd > 0) { msg.payload.memory.regions[fd_num].userspace_addr = reg->userspace_addr; msg.payload.memory.regions[fd_num].memory_size = reg->memory_size; msg.payload.memory.regions[fd_num].guest_phys_addr = reg->guest_phys_addr; msg.payload.memory.regions[fd_num].mmap_offset = reg->userspace_addr - - (uintptr_t) qemu_get_ram_block_host_ptr(ram_addr); + (uintptr_t) qemu_get_ram_block_host_ptr(mr->ram_block); assert(fd_num < VHOST_MEMORY_MAX_NREGIONS); fds[fd_num++] = fd; } @@ -622,11 +623,13 @@ static bool vhost_user_can_merge(struct vhost_dev *dev, mr = qemu_ram_addr_from_host((void *)(uintptr_t)start1, &ram_addr); assert(mr); - mfd = qemu_get_ram_fd(ram_addr); + assert(mr->ram_block); + mfd = mr->ram_block->fd; mr = qemu_ram_addr_from_host((void *)(uintptr_t)start2, &ram_addr); assert(mr); - rfd = qemu_get_ram_fd(ram_addr); + assert(mr->ram_block); + rfd = mr->ram_block->fd; return mfd == rfd; } diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 5b6e1b8..9a01d4a 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -105,9 +105,7 @@ RAMBlock *qemu_ram_alloc_resizeable(ram_addr_t size, ram_addr_t max_size, uint64_t length, void *host), MemoryRegion *mr, Error **errp); -int qemu_get_ram_fd(ram_addr_t addr); -void qemu_set_ram_fd(ram_addr_t addr, int fd); -void *qemu_get_ram_block_host_ptr(ram_addr_t addr); +void *qemu_get_ram_block_host_ptr(RAMBlock *ram_block); void qemu_ram_free(RAMBlock *block); int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp); diff --git a/memory.c b/memory.c index 239e6da..9cff7e2 100644 --- a/memory.c +++ b/memory.c @@ -1641,7 +1641,7 @@ int memory_region_get_fd(MemoryRegion *mr) assert(mr->ram_block); - return qemu_get_ram_fd(memory_region_get_ram_addr(mr) & TARGET_PAGE_MASK); + return mr->ram_block->fd; } void *memory_region_get_ram_ptr(MemoryRegion *mr)