All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 12/22] exec: use memory_region_is_logging to optimize dirty tracking
Date: Thu, 26 Mar 2015 18:38:30 +0100	[thread overview]
Message-ID: <1427391520-29497-13-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1427391520-29497-1-git-send-email-pbonzini@redhat.com>

memory_region_is_logging now returns the exact set of bitmaps that
have to be tracked.  Use it instead of the in_migration variable.

In the next patch, we will also use it to set only DIRTY_MEMORY_VGA
or DIRTY_MEMORY_MIGRATION if necessary.  As a result, fewer expensive
atomic operations will be required.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 exec.c | 62 ++++++++++++++++++++++----------------------------------------
 1 file changed, 22 insertions(+), 40 deletions(-)

diff --git a/exec.c b/exec.c
index 56fd0f5..ab2468b 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.
  */
@@ -871,11 +869,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,
@@ -2137,22 +2130,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;
@@ -2192,8 +2169,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)
@@ -2251,12 +2226,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);
+        dirty_log_mask = memory_region_is_logging(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);
     }
@@ -2339,7 +2320,7 @@ bool address_space_rw(AddressSpace *as, hwaddr addr, uint8_t *buf,
                 /* 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)) {
@@ -2428,7 +2409,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);
@@ -2644,7 +2625,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);
@@ -2868,6 +2849,7 @@ void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val)
     MemoryRegion *mr;
     hwaddr l = 4;
     hwaddr addr1;
+    uint8_t dirty_log_mask;
 
     mr = address_space_translate(as, addr, &addr1, &l,
                                  true);
@@ -2878,13 +2860,13 @@ void stl_phys_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_is_logging(mr);
+        if (dirty_log_mask & (1 << DIRTY_MEMORY_CODE)) {
+            tb_invalidate_phys_page_range(addr1, addr1 + 4, 0);
+            dirty_log_mask &= ~(1 << DIRTY_MEMORY_CODE);
+        }
+        if (dirty_log_mask) {
+            cpu_physical_memory_set_dirty_range_nocode(addr1, 4);
         }
     }
 }
@@ -2927,7 +2909,7 @@ static inline void stl_phys_internal(AddressSpace *as,
             stl_p(ptr, val);
             break;
         }
-        invalidate_and_set_dirty(addr1, 4);
+        invalidate_and_set_dirty(mr, addr1, 4);
     }
 }
 
@@ -2990,7 +2972,7 @@ static inline void stw_phys_internal(AddressSpace *as,
             stw_p(ptr, val);
             break;
         }
-        invalidate_and_set_dirty(addr1, 2);
+        invalidate_and_set_dirty(mr, addr1, 2);
     }
 }
 
-- 
2.3.3

  parent reply	other threads:[~2015-03-26 17:39 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-26 17:38 [Qemu-devel] [PATCH 00/22] Dirty bitmap atomic access and optimizations Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 01/22] memory: add memory_region_ram_resize Paolo Bonzini
2015-03-28 18:58   ` Michael S. Tsirkin
2015-03-29  7:30     ` Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 02/22] acpi-build: remove dependency from ram_addr.h Paolo Bonzini
2015-03-28 18:58   ` Michael S. Tsirkin
2015-03-26 17:38 ` [Qemu-devel] [PATCH 03/22] memory: the only dirty memory flag for users is DIRTY_MEMORY_VGA Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 04/22] display: enable DIRTY_MEMORY_VGA tracking explicitly Paolo Bonzini
2015-04-20 13:11   ` Stefan Hajnoczi
2015-04-20 13:54     ` Paolo Bonzini
2015-04-22  9:12       ` Stefan Hajnoczi
2015-03-26 17:38 ` [Qemu-devel] [PATCH 05/22] memory: return bitmap from memory_region_is_logging Paolo Bonzini
2015-03-27  5:44   ` Fam Zheng
2015-03-27  6:01     ` Paolo Bonzini
2015-03-28 18:54   ` Michael S. Tsirkin
2015-03-29  7:33     ` Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 06/22] framebuffer: check memory_region_is_logging Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 07/22] ui/console: " Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 08/22] memory: track DIRTY_MEMORY_CODE in mr->dirty_log_mask Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 09/22] memory: return DIRTY_MEMORY_MIGRATION from memory_region_is_logging Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 10/22] ram_addr: tweaks to xen_modified_memory Paolo Bonzini
2015-03-28 19:04   ` Stefano Stabellini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 11/22] exec: simplify notdirty_mem_write Paolo Bonzini
2015-03-26 17:38 ` Paolo Bonzini [this message]
2015-03-26 17:38 ` [Qemu-devel] [PATCH 13/22] exec: pass client mask to cpu_physical_memory_set_dirty_range Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 14/22] exec: only check relevant bitmaps for cleanliness Paolo Bonzini
2015-03-27  6:10   ` Fam Zheng
2015-03-27  9:19     ` Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 15/22] memory: do not touch code dirty bitmap unless TCG is enabled Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 16/22] bitmap: add atomic set functions Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 17/22] bitmap: add atomic test and clear Paolo Bonzini
2015-03-27  6:37   ` Fam Zheng
2015-03-27  9:21     ` Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 18/22] memory: use atomic ops for setting dirty memory bits Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 19/22] migration: move dirty bitmap sync to ram_addr.h Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 20/22] memory: replace cpu_physical_memory_reset_dirty() with test-and-clear Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 21/22] memory: make cpu_physical_memory_sync_dirty_bitmap() fully atomic Paolo Bonzini
2015-03-26 17:38 ` [Qemu-devel] [PATCH 22/22] migration: run bitmap sync outside iothread lock Paolo Bonzini
2015-04-20 13:23 ` [Qemu-devel] [PATCH 00/22] Dirty bitmap atomic access and optimizations Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1427391520-29497-13-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.