From 58eaa2174e99d9a05172d03fd2799ab8fd9e6f60 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Mon, 22 Feb 2016 16:34:55 +0800 Subject: exec: store RAMBlock pointer into memory region Each RAM memory region has a unique corresponding RAMBlock. In the current realization, the memory region only stored the ram_addr which means the offset of RAM address space, We need to qurey the global ram.list to find the ram block by ram_addr if we want to get the ram block, which is very expensive. Now, we store the RAMBlock pointer into memory region structure. So, if we know the mr, we can easily get the RAMBlock. Signed-off-by: Gonglei Message-Id: <1456130097-4208-2-git-send-email-arei.gonglei@huawei.com> Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/exec/memory.h') diff --git a/include/exec/memory.h b/include/exec/memory.h index c92734ae2b..683be46cd0 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -34,6 +34,7 @@ #include "qapi/error.h" #include "qom/object.h" #include "qemu/rcu.h" +#include "qemu/typedefs.h" #define MAX_PHYS_ADDR_SPACE_BITS 62 #define MAX_PHYS_ADDR (((hwaddr)1 << MAX_PHYS_ADDR_SPACE_BITS) - 1) @@ -172,6 +173,7 @@ struct MemoryRegion { bool global_locking; uint8_t dirty_log_mask; ram_addr_t ram_addr; + RAMBlock *ram_block; Object *owner; const MemoryRegionIOMMUOps *iommu_ops; -- cgit v1.2.3 From 3655cb9c7375a595a8051ec677c515b24d5c1fe6 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Sat, 20 Feb 2016 10:35:20 +0800 Subject: memory: optimize qemu_get_ram_ptr and qemu_ram_ptr_length these two functions consume too much cpu overhead to find the RAMBlock by ram address. After this patch, we can pass the RAMBlock pointer to them so that they don't need to find the RAMBlock anymore most of the time. We can get better performance in address translation processing. Signed-off-by: Gonglei Message-Id: <1455935721-8804-3-git-send-email-arei.gonglei@huawei.com> Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/exec/memory.h') diff --git a/include/exec/memory.h b/include/exec/memory.h index 683be46cd0..34f21f1aed 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1391,7 +1391,7 @@ MemTxResult address_space_read_continue(AddressSpace *as, hwaddr addr, MemoryRegion *mr); MemTxResult address_space_read_full(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, uint8_t *buf, int len); -void *qemu_get_ram_ptr(ram_addr_t addr); +void *qemu_get_ram_ptr(RAMBlock *ram_block, ram_addr_t addr); static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) { @@ -1432,7 +1432,7 @@ MemTxResult address_space_read(AddressSpace *as, hwaddr addr, MemTxAttrs attrs, mr = address_space_translate(as, addr, &addr1, &l, false); if (len == l && memory_access_is_direct(mr, false)) { addr1 += memory_region_get_ram_addr(mr); - ptr = qemu_get_ram_ptr(addr1); + ptr = qemu_get_ram_ptr(mr->ram_block, addr1); memcpy(buf, ptr, len); } else { result = address_space_read_continue(as, addr, attrs, buf, len, -- cgit v1.2.3 From d61524486c6e503e502241a2ea834f930f98a6a1 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Sat, 20 Feb 2016 10:35:21 +0800 Subject: memory: Remove unreachable return statement Signed-off-by: Gonglei Message-Id: <1455935721-8804-4-git-send-email-arei.gonglei@huawei.com> Signed-off-by: Paolo Bonzini --- include/exec/memory.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'include/exec/memory.h') diff --git a/include/exec/memory.h b/include/exec/memory.h index 34f21f1aed..032400aefa 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1400,8 +1400,6 @@ static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write) } else { return memory_region_is_ram(mr) || memory_region_is_romd(mr); } - - return false; } /** -- cgit v1.2.3