Patchwork [26/30] memory: introduce memory_region_test_and_clear_dirty

login
register
mail settings
Submitter Juan Quintela
Date Oct. 18, 2012, 7:30 a.m.
Message ID <1350545426-23172-27-git-send-email-quintela@redhat.com>
Download mbox | patch
Permalink /patch/192227/
State New
Headers show

Comments

Juan Quintela - Oct. 18, 2012, 7:30 a.m.
This function avoids having to do two calls, one to test the dirty bit, and
other to reset it.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 memory.c | 15 +++++++++++++++
 memory.h | 17 +++++++++++++++++
 2 files changed, 32 insertions(+)

Patch

diff --git a/memory.c b/memory.c
index 4f3ade0..126fb63 100644
--- a/memory.c
+++ b/memory.c
@@ -1080,6 +1080,21 @@  void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr,
     return cpu_physical_memory_set_dirty_range(mr->ram_addr + addr, size, -1);
 }

+bool memory_region_test_and_clear_dirty(MemoryRegion *mr,
+                                        target_phys_addr_t addr,
+                                        target_phys_addr_t size, unsigned client)
+{
+    bool ret;
+    assert(mr->terminates);
+    ret = cpu_physical_memory_get_dirty(mr->ram_addr + addr, size,
+                                        1 << client);
+    if (ret) {
+        cpu_physical_memory_set_dirty_range(mr->ram_addr + addr, size, -1);
+    }
+    return ret;
+}
+
+
 void memory_region_sync_dirty_bitmap(MemoryRegion *mr)
 {
     FlatRange *fr;
diff --git a/memory.h b/memory.h
index 37ce151..08af012 100644
--- a/memory.h
+++ b/memory.h
@@ -434,6 +434,23 @@  void memory_region_set_dirty(MemoryRegion *mr, target_phys_addr_t addr,
                              target_phys_addr_t size);

 /**
+ * memory_region_test_and_clear_dirty: Check whether a range of bytes is dirty
+ *                                     for a specified client. It clears them.
+ *
+ * Checks whether a range of bytes has been written to since the last
+ * call to memory_region_reset_dirty() with the same @client.  Dirty logging
+ * must be enabled.
+ *
+ * @mr: the memory region being queried.
+ * @addr: the address (relative to the start of the region) being queried.
+ * @size: the size of the range being queried.
+ * @client: the user of the logging information; %DIRTY_MEMORY_MIGRATION or
+ *          %DIRTY_MEMORY_VGA.
+ */
+bool memory_region_test_and_clear_dirty(MemoryRegion *mr,
+                                        target_phys_addr_t addr,
+                                        target_phys_addr_t size, unsigned client)
+/**
  * memory_region_sync_dirty_bitmap: Synchronize a region's dirty bitmap with
  *                                  any external TLBs (e.g. kvm)
  *