Commit 74576198d7831674506a8f2142a5fd853584a9ff

Authored by aliguori
1 parent c6ca28d6

Add dirty tracking for live migration

This patch adds a dirty tracking bit for live migration.  We use 0x08 because
kqemu uses 0x04.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5433 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 33 additions and 4 deletions
cpu-all.h
@@ -904,8 +904,10 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr, @@ -904,8 +904,10 @@ void cpu_physical_memory_write_rom(target_phys_addr_t addr,
904 int cpu_memory_rw_debug(CPUState *env, target_ulong addr, 904 int cpu_memory_rw_debug(CPUState *env, target_ulong addr,
905 uint8_t *buf, int len, int is_write); 905 uint8_t *buf, int len, int is_write);
906 906
907 -#define VGA_DIRTY_FLAG 0x01  
908 -#define CODE_DIRTY_FLAG 0x02 907 +#define VGA_DIRTY_FLAG 0x01
  908 +#define CODE_DIRTY_FLAG 0x02
  909 +#define KQEMU_DIRTY_FLAG 0x04
  910 +#define MIGRATION_DIRTY_FLAG 0x08
909 911
910 /* read dirty bit (return 0 or 1) */ 912 /* read dirty bit (return 0 or 1) */
911 static inline int cpu_physical_memory_is_dirty(ram_addr_t addr) 913 static inline int cpu_physical_memory_is_dirty(ram_addr_t addr)
@@ -928,6 +930,10 @@ void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end, @@ -928,6 +930,10 @@ void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
928 int dirty_flags); 930 int dirty_flags);
929 void cpu_tlb_update_dirty(CPUState *env); 931 void cpu_tlb_update_dirty(CPUState *env);
930 932
  933 +int cpu_physical_memory_set_dirty_tracking(int enable);
  934 +
  935 +int cpu_physical_memory_get_dirty_tracking(void);
  936 +
931 void dump_exec_info(FILE *f, 937 void dump_exec_info(FILE *f,
932 int (*cpu_fprintf)(FILE *f, const char *fmt, ...)); 938 int (*cpu_fprintf)(FILE *f, const char *fmt, ...));
933 939
@@ -38,6 +38,7 @@ @@ -38,6 +38,7 @@
38 #include "qemu-common.h" 38 #include "qemu-common.h"
39 #include "tcg.h" 39 #include "tcg.h"
40 #include "hw/hw.h" 40 #include "hw/hw.h"
  41 +#include "osdep.h"
41 #if defined(CONFIG_USER_ONLY) 42 #if defined(CONFIG_USER_ONLY)
42 #include <qemu.h> 43 #include <qemu.h>
43 #endif 44 #endif
@@ -113,6 +114,7 @@ ram_addr_t phys_ram_size; @@ -113,6 +114,7 @@ ram_addr_t phys_ram_size;
113 int phys_ram_fd; 114 int phys_ram_fd;
114 uint8_t *phys_ram_base; 115 uint8_t *phys_ram_base;
115 uint8_t *phys_ram_dirty; 116 uint8_t *phys_ram_dirty;
  117 +static int in_migration;
116 static ram_addr_t phys_ram_alloc_offset = 0; 118 static ram_addr_t phys_ram_alloc_offset = 0;
117 #endif 119 #endif
118 120
@@ -1809,6 +1811,17 @@ void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end, @@ -1809,6 +1811,17 @@ void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
1809 } 1811 }
1810 } 1812 }
1811 1813
  1814 +int cpu_physical_memory_set_dirty_tracking(int enable)
  1815 +{
  1816 + in_migration = enable;
  1817 + return 0;
  1818 +}
  1819 +
  1820 +int cpu_physical_memory_get_dirty_tracking(void)
  1821 +{
  1822 + return in_migration;
  1823 +}
  1824 +
1812 static inline void tlb_update_dirty(CPUTLBEntry *tlb_entry) 1825 static inline void tlb_update_dirty(CPUTLBEntry *tlb_entry)
1813 { 1826 {
1814 ram_addr_t ram_addr; 1827 ram_addr_t ram_addr;
@@ -2964,9 +2977,19 @@ void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val) @@ -2964,9 +2977,19 @@ void stl_phys_notdirty(target_phys_addr_t addr, uint32_t val)
2964 io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); 2977 io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
2965 io_mem_write[io_index][2](io_mem_opaque[io_index], addr, val); 2978 io_mem_write[io_index][2](io_mem_opaque[io_index], addr, val);
2966 } else { 2979 } else {
2967 - ptr = phys_ram_base + (pd & TARGET_PAGE_MASK) +  
2968 - (addr & ~TARGET_PAGE_MASK); 2980 + unsigned long addr1 = (pd & TARGET_PAGE_MASK) + (addr & ~TARGET_PAGE_MASK);
  2981 + ptr = phys_ram_base + addr1;
2969 stl_p(ptr, val); 2982 stl_p(ptr, val);
  2983 +
  2984 + if (unlikely(in_migration)) {
  2985 + if (!cpu_physical_memory_is_dirty(addr1)) {
  2986 + /* invalidate code */
  2987 + tb_invalidate_phys_page_range(addr1, addr1 + 4, 0);
  2988 + /* set dirty bit */
  2989 + phys_ram_dirty[addr1 >> TARGET_PAGE_BITS] |=
  2990 + (0xff & ~CODE_DIRTY_FLAG);
  2991 + }
  2992 + }
2970 } 2993 }
2971 } 2994 }
2972 2995