diff options
| author | Anthony Liguori <aliguori@us.ibm.com> | 2010-12-02 14:16:40 -0600 |
|---|---|---|
| committer | Anthony Liguori <aliguori@us.ibm.com> | 2010-12-02 14:16:40 -0600 |
| commit | 19c71ff41c029517c11ae67d6fbcb093a5d1150f (patch) | |
| tree | c33443ac97aeb57341c2f24626cbc6d809fcdaca /arch_init.c | |
| parent | 393f398b69f9baadc3f29d822a0b5b74ca63b919 (diff) | |
| parent | 0c600ce2a7a419c7247b2ac63327dea5daa3d5a2 (diff) | |
| download | focaccia-qemu-19c71ff41c029517c11ae67d6fbcb093a5d1150f.tar.gz focaccia-qemu-19c71ff41c029517c11ae67d6fbcb093a5d1150f.zip | |
Merge remote branch 'mst/for_anthony' into staging
Diffstat (limited to 'arch_init.c')
| -rw-r--r-- | arch_init.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/arch_init.c b/arch_init.c index 44869255ef..e32e289c8f 100644 --- a/arch_init.c +++ b/arch_init.c @@ -23,6 +23,7 @@ */ #include <stdint.h> #include <stdarg.h> +#include <stdlib.h> #ifndef _WIN32 #include <sys/types.h> #include <sys/mman.h> @@ -212,6 +213,39 @@ uint64_t ram_bytes_total(void) return total; } +static int block_compar(const void *a, const void *b) +{ + RAMBlock * const *ablock = a; + RAMBlock * const *bblock = b; + if ((*ablock)->offset < (*bblock)->offset) { + return -1; + } else if ((*ablock)->offset > (*bblock)->offset) { + return 1; + } + return 0; +} + +static void sort_ram_list(void) +{ + RAMBlock *block, *nblock, **blocks; + int n; + n = 0; + QLIST_FOREACH(block, &ram_list.blocks, next) { + ++n; + } + blocks = qemu_malloc(n * sizeof *blocks); + n = 0; + QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) { + blocks[n++] = block; + QLIST_REMOVE(block, next); + } + qsort(blocks, n, sizeof *blocks, block_compar); + while (--n >= 0) { + QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next); + } + qemu_free(blocks); +} + int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) { ram_addr_t addr; @@ -234,6 +268,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque) bytes_transferred = 0; last_block = NULL; last_offset = 0; + sort_ram_list(); /* Make sure all dirty bits are set */ QLIST_FOREACH(block, &ram_list.blocks, next) { |