[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 14/29] exec: use memory_region_get_dirty_log_mask
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH v3 14/29] exec: use memory_region_get_dirty_log_mask to optimize dirty tracking |
Date: |
Tue, 26 May 2015 18:54:50 +0200 |
The memory API can now return the exact set of bitmaps that have to
be tracked. Use it instead of the in_migration variable.
In the next patches, we will also use it to set only DIRTY_MEMORY_VGA
or DIRTY_MEMORY_MIGRATION if necessary. This can make a difference
for dataplane, especially after the dirty bitmap is changed to use
more expensive atomic operations.
Of some interest is the change to stl_phys_notdirty. When migration
was introduced, stl_phys_notdirty was changed to effectively behave
as stl_phys during migration. In fact, if one looks at the function as it
was in the beginning (commit 8df1cd0, physical memory access functions,
2005-01-28), at the time the dirty bitmap was the equivalent of
DIRTY_MEMORY_CODE nowadays; hence, the function simply should not touch
the dirty code bits. This patch changes it to do the intended thing.
Signed-off-by: Paolo Bonzini <address@hidden>
---
exec.c | 59 +++++++++++++++++++----------------------------------------
1 file changed, 19 insertions(+), 40 deletions(-)
diff --git a/exec.c b/exec.c
index c90dc72..9486347 100644
--- a/exec.c
+++ b/exec.c
@@ -59,8 +59,6 @@
//#define DEBUG_SUBPAGE
#if !defined(CONFIG_USER_ONLY)
-static bool in_migration;
-
/* ram_list is read under rcu_read_lock()/rcu_read_unlock(). Writes
* are protected by the ramlist lock.
*/
@@ -870,11 +868,6 @@ void cpu_physical_memory_reset_dirty(ram_addr_t start,
ram_addr_t length,
}
}
-static void cpu_physical_memory_set_dirty_tracking(bool enable)
-{
- in_migration = enable;
-}
-
/* Called from RCU critical section */
hwaddr memory_region_section_get_iotlb(CPUState *cpu,
MemoryRegionSection *section,
@@ -2165,22 +2158,6 @@ static void tcg_commit(MemoryListener *listener)
}
}
-static void core_log_global_start(MemoryListener *listener)
-{
- cpu_physical_memory_set_dirty_tracking(true);
-}
-
-static void core_log_global_stop(MemoryListener *listener)
-{
- cpu_physical_memory_set_dirty_tracking(false);
-}
-
-static MemoryListener core_memory_listener = {
- .log_global_start = core_log_global_start,
- .log_global_stop = core_log_global_stop,
- .priority = 1,
-};
-
void address_space_init_dispatch(AddressSpace *as)
{
as->dispatch = NULL;
@@ -2220,8 +2197,6 @@ static void memory_map_init(void)
memory_region_init_io(system_io, NULL, &unassigned_io_ops, NULL, "io",
65536);
address_space_init(&address_space_io, system_io, "I/O");
-
- memory_listener_register(&core_memory_listener, &address_space_memory);
}
MemoryRegion *get_system_memory(void)
@@ -2279,12 +2254,18 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong
addr,
#else
-static void invalidate_and_set_dirty(hwaddr addr,
+static void invalidate_and_set_dirty(MemoryRegion *mr, hwaddr addr,
hwaddr length)
{
if (cpu_physical_memory_range_includes_clean(addr, length)) {
- tb_invalidate_phys_range(addr, addr + length, 0);
- cpu_physical_memory_set_dirty_range_nocode(addr, length);
+ uint8_t dirty_log_mask = memory_region_get_dirty_log_mask(mr);
+ if (dirty_log_mask & (1 << DIRTY_MEMORY_CODE)) {
+ tb_invalidate_phys_range(addr, addr + length, 0);
+ dirty_log_mask &= ~(1 << DIRTY_MEMORY_CODE);
+ }
+ if (dirty_log_mask) {
+ cpu_physical_memory_set_dirty_range_nocode(addr, length);
+ }
} else {
xen_modified_memory(addr, length);
}
@@ -2372,7 +2353,7 @@ MemTxResult address_space_rw(AddressSpace *as, hwaddr
addr, MemTxAttrs attrs,
/* RAM case */
ptr = qemu_get_ram_ptr(addr1);
memcpy(ptr, buf, l);
- invalidate_and_set_dirty(addr1, l);
+ invalidate_and_set_dirty(mr, addr1, l);
}
} else {
if (!memory_access_is_direct(mr, is_write)) {
@@ -2469,7 +2450,7 @@ static inline void
cpu_physical_memory_write_rom_internal(AddressSpace *as,
switch (type) {
case WRITE_DATA:
memcpy(ptr, buf, l);
- invalidate_and_set_dirty(addr1, l);
+ invalidate_and_set_dirty(mr, addr1, l);
break;
case FLUSH_CACHE:
flush_icache_range((uintptr_t)ptr, (uintptr_t)ptr + l);
@@ -2694,7 +2675,7 @@ void address_space_unmap(AddressSpace *as, void *buffer,
hwaddr len,
mr = qemu_ram_addr_from_host(buffer, &addr1);
assert(mr != NULL);
if (is_write) {
- invalidate_and_set_dirty(addr1, access_len);
+ invalidate_and_set_dirty(mr, addr1, access_len);
}
if (xen_enabled()) {
xen_invalidate_map_cache_entry(buffer);
@@ -3023,6 +3004,7 @@ void address_space_stl_notdirty(AddressSpace *as, hwaddr
addr, uint32_t val,
hwaddr l = 4;
hwaddr addr1;
MemTxResult r;
+ uint8_t dirty_log_mask;
rcu_read_lock();
mr = address_space_translate(as, addr, &addr1, &l,
@@ -3034,13 +3016,10 @@ void address_space_stl_notdirty(AddressSpace *as,
hwaddr addr, uint32_t val,
ptr = qemu_get_ram_ptr(addr1);
stl_p(ptr, val);
- if (unlikely(in_migration)) {
- if (cpu_physical_memory_is_clean(addr1)) {
- /* invalidate code */
- tb_invalidate_phys_page_range(addr1, addr1 + 4, 0);
- /* set dirty bit */
- cpu_physical_memory_set_dirty_range_nocode(addr1, 4);
- }
+ dirty_log_mask = memory_region_get_dirty_log_mask(mr);
+ dirty_log_mask &= ~(1 << DIRTY_MEMORY_CODE);
+ if (dirty_log_mask) {
+ cpu_physical_memory_set_dirty_range_nocode(addr1, 4);
}
r = MEMTX_OK;
}
@@ -3097,7 +3076,7 @@ static inline void
address_space_stl_internal(AddressSpace *as,
stl_p(ptr, val);
break;
}
- invalidate_and_set_dirty(addr1, 4);
+ invalidate_and_set_dirty(mr, addr1, 4);
r = MEMTX_OK;
}
if (result) {
@@ -3201,7 +3180,7 @@ static inline void
address_space_stw_internal(AddressSpace *as,
stw_p(ptr, val);
break;
}
- invalidate_and_set_dirty(addr1, 2);
+ invalidate_and_set_dirty(mr, addr1, 2);
r = MEMTX_OK;
}
if (result) {
--
1.8.3.1
- [Qemu-devel] [PATCH v3 23/29] bitmap: add atomic set functions, (continued)
- [Qemu-devel] [PATCH v3 23/29] bitmap: add atomic set functions, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 19/29] exec: pass client mask to cpu_physical_memory_set_dirty_range, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 07/29] framebuffer: check memory_region_is_logging, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 11/29] memory: include DIRTY_MEMORY_MIGRATION in the dirty log mask, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 16/29] translate-all: remove unnecessary argument to tb_invalidate_phys_range, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 21/29] exec: only check relevant bitmaps for cleanliness, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 24/29] bitmap: add atomic test and clear, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 14/29] exec: use memory_region_get_dirty_log_mask to optimize dirty tracking,
Paolo Bonzini <=
- [Qemu-devel] [PATCH v3 25/29] memory: use atomic ops for setting dirty memory bits, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 06/29] memory: prepare for multiple bits in the dirty log mask, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 17/29] cputlb: remove useless arguments to tlb_unprotect_code_phys, rename, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 26/29] migration: move dirty bitmap sync to ram_addr.h, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 12/29] kvm: remove special handling of DIRTY_MEMORY_MIGRATION in the dirty log mask, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 08/29] ui/console: remove dpy_gfx_update_dirty, Paolo Bonzini, 2015/05/26
- [Qemu-devel] [PATCH v3 27/29] memory: replace cpu_physical_memory_reset_dirty() with test-and-clear, Paolo Bonzini, 2015/05/26