From patchwork Wed Sep 1 16:19:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1523315 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=U7OHc+er; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H098b1Pjyz9sX3 for ; Thu, 2 Sep 2021 02:52:31 +1000 (AEST) Received: from localhost ([::1]:43794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLTTQ-0006i2-Lp for incoming@patchwork.ozlabs.org; Wed, 01 Sep 2021 12:52:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLSxv-0002Is-45 for qemu-devel@nongnu.org; Wed, 01 Sep 2021 12:19:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45320) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLSxt-0003ni-KN for qemu-devel@nongnu.org; Wed, 01 Sep 2021 12:19:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630513192; 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=U7OHc+er9yo/3xPSHuppzPwqCBUQgggL3n9fRI0liqx6PdyqoiBRDRSOlbq25WRasbuY8G ZzwueNnzs95EZeJJhpUwN9/Ux9KU1gwyp551I6h53PVaBdJKbusQsRuVLGLClzQRdcwcPE FMarzJgl+Dfg4vuwPCGt45xNW4xalcM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-515-R8k2YsKLO7GkQQwm-TuJ_g-1; Wed, 01 Sep 2021 12:19:51 -0400 X-MC-Unique: R8k2YsKLO7GkQQwm-TuJ_g-1 Received: by mail-wm1-f69.google.com with SMTP id p5-20020a7bcc85000000b002e7563efc4cso24928wma.4 for ; Wed, 01 Sep 2021 09:19:51 -0700 (PDT) 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=Hu3UEKIcEvTSFpBz/bXeowKBWLklBxB9b8e2nlbdxaTjq1mujuk7yNR/SLWEjWclxa 4nZWZaeWUXSr4+UOs6sJutKli4KNjbwQAFbyPhS/4MKzvMh3R9XovdXmLAZEVf0NUHIO H78zGNMNMUOqzlxT7TWHQkwYk/aPVOk3YB+GY9yhOQYGjDEijbdh5zgGQ0jUozcGE/V6 bvZNZ3rr4yqCyg5NKzgB/93vDQ69md0KCJV8wHIw+p5oqRAUEzPxrrDJNtddLSH5yOwI 2Uc1D9YL+OnIIWr+MLHf54xuRs2HQYCfRq7pD3Dm5HVM2LbPi2pkN6RoPQJKaNmdWHpl PwtA== X-Gm-Message-State: AOAM5333DO7WKTNUeDqhDaF2kzPO+CoIGYKcrRms9BwoY6T0TP/ZzFqJ b66+BAZlR8vT7SBvvs4gnlGGtO+SMTAuRQEI1tyjDKjLgOXGQ7ORk0mOuJUYdd2v8LQXSPbqW0b JbX6fBe4GhOmJ1MRjElwCW75I5bz2VUfczk3NiUa/p1zsy2rLHnylGZ/55P4vGf0Z X-Received: by 2002:adf:fd8c:: with SMTP id d12mr186613wrr.21.1630513189712; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.392, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , David Hildenbrand , Mark Cave-Ayland , Peter Xu , Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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=blocks'. Suggested-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daudé 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 key, gpointer value, return true; } +static void mtree_info_flatview(bool dispatch_tree, bool owner) +{ + struct FlatViewInfo fvi = { + .counter = 0, + .dispatch_tree = dispatch_tree, + .owner = owner, + }; + AddressSpace *as; + FlatView *view; + GArray *fv_address_spaces; + GHashTable *views = g_hash_table_new(g_direct_hash, g_direct_equal); + AccelClass *ac = ACCEL_GET_CLASS(current_accel()); + + if (ac->has_memory) { + fvi.ac = ac; + } + + /* Gather all FVs in one table */ + QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { + view = address_space_get_flatview(as); + + fv_address_spaces = g_hash_table_lookup(views, view); + if (!fv_address_spaces) { + fv_address_spaces = 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 disabled) { MemoryRegionListHead ml_head; @@ -3253,39 +3291,7 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled) AddressSpace *as; if (flatview) { - FlatView *view; - struct FlatViewInfo fvi = { - .counter = 0, - .dispatch_tree = dispatch_tree, - .owner = owner, - }; - GArray *fv_address_spaces; - GHashTable *views = g_hash_table_new(g_direct_hash, g_direct_equal); - AccelClass *ac = ACCEL_GET_CLASS(current_accel()); - - if (ac->has_memory) { - fvi.ac = ac; - } - - /* Gather all FVs in one table */ - QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { - view = address_space_get_flatview(as); - - fv_address_spaces = g_hash_table_lookup(views, view); - if (!fv_address_spaces) { - fv_address_spaces = 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); return; } From patchwork Wed Sep 1 16:19:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1523285 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hv2oCGEQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H08Wt5jvmz9sX3 for ; Thu, 2 Sep 2021 02:24:10 +1000 (AEST) Received: from localhost ([::1]:45326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLT20-0008Pp-Ij for incoming@patchwork.ozlabs.org; Wed, 01 Sep 2021 12:24:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLSy0-0002VW-Oq for qemu-devel@nongnu.org; Wed, 01 Sep 2021 12:20:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53613) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLSxz-0003rJ-2g for qemu-devel@nongnu.org; Wed, 01 Sep 2021 12:20:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630513198; 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=hv2oCGEQlD6ZyWXNg0bQplsZ2qlw5Pudm8w9rOWBqSlUr+18HL5P0knQGiH+IDiH+sc7Dx Dp+wXVXOxAKHPe/bdRt5TpsbSBbaN27AVdxhxywXY1C/++9LgEn7D5okWm8r7pRpB4V/sl Oyo2RoHazY9ZQ3Dd6+GZFjY2OIkhidg= 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-24-Hd8ZrFhmPauieLtUqaPgkw-1; Wed, 01 Sep 2021 12:19:57 -0400 X-MC-Unique: Hd8ZrFhmPauieLtUqaPgkw-1 Received: by mail-wr1-f70.google.com with SMTP id t15-20020a5d42cf000000b001565f9c9ee8so87844wrr.2 for ; Wed, 01 Sep 2021 09:19:56 -0700 (PDT) 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=FCrDhVQhwX9ZON30wEckqfdsTcTYrLzF+/U7tEe5g8svVkbq90750mwvyyroUXp5LZ c1ILKTbDvqgBCnyVja0pZg5zIps9y4YGFBz8XYKN5D76aboCX5d1k6c5OD2YWQxlX+qY gBnCLnY86KWK1eYIFbQOZoC+Lap46VUjMX7FV/L6RsmUUDLFEhibxMjTL9qIt02LZYu2 mn5JzAhQpDrqOaDEgZhLkMyKL97WJ6Szl6hkTJhAoYmHMItT+u7fTkm8qb5fR9qHAg7K EJ+OUE1McYZvd4m3xM0cu3a65nQ3nnkIYypufWTvRr8c9x98E+jmeYZqOsL4jmhPv3OH L6zw== X-Gm-Message-State: AOAM531CLki8hejiWjh4++lmfdXWKaBeOgcn1GW0xB2sznqPBo64cjx+ jq28HcC439GugnYAk/RoITCeHwNZsGv+EkwxAFvL7/niPjNsI/XcVG41gQKhHHyEYL7UUOGZjHH Tm1iDB4jim6wtcDfRvXuNtzwicY+2YnMUd2qeubmua9HqIP9w3vRmQlBWZ4sTQgao X-Received: by 2002:adf:a2c4:: with SMTP id t4mr208616wra.258.1630513194436; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.392, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , David Hildenbrand , Mark Cave-Ayland , Peter Xu , Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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é 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); } -void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled) +static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled) { MemoryRegionListHead ml_head; MemoryRegionList *ml, *ml2; AddressSpace *as; - if (flatview) { - mtree_info_flatview(dispatch_tree, owner); - - return; - } - QTAILQ_INIT(&ml_head); QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { @@ -3316,6 +3310,15 @@ void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled) } } +void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled) +{ + 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, From patchwork Wed Sep 1 16:19:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1523290 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UobSzUL4; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H08Zy2h8Mz9sCD for ; Thu, 2 Sep 2021 02:26:50 +1000 (AEST) Received: from localhost ([::1]:54138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mLT4a-0005uY-66 for incoming@patchwork.ozlabs.org; Wed, 01 Sep 2021 12:26:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLSyD-0002qw-4z for qemu-devel@nongnu.org; Wed, 01 Sep 2021 12:20:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20506) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mLSy4-0003wh-D5 for qemu-devel@nongnu.org; Wed, 01 Sep 2021 12:20:12 -0400 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= 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-191-ngfFs-AHNoqIDtJVsehEKw-1; Wed, 01 Sep 2021 12:20:00 -0400 X-MC-Unique: ngfFs-AHNoqIDtJVsehEKw-1 Received: by mail-wr1-f69.google.com with SMTP id t15-20020a5d42cf000000b001565f9c9ee8so87905wrr.2 for ; Wed, 01 Sep 2021 09:20:00 -0700 (PDT) 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=CW8kViNn0ey8N5loM39MXAEYAxSCh89wfy42SegPp+6/r27uik2X9Hhd58/mbzWq5k JU7Fdj5WbvAKNY30vrvPrAr2mMF1uKorvKZDxceZOPmUPQbXm71SVOwTgtsVYfFwnv/n 3kH+5St19M/toZ86iqvFJBQ42MA+n+KQxLbMAXuM2ZbDXev2557eTRSHvl7cdadzR5wZ +bMtzEsjFuACyA4zevs+B8ETlyX6pQWSeAkocrWPXeVfI88BV8WpGweg22XqkXc0/6uN IHZu81iU8ZSXITo8yQROhihpsVlR+zZyf4eV/Etpy9n+2i/85AD9subs6O17n+6PkXYy BvvA== X-Gm-Message-State: AOAM532M59dEHKDlOOMVUQjmWHyhk6f33HeG6uTPX2fARsm0dDJ/fjBp PPd8nHdKIbILFpLBIO9stJY75GzeelQjxDc72ip1UdcYwbU13qoOxKc9YLP84PkoAvHleIKntwu 2fYNSXkzhMxbovsiffqRFDAgQsOR9hUkkbvea6giKPvQCe4D53hfj8HFLbqJxCpse X-Received: by 2002:a05:6000:10:: with SMTP id h16mr244921wrx.24.1630513199164; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.392, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , David Hildenbrand , Mark Cave-Ayland , Peter Xu , Gerd Hoffmann , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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-ram-alias[*] @ram 0000000000000000-000000003fffffff 0000000040000000-000000007fffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 000000007e000000-000000007effffff (prio 1, i/o): alias bcm2835-peripherals @bcm2835-peripherals 0000000000000000-0000000000ffffff 0000000080000000-00000000bfffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff 00000000c0000000-00000000ffffffff (prio 0, ram): alias bcm2835-gpu-ram-alias[*] @ram 0000000000000000-000000003fffffff address-space: bcm2835-mbox-memory 0000000000000000-000000000000008f (prio 0, i/o): bcm2835-mbox 0000000000000010-000000000000001f (prio 0, i/o): bcm2835-fb 0000000000000080-000000000000008f (prio 0, i/o): bcm2835-property 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é 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 have 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 = b; positive value if a > b. */ +static gint address_space_compare_name(gconstpointer a, gconstpointer b) +{ + const AddressSpace *as_a = a; + const AddressSpace *as_b = b; + + return g_strcmp0(as_a->name, as_b->name); +} +static void mtree_print_as_name(gpointer data, gpointer user_data) +{ + AddressSpace *as = data; + + qemu_printf(" - %s\n", as->name); +} + +static void mtree_print_as(gpointer key, gpointer value, gpointer user_data) +{ + MemoryRegion *mr = key; + GSList *as_same_root_mr_list = value; + struct AddressSpaceInfo *asi = user_data; + guint same_root_len = g_slist_length(as_same_root_mr_list); + + if (same_root_len == 1) { + AddressSpace *as = g_slist_nth_data(as_same_root_mr_list, 0); + + qemu_printf("address-space: %s\n", as->name); + } else { + qemu_printf("address-space shared %u times:\n", same_root_len); + g_slist_foreach(as_same_root_mr_list, mtree_print_as_name, NULL); + } + mtree_print_mr(mr, 1, 0, asi->ml_head, asi->owner, asi->disabled); + qemu_printf("\n"); +} + +static gboolean mtree_info_as_free(gpointer key, gpointer value, + gpointer user_data) +{ + GSList *as_same_root_mr_list = value; + + g_slist_free(as_same_root_mr_list); + + return true; } static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled) @@ -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 = g_hash_table_new(g_direct_hash, g_direct_equal); + GSList *as_same_root_mr_list; + struct AddressSpaceInfo asi = { + .ml_head = &ml_head, + .owner = owner, + .disabled = disabled, + }; QTAILQ_INIT(&ml_head); QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { - qemu_printf("address-space: %s\n", as->name); - mtree_print_mr(as->root, 1, 0, &ml_head, owner, disabled); - qemu_printf("\n"); + /* Create hashtable, key=AS root MR, value = list of AS */ + as_same_root_mr_list = g_hash_table_lookup(views, as->root); + as_same_root_mr_list = g_slist_insert_sorted(as_same_root_mr_list, as, + address_space_compare_name); + g_hash_table_insert(views, as->root, as_same_root_mr_list); } + /* print address spaces */ + g_hash_table_foreach(views, mtree_print_as, &asi); + g_hash_table_foreach_remove(views, mtree_info_as_free, 0); + g_hash_table_unref(views); + /* print aliased regions */ QTAILQ_FOREACH(ml, &ml_head, mrqueue) { qemu_printf("memory-region: %s\n", memory_region_name(ml->mr));