All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] memory: extend "info mtree" with flat view dump
@ 2016-12-19 14:10 Peter Xu
  2016-12-19 14:10 ` [Qemu-devel] [PATCH 1/2] memory: provide common macros for mtree_print_mr() Peter Xu
  2016-12-19 14:10 ` [Qemu-devel] [PATCH 2/2] memory: hmp: dump flat view for 'info mtree' Peter Xu
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Xu @ 2016-12-19 14:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, peterx

Each address space has its own flatview. It's another way to observe
memory info besides the default memory region hierachy, for example,
if we want to know which memory region will handle the write to
specific address, a flatview will suite more here than the default
hierachical dump.

I used it to debug a vt-d memory region overlap issue. Do we need
this? I think we can at least consider patch 1, which is a cleanup of
existing codes. :)

Please review. Thanks,

Peter Xu (2):
  memory: provide common macros for mtree_print_mr()
  memory: hmp: dump flat view for 'info mtree'

 memory.c | 65 +++++++++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 46 insertions(+), 19 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 1/2] memory: provide common macros for mtree_print_mr()
  2016-12-19 14:10 [Qemu-devel] [PATCH 0/2] memory: extend "info mtree" with flat view dump Peter Xu
@ 2016-12-19 14:10 ` Peter Xu
  2016-12-20 10:50   ` Marc-André Lureau
  2016-12-19 14:10 ` [Qemu-devel] [PATCH 2/2] memory: hmp: dump flat view for 'info mtree' Peter Xu
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Xu @ 2016-12-19 14:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, peterx

mtree_print_mr() has some common codes. Generalize it.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 memory.c | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/memory.c b/memory.c
index 33110e9..5dcc2e1 100644
--- a/memory.c
+++ b/memory.c
@@ -2450,6 +2450,13 @@ struct MemoryRegionList {
 
 typedef QTAILQ_HEAD(queue, MemoryRegionList) MemoryRegionListHead;
 
+#define MR_CHAR_RD(mr) ((mr)->romd_mode ? 'R' : '-')
+#define MR_CHAR_WR(mr) (!(mr)->readonly && !((mr)->rom_device && \
+                                             (mr)->romd_mode) ? 'W' : '-')
+#define MR_SIZE(size) (int128_nz(size) ? (hwaddr)int128_get64( \
+                           int128_sub((size), int128_one())) : 0)
+#define MTREE_INDENT "  "
+
 static void mtree_print_mr(fprintf_function mon_printf, void *f,
                            const MemoryRegion *mr, unsigned int level,
                            hwaddr base,
@@ -2465,7 +2472,7 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f,
     }
 
     for (i = 0; i < level; i++) {
-        mon_printf(f, "  ");
+        mon_printf(f, MTREE_INDENT);
     }
 
     if (mr->alias) {
@@ -2488,34 +2495,23 @@ static void mtree_print_mr(fprintf_function mon_printf, void *f,
                    " (prio %d, %c%c): alias %s @%s " TARGET_FMT_plx
                    "-" TARGET_FMT_plx "%s\n",
                    base + mr->addr,
-                   base + mr->addr
-                   + (int128_nz(mr->size) ?
-                      (hwaddr)int128_get64(int128_sub(mr->size,
-                                                      int128_one())) : 0),
+                   base + mr->addr + MR_SIZE(mr->size),
                    mr->priority,
-                   mr->romd_mode ? 'R' : '-',
-                   !mr->readonly && !(mr->rom_device && mr->romd_mode) ? 'W'
-                                                                       : '-',
+                   MR_CHAR_RD(mr),
+                   MR_CHAR_WR(mr),
                    memory_region_name(mr),
                    memory_region_name(mr->alias),
                    mr->alias_offset,
-                   mr->alias_offset
-                   + (int128_nz(mr->size) ?
-                      (hwaddr)int128_get64(int128_sub(mr->size,
-                                                      int128_one())) : 0),
+                   mr->alias_offset + MR_SIZE(mr->size),
                    mr->enabled ? "" : " [disabled]");
     } else {
         mon_printf(f,
                    TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d, %c%c): %s%s\n",
                    base + mr->addr,
-                   base + mr->addr
-                   + (int128_nz(mr->size) ?
-                      (hwaddr)int128_get64(int128_sub(mr->size,
-                                                      int128_one())) : 0),
+                   base + mr->addr + MR_SIZE(mr->size),
                    mr->priority,
-                   mr->romd_mode ? 'R' : '-',
-                   !mr->readonly && !(mr->rom_device && mr->romd_mode) ? 'W'
-                                                                       : '-',
+                   MR_CHAR_RD(mr),
+                   MR_CHAR_WR(mr),
                    memory_region_name(mr),
                    mr->enabled ? "" : " [disabled]");
     }
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 2/2] memory: hmp: dump flat view for 'info mtree'
  2016-12-19 14:10 [Qemu-devel] [PATCH 0/2] memory: extend "info mtree" with flat view dump Peter Xu
  2016-12-19 14:10 ` [Qemu-devel] [PATCH 1/2] memory: provide common macros for mtree_print_mr() Peter Xu
@ 2016-12-19 14:10 ` Peter Xu
  2016-12-21  7:56   ` Peter Xu
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Xu @ 2016-12-19 14:10 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, peterx

Dumping flat view 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 <peterx@redhat.com>
---
 memory.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/memory.c b/memory.c
index 5dcc2e1..a9154aa 100644
--- a/memory.c
+++ b/memory.c
@@ -2545,6 +2545,36 @@ static void mtree_print_mr(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);
+        return;
+    }
+
+    p(f, MTREE_INDENT "FlatView (address space '%s'):\n", as->name);
+
+    while (n--) {
+        mr = range->mr;
+        p(f, MTREE_INDENT MTREE_INDENT TARGET_FMT_plx "-"
+          TARGET_FMT_plx " (prio %d, %c%c): %s\n",
+          int128_get64(range->addr.start),
+          int128_get64(range->addr.start) + MR_SIZE(mr->size),
+          mr->priority, MR_CHAR_RD(mr), MR_CHAR_WR(mr),
+          memory_region_name(mr));
+        range++;
+    }
+
+    flatview_unref(view);
+}
+
 void mtree_info(fprintf_function mon_printf, void *f)
 {
     MemoryRegionListHead ml_head;
@@ -2556,6 +2586,7 @@ void mtree_info(fprintf_function mon_printf, void *f)
     QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
         mon_printf(f, "address-space: %s\n", as->name);
         mtree_print_mr(mon_printf, f, as->root, 1, 0, &ml_head);
+        mtree_print_flatview(mon_printf, f, as);
         mon_printf(f, "\n");
     }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] memory: provide common macros for mtree_print_mr()
  2016-12-19 14:10 ` [Qemu-devel] [PATCH 1/2] memory: provide common macros for mtree_print_mr() Peter Xu
@ 2016-12-20 10:50   ` Marc-André Lureau
  2016-12-20 10:54     ` Marc-André Lureau
  0 siblings, 1 reply; 6+ messages in thread
From: Marc-André Lureau @ 2016-12-20 10:50 UTC (permalink / raw)
  To: Peter Xu, qemu-devel; +Cc: pbonzini

Hi

On Mon, Dec 19, 2016 at 3:11 PM Peter Xu <peterx@redhat.com> wrote:

> mtree_print_mr() has some common codes. Generalize it.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  memory.c | 34 +++++++++++++++-------------------
>  1 file changed, 15 insertions(+), 19 deletions(-)
>
> diff --git a/memory.c b/memory.c
> index 33110e9..5dcc2e1 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -2450,6 +2450,13 @@ struct MemoryRegionList {
>
>  typedef QTAILQ_HEAD(queue, MemoryRegionList) MemoryRegionListHead;
>
> +#define MR_CHAR_RD(mr) ((mr)->romd_mode ? 'R' : '-')
> +#define MR_CHAR_WR(mr) (!(mr)->readonly && !((mr)->rom_device && \
> +                                             (mr)->romd_mode) ? 'W' : '-')
> +#define MR_SIZE(size) (int128_nz(size) ? (hwaddr)int128_get64( \
> +                           int128_sub((size), int128_one())) : 0)
> +#define MTREE_INDENT "  "
> +
>  static void mtree_print_mr(fprintf_function mon_printf, void *f,
>                             const MemoryRegion *mr, unsigned int level,
>                             hwaddr base,
> @@ -2465,7 +2472,7 @@ static void mtree_print_mr(fprintf_function
> mon_printf, void *f,
>      }
>
>      for (i = 0; i < level; i++) {
> -        mon_printf(f, "  ");
> +        mon_printf(f, MTREE_INDENT);
>

This one is perhaps superfluous


>      }
>
>      if (mr->alias) {
> @@ -2488,34 +2495,23 @@ static void mtree_print_mr(fprintf_function
> mon_printf, void *f,
>                     " (prio %d, %c%c): alias %s @%s " TARGET_FMT_plx
>                     "-" TARGET_FMT_plx "%s\n",
>                     base + mr->addr,
> -                   base + mr->addr
> -                   + (int128_nz(mr->size) ?
> -                      (hwaddr)int128_get64(int128_sub(mr->size,
> -                                                      int128_one())) : 0),
> +                   base + mr->addr + MR_SIZE(mr->size),
>                     mr->priority,
> -                   mr->romd_mode ? 'R' : '-',
> -                   !mr->readonly && !(mr->rom_device && mr->romd_mode) ?
> 'W'
> -                                                                       :
> '-',
> +                   MR_CHAR_RD(mr),
> +                   MR_CHAR_WR(mr),
>                     memory_region_name(mr),
>                     memory_region_name(mr->alias),
>                     mr->alias_offset,
> -                   mr->alias_offset
> -                   + (int128_nz(mr->size) ?
> -                      (hwaddr)int128_get64(int128_sub(mr->size,
> -                                                      int128_one())) : 0),
> +                   mr->alias_offset + MR_SIZE(mr->size),
>                     mr->enabled ? "" : " [disabled]");
>      } else {
>          mon_printf(f,
>                     TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d, %c%c):
> %s%s\n",
>                     base + mr->addr,
> -                   base + mr->addr
> -                   + (int128_nz(mr->size) ?
> -                      (hwaddr)int128_get64(int128_sub(mr->size,
> -                                                      int128_one())) : 0),
> +                   base + mr->addr + MR_SIZE(mr->size),
>                     mr->priority,
> -                   mr->romd_mode ? 'R' : '-',
> -                   !mr->readonly && !(mr->rom_device && mr->romd_mode) ?
> 'W'
> -                                                                       :
> '-',
> +                   MR_CHAR_RD(mr),
> +                   MR_CHAR_WR(mr),
>                     memory_region_name(mr),
>                     mr->enabled ? "" : " [disabled]");
>      }
> --
>


looks good,


Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


-- 
Marc-André Lureau

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] memory: provide common macros for mtree_print_mr()
  2016-12-20 10:50   ` Marc-André Lureau
@ 2016-12-20 10:54     ` Marc-André Lureau
  0 siblings, 0 replies; 6+ messages in thread
From: Marc-André Lureau @ 2016-12-20 10:54 UTC (permalink / raw)
  To: Peter Xu, qemu-devel; +Cc: pbonzini

Hi

On Tue, Dec 20, 2016 at 11:50 AM Marc-André Lureau <
marcandre.lureau@gmail.com> wrote:

> Hi
>
> On Mon, Dec 19, 2016 at 3:11 PM Peter Xu <peterx@redhat.com> wrote:
>
> mtree_print_mr() has some common codes. Generalize it.
>
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  memory.c | 34 +++++++++++++++-------------------
>  1 file changed, 15 insertions(+), 19 deletions(-)
>
> diff --git a/memory.c b/memory.c
> index 33110e9..5dcc2e1 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -2450,6 +2450,13 @@ struct MemoryRegionList {
>
>  typedef QTAILQ_HEAD(queue, MemoryRegionList) MemoryRegionListHead;
>
> +#define MR_CHAR_RD(mr) ((mr)->romd_mode ? 'R' : '-')
> +#define MR_CHAR_WR(mr) (!(mr)->readonly && !((mr)->rom_device && \
> +                                             (mr)->romd_mode) ? 'W' : '-')
> +#define MR_SIZE(size) (int128_nz(size) ? (hwaddr)int128_get64( \
> +                           int128_sub((size), int128_one())) : 0)
> +#define MTREE_INDENT "  "
> +
>  static void mtree_print_mr(fprintf_function mon_printf, void *f,
>                             const MemoryRegion *mr, unsigned int level,
>                             hwaddr base,
> @@ -2465,7 +2472,7 @@ static void mtree_print_mr(fprintf_function
> mon_printf, void *f,
>      }
>
>      for (i = 0; i < level; i++) {
> -        mon_printf(f, "  ");
> +        mon_printf(f, MTREE_INDENT);
>
>
> This one is perhaps superfluous
>

nevermind, just realized you used it in next patch


>
>
>      }
>
>      if (mr->alias) {
> @@ -2488,34 +2495,23 @@ static void mtree_print_mr(fprintf_function
> mon_printf, void *f,
>                     " (prio %d, %c%c): alias %s @%s " TARGET_FMT_plx
>                     "-" TARGET_FMT_plx "%s\n",
>                     base + mr->addr,
> -                   base + mr->addr
> -                   + (int128_nz(mr->size) ?
> -                      (hwaddr)int128_get64(int128_sub(mr->size,
> -                                                      int128_one())) : 0),
> +                   base + mr->addr + MR_SIZE(mr->size),
>                     mr->priority,
> -                   mr->romd_mode ? 'R' : '-',
> -                   !mr->readonly && !(mr->rom_device && mr->romd_mode) ?
> 'W'
> -                                                                       :
> '-',
> +                   MR_CHAR_RD(mr),
> +                   MR_CHAR_WR(mr),
>                     memory_region_name(mr),
>                     memory_region_name(mr->alias),
>                     mr->alias_offset,
> -                   mr->alias_offset
> -                   + (int128_nz(mr->size) ?
> -                      (hwaddr)int128_get64(int128_sub(mr->size,
> -                                                      int128_one())) : 0),
> +                   mr->alias_offset + MR_SIZE(mr->size),
>                     mr->enabled ? "" : " [disabled]");
>      } else {
>          mon_printf(f,
>                     TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d, %c%c):
> %s%s\n",
>                     base + mr->addr,
> -                   base + mr->addr
> -                   + (int128_nz(mr->size) ?
> -                      (hwaddr)int128_get64(int128_sub(mr->size,
> -                                                      int128_one())) : 0),
> +                   base + mr->addr + MR_SIZE(mr->size),
>                     mr->priority,
> -                   mr->romd_mode ? 'R' : '-',
> -                   !mr->readonly && !(mr->rom_device && mr->romd_mode) ?
> 'W'
> -                                                                       :
> '-',
> +                   MR_CHAR_RD(mr),
> +                   MR_CHAR_WR(mr),
>                     memory_region_name(mr),
>                     mr->enabled ? "" : " [disabled]");
>      }
> --
>
>
>
> looks good,
>
>
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>
>
> --
> Marc-André Lureau
>
-- 
Marc-André Lureau

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] memory: hmp: dump flat view for 'info mtree'
  2016-12-19 14:10 ` [Qemu-devel] [PATCH 2/2] memory: hmp: dump flat view for 'info mtree' Peter Xu
@ 2016-12-21  7:56   ` Peter Xu
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Xu @ 2016-12-21  7:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini

On Mon, Dec 19, 2016 at 10:10:23PM +0800, Peter Xu wrote:
> Dumping flat view 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 <peterx@redhat.com>
> ---
>  memory.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/memory.c b/memory.c
> index 5dcc2e1..a9154aa 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -2545,6 +2545,36 @@ static void mtree_print_mr(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);
> +        return;
> +    }
> +
> +    p(f, MTREE_INDENT "FlatView (address space '%s'):\n", as->name);
> +
> +    while (n--) {
> +        mr = range->mr;
> +        p(f, MTREE_INDENT MTREE_INDENT TARGET_FMT_plx "-"
> +          TARGET_FMT_plx " (prio %d, %c%c): %s\n",
> +          int128_get64(range->addr.start),
> +          int128_get64(range->addr.start) + MR_SIZE(mr->size),
                                                       ^^^^^^^^
                                   here it should be range->addr.size

Will repost. Thanks,

-- peterx

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-12-21  7:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-19 14:10 [Qemu-devel] [PATCH 0/2] memory: extend "info mtree" with flat view dump Peter Xu
2016-12-19 14:10 ` [Qemu-devel] [PATCH 1/2] memory: provide common macros for mtree_print_mr() Peter Xu
2016-12-20 10:50   ` Marc-André Lureau
2016-12-20 10:54     ` Marc-André Lureau
2016-12-19 14:10 ` [Qemu-devel] [PATCH 2/2] memory: hmp: dump flat view for 'info mtree' Peter Xu
2016-12-21  7:56   ` Peter Xu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.