Received: from eggs.gnu.org ([140.186.70.92]:54881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3lh7-00025p-0m for qemu-devel@nongnu.org; Wed, 14 Sep 2011 05:23:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R3lh5-0000eZ-Rs for qemu-devel@nongnu.org; Wed, 14 Sep 2011 05:23:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33821) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3lh5-0000eE-Ix for qemu-devel@nongnu.org; Wed, 14 Sep 2011 05:23:47 -0400 From: Avi Kivity Date: Wed, 14 Sep 2011 12:23:42 +0300 Message-Id: <1315992222-24069-4-git-send-email-avi@redhat.com> In-Reply-To: <1315992222-24069-1-git-send-email-avi@redhat.com> References: <1315992222-24069-1-git-send-email-avi@redhat.com> Subject: [Qemu-devel] [PATCH 3/3] memory: optimize empty transactions due to mutators List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Anthony Liguori , Peter Maydell The mutating memory APIs can easily cause empty transactions, where the mutators don't actually change anything, or perhaps only modify disabled regions. Detect these conditions and avoid regenerating the memory topology. Signed-off-by: Avi Kivity --- memory.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/memory.c b/memory.c index 3b0cc25..1370fac 100644 --- a/memory.c +++ b/memory.c @@ -19,6 +19,7 @@ #include unsigned memory_region_transaction_depth = 0; +static bool memory_region_update_pending = false; typedef struct AddrRange AddrRange; @@ -717,6 +718,7 @@ static void address_space_update_topology(AddressSpace *as) static void memory_region_update_topology(MemoryRegion *mr) { if (memory_region_transaction_depth) { + memory_region_update_pending |= !mr || mr->enabled; return; } @@ -730,6 +732,8 @@ static void memory_region_update_topology(MemoryRegion *mr) if (address_space_io.root) { address_space_update_topology(&address_space_io); } + + memory_region_update_pending = false; } void memory_region_transaction_begin(void) @@ -741,7 +745,9 @@ void memory_region_transaction_commit(void) { assert(memory_region_transaction_depth); --memory_region_transaction_depth; - memory_region_update_topology(NULL); + if (!memory_region_transaction_depth && memory_region_update_pending) { + memory_region_update_topology(NULL); + } } static void memory_region_destructor_none(MemoryRegion *mr) -- 1.7.6.3