From patchwork Mon Jan 16 08:40:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 715620 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3v26G66HStz9stc for ; Mon, 16 Jan 2017 19:43:41 +1100 (AEDT) Received: from localhost ([::1]:55055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cT2t8-00052I-Oz for incoming@patchwork.ozlabs.org; Mon, 16 Jan 2017 03:43:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39836) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cT2pt-0002M2-5O for qemu-devel@nongnu.org; Mon, 16 Jan 2017 03:40:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cT2ps-0000sb-78 for qemu-devel@nongnu.org; Mon, 16 Jan 2017 03:40:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36038) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cT2pr-0000sD-Tr for qemu-devel@nongnu.org; Mon, 16 Jan 2017 03:40:16 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DB073D94D; Mon, 16 Jan 2017 08:40:16 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-227.nay.redhat.com [10.66.14.227]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0G8e9h9013587; Mon, 16 Jan 2017 03:40:14 -0500 From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 16 Jan 2017 16:40:05 +0800 Message-Id: <1484556005-29701-3-git-send-email-peterx@redhat.com> In-Reply-To: <1484556005-29701-1-git-send-email-peterx@redhat.com> References: <1484556005-29701-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 16 Jan 2017 08:40:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 2/2] memory: hmp: add "-f" for "info mtree" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, marcandre.lureau@gmail.com, "Dr . David Alan Gilbert" , peterx@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Adding one more option "-f" for "info mtree" to dump the flat views of all the address spaces. This will be useful to debug the memory rendering logic, also it'll be much easier with it to know what memory region is handling what address range. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert --- hmp-commands-info.hx | 6 +++--- include/exec/memory.h | 2 +- memory.c | 41 ++++++++++++++++++++++++++++++++++++++++- monitor.c | 4 +++- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 55d50c4..b0f35e6 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -249,9 +249,9 @@ ETEXI { .name = "mtree", - .args_type = "", - .params = "", - .help = "show memory tree", + .args_type = "flatview:-f", + .params = "[-f]", + .help = "show memory tree (-f: dump flat view for address spaces)", .cmd = hmp_info_mtree, }, diff --git a/include/exec/memory.h b/include/exec/memory.h index bec9756..71db380 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1254,7 +1254,7 @@ void memory_global_dirty_log_start(void); */ void memory_global_dirty_log_stop(void); -void mtree_info(fprintf_function mon_printf, void *f); +void mtree_info(fprintf_function mon_printf, void *f, bool flatview); /** * memory_region_dispatch_read: perform a read directly to the specified diff --git a/memory.c b/memory.c index c42bde4..6498727 100644 --- a/memory.c +++ b/memory.c @@ -2564,12 +2564,51 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f, } } -void mtree_info(fprintf_function mon_printf, void *f) +static void mtree_print_flatview(fprintf_function p, void *f, + AddressSpace *as) +{ + FlatView *view = address_space_get_flatview(as); + FlatRange *range = &view->ranges[0]; + MemoryRegion *mr; + int n = view->nr; + + if (n <= 0) { + p(f, MTREE_INDENT "No rendered FlatView for " + "address space '%s'\n", as->name); + flatview_unref(view); + return; + } + + while (n--) { + mr = range->mr; + p(f, MTREE_INDENT TARGET_FMT_plx "-" + TARGET_FMT_plx " (prio %d, %s): %s\n", + int128_get64(range->addr.start), + int128_get64(range->addr.start) + MR_SIZE(range->addr.size), + mr->priority, + memory_region_type(mr), + memory_region_name(mr)); + range++; + } + + flatview_unref(view); +} + +void mtree_info(fprintf_function mon_printf, void *f, bool flatview) { MemoryRegionListHead ml_head; MemoryRegionList *ml, *ml2; AddressSpace *as; + if (flatview) { + QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { + mon_printf(f, "address-space (flat view): %s\n", as->name); + mtree_print_flatview(mon_printf, f, as); + mon_printf(f, "\n"); + } + return; + } + QTAILQ_INIT(&ml_head); QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { diff --git a/monitor.c b/monitor.c index 0841d43..679cd52 100644 --- a/monitor.c +++ b/monitor.c @@ -1529,7 +1529,9 @@ static void hmp_boot_set(Monitor *mon, const QDict *qdict) static void hmp_info_mtree(Monitor *mon, const QDict *qdict) { - mtree_info((fprintf_function)monitor_printf, mon); + bool flatview = qdict_get_try_bool(qdict, "flatview", false); + + mtree_info((fprintf_function)monitor_printf, mon, flatview); } static void hmp_info_numa(Monitor *mon, const QDict *qdict)