0a122b
From e6b7d9c30dfcdf22dcf87eab667a4212e803ec54 Mon Sep 17 00:00:00 2001
0a122b
From: Juan Quintela <quintela@redhat.com>
0a122b
Date: Tue, 14 Jan 2014 15:07:29 +0100
0a122b
Subject: [PATCH 18/40] memory: split dirty bitmap into three
0a122b
0a122b
RH-Author: Juan Quintela <quintela@redhat.com>
0a122b
Message-id: <1389712071-23303-19-git-send-email-quintela@redhat.com>
0a122b
Patchwork-id: 56673
0a122b
O-Subject: [RHEL7 qemu-kvm PATCH 18/40] memory: split dirty bitmap into three
0a122b
Bugzilla: 997559
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
0a122b
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
0a122b
0a122b
After all the previous patches, spliting the bitmap gets direct.
0a122b
0a122b
Note: For some reason, I have to move DIRTY_MEMORY_* definitions to
0a122b
the beginning of memory.h to make compilation work.
0a122b
0a122b
Signed-off-by: Juan Quintela <quintela@redhat.com>
0a122b
Reviewed-by: Eric Blake <eblake@redhat.com>
0a122b
Reviewed-by: Orit Wasserman <owasserm@redhat.com>
0a122b
(cherry picked from commit 1ab4c8ceaa5ec55af9bb25e88e46d461a8550280)
0a122b
0a122b
Manual compilation fix:
0a122b
0a122b
- For some reason includes get completely wrong, I had to change the
0a122b
  order of memory.h in ioport.c
0a122b
  Upstream has a much saner layout of include dependences
0a122b
0a122b
Signed-off-by: Juan Quintela <quintela@trasno.org>
0a122b
---
0a122b
 exec.c                         |  9 ++++++---
0a122b
 include/exec/cpu-all.h         |  3 ++-
0a122b
 include/exec/memory-internal.h |  9 +++------
0a122b
 include/exec/memory.h          | 10 +++++-----
0a122b
 ioport.c                       |  2 +-
0a122b
 5 files changed, 17 insertions(+), 16 deletions(-)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 exec.c                         |    9 ++++++---
0a122b
 include/exec/cpu-all.h         |    3 ++-
0a122b
 include/exec/memory-internal.h |    9 +++------
0a122b
 include/exec/memory.h          |   10 +++++-----
0a122b
 ioport.c                       |    2 +-
0a122b
 5 files changed, 17 insertions(+), 16 deletions(-)
0a122b
0a122b
diff --git a/exec.c b/exec.c
0a122b
index be99d45..45b2c46 100644
0a122b
--- a/exec.c
0a122b
+++ b/exec.c
0a122b
@@ -1164,9 +1164,12 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
0a122b
     new_ram_size = last_ram_offset() >> TARGET_PAGE_BITS;
0a122b
 
0a122b
     if (new_ram_size > old_ram_size) {
0a122b
-        ram_list.phys_dirty = g_realloc(ram_list.phys_dirty, new_ram_size);
0a122b
-        memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS),
0a122b
-           0, size >> TARGET_PAGE_BITS);
0a122b
+        int i;
0a122b
+        for (i = 0; i < DIRTY_MEMORY_NUM; i++) {
0a122b
+            ram_list.dirty_memory[i] =
0a122b
+                bitmap_zero_extend(ram_list.dirty_memory[i],
0a122b
+                                   old_ram_size, new_ram_size);
0a122b
+       }
0a122b
     }
0a122b
     cpu_physical_memory_set_dirty_range(new_block->offset, size);
0a122b
 
0a122b
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
0a122b
index c369b25..9c85c1c 100644
0a122b
--- a/include/exec/cpu-all.h
0a122b
+++ b/include/exec/cpu-all.h
0a122b
@@ -22,6 +22,7 @@
0a122b
 #include "qemu-common.h"
0a122b
 #include "qemu/tls.h"
0a122b
 #include "exec/cpu-common.h"
0a122b
+#include "exec/memory.h"
0a122b
 #include "qemu/thread.h"
0a122b
 
0a122b
 /* some important defines:
0a122b
@@ -482,7 +483,7 @@ typedef struct RAMBlock {
0a122b
 typedef struct RAMList {
0a122b
     QemuMutex mutex;
0a122b
     /* Protected by the iothread lock.  */
0a122b
-    uint8_t *phys_dirty;
0a122b
+    unsigned long *dirty_memory[DIRTY_MEMORY_NUM];
0a122b
     RAMBlock *mru_block;
0a122b
     /* Protected by the ramlist lock.  */
0a122b
     QTAILQ_HEAD(, RAMBlock) blocks;
0a122b
diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
0a122b
index 2c86add..962b292 100644
0a122b
--- a/include/exec/memory-internal.h
0a122b
+++ b/include/exec/memory-internal.h
0a122b
@@ -53,7 +53,7 @@ static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr,
0a122b
                                                       unsigned client)
0a122b
 {
0a122b
     assert(client < DIRTY_MEMORY_NUM);
0a122b
-    return ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] & (1 << client);
0a122b
+    return test_bit(addr >> TARGET_PAGE_BITS, ram_list.dirty_memory[client]);
0a122b
 }
0a122b
 
0a122b
 /* read dirty bit (return 0 or 1) */
0a122b
@@ -85,7 +85,7 @@ static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr,
0a122b
                                                       unsigned client)
0a122b
 {
0a122b
     assert(client < DIRTY_MEMORY_NUM);
0a122b
-    ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] |= (1 << client);
0a122b
+    set_bit(addr >> TARGET_PAGE_BITS, ram_list.dirty_memory[client]);
0a122b
 }
0a122b
 
0a122b
 static inline void cpu_physical_memory_set_dirty(ram_addr_t addr)
0a122b
@@ -98,11 +98,8 @@ static inline void cpu_physical_memory_set_dirty(ram_addr_t addr)
0a122b
 static inline void cpu_physical_memory_clear_dirty_flag(ram_addr_t addr,
0a122b
                                                        unsigned client)
0a122b
 {
0a122b
-    int mask = ~(1 << client);
0a122b
-
0a122b
     assert(client < DIRTY_MEMORY_NUM);
0a122b
-
0a122b
-    ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] &= mask;
0a122b
+    clear_bit(addr >> TARGET_PAGE_BITS, ram_list.dirty_memory[client]);
0a122b
 }
0a122b
 
0a122b
 static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
0a122b
diff --git a/include/exec/memory.h b/include/exec/memory.h
0a122b
index 0023edf..bd6d31a 100644
0a122b
--- a/include/exec/memory.h
0a122b
+++ b/include/exec/memory.h
0a122b
@@ -16,6 +16,11 @@
0a122b
 
0a122b
 #ifndef CONFIG_USER_ONLY
0a122b
 
0a122b
+#define DIRTY_MEMORY_VGA       0
0a122b
+#define DIRTY_MEMORY_CODE      1
0a122b
+#define DIRTY_MEMORY_MIGRATION 2
0a122b
+#define DIRTY_MEMORY_NUM       3        /* num of dirty bits */
0a122b
+
0a122b
 #include <stdint.h>
0a122b
 #include <stdbool.h>
0a122b
 #include "qemu-common.h"
0a122b
@@ -30,11 +35,6 @@ typedef struct MemoryRegionOps MemoryRegionOps;
0a122b
 typedef struct MemoryRegionPortio MemoryRegionPortio;
0a122b
 typedef struct MemoryRegionMmio MemoryRegionMmio;
0a122b
 
0a122b
-#define DIRTY_MEMORY_VGA       0
0a122b
-#define DIRTY_MEMORY_CODE      1
0a122b
-#define DIRTY_MEMORY_MIGRATION 2
0a122b
-#define DIRTY_MEMORY_NUM       3        /* num of dirty bits */
0a122b
-
0a122b
 struct MemoryRegionMmio {
0a122b
     CPUReadMemoryFunc *read[3];
0a122b
     CPUWriteMemoryFunc *write[3];
0a122b
diff --git a/ioport.c b/ioport.c
0a122b
index a0ac2a0..957e980 100644
0a122b
--- a/ioport.c
0a122b
+++ b/ioport.c
0a122b
@@ -25,8 +25,8 @@
0a122b
  * splitted out ioport related stuffs from vl.c.
0a122b
  */
0a122b
 
0a122b
-#include "exec/ioport.h"
0a122b
 #include "trace.h"
0a122b
+#include "exec/ioport.h"
0a122b
 #include "exec/memory.h"
0a122b
 
0a122b
 /***********************************************************/
0a122b
-- 
0a122b
1.7.1
0a122b