From feff56cc1112adff25b2b2e4fe956321fdb8cc6a Mon Sep 17 00:00:00 2001 From: Gonglei Date: Sat, 24 Feb 2018 02:52:14 -0500 Subject: [PATCH] memory: drop find_ram_block() On the one hand, we have already qemu_get_ram_block() whose function is similar. On the other hand, we can directly use mr->ram_block but searching RAMblock by ram_addr which is a kind of waste. Backports commit fa53a0e53efdc7002497ea4a76aacf6cceb170ef from qemu --- qemu/exec.c | 21 ++------------------- qemu/include/exec/cpu-common.h | 4 ++-- qemu/include/exec/ram_addr.h | 2 +- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/qemu/exec.c b/qemu/exec.c index 65cd043d..72e9951a 100644 --- a/qemu/exec.c +++ b/qemu/exec.c @@ -1049,28 +1049,13 @@ static void qemu_ram_setup_dump(void *addr, ram_addr_t size) { } -static RAMBlock *find_ram_block(struct uc_struct *uc, ram_addr_t addr) -{ - RAMBlock *block; - - QLIST_FOREACH(block, &uc->ram_list.blocks, next) { - if (block->offset == addr) { - return block; - } - } - - return NULL; -} - const char *qemu_ram_get_idstr(RAMBlock *rb) { return rb->idstr; } -void qemu_ram_unset_idstr(struct uc_struct *uc, ram_addr_t addr) +void qemu_ram_unset_idstr(struct uc_struct *uc, RAMBlock *block) { - RAMBlock *block = find_ram_block(uc, addr); - if (block) { memset(block->idstr, 0, sizeof(block->idstr)); } @@ -1088,10 +1073,8 @@ static int memory_try_enable_merging(void *addr, size_t len) * resize callback to update device state and/or add assertions to detect * misuse, if necessary. */ -int qemu_ram_resize(struct uc_struct *uc, ram_addr_t base, ram_addr_t newsize, Error **errp) +int qemu_ram_resize(struct uc_struct *uc, RAMBlock *block, ram_addr_t newsize, Error **errp) { - RAMBlock *block = find_ram_block(uc, base); - assert(block); newsize = TARGET_PAGE_ALIGN(newsize); diff --git a/qemu/include/exec/cpu-common.h b/qemu/include/exec/cpu-common.h index bd9dd988..a3c67f87 100644 --- a/qemu/include/exec/cpu-common.h +++ b/qemu/include/exec/cpu-common.h @@ -52,8 +52,8 @@ MemoryRegion *qemu_ram_addr_from_host(struct uc_struct* uc, void *ptr, ram_addr_ RAMBlock *qemu_ram_block_by_name(struct uc_struct* uc, const char *name); RAMBlock *qemu_ram_block_from_host(struct uc_struct* uc, void *ptr, bool round_offset, ram_addr_t *ram_addr, ram_addr_t *offset); -void qemu_ram_set_idstr(struct uc_struct *uc, ram_addr_t addr, const char *name, DeviceState *dev); -void qemu_ram_unset_idstr(struct uc_struct *uc, ram_addr_t addr); +void qemu_ram_set_idstr(struct uc_struct *uc, RAMBlock *block, const char *name, DeviceState *dev); +void qemu_ram_unset_idstr(struct uc_struct *uc, RAMBlock *block); const char *qemu_ram_get_idstr(RAMBlock *rb); bool cpu_physical_memory_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, diff --git a/qemu/include/exec/ram_addr.h b/qemu/include/exec/ram_addr.h index cae0fa7f..2e5e2ea1 100644 --- a/qemu/include/exec/ram_addr.h +++ b/qemu/include/exec/ram_addr.h @@ -65,7 +65,7 @@ int qemu_get_ram_fd(struct uc_struct *uc, ram_addr_t addr); void *qemu_get_ram_block_host_ptr(struct uc_struct *uc, ram_addr_t addr); void qemu_ram_free(struct uc_struct *c, ram_addr_t addr); -int qemu_ram_resize(struct uc_struct *c, ram_addr_t base, ram_addr_t newsize, Error **errp); +int qemu_ram_resize(struct uc_struct *c, RAMBlock *block, ram_addr_t newsize, Error **errp); #define DIRTY_CLIENTS_ALL ((1 << DIRTY_MEMORY_NUM) - 1) #define DIRTY_CLIENTS_NOCODE (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE))