From nobody Fri May 3 17:07:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1630685196; cv=none; d=zohomail.com; s=zohoarc; b=RYmHuJA2Ej13CyQgyDSsu2bZsb73wXPTKEvSTMhL/3ryk7e2G4EMysFpLtjzIK4BUkWkSwCShQKREsYFYrNxiboW5h/WM15qxIsETBKZxntXlTQiXz4C+nqsRHkSZkWqqP6zxpFN75pHRjphhV/paqx+8laQk0haGMtq63WKyHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630685196; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=Iw9k0Bp351OSq0GNnrA6pD6+12eNcWfk/Y1LfqMHJS0=; b=QLNm4616QPstaTaWCoA/Td21oOvaGzB2jtSN0fb4Gb80hKxs4Ggs1bVRCzP80DyDOtY1p5R+WXAp9T6MPNXGI5Bwr2DGYi1RwkqXygIA1FARPUPswO8WsBUJwmdNVSjYT5mPzZ60zLD5WQUD1Cmx/9QJo7mBjZG57nKywYDPUHs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1630685196382520.9493233405216; Fri, 3 Sep 2021 09:06:36 -0700 (PDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-42-2svAQvDYM8CSUursy_KvYQ-1; Fri, 03 Sep 2021 12:06:33 -0400 Received: by mail-wr1-f69.google.com with SMTP id m16-20020a056000181000b0015964e4ae48so700632wrh.14 for ; Fri, 03 Sep 2021 09:06:33 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id z2sm4500133wma.45.2021.09.03.09.06.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 09:06:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630685195; 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=Iw9k0Bp351OSq0GNnrA6pD6+12eNcWfk/Y1LfqMHJS0=; b=CupUxF8No4St+6RjxDLXE/QGK44Jwn93sKXl7C08Yjv9OmzwarwJv5HLbQqCkUoP9XUduf o1NDPlvu2s0gmOTDaxrc5/Z2a3Clg/eWl6iqq6H2AAa68+Y212pIQYQlSlY+l1+kS72qxs 0Beo010ULApTjIXCoEwwujDqjJ5/Ji8= X-MC-Unique: 2svAQvDYM8CSUursy_KvYQ-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=Iw9k0Bp351OSq0GNnrA6pD6+12eNcWfk/Y1LfqMHJS0=; b=AsR3qA+FSRTrxLlZDW0nT3iYhQCpnMNSJ3YTAzXc03zCN2jkxJZ2NFXbJrqOWVSzkQ VGTJP9Cht5LpEATJdkgC4D7qR1zTRh93k6Om50ZGqB3zWLIwW8G7Tq6O71He95yo3bkp BZM+mNjymzUSA1SlqWi+LpsWW1HH1CUjQPFMG95bB7bZAxeqeU4aVBUCG+wB8E4+tfZO qSqlB6CFVy816cmcMdw2kkh/HIp6GsNG+Zg/k2rgz0u/0kizQKwBjaD5fGwBd1XGxk/O TlTK6/mmf11UTL1xU/3Yl7EN+qLFugq1x6ghHCew5vjity/lvdB56Rd0SM6ZRLozr64d +aMQ== X-Gm-Message-State: AOAM532nFfjI/0l+QD8ORRPoKpNgpUZmuqQGu9bqM0iH+/BFafKKin8c P4WFwgvL5wuqjQj/hbrGQAdSBqX3ynINvCORtX8lua/oYEtt340LtwzfoH7fy404hgtSCGzZ6Vs K83yRWH4KIQ6WMw== X-Received: by 2002:a5d:63d2:: with SMTP id c18mr5051192wrw.240.1630685190809; Fri, 03 Sep 2021 09:06:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSQbt3qV2bzmAvywjF0y1oNeSuwfb+9gpQUEYW05q0H3vHX32DqHb0mSW7j/sLCTvvrkdahg== X-Received: by 2002:a5d:63d2:: with SMTP id c18mr5051172wrw.240.1630685190651; Fri, 03 Sep 2021 09:06:30 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , David Hildenbrand , Gerd Hoffmann , Peter Xu , Mark Cave-Ayland , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell Subject: [PATCH v6 1/2] memory: Split mtree_info() as mtree_info_flatview() + mtree_info_as() Date: Fri, 3 Sep 2021 18:06:18 +0200 Message-Id: <20210903160619.699632-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210903160619.699632-1-philmd@redhat.com> References: <20210903160619.699632-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: 1630685198402100001 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 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 Fri May 3 17:07:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1630685203; cv=none; d=zohomail.com; s=zohoarc; b=efSwueZ4amZNq0d7nFM1oMnnE/H585d6u7OUmA6H3zQVeHxdZfNR5rzzlh2DtiXfe6BOJiPsXV3MV2ateza5pRG4rL8IgK43p5MCE60Mixr1FtwuYCrVDzxZmpjRF/C7a7RtreC8ojGWMhYzx+6pmh1An8JihwkDsp2XUJ7anWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630685203; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=XHKyr01gvCx97VAfaYZAMWFLuahjopao8xNghsdJ+1c=; b=V2Ssc2C1LAaEmLgNWHmf6gZ51vhCoFPf/veRqG6ouYmT5awEoQFsHI1ZPltF2SduBLdDb7vFPcn3iA0rqexSzmD2Qho1Wig3x1/8a9Imrt5SX/3IbtMtcxsP/VPRGf0Jo31Yy6VRiFj/HoR6MWqgbO2TFTYBdhLg4bm5u47YSLA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1630685203731486.2630131364681; Fri, 3 Sep 2021 09:06:43 -0700 (PDT) Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-584-gqUBPWFiOtKQL5aa2IQg4w-1; Fri, 03 Sep 2021 12:06:40 -0400 Received: by mail-wr1-f70.google.com with SMTP id r11-20020a5d4e4b000000b001575c5ed4b4so1741908wrt.4 for ; Fri, 03 Sep 2021 09:06:40 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (163.red-83-52-55.dynamicip.rima-tde.net. [83.52.55.163]) by smtp.gmail.com with ESMTPSA id u26sm5665419wrd.32.2021.09.03.09.06.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 09:06:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630685202; 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=XHKyr01gvCx97VAfaYZAMWFLuahjopao8xNghsdJ+1c=; b=GC5MqMzfaAjY/GZdn/hWygvNLKnF6LKm47i+HPU3w5az/866vB5xNpTCD7lWM2p0/0mjnm ESt6xtimcHFNdGX64twbH9XCRjpZoeuJgjTk48X0HNyJ7ifs0Aj3O7rovZnZCfUIIcBNzl 3AeQU0oF4Xrk22hrqpEoPGVbYzao0uk= X-MC-Unique: gqUBPWFiOtKQL5aa2IQg4w-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=XHKyr01gvCx97VAfaYZAMWFLuahjopao8xNghsdJ+1c=; b=JmxAmB+cgmSKzZv2lNr8ElCDxxr5vVFeLblRqm+XHhMTAgqK39hsQpWvX0VjwHue1l H75km+g9xTzEQA3khE+xBzxEir3zhwRngHt+DuUdPpunEuyF5CEyAq1zifjxLJPsOtmj g+INmFD0YEt9n8RKkvgj2t0/GsZlW3m6bYUduz+0fX2/3A4/dOmWymQWJanK51MQyi4g d1mSws851RZb8idwqW2b4UhIQchW6Rypg0jb1sXDDlmheeTuNhQQZN/XYKVXj6x2/FW3 GA+3d0/GbCyYNClvsYgzKPhRxubvPiuK4RYNrZUnOy/lwofd5+maN92+TOeWs9LWT4gY 4yIQ== X-Gm-Message-State: AOAM531s1noqufHdzedyFm5HnKn/tRo2fPdVRYvD3sWxdSgN0aDViC6g tMMHk9IYuLHHw/kimFXY2IKDaV9kx8cvhmGSj6ZxwXI9t4vGFU+Q4ne6IIN8jxQjppi+u3mB5WZ rTNKu8aYvLAjEZA== X-Received: by 2002:adf:eb4a:: with SMTP id u10mr4966542wrn.11.1630685199034; Fri, 03 Sep 2021 09:06:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzEtBcypaANIpk24VNzSMdqsmFYCjA6xLEra1WnI+b7ZOi+mRtmxlas4iwjphY4vBQL+5gncQ== X-Received: by 2002:adf:eb4a:: with SMTP id u10mr4966508wrn.11.1630685198835; Fri, 03 Sep 2021 09:06:38 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , David Hildenbrand , Gerd Hoffmann , Peter Xu , Mark Cave-Ayland , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell Subject: [PATCH v6 2/2] memory: Have 'info mtree' remove duplicated Address Space information Date: Fri, 3 Sep 2021 18:06:19 +0200 Message-Id: <20210903160619.699632-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210903160619.699632-1-philmd@redhat.com> References: <20210903160619.699632-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: 1630685205762100001 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu --- checkpatch warning (81 chars): WARNING: line over 80 characters #86: FILE: softmmu/memory.c:3348: + address_space_compare_name); --- softmmu/memory.c | 62 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 5be7d5e7412..8311b33ce6a 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3284,20 +3284,76 @@ 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