diff mbox

[v2,2/6] Introduce bit-based phys_ram_dirty for VGA, CODE, MIGRATION and MASTER.

Message ID 1270515084-24120-3-git-send-email-tamura.yoshiaki@lab.ntt.co.jp (mailing list archive)
State New, archived
Headers show

Commit Message

Yoshiaki Tamura April 6, 2010, 12:51 a.m. UTC
None
diff mbox

Patch

diff --git a/exec.c b/exec.c
index c74b0a4..9733892 100644
--- a/exec.c
+++ b/exec.c
@@ -110,7 +110,7 @@  uint8_t *code_gen_ptr;
 
 #if !defined(CONFIG_USER_ONLY)
 int phys_ram_fd;
-uint8_t *phys_ram_dirty;
+unsigned long *phys_ram_dirty[NUM_DIRTY_FLAGS];
 static int in_migration;
 
 typedef struct RAMBlock {
@@ -2825,10 +2825,32 @@  ram_addr_t qemu_ram_alloc(ram_addr_t size)
     new_block->next = ram_blocks;
     ram_blocks = new_block;
 
-    phys_ram_dirty = qemu_realloc(phys_ram_dirty,
-        (last_ram_offset + size) >> TARGET_PAGE_BITS);
-    memset(phys_ram_dirty + (last_ram_offset >> TARGET_PAGE_BITS),
-           0xff, size >> TARGET_PAGE_BITS);
+/* temporarily copy from qemu-kvm.git/qemu-kvm.h */
+#define ALIGN(x, y)  (((x)+(y)-1) & ~((y)-1))
+#define BITMAP_SIZE(m) (ALIGN(((m)>>TARGET_PAGE_BITS), HOST_LONG_BITS) / 8)
+
+    if (BITMAP_SIZE(last_ram_offset + size) != BITMAP_SIZE(last_ram_offset)) {
+        phys_ram_dirty[MASTER_DIRTY_FLAG] =
+            qemu_realloc(phys_ram_dirty[MASTER_DIRTY_FLAG],
+                         BITMAP_SIZE(last_ram_offset + size));
+        phys_ram_dirty[VGA_DIRTY_FLAG] 
+            = qemu_realloc(phys_ram_dirty[VGA_DIRTY_FLAG],
+                           BITMAP_SIZE(last_ram_offset + size));
+        phys_ram_dirty[CODE_DIRTY_FLAG] =
+            qemu_realloc(phys_ram_dirty[CODE_DIRTY_FLAG],
+                         BITMAP_SIZE(last_ram_offset + size));
+        phys_ram_dirty[MIGRATION_DIRTY_FLAG] =
+            qemu_realloc(phys_ram_dirty[MIGRATION_DIRTY_FLAG],
+                         BITMAP_SIZE(last_ram_offset + size));
+        memset((uint8_t *)phys_ram_dirty[MASTER_DIRTY_FLAG] +
+               BITMAP_SIZE(last_ram_offset), 0xff, BITMAP_SIZE(size));
+        memset((uint8_t *)phys_ram_dirty[VGA_DIRTY_FLAG] +
+               BITMAP_SIZE(last_ram_offset), 0xff, BITMAP_SIZE(size));
+        memset((uint8_t *)phys_ram_dirty[CODE_DIRTY_FLAG] +
+               BITMAP_SIZE(last_ram_offset), 0xff, BITMAP_SIZE(size));
+        memset((uint8_t *)phys_ram_dirty[MIGRATION_DIRTY_FLAG] +
+               BITMAP_SIZE(last_ram_offset), 0xff, BITMAP_SIZE(size));
+    }
 
     last_ram_offset += size;