Patchwork [37/39] memory: syncronize kvm bitmap using bitmaps operations

login
register
mail settings
Submitter Juan Quintela
Date Nov. 6, 2013, 1:04 p.m.
Message ID <1383743088-8139-38-git-send-email-quintela@redhat.com>
Download mbox | patch
Permalink /patch/288900/
State New
Headers show

Comments

Juan Quintela - Nov. 6, 2013, 1:04 p.m.
If bitmaps are aligned properly, use bitmap operations.  If they are
not, just use old bit at a time code.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 include/exec/memory-physical.h | 54 +++++++++++++++++++++++++++++-------------
 1 file changed, 38 insertions(+), 16 deletions(-)
Paolo Bonzini - Nov. 6, 2013, 3:58 p.m.
Il 06/11/2013 14:04, Juan Quintela ha scritto:
> +    /* start address is aligned at the start of a word? */
> +    if (((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) {
> +        int k;
> +        int nr = BITS_TO_LONGS(pages);
> +
> +        printf("XXX: aligned start %lx page %lx\n", start, page);
> +        assert(start == ((start >> TARGET_PAGE_BITS) << TARGET_PAGE_BITS));

This test is useless, since you have already tested the zero-ness of the
low bits in the "if" condition: the low bits are 0 in ((page *
BITS_PER_LONG) << TARGET_PAGE_BITS).

Paolo

Patch

diff --git a/include/exec/memory-physical.h b/include/exec/memory-physical.h
index 72faf06..9057714 100644
--- a/include/exec/memory-physical.h
+++ b/include/exec/memory-physical.h
@@ -82,23 +82,45 @@  static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
     ram_addr_t ram_addr;
     unsigned int len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS;
     unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
+    unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);

-    /*
-     * bitmap-traveling is faster than memory-traveling (for addr...)
-     * especially when most of the memory is not dirty.
-     */
-    for (i = 0; i < len; i++) {
-        if (bitmap[i] != 0) {
-            c = leul_to_cpu(bitmap[i]);
-            do {
-                j = ffsl(c) - 1;
-                c &= ~(1ul << j);
-                page_number = (i * HOST_LONG_BITS + j) * hpratio;
-                addr = page_number * TARGET_PAGE_SIZE;
-                ram_addr = start + addr;
-                cpu_physical_memory_set_dirty_range(ram_addr,
-                                                    TARGET_PAGE_SIZE * hpratio);
-            } while (c != 0);
+    /* start address is aligned at the start of a word? */
+    if (((page * BITS_PER_LONG) << TARGET_PAGE_BITS) == start) {
+        int k;
+        int nr = BITS_TO_LONGS(pages);
+
+        printf("XXX: aligned start %lx page %lx\n", start, page);
+        assert(start == ((start >> TARGET_PAGE_BITS) << TARGET_PAGE_BITS));
+
+        for (k = 0; k < nr; k++) {
+            if (bitmap[k]) {
+                unsigned long temp = leul_to_cpu(bitmap[k]);
+
+                ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION][page + k] |= temp;
+                ram_list.dirty_memory[DIRTY_MEMORY_VGA][page + k] |= temp;
+                ram_list.dirty_memory[DIRTY_MEMORY_CODE][page + k] |= temp;
+            }
+        }
+        xen_modified_memory(start, pages);
+    } else {
+        printf("XXX: not aligned start %lx pages %lu\n", start, pages);
+        /*
+         * bitmap-traveling is faster than memory-traveling (for addr...)
+         * especially when most of the memory is not dirty.
+         */
+        for (i = 0; i < len; i++) {
+            if (bitmap[i] != 0) {
+                c = leul_to_cpu(bitmap[i]);
+                do {
+                    j = ffsl(c) - 1;
+                    c &= ~(1ul << j);
+                    page_number = (i * HOST_LONG_BITS + j) * hpratio;
+                    addr = page_number * TARGET_PAGE_SIZE;
+                    ram_addr = start + addr;
+                    cpu_physical_memory_set_dirty_range(ram_addr,
+                                                        TARGET_PAGE_SIZE * hpratio);
+                } while (c != 0);
+            }
         }
     }
 }