9ae3a8
From 7471a0a26dde86aa466e2183c6e43df9c01250d6 Mon Sep 17 00:00:00 2001
9ae3a8
From: Juan Quintela <quintela@redhat.com>
9ae3a8
Date: Tue, 14 Jan 2014 15:07:51 +0100
9ae3a8
Subject: [PATCH 40/40] migration: synchronize memory bitmap 64bits at a time
9ae3a8
9ae3a8
RH-Author: Juan Quintela <quintela@redhat.com>
9ae3a8
Message-id: <1389712071-23303-41-git-send-email-quintela@redhat.com>
9ae3a8
Patchwork-id: 56695
9ae3a8
O-Subject: [RHEL7 qemu-kvm PATCH 40/40] migration: synchronize memory bitmap 64bits at a time
9ae3a8
Bugzilla: 997559
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
9ae3a8
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
9ae3a8
9ae3a8
We use the old code if the bitmaps are not aligned
9ae3a8
9ae3a8
Signed-off-by: Juan Quintela <quintela@redhat.com>
9ae3a8
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
9ae3a8
(cherry picked from commit aa8dc044772ba156cbcf2174b5673cfa11f566a7)
9ae3a8
Signed-off-by: Juan Quintela <quintela@trasno.org>
9ae3a8
---
9ae3a8
 arch_init.c | 38 +++++++++++++++++++++++++++++---------
9ae3a8
 1 file changed, 29 insertions(+), 9 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 arch_init.c |   38 +++++++++++++++++++++++++++++---------
9ae3a8
 1 files changed, 29 insertions(+), 9 deletions(-)
9ae3a8
9ae3a8
diff --git a/arch_init.c b/arch_init.c
9ae3a8
index 23650e7..31aac84 100644
9ae3a8
--- a/arch_init.c
9ae3a8
+++ b/arch_init.c
9ae3a8
@@ -50,6 +50,7 @@
9ae3a8
 #include "exec/cpu-all.h"
9ae3a8
 #include "exec/ram_addr.h"
9ae3a8
 #include "hw/acpi/acpi.h"
9ae3a8
+#include "qemu/host-utils.h"
9ae3a8
 
9ae3a8
 #ifdef DEBUG_ARCH_INIT
9ae3a8
 #define DPRINTF(fmt, ...) \
9ae3a8
@@ -376,15 +377,34 @@ static inline bool migration_bitmap_set_dirty(ram_addr_t addr)
9ae3a8
 static void migration_bitmap_sync_range(ram_addr_t start, ram_addr_t length)
9ae3a8
 {
9ae3a8
     ram_addr_t addr;
9ae3a8
-
9ae3a8
-    for (addr = 0; addr < length; addr += TARGET_PAGE_SIZE) {
9ae3a8
-        if (cpu_physical_memory_get_dirty(start + addr,
9ae3a8
-                                          TARGET_PAGE_SIZE,
9ae3a8
-                                          DIRTY_MEMORY_MIGRATION)) {
9ae3a8
-            cpu_physical_memory_reset_dirty(start + addr,
9ae3a8
-                                            TARGET_PAGE_SIZE,
9ae3a8
-                                            DIRTY_MEMORY_MIGRATION);
9ae3a8
-            migration_bitmap_set_dirty(start + addr);
9ae3a8
+    unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
9ae3a8
+
9ae3a8
+    /* start address is aligned at the start of a word? */
9ae3a8
+    if (((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) {
9ae3a8
+        int k;
9ae3a8
+        int nr = BITS_TO_LONGS(length >> TARGET_PAGE_BITS);
9ae3a8
+        unsigned long *src = ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION];
9ae3a8
+
9ae3a8
+        for (k = page; k < page + nr; k++) {
9ae3a8
+            if (src[k]) {
9ae3a8
+                unsigned long new_dirty;
9ae3a8
+                new_dirty = ~migration_bitmap[k];
9ae3a8
+                migration_bitmap[k] |= src[k];
9ae3a8
+                new_dirty &= src[k];
9ae3a8
+                migration_dirty_pages += ctpopl(new_dirty);
9ae3a8
+                src[k] = 0;
9ae3a8
+            }
9ae3a8
+        }
9ae3a8
+    } else {
9ae3a8
+        for (addr = 0; addr < length; addr += TARGET_PAGE_SIZE) {
9ae3a8
+            if (cpu_physical_memory_get_dirty(start + addr,
9ae3a8
+                                              TARGET_PAGE_SIZE,
9ae3a8
+                                              DIRTY_MEMORY_MIGRATION)) {
9ae3a8
+                cpu_physical_memory_reset_dirty(start + addr,
9ae3a8
+                                                TARGET_PAGE_SIZE,
9ae3a8
+                                                DIRTY_MEMORY_MIGRATION);
9ae3a8
+                migration_bitmap_set_dirty(start + addr);
9ae3a8
+            }
9ae3a8
         }
9ae3a8
     }
9ae3a8
 }
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8