Commit 99e86347 authored by Paolo Bonzini's avatar Paolo Bonzini

memory: access FlatView from a local variable

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: default avatarAnthony Liguori <aliguori@us.ibm.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 5444e768
...@@ -578,13 +578,15 @@ static void address_space_add_del_ioeventfds(AddressSpace *as, ...@@ -578,13 +578,15 @@ static void address_space_add_del_ioeventfds(AddressSpace *as,
static void address_space_update_ioeventfds(AddressSpace *as) static void address_space_update_ioeventfds(AddressSpace *as)
{ {
FlatView *view;
FlatRange *fr; FlatRange *fr;
unsigned ioeventfd_nb = 0; unsigned ioeventfd_nb = 0;
MemoryRegionIoeventfd *ioeventfds = NULL; MemoryRegionIoeventfd *ioeventfds = NULL;
AddrRange tmp; AddrRange tmp;
unsigned i; 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) { for (i = 0; i < fr->mr->ioeventfd_nb; ++i) {
tmp = addrrange_shift(fr->mr->ioeventfds[i].addr, tmp = addrrange_shift(fr->mr->ioeventfds[i].addr,
int128_sub(fr->addr.start, int128_sub(fr->addr.start,
...@@ -1144,7 +1146,8 @@ void memory_region_sync_dirty_bitmap(MemoryRegion *mr) ...@@ -1144,7 +1146,8 @@ void memory_region_sync_dirty_bitmap(MemoryRegion *mr)
FlatRange *fr; FlatRange *fr;
QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { 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) { if (fr->mr == mr) {
MEMORY_LISTENER_UPDATE_REGION(fr, as, Forward, log_sync); MEMORY_LISTENER_UPDATE_REGION(fr, as, Forward, log_sync);
} }
...@@ -1194,12 +1197,14 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr) ...@@ -1194,12 +1197,14 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr)
static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpace *as) static void memory_region_update_coalesced_range_as(MemoryRegion *mr, AddressSpace *as)
{ {
FlatView *view;
FlatRange *fr; FlatRange *fr;
CoalescedMemoryRange *cmr; CoalescedMemoryRange *cmr;
AddrRange tmp; AddrRange tmp;
MemoryRegionSection section; MemoryRegionSection section;
FOR_EACH_FLAT_RANGE(fr, as->current_map) { view = as->current_map;
FOR_EACH_FLAT_RANGE(fr, view) {
if (fr->mr == mr) { if (fr->mr == mr) {
section = (MemoryRegionSection) { section = (MemoryRegionSection) {
.address_space = as, .address_space = as,
...@@ -1490,9 +1495,9 @@ static int cmp_flatrange_addr(const void *addr_, const void *fr_) ...@@ -1490,9 +1495,9 @@ static int cmp_flatrange_addr(const void *addr_, const void *fr_)
return 0; 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); sizeof(FlatRange), cmp_flatrange_addr);
} }
...@@ -1513,6 +1518,7 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr, ...@@ -1513,6 +1518,7 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr,
MemoryRegion *root; MemoryRegion *root;
AddressSpace *as; AddressSpace *as;
AddrRange range; AddrRange range;
FlatView *view;
FlatRange *fr; FlatRange *fr;
addr += mr->addr; addr += mr->addr;
...@@ -1523,13 +1529,14 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr, ...@@ -1523,13 +1529,14 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr,
as = memory_region_to_address_space(root); as = memory_region_to_address_space(root);
range = addrrange_make(int128_make64(addr), int128_make64(size)); 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) { if (!fr) {
return ret; return ret;
} }
while (fr > as->current_map->ranges while (fr > view->ranges && addrrange_intersects(fr[-1].addr, range)) {
&& addrrange_intersects(fr[-1].addr, range)) {
--fr; --fr;
} }
...@@ -1549,9 +1556,11 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr, ...@@ -1549,9 +1556,11 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr,
void address_space_sync_dirty_bitmap(AddressSpace *as) void address_space_sync_dirty_bitmap(AddressSpace *as)
{ {
FlatView *view;
FlatRange *fr; 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); MEMORY_LISTENER_UPDATE_REGION(fr, as, Forward, log_sync);
} }
} }
...@@ -1571,6 +1580,7 @@ void memory_global_dirty_log_stop(void) ...@@ -1571,6 +1580,7 @@ void memory_global_dirty_log_stop(void)
static void listener_add_address_space(MemoryListener *listener, static void listener_add_address_space(MemoryListener *listener,
AddressSpace *as) AddressSpace *as)
{ {
FlatView *view;
FlatRange *fr; FlatRange *fr;
if (listener->address_space_filter if (listener->address_space_filter
...@@ -1584,7 +1594,8 @@ static void listener_add_address_space(MemoryListener *listener, ...@@ -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 = { MemoryRegionSection section = {
.mr = fr->mr, .mr = fr->mr,
.address_space = as, .address_space = as,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment