Hi,
I have created a thread in qemu to periodically print the number of memory pages that get dirtied. I have followed the logic of migration code. However, sometimes an error "qemu-system-x86_64: qemu-kvm/int128.h:18: int128_get64: Assertion `!a.hi' failed." is reported. Is there anything wrong in my code?
// added code in arch_init.c
static int ram_iterate_block(void)
{
RAMBlock *block = last_block;
ram_addr_t offset = last_offset;
int bytes_sent = -1;
MemoryRegion *mr;
if (!block)
block = QLIST_FIRST(&ram_list.blocks);
do {
mr = block->mr;
if (memory_region_get_dirty(mr, offset, TARGET_PAGE_SIZE,
DIRTY_MEMORY_MIGRATION)) {
memory_region_reset_dirty(mr, offset, TARGET_PAGE_SIZE,
DIRTY_MEMORY_MIGRATION);
if (bytes_sent == -1) {
bytes_sent = TARGET_PAGE_SIZE;
}
if (bytes_sent != 0) {
break;
}
}
offset += TARGET_PAGE_SIZE;
if (offset >= block->length) {
offset = 0;
block = QLIST_NEXT(block, next);
if (!block)
block = QLIST_FIRST(&ram_list.blocks);
}
} while (block != last_block || offset != last_offset);
last_block = block;
last_offset = offset;
return bytes_sent;
}
void *print_dirty_page(void *arg)
{
FILE * dirty_log = fopen("dirty_log.txt", "w+");
// ram_save_setup
ram_addr_t addr;
RAMBlock *block;
last_block = NULL;
last_offset = 0;
QLIST_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)) {
memory_region_set_dirty(block->mr, addr, TARGET_PAGE_SIZE);
}
}
}
memory_global_dirty_log_start();
// ram_save_iterate
while (true) {
while (true) {
int bytes_sent;
bytes_sent = ram_iterate_block();
if (bytes_sent < 0) {
break;
}
}
memory_global_sync_dirty_bitmap(get_system_memory());
fprintf(dirty_log, "%"PRIu64"\n", ram_list.dirty_pages);
usleep(1000 * 25); // print every 25ms
}
return NULL;
}