#endif
#include "config.h"
#include "monitor/monitor.h"
-#include "sysemu.h"
-#include "bitops.h"
-#include "bitmap.h"
-#include "arch_init.h"
+#include "sysemu/sysemu.h"
+#include "qemu/bitops.h"
+#include "qemu/bitmap.h"
+#include "sysemu/arch_init.h"
#include "audio/audio.h"
#include "hw/pc.h"
#include "hw/pci/pci.h"
#include "hw/audiodev.h"
-#include "kvm.h"
+#include "sysemu/kvm.h"
#include "migration/migration.h"
#include "exec/gdbstub.h"
#include "hw/smbios.h"
#include "exec/address-spaces.h"
#include "hw/pcspk.h"
#include "migration/page_cache.h"
-#include "qemu-config.h"
+#include "qemu/config-file.h"
#include "qmp-commands.h"
#include "trace.h"
+#include "exec/cpu-all.h"
#ifdef DEBUG_ARCH_INIT
#define DPRINTF(fmt, ...) \
static ram_addr_t last_offset;
static unsigned long *migration_bitmap;
static uint64_t migration_dirty_pages;
+static uint32_t last_version;
static inline bool migration_bitmap_test_and_reset_dirty(MemoryRegion *mr,
ram_addr_t offset)
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)) {
}
}
-
/*
* ram_save_block: Writes a page of memory to the stream f
*
ram_addr_t current_addr;
if (!block)
- block = QLIST_FIRST(&ram_list.blocks);
+ block = QTAILQ_FIRST(&ram_list.blocks);
do {
mr = block->mr;
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);
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;
}
-static int block_compar(const void *a, const void *b)
-{
- RAMBlock * const *ablock = a;
- RAMBlock * const *bblock = b;
-
- return strcmp((*ablock)->idstr, (*bblock)->idstr);
-}
-
-static void sort_ram_list(void)
-{
- RAMBlock *block, *nblock, **blocks;
- int n;
- n = 0;
- QLIST_FOREACH(block, &ram_list.blocks, next) {
- ++n;
- }
- blocks = g_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);
- }
- g_free(blocks);
-}
-
static void migration_end(void)
{
- memory_global_dirty_log_stop();
+ if (migration_bitmap) {
+ memory_global_dirty_log_stop();
+ g_free(migration_bitmap);
+ migration_bitmap = NULL;
+ }
- if (migrate_use_xbzrle()) {
+ if (XBZRLE.cache) {
cache_fini(XBZRLE.cache);
g_free(XBZRLE.cache);
g_free(XBZRLE.encoded_buf);
migration_end();
}
-
static void reset_ram_globals(void)
{
last_block = NULL;
last_offset = 0;
- sort_ram_list();
+ last_version = ram_list.version;
}
#define MAX_WAIT 50 /* ms, half buffered_file limit */
bitmap_set(migration_bitmap, 0, ram_pages);
migration_dirty_pages = ram_pages;
+ qemu_mutex_lock_ramlist();
bytes_transferred = 0;
reset_ram_globals();
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);
}
+ qemu_mutex_unlock_ramlist();
qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
return 0;
uint64_t expected_downtime;
MigrationState *s = migrate_get_current();
+ qemu_mutex_lock_ramlist();
+
+ if (ram_list.version != last_version) {
+ reset_ram_globals();
+ }
+
bytes_transferred_last = bytes_transferred;
bwidth = qemu_get_clock_ns(rt_clock);
bwidth = 0.000001;
}
+ qemu_mutex_unlock_ramlist();
qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
expected_downtime = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
{
migration_bitmap_sync();
+ qemu_mutex_lock_ramlist();
+
/* try transferring iterative blocks of memory */
/* flush all remaining blocks regardless of rate limiting */
}
bytes_transferred += bytes_sent;
}
- memory_global_dirty_log_stop();
+ migration_end();
+ qemu_mutex_unlock_ramlist();
qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
- g_free(migration_bitmap);
- migration_bitmap = NULL;
-
return 0;
}
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;
}
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;