Message ID | 20210819142039.2825366-7-philmd@redhat.com |
---|---|
State | New |
Headers | show |
Series | memory: Introduce address_space_create(), re-use &address_space_memory | expand |
On Thu, 19 Aug 2021 at 15:21, Philippe Mathieu-Daudé <philmd@redhat.com> wrote: > > We already have a global AddressSpace created along with the > global get_system_memory(): address_space_memory. Return it > directly instead of creating the same AS with a different name. > > diff --git a/softmmu/memory.c b/softmmu/memory.c > index 16a2b518d8d..e4506b5a0d5 100644 > --- a/softmmu/memory.c > +++ b/softmmu/memory.c > @@ -2941,6 +2941,10 @@ AddressSpace *address_space_create(MemoryRegion *root, const char *name) > { > AddressSpace *as; > > + if (root == get_system_memory()) { > + return &address_space_memory; > + } But most ASes aren't set up with address_space_create(). This doesn't do anything for the common case where the AS is initialized with address_space_init(). This also seems to me to be the tail wagging the dog. If we think 'info mtree' has too much duplicate information (which it certainly does) then we should make mtree_info() smarter about reducing that duplication. Off the top of my head, we could change the code that prints ASes to do something like: hashtable = an empty hashtable; QEMU_FOREACH(as, ...) { qemu_printf("address-space: %s\n", as->name); name = lookup as->root in hashtable; if (name) { qemu_printf("...same as address-space %s\n", name); continue; } add (as->root, as->name) to hashtable; mtree_print_mr(as->root...); qemu_printf("\n"); } thanks -- PMM
On 8/19/21 4:34 PM, Peter Maydell wrote: > On Thu, 19 Aug 2021 at 15:21, Philippe Mathieu-Daudé <philmd@redhat.com> wrote: >> >> We already have a global AddressSpace created along with the >> global get_system_memory(): address_space_memory. Return it >> directly instead of creating the same AS with a different name. >> > >> diff --git a/softmmu/memory.c b/softmmu/memory.c >> index 16a2b518d8d..e4506b5a0d5 100644 >> --- a/softmmu/memory.c >> +++ b/softmmu/memory.c >> @@ -2941,6 +2941,10 @@ AddressSpace *address_space_create(MemoryRegion *root, const char *name) >> { >> AddressSpace *as; >> >> + if (root == get_system_memory()) { >> + return &address_space_memory; >> + } > > But most ASes aren't set up with address_space_create(). > This doesn't do anything for the common case where the > AS is initialized with address_space_init(). > > This also seems to me to be the tail wagging the dog. If we think > 'info mtree' has too much duplicate information (which it certainly > does) then we should make mtree_info() smarter about reducing that > duplication. Off the top of my head, we could change the code that > prints ASes to do something like: > > hashtable = an empty hashtable; > QEMU_FOREACH(as, ...) { > qemu_printf("address-space: %s\n", as->name); > name = lookup as->root in hashtable; > if (name) { > qemu_printf("...same as address-space %s\n", name); > continue; > } > add (as->root, as->name) to hashtable; > mtree_print_mr(as->root...); > qemu_printf("\n"); > } Got it, thanks for the review, explanation & suggestion :)
Hi, > This also seems to me to be the tail wagging the dog. If we think > 'info mtree' has too much duplicate information (which it certainly > does) then we should make mtree_info() smarter about reducing that > duplication. Off the top of my head, we could change the code that > prints ASes to do something like: > qemu_printf("...same as address-space %s\n", name); Neat idea. Having 'info mtree' accept an (optional) 'name' parameter to pick an address space to be printed would be useful too. take care, Gerd
On 8/20/21 8:07 AM, Gerd Hoffmann wrote: > Hi, > >> This also seems to me to be the tail wagging the dog. If we think >> 'info mtree' has too much duplicate information (which it certainly >> does) then we should make mtree_info() smarter about reducing that >> duplication. Off the top of my head, we could change the code that >> prints ASes to do something like: > >> qemu_printf("...same as address-space %s\n", name); > > Neat idea. > > Having 'info mtree' accept an (optional) 'name' parameter to pick an > address space to be printed would be useful too. Yeah, for now I am thinking of a match string (for my use cases): (qemu) info mtree -a dma # all address spaces matching *dma*
diff --git a/softmmu/memory.c b/softmmu/memory.c index 16a2b518d8d..e4506b5a0d5 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -2941,6 +2941,10 @@ AddressSpace *address_space_create(MemoryRegion *root, const char *name) { AddressSpace *as; + if (root == get_system_memory()) { + return &address_space_memory; + } + as = g_new(AddressSpace, 1); address_space_init(as, root, name); @@ -2961,6 +2965,10 @@ void address_space_destroy(AddressSpace *as) { MemoryRegion *root = as->root; + if (as == &address_space_memory) { + return; + } + /* Flush out anything from MemoryListeners listening in on this */ memory_region_transaction_begin(); as->root = NULL;
We already have a global AddressSpace created along with the global get_system_memory(): address_space_memory. Return it directly instead of creating the same AS with a different name. This drastically reduce 'info mtree' on some boards (diff -c100): (echo info mtree; echo q) | ./qemu-system-aarch64 -S -monitor stdio -M raspi3b QEMU 6.0.93 monitor - type 'help' for more information (qemu) info mtree address-space: memory 0000000000000000-ffffffffffffffff (prio 0, i/o): system 0000000000000000-000000003fffffff (prio 0, ram): ram 000000003f000000-000000003fffffff (prio 1, i/o): bcm2835-peripherals 000000003f003000-000000003f00301f (prio 0, i/o): bcm2835-sys-timer 000000003f004000-000000003f004fff (prio -1000, i/o): bcm2835-txp 000000003f006000-000000003f006fff (prio 0, i/o): mphi 000000003f007000-000000003f007fff (prio 0, i/o): bcm2835-dma 000000003f00b200-000000003f00b3ff (prio 0, i/o): bcm2835-ic 000000003f00b400-000000003f00b43f (prio -1000, i/o): bcm2835-sp804 000000003f00b800-000000003f00bbff (prio 0, i/o): bcm2835-mbox 000000003f100000-000000003f1001ff (prio 0, i/o): bcm2835-powermgt 000000003f101000-000000003f102fff (prio 0, i/o): bcm2835-cprman 000000003f104000-000000003f10400f (prio 0, i/o): bcm2835-rng 000000003f200000-000000003f200fff (prio 0, i/o): bcm2835_gpio 000000003f201000-000000003f201fff (prio 0, i/o): pl011 000000003f202000-000000003f202fff (prio 0, i/o): bcm2835-sdhost 000000003f203000-000000003f2030ff (prio -1000, i/o): bcm2835-i2s 000000003f204000-000000003f20401f (prio -1000, i/o): bcm2835-spi0 000000003f205000-000000003f20501f (prio -1000, i/o): bcm2835-i2c0 000000003f20f000-000000003f20f07f (prio -1000, i/o): bcm2835-otp 000000003f212000-000000003f212007 (prio 0, i/o): bcm2835-thermal 000000003f214000-000000003f2140ff (prio -1000, i/o): bcm2835-spis 000000003f215000-000000003f2150ff (prio 0, i/o): bcm2835-aux 000000003f300000-000000003f3000ff (prio 0, i/o): sdhci 000000003f600000-000000003f6000ff (prio -1000, i/o): bcm2835-smi 000000003f804000-000000003f80401f (prio -1000, i/o): bcm2835-i2c1 000000003f805000-000000003f80501f (prio -1000, i/o): bcm2835-i2c2 000000003f900000-000000003f907fff (prio -1000, i/o): bcm2835-dbus 000000003f910000-000000003f917fff (prio -1000, i/o): bcm2835-ave0 000000003f980000-000000003f990fff (prio 0, i/o): dwc2 000000003f980000-000000003f980fff (prio 0, i/o): dwc2-io 000000003f981000-000000003f990fff (prio 0, i/o): dwc2-fifo 000000003fc00000-000000003fc00fff (prio -1000, i/o): bcm2835-v3d 000000003fe00000-000000003fe000ff (prio -1000, i/o): bcm2835-sdramc 000000003fe05000-000000003fe050ff (prio 0, i/o): bcm2835-dma-chan15 0000000040000000-00000000400000ff (prio 0, i/o): bcm2836-control address-space: I/O 0000000000000000-000000000000ffff (prio 0, i/o): io address-space: bcm2835-mbox-memory 0000000000000000-000000000000008f (prio 0, i/o): bcm2835-mbox 0000000000000010-000000000000001f (prio 0, i/o): bcm2835-fb 0000000000000080-000000000000008f (prio 0, i/o): bcm2835-property address-space: bcm2835-fb-memory 0000000000000000-00000000ffffffff (prio 0, i/o): bcm2835-gpu 0000000000000000-000000003fffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 0000000040000000-000000007fffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 000000007e000000-000000007effffff (prio 1, i/o): alias bcm2835-peripherals @bcm2835-peripherals 0000000000000000-0000000000ffffff 0000000080000000-00000000bfffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 00000000c0000000-00000000ffffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff address-space: bcm2835-property-memory 0000000000000000-00000000ffffffff (prio 0, i/o): bcm2835-gpu 0000000000000000-000000003fffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 0000000040000000-000000007fffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 000000007e000000-000000007effffff (prio 1, i/o): alias bcm2835-peripherals @bcm2835-peripherals 0000000000000000-0000000000ffffff 0000000080000000-00000000bfffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 00000000c0000000-00000000ffffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff address-space: bcm2835-dma-memory 0000000000000000-00000000ffffffff (prio 0, i/o): bcm2835-gpu 0000000000000000-000000003fffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 0000000040000000-000000007fffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 000000007e000000-000000007effffff (prio 1, i/o): alias bcm2835-peripherals @bcm2835-peripherals 0000000000000000-0000000000ffffff 0000000080000000-00000000bfffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 00000000c0000000-00000000ffffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff address-space: dwc2 0000000000000000-00000000ffffffff (prio 0, i/o): bcm2835-gpu 0000000000000000-000000003fffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 0000000040000000-000000007fffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 000000007e000000-000000007effffff (prio 1, i/o): alias bcm2835-peripherals @bcm2835-peripherals 0000000000000000-0000000000ffffff 0000000080000000-00000000bfffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 00000000c0000000-00000000ffffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff - address-space: cpu-secure-memory-0 - 0000000000000000-ffffffffffffffff (prio 0, i/o): system - 0000000000000000-000000003fffffff (prio 0, ram): ram - 000000003f000000-000000003fffffff (prio 1, i/o): bcm2835-peripherals - 000000003f003000-000000003f00301f (prio 0, i/o): bcm2835-sys-timer - 000000003f004000-000000003f004fff (prio -1000, i/o): bcm2835-txp - 000000003f006000-000000003f006fff (prio 0, i/o): mphi - 000000003f007000-000000003f007fff (prio 0, i/o): bcm2835-dma - 000000003f00b200-000000003f00b3ff (prio 0, i/o): bcm2835-ic - 000000003f00b400-000000003f00b43f (prio -1000, i/o): bcm2835-sp804 - 000000003f00b800-000000003f00bbff (prio 0, i/o): bcm2835-mbox - 000000003f100000-000000003f1001ff (prio 0, i/o): bcm2835-powermgt - 000000003f101000-000000003f102fff (prio 0, i/o): bcm2835-cprman - 000000003f104000-000000003f10400f (prio 0, i/o): bcm2835-rng - 000000003f200000-000000003f200fff (prio 0, i/o): bcm2835_gpio - 000000003f201000-000000003f201fff (prio 0, i/o): pl011 - 000000003f202000-000000003f202fff (prio 0, i/o): bcm2835-sdhost - 000000003f203000-000000003f2030ff (prio -1000, i/o): bcm2835-i2s - 000000003f204000-000000003f20401f (prio -1000, i/o): bcm2835-spi0 - 000000003f205000-000000003f20501f (prio -1000, i/o): bcm2835-i2c0 - 000000003f20f000-000000003f20f07f (prio -1000, i/o): bcm2835-otp - 000000003f212000-000000003f212007 (prio 0, i/o): bcm2835-thermal - 000000003f214000-000000003f2140ff (prio -1000, i/o): bcm2835-spis - 000000003f215000-000000003f2150ff (prio 0, i/o): bcm2835-aux - 000000003f300000-000000003f3000ff (prio 0, i/o): sdhci - 000000003f600000-000000003f6000ff (prio -1000, i/o): bcm2835-smi - 000000003f804000-000000003f80401f (prio -1000, i/o): bcm2835-i2c1 - 000000003f805000-000000003f80501f (prio -1000, i/o): bcm2835-i2c2 - 000000003f900000-000000003f907fff (prio -1000, i/o): bcm2835-dbus - 000000003f910000-000000003f917fff (prio -1000, i/o): bcm2835-ave0 - 000000003f980000-000000003f990fff (prio 0, i/o): dwc2 - 000000003f980000-000000003f980fff (prio 0, i/o): dwc2-io - 000000003f981000-000000003f990fff (prio 0, i/o): dwc2-fifo - 000000003fc00000-000000003fc00fff (prio -1000, i/o): bcm2835-v3d - 000000003fe00000-000000003fe000ff (prio -1000, i/o): bcm2835-sdramc - 000000003fe05000-000000003fe050ff (prio 0, i/o): bcm2835-dma-chan15 - 0000000040000000-00000000400000ff (prio 0, i/o): bcm2836-control - - address-space: cpu-memory-0 - 0000000000000000-ffffffffffffffff (prio 0, i/o): system [...] - - address-space: cpu-secure-memory-1 - 0000000000000000-ffffffffffffffff (prio 0, i/o): system [...] - - address-space: cpu-memory-1 - 0000000000000000-ffffffffffffffff (prio 0, i/o): system [...] - - address-space: cpu-secure-memory-2 - 0000000000000000-ffffffffffffffff (prio 0, i/o): system [...] - - address-space: cpu-memory-2 - 0000000000000000-ffffffffffffffff (prio 0, i/o): system [...] - - address-space: cpu-secure-memory-3 - 0000000000000000-ffffffffffffffff (prio 0, i/o): system [...] - - address-space: cpu-memory-3 - 0000000000000000-ffffffffffffffff (prio 0, i/o): system [...] - memory-region: ram 0000000000000000-000000003fffffff (prio 0, ram): ram memory-region: bcm2835-peripherals 000000003f000000-000000003fffffff (prio 1, i/o): bcm2835-peripherals 000000003f003000-000000003f00301f (prio 0, i/o): bcm2835-sys-timer 000000003f004000-000000003f004fff (prio -1000, i/o): bcm2835-txp 000000003f006000-000000003f006fff (prio 0, i/o): mphi 000000003f007000-000000003f007fff (prio 0, i/o): bcm2835-dma 000000003f00b200-000000003f00b3ff (prio 0, i/o): bcm2835-ic 000000003f00b400-000000003f00b43f (prio -1000, i/o): bcm2835-sp804 000000003f00b800-000000003f00bbff (prio 0, i/o): bcm2835-mbox 000000003f100000-000000003f1001ff (prio 0, i/o): bcm2835-powermgt 000000003f101000-000000003f102fff (prio 0, i/o): bcm2835-cprman 000000003f104000-000000003f10400f (prio 0, i/o): bcm2835-rng 000000003f200000-000000003f200fff (prio 0, i/o): bcm2835_gpio 000000003f201000-000000003f201fff (prio 0, i/o): pl011 000000003f202000-000000003f202fff (prio 0, i/o): bcm2835-sdhost 000000003f203000-000000003f2030ff (prio -1000, i/o): bcm2835-i2s 000000003f204000-000000003f20401f (prio -1000, i/o): bcm2835-spi0 000000003f205000-000000003f20501f (prio -1000, i/o): bcm2835-i2c0 000000003f20f000-000000003f20f07f (prio -1000, i/o): bcm2835-otp 000000003f212000-000000003f212007 (prio 0, i/o): bcm2835-thermal 000000003f214000-000000003f2140ff (prio -1000, i/o): bcm2835-spis 000000003f215000-000000003f2150ff (prio 0, i/o): bcm2835-aux 000000003f300000-000000003f3000ff (prio 0, i/o): sdhci 000000003f600000-000000003f6000ff (prio -1000, i/o): bcm2835-smi 000000003f804000-000000003f80401f (prio -1000, i/o): bcm2835-i2c1 000000003f805000-000000003f80501f (prio -1000, i/o): bcm2835-i2c2 000000003f900000-000000003f907fff (prio -1000, i/o): bcm2835-dbus 000000003f910000-000000003f917fff (prio -1000, i/o): bcm2835-ave0 000000003f980000-000000003f990fff (prio 0, i/o): dwc2 000000003f980000-000000003f980fff (prio 0, i/o): dwc2-io 000000003f981000-000000003f990fff (prio 0, i/o): dwc2-fifo 000000003fc00000-000000003fc00fff (prio -1000, i/o): bcm2835-v3d 000000003fe00000-000000003fe000ff (prio -1000, i/o): bcm2835-sdramc 000000003fe05000-000000003fe050ff (prio 0, i/o): bcm2835-dma-chan15 (qemu) q Inspired-by: Jianxian Wen <jianxian.wen@verisilicon.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> --- Note, we loose the specific description of the duplicated address spaces, but this doesn't seem very useful in this output, it is rather more confusing IMO. --- softmmu/memory.c | 8 ++++++++ 1 file changed, 8 insertions(+)