From patchwork Mon Oct 29 14:11:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 195013 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 047922C008F for ; Tue, 30 Oct 2012 01:33:01 +1100 (EST) Received: from localhost ([::1]:44227 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSq6Y-0006Xm-Kf for incoming@patchwork.ozlabs.org; Mon, 29 Oct 2012 10:14:14 -0400 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 Received: from trasno.mitica (ovpn-113-116.phx2.redhat.com [10.3.113.116]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9TEBikT011647; Mon, 29 Oct 2012 10:12:20 -0400 From: Juan Quintela To: qemu-devel@nongnu.org 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> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: owasserm@redhat.com, mtosatti@redhat.com, avi@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 16/18] memory: introduce memory_region_test_and_clear_dirty X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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 | 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) *