From patchwork Sun Dec 4 18:09:39 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 129180 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3E0991007D7 for ; Mon, 5 Dec 2011 05:10:22 +1100 (EST) Received: from localhost ([::1]:58864 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXGW1-0001hg-K5 for incoming@patchwork.ozlabs.org; Sun, 04 Dec 2011 13:10:17 -0500 Received: from eggs.gnu.org ([140.186.70.92]:58253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXGVh-0001Xe-Pv for qemu-devel@nongnu.org; Sun, 04 Dec 2011 13:09:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RXGVf-0004HA-PS for qemu-devel@nongnu.org; Sun, 04 Dec 2011 13:09:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56289) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXGVf-0004Gj-Gh for qemu-devel@nongnu.org; Sun, 04 Dec 2011 13:09:55 -0500 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 pB4I9sRW020498 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 4 Dec 2011 13:09:54 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pB4I9r4i021315 for ; Sun, 4 Dec 2011 13:09:54 -0500 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id C126B250BA1; Sun, 4 Dec 2011 20:09:48 +0200 (IST) From: Avi Kivity To: qemu-devel@nongnu.org Date: Sun, 4 Dec 2011 20:09:39 +0200 Message-Id: <1323022181-28110-5-git-send-email-avi@redhat.com> In-Reply-To: <1323022181-28110-1-git-send-email-avi@redhat.com> References: <1323022181-28110-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 4/6] memory: optimize empty transactions due to mutators 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 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 7e842b3..87639ab 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; @@ -757,6 +758,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; } @@ -770,6 +772,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) @@ -781,7 +785,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)