Message ID | 1482156623-9111-2-git-send-email-peterx@redhat.com |
---|---|
State | New |
Headers | show |
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>
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 >
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]"); }
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(-)