Skip to contentSkip to conversation

memory: Print regions in ascending order

PATCH Applied Jan Kiszka 2 participants 2 messages Sep 27, 2011 – Oct 2, 2011

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 3/3 memory: Print regions in ascending order

Makes reading the output more user friendly.

---
 memory.c |   37 +++++++++++++++++++++++++++++++------
 1 files changed, 31 insertions(+), 6 deletions(-)
memory.c +31 -6
index 24c5abd..6ff78cb 100644
@@ -1339,12 +1339,13 @@ 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)
+                           MemoryRegionListHead *alias_print_queue)
 {
+    MemoryRegionList *new_ml, *ml, *next_ml;
+    MemoryRegionListHead submr_print_queue;
     const MemoryRegion *submr;
     unsigned int i;
 
-
     if (!mr) {
         return;
     }
@@ -1358,7 +1359,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;
             }
@@ -1368,7 +1369,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",
@@ -1386,9 +1387,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);
     }
 }
 
Signature · 1 line
1.7.3.4
Applied
#1 lore raw
Quoted 1 line · Jan Kiszka

Makes reading the output more user friendly.

Thanks, applied all three.

Quoted 60 lines
memory.c +24 -6
@@ -1339,12 +1339,13 @@ 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)
+                           MemoryRegionListHead *alias_print_queue)
  {
+    MemoryRegionList *new_ml, *ml, *next_ml;
+    MemoryRegionListHead submr_print_queue;
      const MemoryRegion *submr;
      unsigned int i;
 
-
      if (!mr) {
          return;
      }
@@ -1358,7 +1359,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;
              }
@@ -1368,7 +1369,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",
@@ -1386,9 +1387,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);
+        }
+    }
+

memory.c static void mtree_print_mr(fprintf_function mon_printf, void *f, · line 1419

Quoted 10 lines
memory.c +7 -0
+    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);
      }
  }
 

Yuck, the whole thing would be a one-liner with a capable library (std::map<> or std::sort())

Signature · 1 line
error compiling committee.c: too many arguments to function