From patchwork Sun Oct 2 14:32:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 117307 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]) by ozlabs.org (Postfix) with ESMTP id 7B8A6B6F75 for ; Mon, 3 Oct 2011 01:37:47 +1100 (EST) Received: from localhost ([::1]:52976 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAN5x-0005M2-Ea for incoming@patchwork.ozlabs.org; Sun, 02 Oct 2011 10:32:45 -0400 Received: from eggs.gnu.org ([140.186.70.92]:38263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAN5l-0005BP-9a for qemu-devel@nongnu.org; Sun, 02 Oct 2011 10:32:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RAN5j-0000be-PB for qemu-devel@nongnu.org; Sun, 02 Oct 2011 10:32:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61752) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RAN5j-0000bX-I2 for qemu-devel@nongnu.org; Sun, 02 Oct 2011 10:32:31 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p92EWREk032711 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 2 Oct 2011 10:32:27 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p92EWQJN024248; Sun, 2 Oct 2011 10:32:27 -0400 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id D0991250B65; Sun, 2 Oct 2011 16:32:22 +0200 (IST) From: Avi Kivity To: Anthony Liguori , Blue Swirl , qemu-devel@nongnu.org Date: Sun, 2 Oct 2011 16:32:19 +0200 Message-Id: <1317565939-14900-5-git-send-email-avi@redhat.com> In-Reply-To: <1317565939-14900-1-git-send-email-avi@redhat.com> References: <1317565939-14900-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/4] memory: Print regions in ascending order 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 From: Jan Kiszka Makes reading the output more user friendly. Signed-off-by: Jan Kiszka Signed-off-by: Avi Kivity --- memory.c | 37 +++++++++++++++++++++++++++++++------ 1 files changed, 31 insertions(+), 6 deletions(-) diff --git a/memory.c b/memory.c index 19f1d36..f46e626 100644 --- a/memory.c +++ b/memory.c @@ -1285,12 +1285,13 @@ struct MemoryRegionList { 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) + MemoryRegionListHead *alias_print_queue) { + MemoryRegionList *new_ml, *ml, *next_ml; + MemoryRegionListHead submr_print_queue; const MemoryRegion *submr; unsigned int i; - if (!mr) { return; } @@ -1304,7 +1305,7 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f, bool found = false; /* check if the alias is already in the queue */ - QTAILQ_FOREACH(ml, print_queue, queue) { + QTAILQ_FOREACH(ml, alias_print_queue, queue) { if (ml->mr == mr->alias && !ml->printed) { found = true; } @@ -1314,7 +1315,7 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f, ml = g_new(MemoryRegionList, 1); ml->mr = mr->alias; ml->printed = false; - QTAILQ_INSERT_TAIL(print_queue, ml, queue); + QTAILQ_INSERT_TAIL(alias_print_queue, ml, queue); } mon_printf(f, TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d): alias %s @%s " TARGET_FMT_plx "-" TARGET_FMT_plx "\n", @@ -1332,9 +1333,33 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f, mr->priority, mr->name); } + + QTAILQ_INIT(&submr_print_queue); + QTAILQ_FOREACH(submr, &mr->subregions, subregions_link) { - mtree_print_mr(mon_printf, f, submr, level + 1, base + mr->addr, - print_queue); + new_ml = g_new(MemoryRegionList, 1); + new_ml->mr = submr; + QTAILQ_FOREACH(ml, &submr_print_queue, queue) { + if (new_ml->mr->addr < ml->mr->addr || + (new_ml->mr->addr == ml->mr->addr && + new_ml->mr->priority > ml->mr->priority)) { + QTAILQ_INSERT_BEFORE(ml, new_ml, queue); + new_ml = NULL; + break; + } + } + if (new_ml) { + QTAILQ_INSERT_TAIL(&submr_print_queue, new_ml, queue); + } + } + + QTAILQ_FOREACH(ml, &submr_print_queue, queue) { + mtree_print_mr(mon_printf, f, ml->mr, level + 1, base + mr->addr, + alias_print_queue); + } + + QTAILQ_FOREACH_SAFE(next_ml, &submr_print_queue, queue, ml) { + g_free(ml); } }