qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH RFC 1/2] Change phys_ram_dirty to phys_ram_status
@ 2010-05-24  3:59 Cam Macdonell
  2010-05-24  3:59 ` [Qemu-devel] [PATCH RFC 2/2] Add support for marking memory to not be migrated Cam Macdonell
  0 siblings, 1 reply; 2+ messages in thread
From: Cam Macdonell @ 2010-05-24  3:59 UTC (permalink / raw)
  To: kvm; +Cc: Cam Macdonell, qemu-devel

The phys_ram_dirty array consists of 8-bit values for storing 3 dirty bits.
Change to more generic phys_ram_flags and use lower 4-bits for dirty status and
leave upper 4 for other uses of marking memory pages.

One potential use for upper bits is to mark certain device pages to not be
migrated.

Some functions such as cpu_physical_memory_get_dirty_flags() may need to be
renamed to cpu_physical_memory_get_flags().  But I wanted to solicite feedback
before making more widespread changes.

Cam

---
 cpu-all.h |   16 +++++++++-------
 exec.c    |   36 ++++++++++++++++++------------------
 2 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/cpu-all.h b/cpu-all.h
index 52a1817..a4bb4fb 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -856,7 +856,7 @@ target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr);
 /* memory API */
 
 extern int phys_ram_fd;
-extern uint8_t *phys_ram_dirty;
+extern uint8_t *phys_ram_flags;
 extern ram_addr_t ram_size;
 extern ram_addr_t last_ram_offset;
 
@@ -885,32 +885,34 @@ extern int mem_prealloc;
 #define CODE_DIRTY_FLAG      0x02
 #define MIGRATION_DIRTY_FLAG 0x08
 
+#define DIRTY_ALL_FLAG  (VGA_DIRTY_FLAG | CODE_DIRTY_FLAG | MIGRATION_DIRTY_FLAG)
+
 /* read dirty bit (return 0 or 1) */
 static inline int cpu_physical_memory_is_dirty(ram_addr_t addr)
 {
-    return phys_ram_dirty[addr >> TARGET_PAGE_BITS] == 0xff;
+    return phys_ram_flags[addr >> TARGET_PAGE_BITS] == DIRTY_ALL_FLAG;
 }
 
 static inline int cpu_physical_memory_get_dirty_flags(ram_addr_t addr)
 {
-    return phys_ram_dirty[addr >> TARGET_PAGE_BITS];
+    return phys_ram_flags[addr >> TARGET_PAGE_BITS];
 }
 
 static inline int cpu_physical_memory_get_dirty(ram_addr_t addr,
                                                 int dirty_flags)
 {
-    return phys_ram_dirty[addr >> TARGET_PAGE_BITS] & dirty_flags;
+    return phys_ram_flags[addr >> TARGET_PAGE_BITS] & dirty_flags;
 }
 
 static inline void cpu_physical_memory_set_dirty(ram_addr_t addr)
 {
-    phys_ram_dirty[addr >> TARGET_PAGE_BITS] = 0xff;
+    phys_ram_flags[addr >> TARGET_PAGE_BITS] = DIRTY_ALL_FLAG;
 }
 
 static inline int cpu_physical_memory_set_dirty_flags(ram_addr_t addr,
                                                       int dirty_flags)
 {
-    return phys_ram_dirty[addr >> TARGET_PAGE_BITS] |= dirty_flags;
+    return phys_ram_flags[addr >> TARGET_PAGE_BITS] |= dirty_flags;
 }
 
 static inline void cpu_physical_memory_mask_dirty_range(ram_addr_t start,
@@ -922,7 +924,7 @@ static inline void cpu_physical_memory_mask_dirty_range(ram_addr_t start,
 
     len = length >> TARGET_PAGE_BITS;
     mask = ~dirty_flags;
-    p = phys_ram_dirty + (start >> TARGET_PAGE_BITS);
+    p = phys_ram_flags + (start >> TARGET_PAGE_BITS);
     for (i = 0; i < len; i++) {
         p[i] &= mask;
     }
diff --git a/exec.c b/exec.c
index a72d681..07dc8b6 100644
--- a/exec.c
+++ b/exec.c
@@ -116,7 +116,7 @@ uint8_t *code_gen_ptr;
 
 #if !defined(CONFIG_USER_ONLY)
 int phys_ram_fd;
-uint8_t *phys_ram_dirty;
+uint8_t *phys_ram_flags;
 static int in_migration;
 
 typedef struct RAMBlock {
@@ -2796,10 +2796,10 @@ ram_addr_t qemu_ram_map(ram_addr_t size, void *host)
     new_block->next = ram_blocks;
     ram_blocks = new_block;
 
-    phys_ram_dirty = qemu_realloc(phys_ram_dirty,
+    phys_ram_flags = qemu_realloc(phys_ram_flags,
         (last_ram_offset + size) >> TARGET_PAGE_BITS);
-    memset(phys_ram_dirty + (last_ram_offset >> TARGET_PAGE_BITS),
-           0xff, size >> TARGET_PAGE_BITS);
+    memset(phys_ram_flags + (last_ram_offset >> TARGET_PAGE_BITS),
+           DIRTY_ALL_FLAG, size >> TARGET_PAGE_BITS);
 
     last_ram_offset += size;
 
@@ -2848,10 +2848,10 @@ 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,
+    phys_ram_flags = qemu_realloc(phys_ram_flags,
         (last_ram_offset + size) >> TARGET_PAGE_BITS);
-    memset(phys_ram_dirty + (last_ram_offset >> TARGET_PAGE_BITS),
-           0xff, size >> TARGET_PAGE_BITS);
+    memset(phys_ram_flags + (last_ram_offset >> TARGET_PAGE_BITS),
+           DIRTY_ALL_FLAG, size >> TARGET_PAGE_BITS);
 
     last_ram_offset += size;
 
@@ -3019,11 +3019,11 @@ static void notdirty_mem_writeb(void *opaque, target_phys_addr_t ram_addr,
 #endif
     }
     stb_p(qemu_get_ram_ptr(ram_addr), val);
-    dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
+    dirty_flags |= (DIRTY_ALL_FLAG & ~CODE_DIRTY_FLAG);
     cpu_physical_memory_set_dirty_flags(ram_addr, dirty_flags);
     /* we remove the notdirty callback only if the code has been
        flushed */
-    if (dirty_flags == 0xff)
+    if (dirty_flags == DIRTY_ALL_FLAG)
         tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
 }
 
@@ -3039,11 +3039,11 @@ static void notdirty_mem_writew(void *opaque, target_phys_addr_t ram_addr,
 #endif
     }
     stw_p(qemu_get_ram_ptr(ram_addr), val);
-    dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
+    dirty_flags |= (DIRTY_ALL_FLAG & ~CODE_DIRTY_FLAG);
     cpu_physical_memory_set_dirty_flags(ram_addr, dirty_flags);
     /* we remove the notdirty callback only if the code has been
        flushed */
-    if (dirty_flags == 0xff)
+    if (dirty_flags == DIRTY_ALL_FLAG)
         tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
 }
 
@@ -3059,11 +3059,11 @@ static void notdirty_mem_writel(void *opaque, target_phys_addr_t ram_addr,
 #endif
     }
     stl_p(qemu_get_ram_ptr(ram_addr), val);
-    dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
+    dirty_flags |= (DIRTY_ALL_FLAG & ~CODE_DIRTY_FLAG);
     cpu_physical_memory_set_dirty_flags(ram_addr, dirty_flags);
     /* we remove the notdirty callback only if the code has been
        flushed */
-    if (dirty_flags == 0xff)
+    if (dirty_flags == DIRTY_ALL_FLAG)
         tlb_set_dirty(cpu_single_env, cpu_single_env->mem_io_vaddr);
 }
 
@@ -3480,7 +3480,7 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
                     tb_invalidate_phys_page_range(addr1, addr1 + l, 0);
                     /* set dirty bit */
                     cpu_physical_memory_set_dirty_flags(
-                        addr1, (0xff & ~CODE_DIRTY_FLAG));
+                        addr1, (DIRTY_ALL_FLAG & ~CODE_DIRTY_FLAG));
                 }
 		/* qemu doesn't execute guest code directly, but kvm does
 		   therefore flush instruction caches */
@@ -3694,7 +3694,7 @@ void cpu_physical_memory_unmap(void *buffer, target_phys_addr_t len,
                     tb_invalidate_phys_page_range(addr1, addr1 + l, 0);
                     /* set dirty bit */
                     cpu_physical_memory_set_dirty_flags(
-                        addr1, (0xff & ~CODE_DIRTY_FLAG));
+                        addr1, (DIRTY_ALL_FLAG & ~CODE_DIRTY_FLAG));
                 }
                 addr1 += l;
                 access_len -= l;
@@ -3855,7 +3855,7 @@ void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val)
                 tb_invalidate_phys_page_range(addr1, addr1 + 4, 0);
                 /* set dirty bit */
                 cpu_physical_memory_set_dirty_flags(
-                    addr1, (0xff & ~CODE_DIRTY_FLAG));
+                    addr1, (DIRTY_ALL_FLAG & ~CODE_DIRTY_FLAG));
             }
         }
     }
@@ -3924,7 +3924,7 @@ void stl_phys(target_phys_addr_t addr, uint32_t val)
             tb_invalidate_phys_page_range(addr1, addr1 + 4, 0);
             /* set dirty bit */
             cpu_physical_memory_set_dirty_flags(addr1,
-                (0xff & ~CODE_DIRTY_FLAG));
+                (DIRTY_ALL_FLAG & ~CODE_DIRTY_FLAG));
         }
     }
 }
@@ -3967,7 +3967,7 @@ void stw_phys(target_phys_addr_t addr, uint32_t val)
             tb_invalidate_phys_page_range(addr1, addr1 + 2, 0);
             /* set dirty bit */
             cpu_physical_memory_set_dirty_flags(addr1,
-                (0xff & ~CODE_DIRTY_FLAG));
+                (DIRTY_ALL_FLAG & ~CODE_DIRTY_FLAG));
         }
     }
 }
-- 
1.6.3.2.198.g6096d

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Qemu-devel] [PATCH RFC 2/2] Add support for marking memory to not be migrated
  2010-05-24  3:59 [Qemu-devel] [PATCH RFC 1/2] Change phys_ram_dirty to phys_ram_status Cam Macdonell
@ 2010-05-24  3:59 ` Cam Macdonell
  0 siblings, 0 replies; 2+ messages in thread
From: Cam Macdonell @ 2010-05-24  3:59 UTC (permalink / raw)
  To: kvm; +Cc: Cam Macdonell, qemu-devel

Non-migrated memory is useful for devices that do not want to take memory
region data with them on migration.

As suggested by Avi, an alternative approach could add a "flags" parameter to
cpu_register_physical_memory() rather than explicityly call
cpu_mark_pages_no_migrate().  However, having a separate function doesn't
require changes to existing call sites.

Cam

---
 arch_init.c  |   29 +++++++++++++++++------------
 cpu-all.h    |    2 ++
 cpu-common.h |    2 ++
 exec.c       |   12 ++++++++++++
 4 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index cfc03ea..c2fcad3 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -118,18 +118,22 @@ static int ram_save_block(QEMUFile *f)
                                             current_addr + TARGET_PAGE_SIZE,
                                             MIGRATION_DIRTY_FLAG);
 
-            p = qemu_get_ram_ptr(current_addr);
-
-            if (is_dup_page(p, *p)) {
-                qemu_put_be64(f, current_addr | RAM_SAVE_FLAG_COMPRESS);
-                qemu_put_byte(f, *p);
-            } else {
-                qemu_put_be64(f, current_addr | RAM_SAVE_FLAG_PAGE);
-                qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
-            }
+            if (!cpu_physical_memory_get_dirty(current_addr,
+                                                    NO_MIGRATION_FLAG)) {
+                p = qemu_get_ram_ptr(current_addr);
+                printf("migrating: %ld\n", (long)current_addr);
+
+                if (is_dup_page(p, *p)) {
+                    qemu_put_be64(f, current_addr | RAM_SAVE_FLAG_COMPRESS);
+                    qemu_put_byte(f, *p);
+                } else {
+                    qemu_put_be64(f, current_addr | RAM_SAVE_FLAG_PAGE);
+                    qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
+                }
 
-            found = 1;
-            break;
+                found = 1;
+                break;
+            }
         }
         addr += TARGET_PAGE_SIZE;
         current_addr = (saved_addr + addr) % last_ram_offset;
@@ -146,7 +150,8 @@ static ram_addr_t ram_save_remaining(void)
     ram_addr_t count = 0;
 
     for (addr = 0; addr < last_ram_offset; addr += TARGET_PAGE_SIZE) {
-        if (cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG)) {
+        if (!cpu_physical_memory_get_dirty(addr, NO_MIGRATION_FLAG) &&
+                cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG)) {
             count++;
         }
     }
diff --git a/cpu-all.h b/cpu-all.h
index a4bb4fb..8e2e8c4 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -885,6 +885,8 @@ extern int mem_prealloc;
 #define CODE_DIRTY_FLAG      0x02
 #define MIGRATION_DIRTY_FLAG 0x08
 
+#define NO_MIGRATION_FLAG 0x10
+
 #define DIRTY_ALL_FLAG  (VGA_DIRTY_FLAG | CODE_DIRTY_FLAG | MIGRATION_DIRTY_FLAG)
 
 /* read dirty bit (return 0 or 1) */
diff --git a/cpu-common.h b/cpu-common.h
index 4b0ba60..a1ebbbe 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -39,6 +39,8 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr,
     cpu_register_physical_memory_offset(start_addr, size, phys_offset, 0);
 }
 
+void cpu_mark_pages_no_migrate(ram_addr_t start, uint64_t size);
+
 ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr);
 ram_addr_t qemu_ram_map(ram_addr_t size, void *host);
 ram_addr_t qemu_ram_alloc(ram_addr_t);
diff --git a/exec.c b/exec.c
index 07dc8b6..8c8053f 100644
--- a/exec.c
+++ b/exec.c
@@ -2781,6 +2781,18 @@ static void *file_ram_alloc(ram_addr_t memory, const char *path)
 }
 #endif
 
+void cpu_mark_pages_no_migrate(ram_addr_t start, uint64_t length)
+{
+    int i, len;
+    uint8_t *p;
+
+    len = length >> TARGET_PAGE_BITS;
+    p = phys_ram_flags + (start >> TARGET_PAGE_BITS);
+    for (i = 0; i < len; i++) {
+        p[i] |= NO_MIGRATION_FLAG;
+    }
+}
+
 ram_addr_t qemu_ram_map(ram_addr_t size, void *host)
 {
     RAMBlock *new_block;
-- 
1.6.3.2.198.g6096d

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-05-24  4:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-24  3:59 [Qemu-devel] [PATCH RFC 1/2] Change phys_ram_dirty to phys_ram_status Cam Macdonell
2010-05-24  3:59 ` [Qemu-devel] [PATCH RFC 2/2] Add support for marking memory to not be migrated Cam Macdonell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).