From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:39067) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSq4r-0003En-Jk for qemu-devel@nongnu.org; Mon, 29 Oct 2012 10:12:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TSq4l-0007Ms-5Y for qemu-devel@nongnu.org; Mon, 29 Oct 2012 10:12:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20231) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSq4k-0007Mf-TQ for qemu-devel@nongnu.org; Mon, 29 Oct 2012 10:12:23 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9TECMCk015110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 29 Oct 2012 10:12:22 -0400 From: Juan Quintela Date: Mon, 29 Oct 2012 15:11:41 +0100 Message-Id: <1351519903-26607-17-git-send-email-quintela@redhat.com> In-Reply-To: <1351519903-26607-1-git-send-email-quintela@redhat.com> References: <1351519903-26607-1-git-send-email-quintela@redhat.com> Subject: [Qemu-devel] [PATCH 16/18] 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 Cc: owasserm@redhat.com, mtosatti@redhat.com, avi@redhat.com, pbonzini@redhat.com 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 | 16 ++++++++++++++++ memory.h | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/memory.c b/memory.c index 36bb9a5..9ddaac9 100644 --- a/memory.c +++ b/memory.c @@ -1078,6 +1078,22 @@ void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr, return cpu_physical_memory_set_dirty_range(mr->ram_addr + addr, size, -1); } +bool memory_region_test_and_clear_dirty(MemoryRegion *mr, hwaddr addr, + hwaddr 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_reset_dirty(mr->ram_addr + addr, + mr->ram_addr + addr + size, + 1 << client); + } + return ret; +} + + void memory_region_sync_dirty_bitmap(MemoryRegion *mr) { AddressSpace *as; diff --git a/memory.h b/memory.h index 9462bfd..99434d8 100644 --- a/memory.h +++ b/memory.h @@ -454,6 +454,24 @@ void memory_region_set_dirty(MemoryRegion *mr, hwaddr addr, hwaddr 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, + hwaddr addr, + hwaddr 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