cryptospore / rpms / qemu-kvm

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