From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54099) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOkZW-0005m4-4R for qemu-devel@nongnu.org; Thu, 18 Oct 2012 03:31:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOkZU-0000iM-Sb for qemu-devel@nongnu.org; Thu, 18 Oct 2012 03:31:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14031) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOkZU-0000hw-KG for qemu-devel@nongnu.org; Thu, 18 Oct 2012 03:31:12 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9I7VCGG021927 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 18 Oct 2012 03:31:12 -0400 From: Juan Quintela Date: Thu, 18 Oct 2012 09:30:22 +0200 Message-Id: <1350545426-23172-27-git-send-email-quintela@redhat.com> In-Reply-To: <1350545426-23172-1-git-send-email-quintela@redhat.com> References: <1350545426-23172-1-git-send-email-quintela@redhat.com> Subject: [Qemu-devel] [PATCH 26/30] memory: introduce memory_region_test_and_clear_dirty List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This function avoids having to do two calls, one to test the dirty bit, and other to reset it. Signed-off-by: Juan Quintela --- memory.c | 15 +++++++++++++++ memory.h | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) 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) * -- 1.7.11.7