memory: extend "info mtree" with flat view dump
cover memory: extend "info mtree" with flat view dump
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(-)
Signature · 1 line
2.7.4
PATCH 1/2 memory: provide common macros for mtree_print_mr()
mtree_print_mr() has some common codes. Generalize it.
--- memory.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)
memory.c +15 -19
@@ -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]" ); }
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 1/2] memory: provide common macros for mtree_print_mr()
Hi
Quoted 26 lines · Peter Xu
mtree_print_mr()has some common codes. Generalize it.Signed-off-by Peter Xu <[email protected]>--- memory.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)memory.c +7
-0@@ -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,
memory.c static void mtree_print_mr(fprintf_function · line 2477
Quoted 7 lines
memory.c +1
-1@@ -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
Quoted 47 lines
memory.c +0
-0}if (mr->alias) {memory.c +1
-6@@ -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'
- :
'-',memory.c +3
-4+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,memory.c +1
-6- 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'
- :
'-',
memory.c static void mtree_print_mr(fprintf_function mon_printf, void *f,
Quoted 6 lines
memory.c +2
-1+MR_CHAR_RD (mr), +MR_CHAR_WR (mr),memory_region_name (mr), mr->enabled ? "" : " [disabled]"); } --
looks good,
Signature · 1 line
Marc-André Lureau
Re: [Qemu-devel] [PATCH 1/2] memory: provide common macros for mtree_print_mr()
Hi
Quoted 38 lines · Marc-André Lureau
Hi
On Mon, Dec 19, 2016 at 3:11 PM Peter Xu <[email protected]> wrote:
mtree_print_mr()has some common codes. Generalize it.Signed-off-by Peter Xu <[email protected]>--- memory.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)memory.c +8
-1@@ -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 );
Quoted 2 lines
This one is perhaps superfluous
nevermind, just realized you used it in next patch
Quoted 66 lines
} if (mr->alias) {memory.c +1
-6@@ -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'
- :
'-',memory.c +3
-4+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,memory.c +1
-6- 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'
- :
'-',memory.c +2
-1+MR_CHAR_RD (mr), +MR_CHAR_WR (mr),memory_region_name (mr), mr->enabled ? "" : " [disabled]"); } --looks good,
Reviewed-by Marc-André Lureau <[email protected]>--
Marc-André Lureau
Signature · 1 line
Marc-André Lureau
PATCH 2/2 memory: hmp: dump flat view for 'info mtree'
In reply to Peter XuDumping 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.
--- memory.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
memory.c +31 -0
@@ -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" ); }
Signature · 1 line
2.7.4
Re: [Qemu-devel] [PATCH 2/2] memory: hmp: dump flat view for 'info mtree'
Quoted 29 lines · Peter Xu
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 <[email protected]>--- memory.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)memory.c +12
-0@@ -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 ;
memory.c static void mtree_print_mr(fprintf_function mon_printf, void *f, · line 2569
Quoted 10 lines
memory.c +10
-0+ } + +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.sizeWill repost. Thanks,
-- peterx