From patchwork Mon Sep 26 20:03:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Blue Swirl X-Patchwork-Id: 116475 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9160AB6F72 for ; Tue, 27 Sep 2011 06:04:06 +1000 (EST) Received: from localhost ([::1]:59445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8HPB-00042g-52 for incoming@patchwork.ozlabs.org; Mon, 26 Sep 2011 16:03:57 -0400 Received: from eggs.gnu.org ([140.186.70.92]:48057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8HOz-00040l-I3 for qemu-devel@nongnu.org; Mon, 26 Sep 2011 16:03:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R8HOx-0007Am-JD for qemu-devel@nongnu.org; Mon, 26 Sep 2011 16:03:45 -0400 Received: from mail-qy0-f173.google.com ([209.85.216.173]:52744) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R8HOx-0007Ai-De for qemu-devel@nongnu.org; Mon, 26 Sep 2011 16:03:43 -0400 Received: by qyc1 with SMTP id 1so97858qyc.4 for ; Mon, 26 Sep 2011 13:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; bh=K8F6zjWw6FGsME83lfNXo61qXPupjPOLc0jN2K51VNQ=; b=Jnnrq2Yctgdzq4GgNT1WmFDSF0cFty3VI25X+nCK3sE1gRoBsQzXseVSMMn7Tqj7Zg tC3s6gCJE2T5k+avH8HM1Vyvitct1P+2fYgKZj4Ds2s7abhGCoaesenXr5XWPCEvxcOv +fnA5aWiNLyUHBqhVAVcl2e6eDjCpdKXHVCwk= Received: by 10.224.210.137 with SMTP id gk9mr5294769qab.209.1317067422139; Mon, 26 Sep 2011 13:03:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.6.129 with HTTP; Mon, 26 Sep 2011 13:03:22 -0700 (PDT) From: Blue Swirl Date: Mon, 26 Sep 2011 20:03:22 +0000 Message-ID: To: Avi Kivity , qemu-devel X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.216.173 Subject: [Qemu-devel] [PATCH v3] memory: simple memory tree printer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add a monitor command 'info mtree' to show the memory hierarchy much like /proc/iomem in Linux. Signed-off-by: Blue Swirl --- The alias addresses are unbiased (PPC): 00000000-fffffffe : system 800a0000-800affff : alias vga.chain4 @vga.vram 00000000-0000ffff 80880000-808fffff : macio 808e0000-808fffff : macio-nvram 808a0000-808a0fff : pmac-ide 80896000-80895fff : (null) 80893000-8089303f : alias escc-bar @escc 00000000-0000003f 80888000-80888fff : dbdma 80880000-80880fff : heathrow-pic 80800000-8080ffff : vga.rom 80000000-807fffff : vga.vram 800a0000-800bffff : vga-lowmem 80013000-8001303f : escc fee00000-fee00fff : pci-data-idx fec00000-fec00fff : pci-conf-idx fe000000-fe1fffff : isa-mmio vga.vram 80000000-807fffff : vga.vram escc 80013000-8001303f : escc --- memory.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ memory.h | 2 + monitor.c | 13 +++++++++ 3 files changed, 103 insertions(+), 0 deletions(-) From dd0361fce6a49705ae1ee372f714d964619c96bb Mon Sep 17 00:00:00 2001 Message-Id: From: Blue Swirl Date: Sun, 11 Sep 2011 20:22:05 +0000 Subject: [PATCH] memory: simple memory tree printer Add a monitor command 'info mtree' to show the memory hierarchy much like /proc/iomem in Linux. Signed-off-by: Blue Swirl --- memory.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ memory.h | 2 + monitor.c | 13 +++++++++ 3 files changed, 103 insertions(+), 0 deletions(-) diff --git a/memory.c b/memory.c index 71e769e..53264be 100644 --- a/memory.c +++ b/memory.c @@ -1271,3 +1271,91 @@ void set_system_io_map(MemoryRegion *mr) address_space_io.root = mr; memory_region_update_topology(); } + +typedef struct MemoryRegionList MemoryRegionList; + +struct MemoryRegionList { + const MemoryRegion *mr; + bool printed; + QTAILQ_ENTRY(MemoryRegionList) queue; +}; + +typedef QTAILQ_HEAD(queue, MemoryRegionList) MemoryRegionListHead; + +static void mtree_print_mr(fprintf_function mon_printf, void *f, + const MemoryRegion *mr, unsigned int level, + target_phys_addr_t base, + MemoryRegionListHead *print_queue) +{ + const MemoryRegion *submr; + unsigned int i; + + for (i = 0; i < level; i++) { + mon_printf(f, " "); + } + + if (mr->alias) { + MemoryRegionList *ml; + bool found = false; + + /* check if the alias is already in the queue */ + QTAILQ_FOREACH(ml, print_queue, queue) { + if (ml->mr == mr->alias && !ml->printed) { + found = true; + } + } + + if (!found) { + ml = g_new(MemoryRegionList, 1); + ml->mr = mr->alias; + ml->printed = false; + QTAILQ_INSERT_TAIL(print_queue, ml, queue); + } + mon_printf(f, TARGET_FMT_plx "-" TARGET_FMT_plx " : alias %s @%s " + TARGET_FMT_plx "-" TARGET_FMT_plx "\n", + base + mr->addr, + base + mr->addr + (target_phys_addr_t)mr->size - 1, + mr->name, + mr->alias->name, + mr->alias_offset, + mr->alias_offset + (target_phys_addr_t)mr->size - 1); + } else { + mon_printf(f, TARGET_FMT_plx "-" TARGET_FMT_plx " : %s\n", + base + mr->addr, + base + mr->addr + (target_phys_addr_t)mr->size - 1, + mr->name); + } + QTAILQ_FOREACH(submr, &mr->subregions, subregions_link) { + mtree_print_mr(mon_printf, f, submr, level + 1, base + mr->addr, + print_queue); + } +} + +void mtree_info(fprintf_function mon_printf, void *f) +{ + MemoryRegionListHead ml_head; + MemoryRegionList *ml, *ml2; + + QTAILQ_INIT(&ml_head); + + mon_printf(f, "memory\n"); + mtree_print_mr(mon_printf, f, address_space_memory.root, 0, 0, &ml_head); + + /* print aliased regions */ + QTAILQ_FOREACH(ml, &ml_head, queue) { + if (!ml->printed) { + mon_printf(f, "%s\n", ml->mr->name); + mtree_print_mr(mon_printf, f, ml->mr, 0, 0, &ml_head); + } + } + + QTAILQ_FOREACH_SAFE(ml, &ml_head, queue, ml2) { + g_free(ml2); + } + +#ifdef TARGET_I386 + QTAILQ_INIT(&ml_head); + mon_printf(f, "I/O\n"); + mtree_print_mr(mon_printf, f, address_space_io.root, 0, 0, &ml_head); +#endif +} diff --git a/memory.h b/memory.h index e93e65a..d5b47da 100644 --- a/memory.h +++ b/memory.h @@ -501,6 +501,8 @@ void memory_region_transaction_begin(void); */ void memory_region_transaction_commit(void); +void mtree_info(fprintf_function mon_printf, void *f); + #endif #endif diff --git a/monitor.c b/monitor.c index 8ec2c5e..d323ea5 100644 --- a/monitor.c +++ b/monitor.c @@ -63,6 +63,7 @@ #endif #include "trace/control.h" #include "ui/qemu-spice.h" +#include "memory.h" //#define DEBUG //#define DEBUG_COMPLETION @@ -2470,6 +2471,11 @@ static void tlb_info(Monitor *mon) } #endif +static void do_info_mtree(Monitor *mon) +{ + mtree_info((fprintf_function)monitor_printf, mon); +} + static void do_info_kvm_print(Monitor *mon, const QObject *data) { QDict *qdict; @@ -2978,6 +2984,13 @@ static const mon_cmd_t info_cmds[] = { }, #endif { + .name = "mtree", + .args_type = "", + .params = "", + .help = "show memory tree", + .mhandler.info = do_info_mtree, + }, + { .name = "jit", .args_type = "", .params = "", -- 1.7.2.5