From nobody Sat Apr 27 13:45:49 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=1630797073; cv=none; d=zohomail.com; s=zohoarc; b=DVGXPkJWRqmJNBk3zrnrmmNMacmVQ7Olm+wcZPWufsT3uCbnPxEnlksHeVTmDO2pS4Xsk+9CUzWwEYgRmmFa0PjrvTkQiOhqevocQ4YpjVj5+c8hLuDdfN3u79AcYninZC1Zm1IlXhbjtyb2POox02/DwwQYpKUjesYXt0ZNkK0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630797073; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=E7OUJQ6DOzLFM/7MMg/7DQM5A7kD9dWaLRz2q+KNlto=; b=bVZwnUNgvAZc4ks/5Dx/H+ZsLP028EXmXLWwHLpE03Wb0DxvfbARwgovVRdlLDnfQvEVgzVg2Op5xc2+5eEGeVRbTpz8uIVB1uL8tofapBfWQVQ4jlhoQvdYAewHj8VOKl/SF2B+VSjvSgU9DaG/nCjj+GMabYv8WtwhuGgo3dk= 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 1630797073551304.04300409973064; Sat, 4 Sep 2021 16:11:13 -0700 (PDT) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-453-wN0mw959P4yUKK0spqinUg-1; Sat, 04 Sep 2021 19:11:11 -0400 Received: by mail-wm1-f72.google.com with SMTP id y188-20020a1c7dc5000000b002e80e0b2f87so1778244wmc.1 for ; Sat, 04 Sep 2021 16:11:10 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (21.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.21]) by smtp.gmail.com with ESMTPSA id s1sm3379391wrs.53.2021.09.04.16.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Sep 2021 16:11:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630797072; 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=E7OUJQ6DOzLFM/7MMg/7DQM5A7kD9dWaLRz2q+KNlto=; b=N5S/zFGdk9iHj93FirtPTI4WA620He00sf3u9YLXKfirdG4wEE80T0kj//2mlFPq/P4yjA YyGVk2NS4SDZlo2yCdaTArVVJyi1BLI1zCODq3MHknh3smQVyzGFLu8eXOkUY2nPfi8lcv fz9h+VXTkiMG8SVRwN5xHZB30+3pohQ= X-MC-Unique: wN0mw959P4yUKK0spqinUg-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=E7OUJQ6DOzLFM/7MMg/7DQM5A7kD9dWaLRz2q+KNlto=; b=TAG+TfjtwqzuTpnAh7Fg6ohT/in9HXdyt4aY0mTrBwKiSSsuvToGNqdfgtJwL9D4kf pNJOS+z2+HK9+hFjUdotuX1ikPKjAFQOFlcNPYC4iyIcDu9gdKCeXFjaqX42obG7QmNo 4QnVhAfgD1Y9XkQNeJouIJrgINQ3roddBu4OdyYXV8TIJkK476rMyT+eu9TfTOKPIfSm sfsQnlnCpddZDsXw4szBr+bcfEhBqv00Xw5TJeDsyOe0fCD46YDO6sCrEN582QaQT/gQ oOZdl+vbUMU3SE19Iz33Fz1vB6FLJehL7d0aS/ov3mSUCQRrZGLf26R7gpeBKvlATov4 Uy8g== X-Gm-Message-State: AOAM531UygG3Nt8vXGyhR8k5Q2giZp0FadXyGz4veh/nB58VVEXPr31c KTqnZwcvpq6kpLvQXIcnIacWsX5YvZmTWw8HPwE2crKkJV29OjGoPPIDWtXD2cWyHbF1AzAJxnK Ruagvhh5hUSIcoQ== X-Received: by 2002:adf:b78d:: with SMTP id s13mr5869271wre.344.1630797068008; Sat, 04 Sep 2021 16:11:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy17iWUgWcle2gjUTeiHlxgq9jEr5+ofzJwb57bxRy5hTMNw7kqk8U7udrEzV3JuAZsGrun3A== X-Received: by 2002:adf:b78d:: with SMTP id s13mr5869257wre.344.1630797067825; Sat, 04 Sep 2021 16:11:07 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: David Hildenbrand , Peter Xu , Mark Cave-Ayland , Paolo Bonzini , Gerd Hoffmann , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell , Richard Henderson Subject: [PATCH v7 1/2] memory: Split mtree_info() as mtree_info_flatview() + mtree_info_as() Date: Sun, 5 Sep 2021 01:11:00 +0200 Message-Id: <20210904231101.1071929-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210904231101.1071929-1-philmd@redhat.com> References: <20210904231101.1071929-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: 1630797074316100001 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 Reviewed-by: Peter Xu Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- 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 Sat Apr 27 13:45:49 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=1630797077; cv=none; d=zohomail.com; s=zohoarc; b=k5jZk0fu9OB+aenfFA1JftS+hUt2FhhuN7VOEcQVXbi1xLzZFYznkVyfR0aBlyy7Rz+N+yOXtrX7kxezToe9QWrf39hZzTcTl/KSNdy9HzHjvAFa+LIgSaa2NW1GqLB0kUX4lIHRrDLYljVaxQLYJarWLPI3wCQNOKdQxfUC3Zc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630797077; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=KVY5s7Ej5sbjg7B8ruPNuC3GirHMa+aQnRQ8uX+CC4Q=; b=ikl3UWyZEMnPB+RY9eMeQ/DnxmTE4mn0Ruj0ojL/kQ7wlIcjttij6qXS+9YhzXh+iK8d0EcVYbvdLhJlyCY1bWKZQF34e00Z/ot+zHWkNTJPJYD4lAKP9siVAv/37vgElI5kFNe2stwTEvDqWHdoQk7g+wq4ztkyNLG1/QRSOdY= 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 1630797077737911.5603591015871; Sat, 4 Sep 2021 16:11:17 -0700 (PDT) Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-437-0lxywCNwNsKEc1G8mGctMQ-1; Sat, 04 Sep 2021 19:11:14 -0400 Received: by mail-wm1-f70.google.com with SMTP id y24-20020a7bcd98000000b002eb50db2b62so1408121wmj.5 for ; Sat, 04 Sep 2021 16:11:13 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (21.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.21]) by smtp.gmail.com with ESMTPSA id u17sm3023554wmm.33.2021.09.04.16.11.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Sep 2021 16:11:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630797076; 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=KVY5s7Ej5sbjg7B8ruPNuC3GirHMa+aQnRQ8uX+CC4Q=; b=b5FwyIrUn3cJlBtkGQpKY5KkdKIKCAaKhkz4VMqHzD6KKi/74USLzllMQacuzeyuraqpKs 1YR5LgoAcV1vaIERLFdrOBRBX9F7uiVHvaEWuKl7g4+slCufmZLjVi8xBIEFaEir9T0eP/ M/U4j/3Z0j4x4hf02hNU1vz3G+M6Th8= X-MC-Unique: 0lxywCNwNsKEc1G8mGctMQ-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=KVY5s7Ej5sbjg7B8ruPNuC3GirHMa+aQnRQ8uX+CC4Q=; b=rDkVj2xRFRua5lj6aVCWUZUf22mLwVzg6u8MLevl2T3fSIY0TamA1QxC9wh4KPszKq orChfiCPzQ8STmQ+mBmv8SoeCurUR9/+NXeYWG0iHbTISpc0g3dxokPjolwyglCssbQP 1TgbHu37/lqD8Iv1XL2Xj/YIrWDLj4MH4+kzT76XaK36Si8Oww9IKf9vpat/iZ8/PhtR sGxeihLYGqq41mM3lVdGb+qbyp9qxtpiuDAeMjTD8sMCUpTlxIljfYXbeqY3lHy2g2gy NcSY7vbUFSzBwqxJpUnTjiE3pjb361D8xPQQgY2UsyVYal+PsrcPrY/fK/JcaaqkzJC5 5xzw== X-Gm-Message-State: AOAM531oNOSkqcTPMnUzVAeByVWzPuLlo7gJtVZepH77B2Q+TdOUWxov 6xALbIrtap1ACPG218ExGeDVWXkorJM4GK8sISQ0x85AeNVJ1B/dL7r0fm09jnSUGNQ3AQOFWKE rDje/whUn7IPKjw== X-Received: by 2002:adf:cf0b:: with SMTP id o11mr5716912wrj.72.1630797072842; Sat, 04 Sep 2021 16:11:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaRj7AFyygdWRYmK9p3SbTRBJeHrGZZjzkjH+3Q/PQ9MF4d5ssledTuMOgq05g8xMhNwJPFg== X-Received: by 2002:adf:cf0b:: with SMTP id o11mr5716890wrj.72.1630797072630; Sat, 04 Sep 2021 16:11:12 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: David Hildenbrand , Peter Xu , Mark Cave-Ayland , Paolo Bonzini , Gerd Hoffmann , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell , Richard Henderson Subject: [PATCH v7 2/2] memory: Have 'info mtree' remove duplicated Address Space information Date: Sun, 5 Sep 2021 01:11:01 +0200 Message-Id: <20210904231101.1071929-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210904231101.1071929-1-philmd@redhat.com> References: <20210904231101.1071929-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: 1630797078443100001 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 106 (qemu) info mtree address-space: I/O 0000000000000000-000000000000ffff (prio 0, i/o): io address-space: cpu-memory-0 address-space: cpu-memory-1 address-space: cpu-memory-2 address-space: cpu-memory-3 address-space: cpu-secure-memory-0 address-space: cpu-secure-memory-1 address-space: cpu-secure-memory-2 address-space: cpu-secure-memory-3 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: bcm2835-dma-memory address-space: bcm2835-fb-memory address-space: bcm2835-property-memory address-space: 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 Reviewed-by: Peter Xu Reviewed-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- checkpatch warning (81 chars): WARNING: line over 80 characters #86: FILE: softmmu/memory.c:3348: + address_space_compare_name); --- softmmu/memory.c | 63 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 5be7d5e7412..4d62357da64 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3284,20 +3284,77 @@ static void mtree_info_flatview(bool dispatch_tree,= bool owner) g_hash_table_unref(views); } =20 +struct AddressSpaceInfo { + MemoryRegionListHead *ml_head; + 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("address-space: %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; + + 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