Skip to content

Commit

Permalink
exec: change RAM list to a TAILQ
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
  • Loading branch information
bonzini authored and Juan Quintela committed Dec 20, 2012
1 parent 0d6d3c8 commit a316103
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
24 changes: 12 additions & 12 deletions arch_init.c
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions dump.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
34 changes: 17 additions & 17 deletions exec.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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) {
;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions include/exec/cpu-all.h
Expand Up @@ -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
Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions memory_mapping.c
Expand Up @@ -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);
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion target-i386/arch_dump.c
Expand Up @@ -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;
Expand Down

0 comments on commit a316103

Please sign in to comment.