From nobody Tue May 7 16:09:48 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=1630513195; cv=none; d=zohomail.com; s=zohoarc; b=EhD+/OcPia5+fgNH8feB+CHDvjKL1wBrKg+HXqRcxVK1Vrdw9kTmUWL+imbIhS2ZW8126eXDpuItAE29uQLGzi5UVWhsYXRCVBVenZJTJGvTI0xc+Z1ZUmWWj62bQwmixah1cyrDM2vHDfzPyQfxZyitJdsHHFQq0U/VJ6p31ps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630513195; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=tAiJThYlf1S7x56S9WL4YRBDxzxck2gItvUxPEZ3WZ0=; b=i3pLfPOuNdp/QHLfP+V5dZR2MhWWUEA1LGJAnJ3vu+j/duaj2IY/Yu/2X0eLlzPNThypkwPjKqz43bdol/4hysIYuKfm0uW/tJjguobBW7aMkroPhUQYJ4KbmA2Wqs55Se1x8lk0DWalgwkSr/BschWExf5IpSL43u12i7RTCQM= 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 1630513195487594.5253455842079; Wed, 1 Sep 2021 09:19:55 -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-117-Pr-UOv1EM0GtoJ92kO_Qrg-1; Wed, 01 Sep 2021 12:19:50 -0400 Received: by mail-wm1-f70.google.com with SMTP id m16-20020a7bca50000000b002ee5287d4bfso20844wml.7 for ; Wed, 01 Sep 2021 09:19:50 -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 o15sm6273559wra.3.2021.09.01.09.19.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 09:19:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630513194; 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=tAiJThYlf1S7x56S9WL4YRBDxzxck2gItvUxPEZ3WZ0=; b=U6crk7wUmttDgntYBlQDUYTsR251dkdo73g0IuKz7YQFXa9X6WfToTgFCd72hpE5FB71Dg phZAoyo0DdNlcO/D/g5We8ZHkLjhoRCwXLYMXIBtRzlVcj1OI5yv4AKFFOHqZ1+pDj8r/d EvUteoq6QLRXygs5fBQ1bMCcfGH7CZg= X-MC-Unique: Pr-UOv1EM0GtoJ92kO_Qrg-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=tAiJThYlf1S7x56S9WL4YRBDxzxck2gItvUxPEZ3WZ0=; b=XpqwAQJgZmEZkn429UaYdxGP7s7D9kLmBfX2h934g3WxF344RfWbyEkbi0MygVqor7 EvR8ORGnvHdHH9VdgmwoGPLnkAoFzb3O/2/aSB+/R8PVrq9P8VNOLMAdEzBjTUd9xI2N EK+PFWB1NombfABEYC59SHct8auFEZj3sGvdVCGk5FYS/zzxslD8zAiE/M0UF3b0igci dBv222+Te66PC+mY+3NkPTGO6BAsKVqNBycp+iYyFb9Eu+wq5qjY/9iGMM+pulXXfrTO bFdmACkwHCUevBevZCeyUXd/jhvNnodj4iXqCcnwue/GB4FTf8H6m2r2FIMIF3Dp+NSu M/Ww== X-Gm-Message-State: AOAM532EAZazF6O/xVZ1R65H4fl9ViV/ckyJ8+rQ8WHOQXZgkxrKgQTY 7gOlkkKb6SfY3QYPgD0bWo4xyFHu3BBSu9EaBeSml0dPIXTurhsX2mcdqArvLMx5x8h//dmfaH1 RUPxwhHbcBbLS/Q== X-Received: by 2002:adf:fd8c:: with SMTP id d12mr186608wrr.21.1630513189689; Wed, 01 Sep 2021 09:19:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQUi9fb8zCAfTxFoBTcrpsjRDxcs2UQiylWLGolXdY2BluMogTiqqv3xmyf20DdhU1/3WS7w== X-Received: by 2002:adf:fd8c:: with SMTP id d12mr186589wrr.21.1630513189532; Wed, 01 Sep 2021 09:19:49 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Peter Xu , Gerd Hoffmann , Mark Cave-Ayland , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell Subject: [PATCH v4 1/3] memory: Extract mtree_info_flatview() from mtree_info() Date: Wed, 1 Sep 2021 18:19:41 +0200 Message-Id: <20210901161943.4174212-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210901161943.4174212-1-philmd@redhat.com> References: <20210901161943.4174212-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: 1630513196969100003 While mtree_info() handles both ASes and flatviews cases, the two cases share basically no code. Split mtree_info_flatview() out of mtree_info() to simplify. Note: Patch easier to review using 'git-diff --color-moved=3Dblocks'. Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: David Hildenbrand Reviewed-by: Richard Henderson --- softmmu/memory.c | 72 ++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index bfedaf9c4df..3eb6f52de67 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3246,6 +3246,44 @@ static gboolean mtree_info_flatview_free(gpointer ke= y, gpointer value, return true; } =20 +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); +} + void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabl= ed) { MemoryRegionListHead ml_head; @@ -3253,39 +3291,7 @@ void mtree_info(bool flatview, bool dispatch_tree, b= ool owner, bool disabled) 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); + mtree_info_flatview(dispatch_tree, owner); =20 return; } --=20 2.31.1 From nobody Tue May 7 16:09:48 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=1630513198; cv=none; d=zohomail.com; s=zohoarc; b=Pd5QPd+KzqLVHo5Uv94TFnQ4A1r1oA3BXabrurkUF2rpxGE77LARrDXymSsLfuSuX+anvGrZGHiUfkPEFi9rYyW82yidTdS/kYelq1Li2/nFB0b6unVyXkSXlOGMQ6e8KWibQfDgNXPXvr65EgVP/AWL2TtbaA5fKgbMcstQi18= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630513198; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=Kk7AoJgI8qARtyKWpkBg86PldAYgZZy6ZQx9AZo/Lg8=; b=SkRt14UkN1qMKo1PcpIngk/GNUNZGSuYZQZY/rfY+CWLRPFKgSehCLmrsuz4u1G7ze4KCJg8jmI1iICB+zdQZ9ehRDt1SprnDPWMz2AiPHlUcyaLuydMPqdtwIYORE80xXuRQvCkXbPpPMh38H4cWS93Fp5KeW0gSntlbcWH9dM= 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 1630513198491588.5042496780931; Wed, 1 Sep 2021 09:19:58 -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-559-lK98YFlQOECqjoz993o7Qw-1; Wed, 01 Sep 2021 12:19:56 -0400 Received: by mail-wm1-f71.google.com with SMTP id g3-20020a1c2003000000b002e751c4f439so23860wmg.7 for ; Wed, 01 Sep 2021 09:19:56 -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 f17sm25160170wrt.63.2021.09.01.09.19.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 09:19:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630513197; 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=Kk7AoJgI8qARtyKWpkBg86PldAYgZZy6ZQx9AZo/Lg8=; b=X310MQnEW0RBvGXRyedkAGRt3UpvgzUSjzsWnEGk/bcWSlOBTOvjo8ZFo90vyFiXAlkxap PoQkJnmFbfzfE+b3Qj9HpMCNH77XD928Ah0fLy3vcXh3fBDobV/y9ZRh8M4JTxFchuoy0A llHv/cFNXepi6QkV8zBHpaT+ulm8qIY= X-MC-Unique: lK98YFlQOECqjoz993o7Qw-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=Kk7AoJgI8qARtyKWpkBg86PldAYgZZy6ZQx9AZo/Lg8=; b=IcdCtZSKq9+I2HipOx/O6OIIfhULlV99R4PTjiEoEZai0wLGsOolwLfmyH3O2Jzh3/ CGm2T32YH6bKDKLXGlB0XHyO3wDUjIFQfPBRw7W2V0Uvvbd0SSKjCVmYdE1m7FAiT30h CJarpXWZD5D/zaXwA8XYnAfzw0jJLak/ksNLCW/ignTkDfhztqAFuR+dCz5Uuul9Ve8l C2cdQ6knqAdTfSGg8IyfCdMLWxEXpWAgtXS9grw92Lhf46VzOqei4LnqdQEslLKgtLzg 8wkk1p6cHyJrmJ1eyTyHA7pN5J9n7eznoylHEk5HrnL3/E8jRqD0PGmDIq/P87Eir1Qq wYKg== X-Gm-Message-State: AOAM532S9pVP+M3axqb7KmZjD2NOAkMMp+1B7SgXx3ECDKfQd0cQsItC qkfb5QK/XXljYnAl6sCjMM5fWwnDOAcfeDYudMTE5YXaFJ8qb4Pc2QtYSTvXLBhDLZuKwu/RhGB 4qhExrFtj5qsd9A== X-Received: by 2002:adf:a2c4:: with SMTP id t4mr208613wra.258.1630513194405; Wed, 01 Sep 2021 09:19:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXtjZrT9i4QhHU7/wjj9AHlEXNgoQApqEN/duEol5J/c/TZeHwzBqCWcrDF/6SnClSX0v8Ew== X-Received: by 2002:adf:a2c4:: with SMTP id t4mr208587wra.258.1630513194282; Wed, 01 Sep 2021 09:19:54 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Peter Xu , Gerd Hoffmann , Mark Cave-Ayland , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell Subject: [PATCH v4 2/3] memory: Extract mtree_info_as() from mtree_info() Date: Wed, 1 Sep 2021 18:19:42 +0200 Message-Id: <20210901161943.4174212-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210901161943.4174212-1-philmd@redhat.com> References: <20210901161943.4174212-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: 1630513199618100001 While mtree_info() handles both ASes and flatviews cases, the two cases share basically no code. Split mtree_info_as() out of mtree_info() to simplify. Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: David Hildenbrand Reviewed-by: Richard Henderson --- softmmu/memory.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 3eb6f52de67..5be7d5e7412 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3284,18 +3284,12 @@ static void mtree_info_flatview(bool dispatch_tree,= bool owner) g_hash_table_unref(views); } =20 -void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabl= ed) +static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled) { MemoryRegionListHead ml_head; MemoryRegionList *ml, *ml2; AddressSpace *as; =20 - if (flatview) { - mtree_info_flatview(dispatch_tree, owner); - - return; - } - QTAILQ_INIT(&ml_head); =20 QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { @@ -3316,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 Tue May 7 16:09:48 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=1630513204; cv=none; d=zohomail.com; s=zohoarc; b=JTI/JANg+fzGwLOGkF0uAK3L8eLh16JVS6s7qCHzQANZt52B0oRa0QBhJ36impb0eTLbZud4lV7SXFAQx5CcLXOLfeOGNctsN9i8+pOAtYEPw0N0n/h6G433Me2TTDi1ufmDBS1cIt+zJZDi97nMU89vATnNpF6/u101vTOOyvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630513204; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=mqZ4QMnle7fwtbPQ8ukScqFi6F88Fa50C7r2uFtQeyM=; b=ZHK8cSv3JL8IRMCYr88+hO4o9ZWjqsn3H5y4Qr5Km/Er/3Z0ifA1i0bC2gnCptcmvilnpdljGm0JyxaoMzaKPqMQ0AgOVNDZyVklbbPN4HtxSknOJb6HqN8C0eqHpacXoy4A7WTyktJReAmf4AWDB3Yq7pa/rREQBRqZZO539eg= 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 1630513204340820.456740373197; Wed, 1 Sep 2021 09:20:04 -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-600-j_THssdWPL2XbKjLFJ2CKw-1; Wed, 01 Sep 2021 12:20:00 -0400 Received: by mail-wm1-f71.google.com with SMTP id u1-20020a05600c210100b002e74fc5af71so95791wml.1 for ; Wed, 01 Sep 2021 09:20:00 -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 c14sm35251wme.6.2021.09.01.09.19.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Sep 2021 09:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630513203; 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=mqZ4QMnle7fwtbPQ8ukScqFi6F88Fa50C7r2uFtQeyM=; b=UobSzUL41m+CqubmMrdEgpXDNOWYukhARfrSkTkUMnJxCmIQAheofoSxNTQcKua6AlowWj jBqrUjd8wErieRegdSwY3s+wAjHAxh7SL0NZo4rdqpTCNeZOlIfglseGTsDnT+0NL5eIol PmHDkbHSEMRGHh0s21AQrGmMbvE00K4= X-MC-Unique: j_THssdWPL2XbKjLFJ2CKw-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=mqZ4QMnle7fwtbPQ8ukScqFi6F88Fa50C7r2uFtQeyM=; b=JlnzyB7fShx8inUglJrVyGEPiODA+xlVGcmXx0ZZ4wzEkxOHNhTgB+FHROf1Dx2ASI EmHdgYpaMbVUhoeWWTVTNxbTb5Na/hsOrVzvkRtah6Y3ck+1yFc+toVoX6TiUxCewYa2 Yrc2ImDP+nrp2zbVqV1RtEKRX+xzIC72z6vfJBWM6YzHSyz9wSp6sxlnoXbrYvpP/Arq 6AqrYEVyhT0mrqnQtI2DDxj4yXowq9AjCL8H+nDVsdP/nGWU3bkmw00R1OjbqThTJQXl daE/BqPzCr9EQxMM4k1kJY6QUD69Uhr77TsHtms8irDUXqEn3hjDZIIXoKbzImrx1EJc ZVug== X-Gm-Message-State: AOAM531bA9PFFSLxD12AZUvnUfLgybIx8ANmfxGN4EfnjzcPUcMaf0Ab OR/fh5xUaw0dtKMGu3EY+fQVdiNJaiUgKtPa/l1Wdpf0tspJey+DKXFkUxpKA9hKo/ibXXzCS52 d1T/1Iqo0SaFdaA== X-Received: by 2002:a05:6000:10:: with SMTP id h16mr244903wrx.24.1630513199076; Wed, 01 Sep 2021 09:19:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4xo6F5HQUokXPtwznbTKoGysNObIhUiaFtcFWNOFqCBC9jQI/Vw+2Ea7S66iykJS4SPtyCA== X-Received: by 2002:a05:6000:10:: with SMTP id h16mr244865wrx.24.1630513198812; Wed, 01 Sep 2021 09:19:58 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Peter Xu , Gerd Hoffmann , Mark Cave-Ayland , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell Subject: [PATCH v4 3/3] memory: Have 'info mtree' remove duplicated Address Space information Date: Wed, 1 Sep 2021 18:19:43 +0200 Message-Id: <20210901161943.4174212-4-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210901161943.4174212-1-philmd@redhat.com> References: <20210901161943.4174212-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: 1630513204673100004 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 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: David Hildenbrand Reviewed-by: Richard Henderson --- Pending question from David on v3: We can still distinguish from a completely empty AS, because we don't hav= e an empty line here, correct? checkpatch warning (81 chars): WARNING: line over 80 characters #86: FILE: softmmu/memory.c:3359: + address_space_compare_name); --- softmmu/memory.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/softmmu/memory.c b/softmmu/memory.c index 5be7d5e7412..9be2017bc38 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -3282,6 +3282,59 @@ static void mtree_info_flatview(bool dispatch_tree, = bool owner) /* Free */ g_hash_table_foreach_remove(views, mtree_info_flatview_free, 0); g_hash_table_unref(views); + + return; +} + +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; } =20 static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled) @@ -3289,15 +3342,29 @@ 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