qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

memory: inline some performance-sensitive accessors

These accessors are called from inlined functions, and the call sequence
is much more expensive than just inlining the access. Move the
struct declaration to memory-internal.h so that exec.c and memory.c
can both use an inline function.

Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

+30 -35
+9 -4
include/exec/memory-internal.h
··· 21 21 #define MEMORY_INTERNAL_H 22 22 23 23 #ifndef CONFIG_USER_ONLY 24 - typedef struct AddressSpaceDispatch AddressSpaceDispatch; 24 + static inline AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv) 25 + { 26 + return fv->dispatch; 27 + } 28 + 29 + static inline AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as) 30 + { 31 + return flatview_to_dispatch(address_space_to_flatview(as)); 32 + } 25 33 26 34 extern const MemoryRegionOps unassigned_mem_ops; 27 35 ··· 31 39 void flatview_add_to_dispatch(FlatView *fv, MemoryRegionSection *section); 32 40 AddressSpaceDispatch *address_space_dispatch_new(FlatView *fv); 33 41 void address_space_dispatch_compact(AddressSpaceDispatch *d); 34 - 35 - AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as); 36 - AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv); 37 42 void address_space_dispatch_free(AddressSpaceDispatch *d); 38 43 39 44 void mtree_print_dispatch(fprintf_function mon, void *f,
+21 -1
include/exec/memory.h
··· 326 326 QTAILQ_ENTRY(AddressSpace) address_spaces_link; 327 327 }; 328 328 329 - FlatView *address_space_to_flatview(AddressSpace *as); 329 + typedef struct AddressSpaceDispatch AddressSpaceDispatch; 330 + typedef struct FlatRange FlatRange; 331 + 332 + /* Flattened global view of current active memory hierarchy. Kept in sorted 333 + * order. 334 + */ 335 + struct FlatView { 336 + struct rcu_head rcu; 337 + unsigned ref; 338 + FlatRange *ranges; 339 + unsigned nr; 340 + unsigned nr_allocated; 341 + struct AddressSpaceDispatch *dispatch; 342 + MemoryRegion *root; 343 + }; 344 + 345 + static inline FlatView *address_space_to_flatview(AddressSpace *as) 346 + { 347 + return atomic_rcu_read(&as->current_map); 348 + } 349 + 330 350 331 351 /** 332 352 * MemoryRegionSection: describes a fragment of a #MemoryRegion
-30
memory.c
··· 210 210 && !memory_region_ioeventfd_before(b, a); 211 211 } 212 212 213 - typedef struct FlatRange FlatRange; 214 - 215 213 /* Range of memory in the global map. Addresses are absolute. */ 216 214 struct FlatRange { 217 215 MemoryRegion *mr; ··· 220 218 uint8_t dirty_log_mask; 221 219 bool romd_mode; 222 220 bool readonly; 223 - }; 224 - 225 - /* Flattened global view of current active memory hierarchy. Kept in sorted 226 - * order. 227 - */ 228 - struct FlatView { 229 - struct rcu_head rcu; 230 - unsigned ref; 231 - FlatRange *ranges; 232 - unsigned nr; 233 - unsigned nr_allocated; 234 - struct AddressSpaceDispatch *dispatch; 235 - MemoryRegion *root; 236 221 }; 237 222 238 223 typedef struct AddressSpaceOps AddressSpaceOps; ··· 320 305 assert(view->root); 321 306 call_rcu(view, flatview_destroy, rcu); 322 307 } 323 - } 324 - 325 - FlatView *address_space_to_flatview(AddressSpace *as) 326 - { 327 - return atomic_rcu_read(&as->current_map); 328 - } 329 - 330 - AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv) 331 - { 332 - return fv->dispatch; 333 - } 334 - 335 - AddressSpaceDispatch *address_space_to_dispatch(AddressSpace *as) 336 - { 337 - return flatview_to_dispatch(address_space_to_flatview(as)); 338 308 } 339 309 340 310 static bool can_merge(FlatRange *r1, FlatRange *r2)