Received: from eggs.gnu.org ([2001:4830:134:3::10]:45437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UulGj-0002rF-1F for qemu-devel@nongnu.org; Thu, 04 Jul 2013 11:16:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UulGh-0005zP-9v for qemu-devel@nongnu.org; Thu, 04 Jul 2013 11:16:24 -0400 Received: from mail-wi0-x22a.google.com ([2a00:1450:400c:c05::22a]:46776) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UulGh-0005z7-0g for qemu-devel@nongnu.org; Thu, 04 Jul 2013 11:16:23 -0400 Received: by mail-wi0-f170.google.com with SMTP id ey16so7444412wid.3 for ; Thu, 04 Jul 2013 08:16:22 -0700 (PDT) Received: from playground.station (net-37-117-148-210.cust.dsl.vodafone.it. [37.117.148.210]) by mx.google.com with ESMTPSA id d8sm4212546wiz.0.2013.07.04.08.16.20 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 04 Jul 2013 08:16:21 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 4 Jul 2013 17:13:51 +0200 Message-Id: <1372950842-32422-56-git-send-email-pbonzini@redhat.com> In-Reply-To: <1372950842-32422-1-git-send-email-pbonzini@redhat.com> References: <1372950842-32422-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 55/66] memory: access FlatView from a local variable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org We will soon require accesses to as->current_map to be placed under a lock (with reference counting so as to keep the critical section small). To simplify this change, always fetch as->current_map into a local variable and access it through that variable. Reviewed-by: Anthony Liguori Signed-off-by: Paolo Bonzini --- memory.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/memory.c b/memory.c index 543e0cc..4449462 100644 --- a/memory.c +++ b/memory.c @@ -578,13 +578,15 @@ static void address_space_add_del_ioeventfds(AddressSpace *as, static void address_space_update_ioeventfds(AddressSpace *as) { + FlatView *view; FlatRange *fr; unsigned ioeventfd_nb = 0; MemoryRegionIoeventfd *ioeventfds = NULL; AddrRange tmp; unsigned i; - FOR_EACH_FLAT_RANGE(fr, as->current_map) { + view = as->current_map; + FOR_EACH_FLAT_RANGE(fr, view) { for (i = 0; i < fr->mr->ioeventfd_nb; ++i) { tmp = addrrange_shift(fr->mr->ioeventfds[i].addr, int128_sub(fr->addr.start, @@ -1144,7 +1146,8 @@ void memory_region_sync_dirty_bitmap(MemoryRegion *mr) FlatRange *fr; QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { - FOR_EACH_FLAT_RANGE(fr, as->current_map) { + FlatView *view = as->current_map; + FOR_EACH_FLAT_RANGE(fr, view) { if (fr->mr == mr) { MEMORY_LISTENER_UPDATE_REGION(fr, as, Forward, log_sync); } @@ -1194,12 +1197,14 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr) static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpace *as) { + FlatView *view; FlatRange *fr; CoalescedMemoryRange *cmr; AddrRange tmp; MemoryRegionSection section; - FOR_EACH_FLAT_RANGE(fr, as->current_map) { + view = as->current_map; + FOR_EACH_FLAT_RANGE(fr, view) { if (fr->mr == mr) { section = (MemoryRegionSection) { .address_space = as, @@ -1490,9 +1495,9 @@ static int cmp_flatrange_addr(const void *addr_, const void *fr_) return 0; } -static FlatRange *address_space_lookup(AddressSpace *as, AddrRange addr) +static FlatRange *flatview_lookup(FlatView *view, AddrRange addr) { - return bsearch(&addr, as->current_map->ranges, as->current_map->nr, + return bsearch(&addr, view->ranges, view->nr, sizeof(FlatRange), cmp_flatrange_addr); } @@ -1513,6 +1518,7 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr, MemoryRegion *root; AddressSpace *as; AddrRange range; + FlatView *view; FlatRange *fr; addr += mr->addr; @@ -1523,13 +1529,14 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr, as = memory_region_to_address_space(root); range = addrrange_make(int128_make64(addr), int128_make64(size)); - fr = address_space_lookup(as, range); + + view = as->current_map; + fr = flatview_lookup(view, range); if (!fr) { return ret; } - while (fr > as->current_map->ranges - && addrrange_intersects(fr[-1].addr, range)) { + while (fr > view->ranges && addrrange_intersects(fr[-1].addr, range)) { --fr; } @@ -1549,9 +1556,11 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr, void address_space_sync_dirty_bitmap(AddressSpace *as) { + FlatView *view; FlatRange *fr; - FOR_EACH_FLAT_RANGE(fr, as->current_map) { + view = as->current_map; + FOR_EACH_FLAT_RANGE(fr, view) { MEMORY_LISTENER_UPDATE_REGION(fr, as, Forward, log_sync); } } @@ -1571,6 +1580,7 @@ void memory_global_dirty_log_stop(void) static void listener_add_address_space(MemoryListener *listener, AddressSpace *as) { + FlatView *view; FlatRange *fr; if (listener->address_space_filter @@ -1584,7 +1594,8 @@ static void listener_add_address_space(MemoryListener *listener, } } - FOR_EACH_FLAT_RANGE(fr, as->current_map) { + view = as->current_map; + FOR_EACH_FLAT_RANGE(fr, view) { MemoryRegionSection section = { .mr = fr->mr, .address_space = as, -- 1.8.1.4