Blame SOURCES/kvm-memory-Open-code-FlatView-rendering.patch

4a2fec
From 8ce98f8422946cc39437a06fcab4498350d4d482 Mon Sep 17 00:00:00 2001
4a2fec
From: David Gibson <dgibson@redhat.com>
4a2fec
Date: Thu, 16 Nov 2017 03:07:15 +0100
4a2fec
Subject: [PATCH 11/30] memory: Open code FlatView rendering
4a2fec
4a2fec
RH-Author: David Gibson <dgibson@redhat.com>
4a2fec
Message-id: <20171116030732.8560-6-dgibson@redhat.com>
4a2fec
Patchwork-id: 77695
4a2fec
O-Subject: [PATCH 05/22] memory: Open code FlatView rendering
4a2fec
Bugzilla: 1481593
4a2fec
RH-Acked-by: Thomas Huth <thuth@redhat.com>
4a2fec
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
4a2fec
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
4a2fec
4a2fec
From: Alexey Kardashevskiy <aik@ozlabs.ru>
4a2fec
4a2fec
We are going to share FlatView's between AddressSpace's and per-AS
4a2fec
memory listeners won't suit the purpose anymore so open code
4a2fec
the dispatch tree rendering.
4a2fec
4a2fec
Since there is a good chance that dispatch_listener was the only
4a2fec
listener, this avoids address_space_update_topology_pass() if there is
4a2fec
no registered listeners; this should improve starting time.
4a2fec
4a2fec
This should cause no behavioural change.
4a2fec
4a2fec
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
4a2fec
Message-Id: <20170921085110.25598-3-aik@ozlabs.ru>
4a2fec
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
(cherry picked from commit 9a62e24f45bc97f8eaf198caf58906b47c50a8d5)
4a2fec
4a2fec
Signed-off-by: David Gibson <dgibson@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 exec.c                         | 27 +++------------------------
4a2fec
 include/exec/memory-internal.h |  6 ++++--
4a2fec
 include/exec/memory.h          |  1 -
4a2fec
 memory.c                       | 19 ++++++++++++++-----
4a2fec
 4 files changed, 21 insertions(+), 32 deletions(-)
4a2fec
4a2fec
diff --git a/exec.c b/exec.c
4a2fec
index f00bd4e..4fed7b7 100644
4a2fec
--- a/exec.c
4a2fec
+++ b/exec.c
4a2fec
@@ -1358,9 +1358,8 @@ static void register_multipage(AddressSpaceDispatch *d,
4a2fec
     phys_page_set(d, start_addr >> TARGET_PAGE_BITS, num_pages, section_index);
4a2fec
 }
4a2fec
 
4a2fec
-static void mem_add(MemoryListener *listener, MemoryRegionSection *section)
4a2fec
+void mem_add(AddressSpace *as, MemoryRegionSection *section)
4a2fec
 {
4a2fec
-    AddressSpace *as = container_of(listener, AddressSpace, dispatch_listener);
4a2fec
     AddressSpaceDispatch *d = as->next_dispatch;
4a2fec
     MemoryRegionSection now = *section, remain = *section;
4a2fec
     Int128 page_size = int128_make64(TARGET_PAGE_SIZE);
4a2fec
@@ -2684,9 +2683,8 @@ static void io_mem_init(void)
4a2fec
                           NULL, UINT64_MAX);
4a2fec
 }
4a2fec
 
4a2fec
-static void mem_begin(MemoryListener *listener)
4a2fec
+void mem_begin(AddressSpace *as)
4a2fec
 {
4a2fec
-    AddressSpace *as = container_of(listener, AddressSpace, dispatch_listener);
4a2fec
     AddressSpaceDispatch *d = g_new0(AddressSpaceDispatch, 1);
4a2fec
     uint16_t n;
4a2fec
 
4a2fec
@@ -2710,9 +2708,8 @@ static void address_space_dispatch_free(AddressSpaceDispatch *d)
4a2fec
     g_free(d);
4a2fec
 }
4a2fec
 
4a2fec
-static void mem_commit(MemoryListener *listener)
4a2fec
+void mem_commit(AddressSpace *as)
4a2fec
 {
4a2fec
-    AddressSpace *as = container_of(listener, AddressSpace, dispatch_listener);
4a2fec
     AddressSpaceDispatch *cur = as->dispatch;
4a2fec
     AddressSpaceDispatch *next = as->next_dispatch;
4a2fec
 
4a2fec
@@ -2742,24 +2739,6 @@ static void tcg_commit(MemoryListener *listener)
4a2fec
     tlb_flush(cpuas->cpu);
4a2fec
 }
4a2fec
 
4a2fec
-void address_space_init_dispatch(AddressSpace *as)
4a2fec
-{
4a2fec
-    as->dispatch = NULL;
4a2fec
-    as->dispatch_listener = (MemoryListener) {
4a2fec
-        .begin = mem_begin,
4a2fec
-        .commit = mem_commit,
4a2fec
-        .region_add = mem_add,
4a2fec
-        .region_nop = mem_add,
4a2fec
-        .priority = 0,
4a2fec
-    };
4a2fec
-    memory_listener_register(&as->dispatch_listener, as);
4a2fec
-}
4a2fec
-
4a2fec
-void address_space_unregister(AddressSpace *as)
4a2fec
-{
4a2fec
-    memory_listener_unregister(&as->dispatch_listener);
4a2fec
-}
4a2fec
-
4a2fec
 void address_space_destroy_dispatch(AddressSpace *as)
4a2fec
 {
4a2fec
     AddressSpaceDispatch *d = as->dispatch;
4a2fec
diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
4a2fec
index fb467ac..9abde2f 100644
4a2fec
--- a/include/exec/memory-internal.h
4a2fec
+++ b/include/exec/memory-internal.h
4a2fec
@@ -22,8 +22,6 @@
4a2fec
 #ifndef CONFIG_USER_ONLY
4a2fec
 typedef struct AddressSpaceDispatch AddressSpaceDispatch;
4a2fec
 
4a2fec
-void address_space_init_dispatch(AddressSpace *as);
4a2fec
-void address_space_unregister(AddressSpace *as);
4a2fec
 void address_space_destroy_dispatch(AddressSpace *as);
4a2fec
 
4a2fec
 extern const MemoryRegionOps unassigned_mem_ops;
4a2fec
@@ -31,5 +29,9 @@ extern const MemoryRegionOps unassigned_mem_ops;
4a2fec
 bool memory_region_access_valid(MemoryRegion *mr, hwaddr addr,
4a2fec
                                 unsigned size, bool is_write);
4a2fec
 
4a2fec
+void mem_add(AddressSpace *as, MemoryRegionSection *section);
4a2fec
+void mem_begin(AddressSpace *as);
4a2fec
+void mem_commit(AddressSpace *as);
4a2fec
+
4a2fec
 #endif
4a2fec
 #endif
4a2fec
diff --git a/include/exec/memory.h b/include/exec/memory.h
4a2fec
index 400dd44..9ee0f2e 100644
4a2fec
--- a/include/exec/memory.h
4a2fec
+++ b/include/exec/memory.h
4a2fec
@@ -328,7 +328,6 @@ struct AddressSpace {
4a2fec
     struct MemoryRegionIoeventfd *ioeventfds;
4a2fec
     struct AddressSpaceDispatch *dispatch;
4a2fec
     struct AddressSpaceDispatch *next_dispatch;
4a2fec
-    MemoryListener dispatch_listener;
4a2fec
     QTAILQ_HEAD(memory_listeners_as, MemoryListener) listeners;
4a2fec
     QTAILQ_ENTRY(AddressSpace) address_spaces_link;
4a2fec
 };
4a2fec
diff --git a/memory.c b/memory.c
4a2fec
index ca160de..8bc1f56 100644
4a2fec
--- a/memory.c
4a2fec
+++ b/memory.c
4a2fec
@@ -883,14 +883,24 @@ static void address_space_update_topology_pass(AddressSpace *as,
4a2fec
     }
4a2fec
 }
4a2fec
 
4a2fec
-
4a2fec
 static void address_space_update_topology(AddressSpace *as)
4a2fec
 {
4a2fec
     FlatView *old_view = address_space_get_flatview(as);
4a2fec
     FlatView *new_view = generate_memory_topology(as->root);
4a2fec
+    int i;
4a2fec
 
4a2fec
-    address_space_update_topology_pass(as, old_view, new_view, false);
4a2fec
-    address_space_update_topology_pass(as, old_view, new_view, true);
4a2fec
+    mem_begin(as);
4a2fec
+    for (i = 0; i < new_view->nr; i++) {
4a2fec
+        MemoryRegionSection mrs =
4a2fec
+            section_from_flat_range(&new_view->ranges[i], as);
4a2fec
+        mem_add(as, &mrs);
4a2fec
+    }
4a2fec
+    mem_commit(as);
4a2fec
+
4a2fec
+    if (!QTAILQ_EMPTY(&as->listeners)) {
4a2fec
+        address_space_update_topology_pass(as, old_view, new_view, false);
4a2fec
+        address_space_update_topology_pass(as, old_view, new_view, true);
4a2fec
+    }
4a2fec
 
4a2fec
     /* Writes are protected by the BQL.  */
4a2fec
     atomic_rcu_set(&as->current_map, new_view);
4a2fec
@@ -2625,7 +2635,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)
4a2fec
     QTAILQ_INIT(&as->listeners);
4a2fec
     QTAILQ_INSERT_TAIL(&address_spaces, as, address_spaces_link);
4a2fec
     as->name = g_strdup(name ? name : "anonymous");
4a2fec
-    address_space_init_dispatch(as);
4a2fec
+    as->dispatch = NULL;
4a2fec
     memory_region_update_pending |= root->enabled;
4a2fec
     memory_region_transaction_commit();
4a2fec
 }
4a2fec
@@ -2676,7 +2686,6 @@ void address_space_destroy(AddressSpace *as)
4a2fec
     as->root = NULL;
4a2fec
     memory_region_transaction_commit();
4a2fec
     QTAILQ_REMOVE(&address_spaces, as, address_spaces_link);
4a2fec
-    address_space_unregister(as);
4a2fec
 
4a2fec
     /* At this point, as->dispatch and as->current_map are dummy
4a2fec
      * entries that the guest should never use.  Wait for the old
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec