From a3161038a1fd17a638a0c606f71e1f799f65f41b Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 14 Nov 2012 15:54:48 +0100 Subject: [PATCH] exec: change RAM list to a TAILQ Signed-off-by: Paolo Bonzini Signed-off-by: Juan Quintela --- arch_init.c | 24 ++++++++++++------------ dump.c | 8 ++++---- exec.c | 34 +++++++++++++++++----------------- include/exec/cpu-all.h | 4 ++-- memory_mapping.c | 4 ++-- target-i386/arch_dump.c | 2 +- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/arch_init.c b/arch_init.c index 6695ccfdc..67b14d24c 100644 --- a/arch_init.c +++ b/arch_init.c @@ -382,7 +382,7 @@ static void migration_bitmap_sync(void) trace_migration_bitmap_sync_start(); memory_global_sync_dirty_bitmap(get_system_memory()); - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { for (addr = 0; addr < block->length; addr += TARGET_PAGE_SIZE) { if (memory_region_get_dirty(block->mr, addr, TARGET_PAGE_SIZE, DIRTY_MEMORY_MIGRATION)) { @@ -424,7 +424,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage) ram_addr_t current_addr; if (!block) - block = QLIST_FIRST(&ram_list.blocks); + block = QTAILQ_FIRST(&ram_list.blocks); do { mr = block->mr; @@ -465,9 +465,9 @@ static int ram_save_block(QEMUFile *f, bool last_stage) offset += TARGET_PAGE_SIZE; if (offset >= block->length) { offset = 0; - block = QLIST_NEXT(block, next); + block = QTAILQ_NEXT(block, next); if (!block) - block = QLIST_FIRST(&ram_list.blocks); + block = QTAILQ_FIRST(&ram_list.blocks); } } while (block != last_block || offset != last_offset); @@ -499,7 +499,7 @@ uint64_t ram_bytes_total(void) RAMBlock *block; uint64_t total = 0; - QLIST_FOREACH(block, &ram_list.blocks, next) + QTAILQ_FOREACH(block, &ram_list.blocks, next) total += block->length; return total; @@ -518,18 +518,18 @@ static void sort_ram_list(void) RAMBlock *block, *nblock, **blocks; int n; n = 0; - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { ++n; } blocks = g_malloc(n * sizeof *blocks); n = 0; - QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) { + QTAILQ_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) { blocks[n++] = block; - QLIST_REMOVE(block, next); + QTAILQ_REMOVE(&ram_list.blocks, block, next); } qsort(blocks, n, sizeof *blocks, block_compar); while (--n >= 0) { - QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next); + QTAILQ_INSERT_HEAD(&ram_list.blocks, blocks[n], next); } g_free(blocks); } @@ -597,7 +597,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque) qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE); - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { qemu_put_byte(f, strlen(block->idstr)); qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr)); qemu_put_be64(f, block->length); @@ -763,7 +763,7 @@ static inline void *host_from_stream_offset(QEMUFile *f, qemu_get_buffer(f, (uint8_t *)id, len); id[len] = 0; - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (!strncmp(id, block->idstr, sizeof(id))) return memory_region_get_ram_ptr(block->mr) + offset; } @@ -807,7 +807,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) id[len] = 0; length = qemu_get_be64(f); - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (!strncmp(id, block->idstr, sizeof(id))) { if (block->length != length) { ret = -EINVAL; diff --git a/dump.c b/dump.c index a26b1a5e1..4ed1fa862 100644 --- a/dump.c +++ b/dump.c @@ -427,7 +427,7 @@ static hwaddr get_offset(hwaddr phys_addr, } } - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (s->has_filter) { if (block->offset >= s->begin + s->length || block->offset + block->length <= s->begin) { @@ -594,7 +594,7 @@ static int dump_completed(DumpState *s) static int get_next_block(DumpState *s, RAMBlock *block) { while (1) { - block = QLIST_NEXT(block, next); + block = QTAILQ_NEXT(block, next); if (!block) { /* no more block */ return 1; @@ -670,11 +670,11 @@ static ram_addr_t get_start_block(DumpState *s) RAMBlock *block; if (!s->has_filter) { - s->block = QLIST_FIRST(&ram_list.blocks); + s->block = QTAILQ_FIRST(&ram_list.blocks); return 0; } - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (block->offset >= s->begin + s->length || block->offset + block->length <= s->begin) { /* This block is out of the range */ diff --git a/exec.c b/exec.c index 78bae1c7a..584279a2e 100644 --- a/exec.c +++ b/exec.c @@ -57,7 +57,7 @@ int phys_ram_fd; static int in_migration; -RAMList ram_list = { .blocks = QLIST_HEAD_INITIALIZER(ram_list.blocks) }; +RAMList ram_list = { .blocks = QTAILQ_HEAD_INITIALIZER(ram_list.blocks) }; static MemoryRegion *system_memory; static MemoryRegion *system_io; @@ -902,15 +902,15 @@ static ram_addr_t find_ram_offset(ram_addr_t size) RAMBlock *block, *next_block; ram_addr_t offset = RAM_ADDR_MAX, mingap = RAM_ADDR_MAX; - if (QLIST_EMPTY(&ram_list.blocks)) + if (QTAILQ_EMPTY(&ram_list.blocks)) return 0; - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { ram_addr_t end, next = RAM_ADDR_MAX; end = block->offset + block->length; - QLIST_FOREACH(next_block, &ram_list.blocks, next) { + QTAILQ_FOREACH(next_block, &ram_list.blocks, next) { if (next_block->offset >= end) { next = MIN(next, next_block->offset); } @@ -935,7 +935,7 @@ ram_addr_t last_ram_offset(void) RAMBlock *block; ram_addr_t last = 0; - QLIST_FOREACH(block, &ram_list.blocks, next) + QTAILQ_FOREACH(block, &ram_list.blocks, next) last = MAX(last, block->offset + block->length); return last; @@ -964,7 +964,7 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev) RAMBlock *new_block, *block; new_block = NULL; - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (block->offset == addr) { new_block = block; break; @@ -982,7 +982,7 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, DeviceState *dev) } pstrcat(new_block->idstr, sizeof(new_block->idstr), name); - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (block != new_block && !strcmp(block->idstr, new_block->idstr)) { fprintf(stderr, "RAMBlock \"%s\" already registered, abort!\n", new_block->idstr); @@ -1043,7 +1043,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, } new_block->length = size; - QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next); + QTAILQ_INSERT_HEAD(&ram_list.blocks, new_block, next); ram_list.mru_block = NULL; ram_list.phys_dirty = g_realloc(ram_list.phys_dirty, @@ -1070,9 +1070,9 @@ void qemu_ram_free_from_ptr(ram_addr_t addr) { RAMBlock *block; - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (addr == block->offset) { - QLIST_REMOVE(block, next); + QTAILQ_REMOVE(&ram_list.blocks, block, next); ram_list.mru_block = NULL; g_free(block); return; @@ -1084,9 +1084,9 @@ void qemu_ram_free(ram_addr_t addr) { RAMBlock *block; - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (addr == block->offset) { - QLIST_REMOVE(block, next); + QTAILQ_REMOVE(&ram_list.blocks, block, next); ram_list.mru_block = NULL; if (block->flags & RAM_PREALLOC_MASK) { ; @@ -1127,7 +1127,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length) int flags; void *area, *vaddr; - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { offset = addr - block->offset; if (offset < block->length) { vaddr = block->host + offset; @@ -1197,7 +1197,7 @@ void *qemu_get_ram_ptr(ram_addr_t addr) if (block && addr - block->offset < block->length) { goto found; } - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (addr - block->offset < block->length) { goto found; } @@ -1232,7 +1232,7 @@ static void *qemu_safe_ram_ptr(ram_addr_t addr) { RAMBlock *block; - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (addr - block->offset < block->length) { if (xen_enabled()) { /* We need to check if the requested address is in the RAM @@ -1268,7 +1268,7 @@ static void *qemu_ram_ptr_length(ram_addr_t addr, ram_addr_t *size) } else { RAMBlock *block; - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (addr - block->offset < block->length) { if (addr - block->offset + *size > block->length) *size = block->length - addr + block->offset; @@ -1296,7 +1296,7 @@ int qemu_ram_addr_from_host(void *ptr, ram_addr_t *ram_addr) return 0; } - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { /* This case append when the block is not mapped. */ if (block->host == NULL) { continue; diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 9fe6fc075..612e95005 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -487,7 +487,7 @@ typedef struct RAMBlock { ram_addr_t length; uint32_t flags; char idstr[256]; - QLIST_ENTRY(RAMBlock) next; + QTAILQ_ENTRY(RAMBlock) next; #if defined(__linux__) && !defined(TARGET_S390X) int fd; #endif @@ -496,7 +496,7 @@ typedef struct RAMBlock { typedef struct RAMList { uint8_t *phys_dirty; RAMBlock *mru_block; - QLIST_HEAD(, RAMBlock) blocks; + QTAILQ_HEAD(, RAMBlock) blocks; } RAMList; extern RAMList ram_list; diff --git a/memory_mapping.c b/memory_mapping.c index 530f1d679..ff45b3a23 100644 --- a/memory_mapping.c +++ b/memory_mapping.c @@ -200,7 +200,7 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list) * If the guest doesn't use paging, the virtual address is equal to physical * address. */ - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { offset = block->offset; length = block->length; create_new_memory_mapping(list, offset, offset, length); @@ -213,7 +213,7 @@ void qemu_get_guest_simple_memory_mapping(MemoryMappingList *list) { RAMBlock *block; - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { create_new_memory_mapping(list, block->offset, 0, block->length); } } diff --git a/target-i386/arch_dump.c b/target-i386/arch_dump.c index 8209ce9ee..2cd2f7f09 100644 --- a/target-i386/arch_dump.c +++ b/target-i386/arch_dump.c @@ -403,7 +403,7 @@ int cpu_get_dump_info(ArchDumpInfo *info) } else { info->d_class = ELFCLASS32; - QLIST_FOREACH(block, &ram_list.blocks, next) { + QTAILQ_FOREACH(block, &ram_list.blocks, next) { if (block->offset + block->length > UINT_MAX) { /* The memory size is greater than 4G */ info->d_class = ELFCLASS64; -- 2.39.2