From nobody Wed May 8 21:40:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1630563975; cv=none; d=zohomail.com; s=zohoarc; b=FDo5/bh8cG8pA82XYx4nl1fEE+AwaegcGEnEuF5T1BC6HOT+IpI0YjZ1dATbBtUsNfPbmc0DbZbA+kLSovw3rFEbth0M1cpv9sqyt5pVDyMGJZRtSHhCvNLxGrB5fCF9N+X7JM1tZcZz2WuRE7QlX9LRPKOjk+teu0yrLEO9gjs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630563975; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=axU1eGtomFFs/YWvr0SMZ0YoAylghsRvdBxczilBqhA=; b=PfWKx2nUsjJ65boCKKySvg7xnklhxa5WBkL72jdrpr/2UC7Khku2R4hbpQl9Lt06i6w5d8zSjOpSdjGhGgPWlIJyEXn0SWU3YKZxmIj7DHdSjAdumJ6xC+CsroSWnSN0bWFDuiLaN3HVjiugCWPq4pFi3NxFSeDn9HBfj6ZxD+o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1630563975302287.0833243142748; Wed, 1 Sep 2021 23:26:15 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-21-ODeDcCpVNbO4nylhAObsTA-1; Thu, 02 Sep 2021 02:26:12 -0400 Received: by mail-wr1-f71.google.com with SMTP id v18-20020adfe2920000b029013bbfb19640so186710wri.17 for ; Wed, 01 Sep 2021 23:26:12 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id a133sm716565wme.5.2021.09.01.23.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 23:26:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630563974; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=axU1eGtomFFs/YWvr0SMZ0YoAylghsRvdBxczilBqhA=; b=d5/In5e+B6XREEMLDawV4aILtakYisqSyqaaXGP/uGh9JqjCle2CdH/bq4WeoVuEAiuiyb SSwV28MzTLt3dPZnrM1XG2dFAhYlwjqLMj0nygGXCEFfiJciL8woiijtDQLg1NtqIfPzSW /RvEDg+MU/jr5V1DxakdRhRVhbFBuTc= X-MC-Unique: ODeDcCpVNbO4nylhAObsTA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=axU1eGtomFFs/YWvr0SMZ0YoAylghsRvdBxczilBqhA=; b=KNQHyrV1K8+cchCnaePgBDMF2sZXmY4CNHBsAtj8okj2v7nAFTZ0Cz15mjbb0KIs4i u1sTEeN3C2TBjXQzLEeUip/l1c67L6Mlqf3ndkjRcam+eBQzDoPwqD/ABY7s9zidYrWe TTSQ+GL6+h42tF+VAJU5L6AXaLfHfp30Zg4CO6Aunsm65Fgqx2MhvPxjhdJzXtWjyxYt zsxjS5Vm84/6eoRN2fJ2UmVfhm6wMSfp1gB5UnqfDE+cgPZTF6GTGisNrC7oHaFGn849 4QCkczn9cLVGbMbanrF5D0o0W24WDWKM8N3bWgm4nczYepjNOFChJmmEW1W/JMzlJDhq qKJQ== X-Gm-Message-State: AOAM530KngDglQSc3uUJhjdMBDZzbknEy2NkIUUFCeUlme0MLS3go89r aupPC+cP91jS/gAGoJ8OeUlPTsFDKfxve0Za5k03+tA4ya7ROrgzbcg5vo5wZAKaPHlEMzlSWed zREESKadkLs9YYg== X-Received: by 2002:a05:600c:350b:: with SMTP id h11mr1388915wmq.101.1630563970313; Wed, 01 Sep 2021 23:26:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJythrPuQcQAGFwmlP+GprwYn0Omg7UL4Va9MWSc8udffXt4K6RTw3n4VuMfebcHo9WfGGFGoQ== X-Received: by 2002:a05:600c:350b:: with SMTP id h11mr1388886wmq.101.1630563970033; Wed, 01 Sep 2021 23:26:10 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: David Hildenbrand , Peter Xu , Paolo Bonzini , Gerd Hoffmann , Mark Cave-Ayland , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell Subject: [PATCH v5 1/2] memory: Split mtree_info() as mtree_info_flatview() + mtree_info_as() Date: Thu, 2 Sep 2021 08:26:03 +0200 Message-Id: <20210902062604.182620-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902062604.182620-1-philmd@redhat.com> References: <20210902062604.182620-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1630563976413100001 While mtree_info() handles both ASes and flatviews cases, the two cases share basically no code. Split mtree_info() as mtree_info_flatview() + mtree_info_as() to simplify. Suggested-by: Peter Maydell Reviewed-by: David Hildenbrand Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu --- softmmu/memory.c | 87 ++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index bfedaf9c4df..5be7d5e7412 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3246,50 +3246,50 @@ static gboolean mtree_info_flatview_free(gpointer k= ey, gpointer value, return true; } =20 -void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabl= ed) +static void mtree_info_flatview(bool dispatch_tree, bool owner) +{ + struct FlatViewInfo fvi =3D { + .counter =3D 0, + .dispatch_tree =3D dispatch_tree, + .owner =3D owner, + }; + AddressSpace *as; + FlatView *view; + GArray *fv_address_spaces; + GHashTable *views =3D g_hash_table_new(g_direct_hash, g_direct_equal); + AccelClass *ac =3D ACCEL_GET_CLASS(current_accel()); + + if (ac->has_memory) { + fvi.ac =3D ac; + } + + /* Gather all FVs in one table */ + QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { + view =3D address_space_get_flatview(as); + + fv_address_spaces =3D g_hash_table_lookup(views, view); + if (!fv_address_spaces) { + fv_address_spaces =3D g_array_new(false, false, sizeof(as)); + g_hash_table_insert(views, view, fv_address_spaces); + } + + g_array_append_val(fv_address_spaces, as); + } + + /* Print */ + g_hash_table_foreach(views, mtree_print_flatview, &fvi); + + /* Free */ + g_hash_table_foreach_remove(views, mtree_info_flatview_free, 0); + g_hash_table_unref(views); +} + +static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled) { MemoryRegionListHead ml_head; MemoryRegionList *ml, *ml2; AddressSpace *as; =20 - if (flatview) { - FlatView *view; - struct FlatViewInfo fvi =3D { - .counter =3D 0, - .dispatch_tree =3D dispatch_tree, - .owner =3D owner, - }; - GArray *fv_address_spaces; - GHashTable *views =3D g_hash_table_new(g_direct_hash, g_direct_equ= al); - AccelClass *ac =3D ACCEL_GET_CLASS(current_accel()); - - if (ac->has_memory) { - fvi.ac =3D ac; - } - - /* Gather all FVs in one table */ - QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { - view =3D address_space_get_flatview(as); - - fv_address_spaces =3D g_hash_table_lookup(views, view); - if (!fv_address_spaces) { - fv_address_spaces =3D g_array_new(false, false, sizeof(as)= ); - g_hash_table_insert(views, view, fv_address_spaces); - } - - g_array_append_val(fv_address_spaces, as); - } - - /* Print */ - g_hash_table_foreach(views, mtree_print_flatview, &fvi); - - /* Free */ - g_hash_table_foreach_remove(views, mtree_info_flatview_free, 0); - g_hash_table_unref(views); - - return; - } - QTAILQ_INIT(&ml_head); =20 QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { @@ -3310,6 +3310,15 @@ void mtree_info(bool flatview, bool dispatch_tree, b= ool owner, bool disabled) } } =20 +void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabl= ed) +{ + if (flatview) { + mtree_info_flatview(dispatch_tree, owner); + } else { + mtree_info_as(dispatch_tree, owner, disabled); + } +} + void memory_region_init_ram(MemoryRegion *mr, Object *owner, const char *name, --=20 2.31.1 From nobody Wed May 8 21:40:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1630563979; cv=none; d=zohomail.com; s=zohoarc; b=fe2f5XnBqtwBdMCFdXEnvt29j0CwOM/nrEFybwTzEFIzRniJ08jhlprdDb0RovsfFfkfrofx2ytA5KY4I53cycHkppXVlRdn2uPsLFDSyBamTvbd+wxYKhIGuAKSaTp3zuC7rFcMwBg6pDF7D5sRykAiAGHNAFBfTt9lSMT306I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630563979; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=kdU5Aqza9ZWbPymBqSm4kyPMeV694lTfymI4s4A9Y3Y=; b=FkRwXm8fg4WnBXD+/M80nZmYDLKpfh1wqRvykt/hN9V8FDJrfm2ErWJP6/SwtNXTLXiCw5zFKrj5EYhzFXXOLYu7ovlk2EvOVH/z+TDm1uP0BWbTEzoWPyVf7i6aqNwMSJvK1XAydz7HAfvOsMFRUR4+ddmZVy2TMvnTp+0NvCE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1630563979809286.96611437233787; Wed, 1 Sep 2021 23:26:19 -0700 (PDT) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-191-4XcK_HEcP_iDyQFx94WQ4Q-1; Thu, 02 Sep 2021 02:26:16 -0400 Received: by mail-wm1-f71.google.com with SMTP id u1-20020a05600c210100b002e74fc5af71so304306wml.1 for ; Wed, 01 Sep 2021 23:26:16 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id l1sm856476wrb.15.2021.09.01.23.26.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 23:26:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630563978; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kdU5Aqza9ZWbPymBqSm4kyPMeV694lTfymI4s4A9Y3Y=; b=CNMWqdWB8ZJ5lVC1Ixl4XNOtCVXGLbJx6fIj2d2ZqndulRag6qntOoR+e9DPOlt4hQnlUQ y+TCvpvg1ekw7JDFVf9CR8e93NjTcPAK5FpU3g9g7IcVukXrBRwNV7KoxagSVdU3A9F9YY T2QPStFXNGZpFOszmyi2BuBdFxESMnQ= X-MC-Unique: 4XcK_HEcP_iDyQFx94WQ4Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kdU5Aqza9ZWbPymBqSm4kyPMeV694lTfymI4s4A9Y3Y=; b=ZF9AQEU/awDaiyIoJqIWZfWHpEiv2Rl1vyiPaleoN5e459xdDe6xN1O0V8tN90KNQs +7Zd9IYp6OCJ7/g6hFijMX2BcVTUiso01j0o2PK0aFr94gxacs4CFVwVdov7dKrJKt+H 7Dq8Zfw/mUAKZ/Ge6t9r8jhFhGo4ANJFVuU5feHZbRRD7u2HwSFYhM8GhAMQGn1g8gjP XvYYp8g5UU+lkYakCBV/eh7Su0GA1DxNlPT4ufAXxYyLNWSlpisqDqtr5vg1DjvzmQfc CjvnRHmVFe1Y8MmY/ymZkXfnKsQuyGaeHGuY0fkeDVqcGpwA13Y1BS3z7JTlcY+rgYxi 6vsg== X-Gm-Message-State: AOAM5304tsvit1wjbtfTiM8RbpvV+EScwfmZXHDPtcDpsZYrB0rlTwgL nsyZ64mnkR93M6faIVT7tB2MeuFNF8TEzjvWShf3uD+M+CRq0ueM8FtWi5LQB6LesnM122sze1s bo3XQ0iqYtriEMA== X-Received: by 2002:a05:6000:1091:: with SMTP id y17mr1638122wrw.202.1630563974834; Wed, 01 Sep 2021 23:26:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTxb930UvmxIGhw6D82IqIqOPDyv+b+ErXok0n7MBRKTzhoUuSzqutnAF6XW4hbS7GYbXN3w== X-Received: by 2002:a05:6000:1091:: with SMTP id y17mr1638105wrw.202.1630563974584; Wed, 01 Sep 2021 23:26:14 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: David Hildenbrand , Peter Xu , Paolo Bonzini , Gerd Hoffmann , Mark Cave-Ayland , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell Subject: [PATCH v5 2/2] memory: Have 'info mtree' remove duplicated Address Space information Date: Thu, 2 Sep 2021 08:26:04 +0200 Message-Id: <20210902062604.182620-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902062604.182620-1-philmd@redhat.com> References: <20210902062604.182620-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1630563980568100001 Per Peter Maydell [*]: 'info mtree' monitor command was designed on the assumption that there's really only one or two interesting address spaces, and with more recent developments that's just not the case any more. Similarly about how the FlatView are sorted using a GHashTable, sort the AddressSpace objects to remove the duplications (AS using the same root MemoryRegion). This drastically reduces the output of 'info mtree' on some boards. Before: $ (echo info mtree; echo q) \ | qemu-system-aarch64 -S -monitor stdio -M raspi3b \ | wc -l 423 After: $ (echo info mtree; echo q) \ | qemu-system-aarch64 -S -monitor stdio -M raspi3b \ | wc -l 108 (qemu) info mtree address-space: I/O 0000000000000000-000000000000ffff (prio 0, i/o): io address-space shared 9 times: - cpu-memory-0 - cpu-memory-1 - cpu-memory-2 - cpu-memory-3 - cpu-secure-memory-0 - cpu-secure-memory-1 - cpu-secure-memory-2 - cpu-secure-memory-3 - 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 shared 4 times: - 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-ra= m-alias[*] @ram 0000000000000000-000000003fffffff 0000000040000000-000000007fffffff (prio 0, ram): alias bcm2835-gpu-ra= m-alias[*] @ram 0000000000000000-000000003fffffff 000000007e000000-000000007effffff (prio 1, i/o): alias bcm2835-periph= erals @bcm2835-peripherals 0000000000000000-0000000000ffffff 0000000080000000-00000000bfffffff (prio 0, ram): alias bcm2835-gpu-ra= m-alias[*] @ram 0000000000000000-000000003fffffff 00000000c0000000-00000000ffffffff (prio 0, ram): alias bcm2835-gpu-ra= m-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 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 [*] https://www.mail-archive.com/qemu-devel@nongnu.org/msg829821.html Suggested-by: Peter Maydell Reviewed-by: Peter Maydell Reviewed-by: David Hildenbrand Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- checkpatch warning (81 chars): WARNING: line over 80 characters #86: FILE: softmmu/memory.c:3359: + address_space_compare_name); --- softmmu/memory.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 3 deletions(-) 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); } =20 +struct AddressSpaceInfo { + MemoryRegionListHead *ml_head; + int counter; + bool owner; + bool disabled; +}; + +/* Returns negative value if a < b; zero if a =3D b; positive value if a >= b. */ +static gint address_space_compare_name(gconstpointer a, gconstpointer b) +{ + const AddressSpace *as_a =3D a; + const AddressSpace *as_b =3D b; + + return g_strcmp0(as_a->name, as_b->name); +} +static void mtree_print_as_name(gpointer data, gpointer user_data) +{ + AddressSpace *as =3D data; + + qemu_printf(" - %s\n", as->name); +} + +static void mtree_print_as(gpointer key, gpointer value, gpointer user_dat= a) +{ + MemoryRegion *mr =3D key; + GSList *as_same_root_mr_list =3D value; + struct AddressSpaceInfo *asi =3D user_data; + guint same_root_len =3D g_slist_length(as_same_root_mr_list); + + if (same_root_len =3D=3D 1) { + AddressSpace *as =3D 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 =3D 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 =3D g_hash_table_new(g_direct_hash, g_direct_equal); + GSList *as_same_root_mr_list; + struct AddressSpaceInfo asi =3D { + .ml_head =3D &ml_head, + .owner =3D owner, + .disabled =3D disabled, + }; =20 QTAILQ_INIT(&ml_head); =20 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=3DAS root MR, value =3D list of AS */ + as_same_root_mr_list =3D g_hash_table_lookup(views, as->root); + as_same_root_mr_list =3D g_slist_insert_sorted(as_same_root_mr_lis= t, as, + address_space_compare= _name); + g_hash_table_insert(views, as->root, as_same_root_mr_list); } =20 + /* 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)); --=20 2.31.1