Message ID | 20210902062604.182620-3-philmd@redhat.com |
---|---|
State | New |
Headers | show |
Series | memory: Have 'info mtree' remove duplicated Address Space information | expand |
Hi, Phil, On Thu, Sep 02, 2021 at 08:26:04AM +0200, Philippe Mathieu-Daudé wrote: > address-space shared 4 times: I commented on the format of the output, I saw that it's switched back to the v1. Any reason? Although I still think what I proposed looks better, I don't have a strong "no" to this either. Just want to know the motivations. E.g., for a script parsing this output, it can easily skip and identify duplications when scanned "address-space:" following another "address-space:". Now it needs to understand two layouts, and that "N times" looks superfluous. > - bcm2835-dma-memory > - bcm2835-fb-memory > - bcm2835-property-memory > - 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: 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
On 9/2/21 11:55 PM, Peter Xu wrote: > Hi, Phil, > > On Thu, Sep 02, 2021 at 08:26:04AM +0200, Philippe Mathieu-Daudé wrote: >> address-space shared 4 times: > > I commented on the format of the output, I saw that it's switched back to the > v1. Any reason? The code uses the format you asked, I simply forgot to update the commit description :/ Sorry, I'll respin. > > Although I still think what I proposed looks better, I don't have a strong "no" > to this either. Just want to know the motivations. > > E.g., for a script parsing this output, it can easily skip and identify > duplications when scanned "address-space:" following another "address-space:". > Now it needs to understand two layouts, and that "N times" looks superfluous.
On Fri, Sep 03, 2021 at 10:40:25AM +0200, Philippe Mathieu-Daudé wrote: > On 9/2/21 11:55 PM, Peter Xu wrote: > > Hi, Phil, > > > > On Thu, Sep 02, 2021 at 08:26:04AM +0200, Philippe Mathieu-Daudé wrote: > >> address-space shared 4 times: > > > > I commented on the format of the output, I saw that it's switched back to the > > v1. Any reason? > > The code uses the format you asked, I simply forgot to update the > commit description :/ Sorry, I'll respin. But I'm talking actually about the code too. :) After your answer I feel like it's just an accident anyway. Thanks,
On 9/3/21 5:39 PM, Peter Xu wrote: > On Fri, Sep 03, 2021 at 10:40:25AM +0200, Philippe Mathieu-Daudé wrote: >> On 9/2/21 11:55 PM, Peter Xu wrote: >>> Hi, Phil, >>> >>> On Thu, Sep 02, 2021 at 08:26:04AM +0200, Philippe Mathieu-Daudé wrote: >>>> address-space shared 4 times: >>> >>> I commented on the format of the output, I saw that it's switched back to the >>> v1. Any reason? >> >> The code uses the format you asked, I simply forgot to update the >> commit description :/ Sorry, I'll respin. > > But I'm talking actually about the code too. :) After your answer I feel like > it's just an accident anyway. Thanks, Doh sorry... Not sure how I messed that bad :S
diff --git a/softmmu/memory.c b/softmmu/memory.c index 5be7d5e7412..da58edfba04 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3284,20 +3284,85 @@ static void mtree_info_flatview(bool dispatch_tree, bool owner) g_hash_table_unref(views); } +struct AddressSpaceInfo { + MemoryRegionListHead *ml_head; + int counter; + bool owner; + bool disabled; +}; + +/* Returns negative value if a < b; zero if a = b; positive value if a > b. */ +static gint address_space_compare_name(gconstpointer a, gconstpointer b) +{ + const AddressSpace *as_a = a; + const AddressSpace *as_b = b; + + return g_strcmp0(as_a->name, as_b->name); +} +static void mtree_print_as_name(gpointer data, gpointer user_data) +{ + AddressSpace *as = data; + + qemu_printf(" - %s\n", as->name); +} + +static void mtree_print_as(gpointer key, gpointer value, gpointer user_data) +{ + MemoryRegion *mr = key; + GSList *as_same_root_mr_list = value; + struct AddressSpaceInfo *asi = user_data; + guint same_root_len = g_slist_length(as_same_root_mr_list); + + if (same_root_len == 1) { + AddressSpace *as = g_slist_nth_data(as_same_root_mr_list, 0); + + qemu_printf("address-space: %s\n", as->name); + } else { + qemu_printf("address-space shared %u times:\n", same_root_len); + g_slist_foreach(as_same_root_mr_list, mtree_print_as_name, NULL); + } + mtree_print_mr(mr, 1, 0, asi->ml_head, asi->owner, asi->disabled); + qemu_printf("\n"); +} + +static gboolean mtree_info_as_free(gpointer key, gpointer value, + gpointer user_data) +{ + GSList *as_same_root_mr_list = value; + + g_slist_free(as_same_root_mr_list); + + return true; +} + static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled) { MemoryRegionListHead ml_head; MemoryRegionList *ml, *ml2; AddressSpace *as; + GHashTable *views = g_hash_table_new(g_direct_hash, g_direct_equal); + GSList *as_same_root_mr_list; + struct AddressSpaceInfo asi = { + .ml_head = &ml_head, + .owner = owner, + .disabled = disabled, + }; QTAILQ_INIT(&ml_head); QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { - qemu_printf("address-space: %s\n", as->name); - mtree_print_mr(as->root, 1, 0, &ml_head, owner, disabled); - qemu_printf("\n"); + /* Create hashtable, key=AS root MR, value = list of AS */ + as_same_root_mr_list = g_hash_table_lookup(views, as->root); + as_same_root_mr_list = g_slist_insert_sorted(as_same_root_mr_list, as, + address_space_compare_name); + g_hash_table_insert(views, as->root, as_same_root_mr_list); } + /* print address spaces */ + g_hash_table_foreach(views, mtree_print_as, &asi); + g_hash_table_foreach_remove(views, mtree_info_as_free, 0); + g_hash_table_unref(views); + /* print aliased regions */ QTAILQ_FOREACH(ml, &ml_head, mrqueue) { qemu_printf("memory-region: %s\n", memory_region_name(ml->mr));