system/memory: Improve 'info mtree' readability
cover system/memory: Improve 'info mtree' readability
Cleaning dust, I had forgotten about this branch. In short, it improves 'info mtree' readability of addresses.
Currently with Q35:
address-space: I/O
0000000000000000-000000000000ffff (prio 0, i/o): io
0000000000000000-0000000000000003 (prio 0, i/o): acpi-evt
0000000000000004-0000000000000005 (prio 0, i/o): acpi-cnt
0000000000000008-000000000000000b (prio 0, i/o): acpi-tmr
0000000000000020-000000000000002f (prio 0, i/o): acpi-gpe0
0000000000000030-0000000000000037 (prio 0, i/o): acpi-smi
0000000000000060-000000000000007f (prio 0, i/o): sm-tco
0000000000000000-0000000000000007 (prio 0, i/o): dma-chan
0000000000000008-000000000000000f (prio 0, i/o): dma-cont
0000000000000020-0000000000000021 (prio 0, i/o): pic
0000000000000040-0000000000000043 (prio 0, i/o): pit
...
memory-region: pc.ram
0000000000000000-0000000007ffffff (prio 0, ram): pc.ram
memory-region: pc.bios
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios
memory-region: pci
0000000000000000-ffffffffffffffff (prio -1, i/o): pci
00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem
00000000000c0000-00000000000dffff (prio 1, rom): pc.rom
00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios
...With this series:
address-space: I/O
0000-ffff (prio 0, container): io
0000-0003 (prio 0, i/o): acpi-evt
0004-0005 (prio 0, i/o): acpi-cnt
0008-000b (prio 0, i/o): acpi-tmr
0020-002f (prio 0, i/o): acpi-gpe0
0030-0037 (prio 0, i/o): acpi-smi
0060-007f (prio 0, i/o): sm-tco
0000-0007 (prio 0, i/o): dma-chan
0008-000f (prio 0, i/o): dma-cont
0020-0021 (prio 0, i/o): pic
0040-0043 (prio 0, i/o): pit
...
memory-region: pc.ram
00000000-07ffffff (prio 0, ram): pc.ram
memory-region: pc.bios
fffc0000-ffffffff (prio 0, rom): pc.bios
memory-region: pci
0000000000000000-ffffffffffffffff (prio -1, i/o): pci
00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem
00000000000c0000-00000000000dffff (prio 1, rom): pc.rom
00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios
...Philippe Mathieu-Daudé (7):
stubs: Merge physmem.c within ram-block.c
system/ramblock: Constify various RAMBlock arguments system/memory: Constify various MemoryRegion arguments system/memory: Have memory_region_type() correctly describe containers system/memory: Display address spaces starting at 0x0000.0000 system/memory: Allow mtree_print_mr() to display distinct address
width
system/memory: Have 'info mtree' display addresses nicely
include/system/memory.h | 28 +++++----- include/system/ramblock.h | 26 ++++----- stubs/physmem.c | 13 ----- stubs/ram-block.c | 17 ++++-- system/memory.c | 108 ++++++++++++++++++++++++-------------- system/physmem.c | 26 ++++----- stubs/meson.build | 1 - 7 files changed, 123 insertions(+), 96 deletions(-) delete mode 100644 stubs/physmem.c
Signature · 1 line
2.52.0
PATCH 1/7 stubs: Merge physmem.c within ram-block.c
physmem.c defines 2 stubs which are related to ram-block:qemu_ram_block_from_host() and qemu_ram_get_fd(). Move them with the other ram-block stubs.
--- stubs/physmem.c | 13 ------------- stubs/ram-block.c | 11 +++++++++++ stubs/meson.build | 1 - 3 files changed, 11 insertions(+), 14 deletions(-) delete mode 100644 stubs/physmem.c
stubs/physmem.c deleted +0 -13
@@ -1,13 +0,0 @@ -#include "qemu/osdep.h" -#include "system/ramblock.h" - -RAMBlock *qemu_ram_block_from_host (void *ptr,bool round_offset, -ram_addr_t *offset) -{ -return NULL ; -} - -int qemu_ram_get_fd (RAMBlock *rb) -{ -return -1 ; -}
stubs/ram-block.c +11 -0
@@ -35,3 +35,14 @@ int ram_block_discard_disable(bool state) {return 0 ; } + +RAMBlock *qemu_ram_block_from_host (void *ptr,bool round_offset, +ram_addr_t *offset) +{ +return NULL ; +} + +int qemu_ram_get_fd (RAMBlock *rb) +{ +return -1 ; +}
stubs/meson.build +0 -1
@@ -20,7 +20,6 @@ if have_block stub_ss.add(files('get-vm-name.c')) stub_ss.add(files('iothread-lock-block.c')) stub_ss.add(files('migr-blocker.c')) - stub_ss.add(files('physmem.c')) stub_ss.add(files('ram-block.c')) stub_ss.add(files('runstate-check.c')) stub_ss.add(files('uuid.c'))
Signature · 1 line
2.52.0
Re: [PATCH 1/7] stubs: Merge physmem.c within ram-block.c
Quoted 4 lines · Philippe Mathieu-Daudé
physmem.cdefines 2 stubs which are related to ram-block:qemu_ram_block_from_host()andqemu_ram_get_fd(). Move them with the other ram-block stubs.
Quoted 8 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- stubs/physmem.c | 13 ------------- stubs/ram-block.c | 11 +++++++++++ stubs/meson.build | 1 - 3 files changed, 11 insertions(+), 14 deletions(-)delete mode 100644
stubs/physmem.c
Re: [PATCH 1/7] stubs: Merge physmem.c within ram-block.c
In reply to Philippe Mathieu-DaudéQuoted 8 lines · Philippe Mathieu-Daudé
physmem.cdefines 2 stubs which are related to ram-block:qemu_ram_block_from_host()andqemu_ram_get_fd(). Move them with the other ram-block stubs.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
stubs/physmem.c| 13 -------------stubs/ram-block.c| 11 +++++++++++
Maybe should be the other way around moving what's in subs/ram-block.c to stubs/physmem.c considering the the functions these stub out are in system/physmem.c and there's no system/ram-block.c.
Regards,
BALATON Zoltan
Quoted 55 lines
stubs/meson.build | 1 -
3 files changed, 11 insertions(+), 14 deletions(-)delete mode 100644
stubs/physmem.cstubs/physmem.c deleted +0
-13@@ -1,13 +0,0 @@ -#include "qemu/osdep.h" -#include "system/ramblock.h" - -RAMBlock *qemu_ram_block_from_host (void *ptr,bool round_offset, -ram_addr_t *offset) -{ -return NULL ; -} - -int qemu_ram_get_fd (RAMBlock *rb) -{ -return -1 ; -}stubs/ram-block.c +11
-0@@ -35,3 +35,14 @@ int ram_block_discard_disable(bool state) {return 0 ; } + +RAMBlock *qemu_ram_block_from_host (void *ptr,bool round_offset, +ram_addr_t *offset) +{ +return NULL ; +} + +int qemu_ram_get_fd (RAMBlock *rb) +{ +return -1 ; +}stubs/meson.build +0
-1@@ -20,7 +20,6 @@ if have_block stub_ss.add(files('get-vm-name.c')) stub_ss.add(files('iothread-lock-block.c')) stub_ss.add(files('migr-blocker.c')) - stub_ss.add(files('physmem.c')) stub_ss.add(files('ram-block.c')) stub_ss.add(files('runstate-check.c')) stub_ss.add(files('uuid.c'))
Re: [PATCH 1/7] stubs: Merge physmem.c within ram-block.c
Quoted 11 lines · BALATON Zoltan
Quoted 8 lines · Philippe Mathieu-Daudé
physmem.cdefines 2 stubs which are related to ram-block:qemu_ram_block_from_host()andqemu_ram_get_fd(). Move them with the other ram-block stubs.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
stubs/physmem.c | 13 -------------stubs/ram-block.c| 11 +++++++++++Maybe should be the other way around moving what's in
subs/ram-block.ctostubs/physmem.cconsidering the the functions these stub out are insystem/physmem.cand there's nosystem/ram-block.c.
But this stubs out functions in "ramblock.h" (though it's not "ram-block.h")
Regards,
Akihiko Odaki
Quoted 59 lines
Regards,
BALATON ZoltanQuoted 55 lines
stubs/meson.build | 1 -
3 files changed, 11 insertions(+), 14 deletions(-)delete mode 100644
stubs/physmem.cstubs/physmem.c deleted +0
-13@@ -1,13 +0,0 @@ -#include "qemu/osdep.h" -#include "system/ramblock.h" - -RAMBlock *qemu_ram_block_from_host (void *ptr,bool round_offset, - ram_addr_t *offset) -{ - return NULL; -} - -int qemu_ram_get_fd (RAMBlock *rb) -{ - return -1; -}stubs/ram-block.c +11
-0@@ -35,3 +35,14 @@ int ram_block_discard_disable(bool state) { return 0; } + +RAMBlock *qemu_ram_block_from_host (void *ptr,bool round_offset, + ram_addr_t *offset) +{ + return NULL; +} + +int qemu_ram_get_fd (RAMBlock *rb) +{ + return -1; +}stubs/meson.build +0
-1@@ -20,7 +20,6 @@ if have_block stub_ss.add(files('get-vm-name.c')) stub_ss.add(files('iothread-lock-block.c')) stub_ss.add(files('migr-blocker.c')) - stub_ss.add(files('physmem.c')) stub_ss.add(files('ram-block.c')) stub_ss.add(files('runstate-check.c')) stub_ss.add(files('uuid.c'))
Re: [PATCH 1/7] stubs: Merge physmem.c within ram-block.c
Quoted 6 lines · Akihiko Odaki
Quoted 5 lines · BALATON Zoltan
Quoted 4 lines · Philippe Mathieu-Daudé
physmem.cdefines 2 stubs which are related to ram-block:qemu_ram_block_from_host()andqemu_ram_get_fd(). Move them with the other ram-block stubs.
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
stubs/physmem.c | 13 -------------stubs/ram-block.c| 11 +++++++++++Maybe should be the other way around moving what's in
subs/ram-block.ctostubs/physmem.cconsidering the the functions these stub out are insystem/physmem.cand there's nosystem/ram-block.c.
Fine, I'll drop this patch if you think it is not worthwhile.
Quoted 10 lines
But this stubs out functions in "
ramblock.h" (though it's not "ram-block.h")Regards,
Akihiko OdakiQuoted 3 lines
Regards,
BALATON Zoltan
Re: [PATCH 1/7] stubs: Merge physmem.c within ram-block.c
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Akihiko Odaki
Quoted 5 lines · BALATON Zoltan
Quoted 4 lines · Philippe Mathieu-Daudé
physmem.cdefines 2 stubs which are related to ram-block:qemu_ram_block_from_host()andqemu_ram_get_fd(). Move them with the other ram-block stubs.
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
stubs/physmem.c | 13 -------------stubs/ram-block.c| 11 +++++++++++Maybe should be the other way around moving what's in
subs/ram-block.ctostubs/physmem.cconsidering the the functions these stub out are insystem/physmem.cand there's nosystem/ram-block.c.Fine, I'll drop this patch if you think it is not worthwhile.
I did not say that, only that the functions are in system/physmem.c so why not put the stubs in stubs/physmem.c to match? Since there's no system/ram-block.c I think it makes more sense to merge these into stubs/physmem.c instead. But just leaving it as it is is also OK.
Regards,
BALATON Zoltan
Re: [PATCH 1/7] stubs: Merge physmem.c within ram-block.c
Quoted 13 lines · BALATON Zoltan
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Akihiko Odaki
Quoted 10 lines · BALATON Zoltan
Quoted 8 lines · Philippe Mathieu-Daudé
physmem.cdefines 2 stubs which are related to ram-block:qemu_ram_block_from_host()andqemu_ram_get_fd(). Move them with the other ram-block stubs.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
stubs/physmem.c | 13 -------------stubs/ram-block.c| 11 +++++++++++
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Maybe should be the other way around moving what's in subs/ram-
block.ctostubs/physmem.cconsidering the the functions these stub out are insystem/physmem.cand there's nosystem/ram-block.c.Fine, I'll drop this patch if you think it is not worthwhile.
I did not say that, only that the functions are in
system/physmem.cso why not put the stubs instubs/physmem.cto match? Since there's nosystem/ram-block.cI think it makes more sense to merge these intostubs/physmem.cinstead.
Unfortunately I won't have time to address this change before soft-freeze, do you mind posting the patch?
Thanks for your review and help here,
Phil.
Quoted 4 lines
But just leaving it as it is is also OK.
Regards,
BALATON Zoltan
Re: [PATCH 1/7] stubs: Merge physmem.c within ram-block.c
Quoted 14 lines · Philippe Mathieu-Daudé
Quoted 13 lines · BALATON Zoltan
Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Akihiko Odaki
Quoted 10 lines · BALATON Zoltan
Quoted 8 lines · Philippe Mathieu-Daudé
physmem.cdefines 2 stubs which are related to ram-block:qemu_ram_block_from_host()andqemu_ram_get_fd(). Move them with the other ram-block stubs.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
stubs/physmem.c | 13 -------------stubs/ram-block.c| 11 +++++++++++
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Maybe should be the other way around moving what's in subs/ram-
block.ctostubs/physmem.cconsidering the the functions these stub out are insystem/physmem.cand there's nosystem/ram-block.c.Fine, I'll drop this patch if you think it is not worthwhile.
I did not say that, only that the functions are in
system/physmem.cso why not put the stubs instubs/physmem.cto match? Since there's nosystem/ram-block.cI think it makes more sense to merge these intostubs/physmem.cinstead.Unfortunately I won't have time to address this change before soft-freeze, do you mind posting the patch?
I don't think this is a big issue to put much effort in so as I said dropping the patch and not changing it is probably the simplest.
Quoted 5 lines
Thanks for your review and help here,
Phil.
Quoted 1 line
But just leaving it as it is is also OK.
Regards,
BALATON Zoltan
Re: [PATCH 1/7] stubs: Merge physmem.c within ram-block.c
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
physmem.cdefines 2 stubs which are related to ram-block:qemu_ram_block_from_host()andqemu_ram_get_fd(). Move them with the other ram-block stubs.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 1 line
Peter Xu
PATCH 2/7 system/ramblock: Constify various RAMBlock arguments
In reply to Philippe Mathieu-DaudéMark the RAMBlock structure const when is only accessed read-only.
--- include/system/ramblock.h | 26 +++++++++++++------------- stubs/ram-block.c | 8 ++++---- system/physmem.c | 26 +++++++++++++------------- 3 files changed, 30 insertions(+), 30 deletions(-)
include/system/ramblock.h +13 -13
@@ -154,24 +154,24 @@ RAMBlock *qemu_ram_block_by_name(const char *name);*/ RAMBlock *qemu_ram_block_from_host (void *ptr,bool round_offset,ram_addr_t *offset); -ram_addr_t qemu_ram_block_host_offset (RAMBlock *rb,void *host); +ram_addr_t qemu_ram_block_host_offset (const RAMBlock *rb,void *host);void qemu_ram_set_idstr (RAMBlock *block,const char *name,DeviceState *dev);void qemu_ram_unset_idstr (RAMBlock *block); -const char *qemu_ram_get_idstr (RAMBlock *rb); -void *qemu_ram_get_host_addr (RAMBlock *rb); -ram_addr_t qemu_ram_get_offset (RAMBlock *rb); -ram_addr_t qemu_ram_get_fd_offset (RAMBlock *rb); -ram_addr_t qemu_ram_get_used_length (RAMBlock *rb); -ram_addr_t qemu_ram_get_max_length (RAMBlock *rb); -bool qemu_ram_is_shared (RAMBlock *rb); -bool qemu_ram_is_noreserve (RAMBlock *rb); -bool qemu_ram_is_uf_zeroable (RAMBlock *rb); +const char *qemu_ram_get_idstr (const RAMBlock *rb); +void *qemu_ram_get_host_addr (const RAMBlock *rb); +ram_addr_t qemu_ram_get_offset (const RAMBlock *rb); +ram_addr_t qemu_ram_get_fd_offset (const RAMBlock *rb); +ram_addr_t qemu_ram_get_used_length (const RAMBlock *rb); +ram_addr_t qemu_ram_get_max_length (const RAMBlock *rb); +bool qemu_ram_is_shared (const RAMBlock *rb); +bool qemu_ram_is_noreserve (const RAMBlock *rb); +bool qemu_ram_is_uf_zeroable (const RAMBlock *rb);void qemu_ram_set_uf_zeroable (RAMBlock *rb); -bool qemu_ram_is_migratable (RAMBlock *rb); +bool qemu_ram_is_migratable (const RAMBlock *rb);void qemu_ram_set_migratable (RAMBlock *rb);void qemu_ram_unset_migratable (RAMBlock *rb); -bool qemu_ram_is_named_file (RAMBlock *rb); -int qemu_ram_get_fd (RAMBlock *rb); +bool qemu_ram_is_named_file (const RAMBlock *rb); +int qemu_ram_get_fd (const RAMBlock *rb);size_t qemu_ram_pagesize (RAMBlock *block);size_t qemu_ram_pagesize_largest (void );
stubs/ram-block.c +4 -4
@@ -3,17 +3,17 @@#include "system/ramblock.h" #include "system/memory.h" -void *qemu_ram_get_host_addr (RAMBlock *rb) +void *qemu_ram_get_host_addr (const RAMBlock *rb) {return 0 ; } -ram_addr_t qemu_ram_get_offset (RAMBlock *rb) +ram_addr_t qemu_ram_get_offset (const RAMBlock *rb) {return 0 ; } -ram_addr_t qemu_ram_get_used_length (RAMBlock *rb) +ram_addr_t qemu_ram_get_used_length (const RAMBlock *rb) {return 0 ; }
@@ -42,7 +42,7 @@ RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset,return NULL ; } -int qemu_ram_get_fd (RAMBlock *rb) +int qemu_ram_get_fd (const RAMBlock *rb) {return -1 ; }
system/physmem.c +13 -13
@@ -1857,48 +1857,48 @@ static void qemu_ram_setup_dump(void *addr, ram_addr_t size) } } -const char *qemu_ram_get_idstr (RAMBlock *rb) +const char *qemu_ram_get_idstr (const RAMBlock *rb) {return rb->idstr; } -void *qemu_ram_get_host_addr (RAMBlock *rb) +void *qemu_ram_get_host_addr (const RAMBlock *rb) {return rb->host; } -ram_addr_t qemu_ram_get_offset (RAMBlock *rb) +ram_addr_t qemu_ram_get_offset (const RAMBlock *rb) {return rb->offset; } -ram_addr_t qemu_ram_get_fd_offset (RAMBlock *rb) +ram_addr_t qemu_ram_get_fd_offset (const RAMBlock *rb) {return rb->fd_offset; } -ram_addr_t qemu_ram_get_used_length (RAMBlock *rb) +ram_addr_t qemu_ram_get_used_length (const RAMBlock *rb) {return rb->used_length; } -ram_addr_t qemu_ram_get_max_length (RAMBlock *rb) +ram_addr_t qemu_ram_get_max_length (const RAMBlock *rb) {return rb->max_length; } -bool qemu_ram_is_shared (RAMBlock *rb) +bool qemu_ram_is_shared (const RAMBlock *rb) {return rb->flags &RAM_SHARED ; } -bool qemu_ram_is_noreserve (RAMBlock *rb) +bool qemu_ram_is_noreserve (const RAMBlock *rb) {return rb->flags &RAM_NORESERVE ; }/* Note: Only set at the start of postcopy */ -bool qemu_ram_is_uf_zeroable (RAMBlock *rb) +bool qemu_ram_is_uf_zeroable (const RAMBlock *rb) {return rb->flags &RAM_UF_ZEROPAGE ; }
@@ -1908,7 +1908,7 @@ void qemu_ram_set_uf_zeroable(RAMBlock *rb) rb->flags |=RAM_UF_ZEROPAGE ; } -bool qemu_ram_is_migratable (RAMBlock *rb) +bool qemu_ram_is_migratable (const RAMBlock *rb) {return rb->flags &RAM_MIGRATABLE ; }
@@ -1923,12 +1923,12 @@ void qemu_ram_unset_migratable(RAMBlock *rb) rb->flags &= ~RAM_MIGRATABLE ; } -bool qemu_ram_is_named_file (RAMBlock *rb) +bool qemu_ram_is_named_file (const RAMBlock *rb) {return rb->flags &RAM_NAMED_FILE ; } -int qemu_ram_get_fd (RAMBlock *rb) +int qemu_ram_get_fd (const RAMBlock *rb) {return rb->fd; }
@@ -2770,7 +2770,7 @@ void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr) }/* Return the offset of a hostpointer within a ramblock */ -ram_addr_t qemu_ram_block_host_offset (RAMBlock *rb,void *host) +ram_addr_t qemu_ram_block_host_offset (const RAMBlock *rb,void *host) {ram_addr_t res = (uint8_t *)host - (uint8_t *)rb->host;assert ((uintptr_t )host >= (uintptr_t )rb->host);
Signature · 1 line
2.52.0
Re: [PATCH 2/7] system/ramblock: Constify various RAMBlock arguments
Quoted 9 lines · Philippe Mathieu-Daudé
Mark the RAMBlock structure const when is only accessed read-only.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/system/ramblock.h | 26 +++++++++++++------------- stubs/ram-block.c | 8 ++++---- system/physmem.c | 26 +++++++++++++------------- 3 files changed, 30 insertions(+), 30 deletions(-)
Re: [PATCH 2/7] system/ramblock: Constify various RAMBlock arguments
In reply to Philippe Mathieu-DaudéQuoted 3 lines · Philippe Mathieu-Daudé
Mark the RAMBlock structure const when is only accessed read-only.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 1 line
Peter Xu
PATCH 3/7 system/memory: Constify various MemoryRegion arguments
In reply to Philippe Mathieu-DaudéMark the MemoryRegion structure const when is only accessed read-only.
--- include/system/memory.h | 28 ++++++++++++++-------------- system/memory.c | 34 ++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 30 deletions(-)
include/system/memory.h +14 -14
@@ -1749,14 +1749,14 @@ bool memory_region_init_rom_device(MemoryRegion *mr,* * @mr: the memory region being queried. */ -Object *memory_region_owner (MemoryRegion *mr); +Object *memory_region_owner (const MemoryRegion *mr);/** * memory_region_size: get a memory region's size. * * @mr: the memory region being queried. */ -uint64_t memory_region_size (MemoryRegion *mr); +uint64_t memory_region_size (const MemoryRegion *mr);/** * memory_region_is_ram: check whether a memory region is random access
@@ -1765,7 +1765,7 @@ uint64_t memory_region_size(MemoryRegion *mr);* * @mr: the memory region being queried */ -static inline bool memory_region_is_ram (MemoryRegion *mr) +static inline bool memory_region_is_ram (const MemoryRegion *mr) {return mr->ram; }
@@ -1777,7 +1777,7 @@ static inline bool memory_region_is_ram(MemoryRegion *mr)* * @mr: the memory region being queried */ -bool memory_region_is_ram_device (MemoryRegion *mr); +bool memory_region_is_ram_device (const MemoryRegion *mr);/** * memory_region_is_romd: check whether a memory region is in ROMD mode
@@ -1787,7 +1787,7 @@ bool memory_region_is_ram_device(MemoryRegion *mr);* * @mr: the memory region being queried */ -static inline bool memory_region_is_romd (MemoryRegion *mr) +static inline bool memory_region_is_romd (const MemoryRegion *mr) {return mr->rom_device && mr->romd_mode; }
@@ -1800,7 +1800,7 @@ static inline bool memory_region_is_romd(MemoryRegion *mr)* * @mr: the memory region being queried */ -bool memory_region_is_protected (MemoryRegion *mr); +bool memory_region_is_protected (const MemoryRegion *mr);/** * memory_region_has_guest_memfd: check whether a memory region has guest_memfd
@@ -1810,7 +1810,7 @@ bool memory_region_is_protected(MemoryRegion *mr);* * @mr: the memory region being queried */ -bool memory_region_has_guest_memfd (MemoryRegion *mr); +bool memory_region_has_guest_memfd (const MemoryRegion *mr);/** * memory_region_get_iommu: check whether a memory region is an iommu
@@ -1820,7 +1820,7 @@ bool memory_region_has_guest_memfd(MemoryRegion *mr);* * @mr: the memory region being queried */ -static inline IOMMUMemoryRegion *memory_region_get_iommu (MemoryRegion *mr) +static inline IOMMUMemoryRegion *memory_region_get_iommu (const MemoryRegion *mr) {if (mr->alias) {return memory_region_get_iommu (mr->alias);
@@ -1991,7 +1991,7 @@ const char *memory_region_name(const MemoryRegion *mr);* @mr: the memory region being queried * @client: the client being queried */ -bool memory_region_is_logging (MemoryRegion *mr,uint8_t client); +bool memory_region_is_logging (const MemoryRegion *mr,uint8_t client);/** * memory_region_get_dirty_log_mask: return the clients for which a
@@ -2002,7 +2002,7 @@ bool memory_region_is_logging(MemoryRegion *mr, uint8_t client);* * @mr: the memory region being queried */ -uint8_t memory_region_get_dirty_log_mask (MemoryRegion *mr); +uint8_t memory_region_get_dirty_log_mask (const MemoryRegion *mr);/** * memory_region_is_rom: check whether a memory region is ROM
@@ -2011,7 +2011,7 @@ uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr);* * @mr: the memory region being queried */ -static inline bool memory_region_is_rom (MemoryRegion *mr) +static inline bool memory_region_is_rom (const MemoryRegion *mr) {return mr->ram && mr->readonly; }
@@ -2023,7 +2023,7 @@ static inline bool memory_region_is_rom(MemoryRegion *mr)* * @mr: the memory region being queried */ -static inline bool memory_region_is_nonvolatile (MemoryRegion *mr) +static inline bool memory_region_is_nonvolatile (const MemoryRegion *mr) {return mr->nonvolatile; }
@@ -2036,7 +2036,7 @@ static inline bool memory_region_is_nonvolatile(MemoryRegion *mr)* * @mr: the RAM or alias memory region being queried. */ -int memory_region_get_fd (MemoryRegion *mr); +int memory_region_get_fd (const MemoryRegion *mr);/** * memory_region_from_host: Convert a pointer into a RAM memory region
@@ -2521,7 +2521,7 @@ bool memory_region_present(MemoryRegion *container, hwaddr addr);* * @mr: a #MemoryRegion which should be checked if it's mapped */ -bool memory_region_is_mapped (MemoryRegion *mr); +bool memory_region_is_mapped (const MemoryRegion *mr);/** * memory_region_get_ram_discard_manager: get the #RamDiscardManager for a
system/memory.c +18 -16
@@ -1819,9 +1819,9 @@ static void memory_region_finalize(Object *obj)g_free (mr->ioeventfds); } -Object *memory_region_owner (MemoryRegion *mr) +Object *memory_region_owner (const MemoryRegion *mr) { -Object *obj =OBJECT (mr); +const Object *obj =OBJECT (mr);return obj->parent; }
@@ -1849,7 +1849,7 @@ void memory_region_unref(MemoryRegion *mr) } } -uint64_t memory_region_size (MemoryRegion *mr) +uint64_t memory_region_size (const MemoryRegion *mr) {if (int128_eq (mr->size,int128_2_64 ())) {return UINT64_MAX ;
@@ -1866,25 +1866,25 @@ const char *memory_region_name(const MemoryRegion *mr)return mr->name; } -bool memory_region_is_ram_device (MemoryRegion *mr) +bool memory_region_is_ram_device (const MemoryRegion *mr) {return mr->ram_device; } -bool memory_region_is_protected (MemoryRegion *mr) +bool memory_region_is_protected (const MemoryRegion *mr) {return mr->ram && (mr->ram_block->flags &RAM_PROTECTED ); } -bool memory_region_has_guest_memfd (MemoryRegion *mr) +bool memory_region_has_guest_memfd (const MemoryRegion *mr) {return mr->ram_block && mr->ram_block->guest_memfd >=0 ; } -uint8_t memory_region_get_dirty_log_mask (MemoryRegion *mr) +uint8_t memory_region_get_dirty_log_mask (const MemoryRegion *mr) {uint8_t mask = mr->dirty_log_mask; -RAMBlock *rb = mr->ram_block; +const RAMBlock *rb = mr->ram_block;if (global_dirty_tracking && ((rb &&qemu_ram_is_migratable (rb)) ||memory_region_is_iommu (mr))) {
@@ -1898,7 +1898,7 @@ uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr)return mask; } -bool memory_region_is_logging (MemoryRegion *mr,uint8_t client) +bool memory_region_is_logging (const MemoryRegion *mr,uint8_t client) {return memory_region_get_dirty_log_mask (mr) & (1 << client); }
@@ -2406,7 +2406,7 @@ void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr, memory_region_get_ram_addr(mr) + addr, size, client, NULL); } -int memory_region_get_fd (MemoryRegion *mr) +int memory_region_get_fd (const MemoryRegion *mr) {RCU_READ_LOCK_GUARD ();while (mr->alias) {
@@ -2806,7 +2806,7 @@ static FlatRange *flatview_lookup(FlatView *view, AddrRange addr) sizeof(FlatRange), cmp_flatrange_addr); } -bool memory_region_is_mapped (MemoryRegion *mr) +bool memory_region_is_mapped (const MemoryRegion *mr) {return !!mr->container || mr->mapped_via_alias; }
@@ -3290,7 +3290,7 @@ void address_space_destroy_free(AddressSpace *as)call_rcu (as, do_address_space_destroy_free, rcu); } -static const char *memory_region_type (MemoryRegion *mr) +static const char *memory_region_type (const MemoryRegion *mr) {if (mr->alias) {return memory_region_type (mr->alias);
@@ -3483,7 +3483,6 @@ static void mtree_print_flatview(gpointer key, gpointer value,GArray *fv_address_spaces = value;struct FlatViewInfo *fvi = user_data;FlatRange *range = &view->ranges[0 ]; -MemoryRegion *mr;int n = view->nr;int i;AddressSpace *as;
@@ -3510,7 +3509,8 @@ static void mtree_print_flatview(gpointer key, gpointer value, }while (n--) { - mr = range->mr; +const MemoryRegion *mr = range->mr; +if (range->offset_in_region) { qemu_printf(MTREE_INDENT HWADDR_FMT_plx "-" HWADDR_FMT_plx " (prio %d, %s%s): %s @" HWADDR_FMT_plx,
@@ -3683,8 +3683,10 @@ static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled)/* print aliased regions */ QTAILQ_FOREACH(ml, &ml_head, mrqueue) { -qemu_printf ("memory-region: %s\n" ,memory_region_name (ml->mr)); -mtree_print_mr (ml->mr,1 ,0 , &ml_head, owner, disabled); +const MemoryRegion *mr = ml->mr; + +qemu_printf ("memory-region: %s\n" ,memory_region_name (mr)); +mtree_print_mr (mr,1 ,0 , &ml_head, owner, disabled);qemu_printf ("\n" ); }
Signature · 1 line
2.52.0
Re: [PATCH 3/7] system/memory: Constify various MemoryRegion arguments
Quoted 8 lines · Philippe Mathieu-Daudé
Mark the MemoryRegion structure const when is only accessed read-only.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/system/memory.h | 28 ++++++++++++++-------------- system/memory.c | 34 ++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 30 deletions(-)
Re: [PATCH 3/7] system/memory: Constify various MemoryRegion arguments
In reply to Philippe Mathieu-DaudéQuoted 3 lines · Philippe Mathieu-Daudé
Mark the MemoryRegion structure const when is only accessed read-only.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 1 line
Peter Xu
PATCH 4/7 system/memory: Have memory_region_type() correctly describe containers
In reply to Philippe Mathieu-DaudéMemoryRegion containers are not I/O regions,
describe them as 'container'.
--- system/memory.c | 2 ++ 1 file changed, 2 insertions(+)
system/memory.c +2 -0
@@ -3303,6 +3303,8 @@ static const char *memory_region_type(const MemoryRegion *mr)return "rom" ; }else if (memory_region_is_ram (mr)) {return "ram" ; + }else if (!mr->container) { +return "container" ; }else {return "i/o" ; }
Signature · 1 line
2.52.0
Re: [PATCH 4/7] system/memory: Have memory_region_type() correctly describe containers
Quoted 8 lines · Philippe Mathieu-Daudé
MemoryRegion containers are not I/O regions,
describe them as 'container'.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- system/memory.c | 2 ++ 1 file changed, 2 insertions(+)
Re: [PATCH 4/7] system/memory: Have memory_region_type() correctly describe containers
In reply to Philippe Mathieu-DaudéQuoted 4 lines · Philippe Mathieu-Daudé
MemoryRegion containers are not I/O regions,
describe them as 'container'.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 1 line
Peter Xu
PATCH 5/7 system/memory: Display address spaces starting at 0x0000.0000
In reply to Philippe Mathieu-DaudéSince AddressSpace root MemoryRegion can be remapped, it is bogus to use the MemoryRegion address as the AddressSpace absolute address. Besides, the AddressSpace APIs take an @addr argument expecting AddressSpaces start at 0x0000.0000.
Substract the MemoryRegion address in mtree_print_mr() to display AddressSpaces starting at 0x0000.0000.
--- system/memory.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
system/memory.c +7 -6
@@ -3360,7 +3360,7 @@ static void mtree_print_mr_owner(const MemoryRegion *mr) }static void mtree_print_mr (const MemoryRegion *mr,unsigned int level, -hwaddr base, +hwaddr offset,bool detect_overflow,MemoryRegionListHead *alias_print_queue,bool owner,bool display_disabled) {
@@ -3374,7 +3374,7 @@ static void mtree_print_mr(const MemoryRegion *mr, unsigned int level,return ; } - cur_start = base + mr->addr; + cur_start = mr->addr + offset; cur_end = cur_start +MR_SIZE (mr->size);/*
@@ -3382,7 +3382,7 @@ static void mtree_print_mr(const MemoryRegion *mr, unsigned int level,* happen normally. When it happens, we dump something to warn the * user who is observing this. */ -if (cur_start < base || cur_end < cur_start) { +if (detect_overflow && (cur_start < offset || cur_end < cur_start)) {qemu_printf ("[DETECTED OVERFLOW!] " ); }
@@ -3462,7 +3462,7 @@ static void mtree_print_mr(const MemoryRegion *mr, unsigned int level, } QTAILQ_FOREACH(ml, &submr_print_queue, mrqueue) { -mtree_print_mr (ml->mr, level +1 , cur_start, +mtree_print_mr (ml->mr, level +1 , cur_start, true, alias_print_queue, owner, display_disabled); }
@@ -3641,7 +3641,8 @@ static void mtree_print_as(gpointer key, gpointer value, gpointer user_data)struct AddressSpaceInfo *asi = user_data;g_slist_foreach (as_same_root_mr_list, mtree_print_as_name,NULL ); -mtree_print_mr (mr,1 ,0 , asi->ml_head, asi->owner, asi->disabled); +mtree_print_mr (mr,1 , -mr->addr, false, + asi->ml_head, asi->owner, asi->disabled);qemu_printf ("\n" ); }
@@ -3688,7 +3689,7 @@ static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled)const MemoryRegion *mr = ml->mr;qemu_printf ("memory-region: %s\n" ,memory_region_name (mr)); -mtree_print_mr (mr,1 ,0 , &ml_head, owner, disabled); +mtree_print_mr (mr,1 ,0 , false, &ml_head, owner, disabled);qemu_printf ("\n" ); }
Signature · 1 line
2.52.0
Re: [PATCH 5/7] system/memory: Display address spaces starting at 0x0000.0000
Quoted 5 lines · Philippe Mathieu-Daudé
Since AddressSpace root MemoryRegion can be remapped, it is bogus to use the MemoryRegion address as the AddressSpace absolute address. Besides, the AddressSpace APIs take an @addr argument expecting AddressSpaces start at 0x0000.0000.
Quoted 8 lines
Substract the MemoryRegion address in
mtree_print_mr()to display AddressSpaces starting at 0x0000.0000.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- system/memory.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
Re: [PATCH 5/7] system/memory: Display address spaces starting at 0x0000.0000
In reply to Philippe Mathieu-DaudéHi, Phil!
Quoted 4 lines · Philippe Mathieu-Daudé
Since AddressSpace root MemoryRegion can be remapped, it is bogus to use the MemoryRegion address as the AddressSpace absolute address. Besides, the AddressSpace APIs take an @addr argument expecting AddressSpaces start at 0x0000.0000.
Could you share an example where a root MR can have addr!=0, and be remapped while being the root MR of an AS?
Thanks,
Quoted 71 lines
Substract the MemoryRegion address in
mtree_print_mr()to display AddressSpaces starting at 0x0000.0000.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- system/memory.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)system/memory.c +7
-6@@ -3360,7 +3360,7 @@ static void mtree_print_mr_owner(const MemoryRegion *mr) }static void mtree_print_mr (const MemoryRegion *mr,unsigned int level, -hwaddr base, +hwaddr offset,bool detect_overflow,MemoryRegionListHead *alias_print_queue,bool owner,bool display_disabled) {@@ -3374,7 +3374,7 @@ static void mtree_print_mr(const MemoryRegion *mr, unsigned int level,return ; } - cur_start = base + mr->addr; + cur_start = mr->addr + offset; cur_end = cur_start +MR_SIZE (mr->size);/* @@ -3382,7 +3382,7 @@ static void mtree_print_mr(const MemoryRegion *mr, unsigned int level,* happen normally. When it happens, we dump something to warn the * user who is observing this. */ -if (cur_start < base || cur_end < cur_start) { +if (detect_overflow && (cur_start < offset || cur_end < cur_start)) {qemu_printf ("[DETECTED OVERFLOW!] " ); }@@ -3462,7 +3462,7 @@ static void mtree_print_mr(const MemoryRegion *mr, unsigned int level, } QTAILQ_FOREACH(ml, &submr_print_queue, mrqueue) { -mtree_print_mr (ml->mr, level +1 , cur_start, +mtree_print_mr (ml->mr, level +1 , cur_start, true, alias_print_queue, owner, display_disabled); }@@ -3641,7 +3641,8 @@ static void mtree_print_as(gpointer key, gpointer value, gpointer user_data)struct AddressSpaceInfo *asi = user_data;g_slist_foreach (as_same_root_mr_list, mtree_print_as_name,NULL ); -mtree_print_mr (mr,1 ,0 , asi->ml_head, asi->owner, asi->disabled); +mtree_print_mr (mr,1 , -mr->addr, false, + asi->ml_head, asi->owner, asi->disabled);qemu_printf ("\n" ); }@@ -3688,7 +3689,7 @@ static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled)const MemoryRegion *mr = ml->mr;qemu_printf ("memory-region: %s\n" ,memory_region_name (mr)); -mtree_print_mr (mr,1 ,0 , &ml_head, owner, disabled); +mtree_print_mr (mr,1 ,0 , false, &ml_head, owner, disabled);qemu_printf ("\n" ); }Signature · 1 line
2.52.0
Signature · 1 line
Peter Xu
PATCH 6/7 system/memory: Allow mtree_print_mr() to display distinct address width
In reply to Philippe Mathieu-Daudémtree_print_mr() display addresses using 16 chars on 64-bit binaries, and 8 chars on 32-bit ones. Some MR / AS don't always benefit of 16 chars, for example the ISA I/O region fits in 16 bits, and displaying 12 extra '0' in 64-bit binaries isn't really a good user experience.
Add an extra @width argument to mtree_print_mr(). Next commit will make use of it.
--- system/memory.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-)
system/memory.c +27 -21
@@ -3321,6 +3321,7 @@ typedef QTAILQ_HEAD(, MemoryRegionList) MemoryRegionListHead;#define MR_SIZE (size) (int128_nz(size) ? (hwaddr)int128_get64( \ int128_sub((size), int128_one())) : 0) +#define MR_ADDR_WIDTH 16#define MTREE_INDENT " "static void mtree_expand_owner (const char *label,Object *obj)
@@ -3360,6 +3361,7 @@ static void mtree_print_mr_owner(const MemoryRegion *mr) }static void mtree_print_mr (const MemoryRegion *mr,unsigned int level, +unsigned int width,hwaddr offset,bool detect_overflow,MemoryRegionListHead *alias_print_queue,bool owner,bool display_disabled)
@@ -3405,17 +3407,17 @@ static void mtree_print_mr(const MemoryRegion *mr, unsigned int level,for (i =0 ; i < level; i++) {qemu_printf (MTREE_INDENT ); } -qemu_printf (HWADDR_FMT_plx"-" HWADDR_FMT_plx -" (prio %d, %s%s): alias %s @%s " HWADDR_FMT_plx -"-" HWADDR_FMT_plx"%s" , - cur_start, cur_end, +qemu_printf ("%0*" PRIx64"-" "%0*" PRIx64 +" (prio %d, %s%s): alias %s @%s " +"%0*" PRIx64"-" "%0*" PRIx64"%s" , + width, cur_start, width, cur_end, mr->priority, mr->nonvolatile ?"nv-" :"" ,memory_region_type ((MemoryRegion *)mr),memory_region_name (mr),memory_region_name (mr->alias), - mr->alias_offset, - mr->alias_offset +MR_SIZE (mr->size), + width, mr->alias_offset, + width, mr->alias_offset +MR_SIZE (mr->size), mr->enabled ?"" :" [disabled]" );if (owner) {mtree_print_mr_owner (mr);
@@ -3427,9 +3429,9 @@ static void mtree_print_mr(const MemoryRegion *mr, unsigned int level,for (i =0 ; i < level; i++) {qemu_printf (MTREE_INDENT ); } - qemu_printf(HWADDR_FMT_plx "-" HWADDR_FMT_plx + qemu_printf("%0*" PRIx64 "-" "%0*" PRIx64 " (prio %d, %s%s): %s%s", - cur_start, cur_end, + width, cur_start, width, cur_end, mr->priority, mr->nonvolatile ? "nv-" : "", memory_region_type((MemoryRegion *)mr),
@@ -3462,7 +3464,7 @@ static void mtree_print_mr(const MemoryRegion *mr, unsigned int level, } QTAILQ_FOREACH(ml, &submr_print_queue, mrqueue) { -mtree_print_mr (ml->mr, level +1 , cur_start, true, +mtree_print_mr (ml->mr, level +1 , width, cur_start, true, alias_print_queue, owner, display_disabled); }
@@ -3485,6 +3487,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,GArray *fv_address_spaces = value;struct FlatViewInfo *fvi = user_data;FlatRange *range = &view->ranges[0 ]; +unsigned int width;int n = view->nr;int i;AddressSpace *as;
@@ -3510,26 +3513,27 @@ static void mtree_print_flatview(gpointer key, gpointer value,return ; } + width =MR_ADDR_WIDTH ;while (n--) {const MemoryRegion *mr = range->mr;if (range->offset_in_region) { - qemu_printf(MTREE_INDENT HWADDR_FMT_plx "-" HWADDR_FMT_plx -" (prio %d, %s%s): %s @" HWADDR_FMT_plx, -int128_get64 (range->addr.start), -int128_get64 (range->addr.start) - +MR_SIZE (range->addr.size), +qemu_printf (MTREE_INDENT "%0*" PRIx64"-" "%0*" PRIx64 +" (prio %d, %s%s): %s @" "%0*" PRIx64, + width,int128_get64 (range->addr.start), + width,int128_get64 (range->addr.start) + +MR_SIZE (range->addr.size), mr->priority, range->nonvolatile ?"nv-" :"" , range->readonly ?"rom" :memory_region_type (mr),memory_region_name (mr), - range->offset_in_region); + width, range->offset_in_region); }else { - qemu_printf(MTREE_INDENT HWADDR_FMT_plx "-" HWADDR_FMT_plx + qemu_printf(MTREE_INDENT "%0*" PRIx64 "-" "%0*" PRIx64 " (prio %d, %s%s): %s", -int128_get64 (range->addr.start), -int128_get64 (range->addr.start) - +MR_SIZE (range->addr.size), + width, int128_get64(range->addr.start), + width, int128_get64(range->addr.start) + + MR_SIZE(range->addr.size), mr->priority, range->nonvolatile ? "nv-" : "", range->readonly ? "rom" : memory_region_type(mr),
@@ -3639,9 +3643,10 @@ static void mtree_print_as(gpointer key, gpointer value, gpointer user_data)MemoryRegion *mr = key;GSList *as_same_root_mr_list = value;struct AddressSpaceInfo *asi = user_data; +const unsigned int width =MR_ADDR_WIDTH ;g_slist_foreach (as_same_root_mr_list, mtree_print_as_name,NULL ); -mtree_print_mr (mr,1 , -mr->addr, false, +mtree_print_mr (mr,1 , width, -mr->addr, false, asi->ml_head, asi->owner, asi->disabled);qemu_printf ("\n" ); }
@@ -3687,9 +3692,10 @@ static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled)/* print aliased regions */ QTAILQ_FOREACH(ml, &ml_head, mrqueue) {const MemoryRegion *mr = ml->mr; +const unsigned int width =MR_ADDR_WIDTH ;qemu_printf ("memory-region: %s\n" ,memory_region_name (mr)); -mtree_print_mr (mr,1 ,0 , false, &ml_head, owner, disabled); +mtree_print_mr (mr,1 , width,0 , false, &ml_head, owner, disabled);qemu_printf ("\n" ); }
Signature · 1 line
2.52.0
Re: [PATCH 6/7] system/memory: Allow mtree_print_mr() to display distinct address width
Quoted 6 lines · Philippe Mathieu-Daudé
mtree_print_mr()display addresses using 16 chars on 64-bit binaries, and 8 chars on 32-bit ones. Some MR / AS don't always benefit of 16 chars, for example the ISA I/O region fits in 16 bits, and displaying 12 extra '0' in 64-bit binaries isn't really a good user experience.
Quoted 8 lines
Add an extra @width argument to
mtree_print_mr(). Next commit will make use of it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- system/memory.c | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-)
Re: [PATCH 6/7] system/memory: Allow mtree_print_mr() to display distinct address width
In reply to Philippe Mathieu-DaudéQuoted 10 lines · Philippe Mathieu-Daudé
mtree_print_mr()display addresses using 16 chars on 64-bit binaries, and 8 chars on 32-bit ones. Some MR / AS don't always benefit of 16 chars, for example the ISA I/O region fits in 16 bits, and displaying 12 extra '0' in 64-bit binaries isn't really a good user experience.Add an extra @width argument to
mtree_print_mr(). Next commit will make use of it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Signature · 1 line
Peter Xu
PATCH 7/7 system/memory: Have 'info mtree' display addresses nicely
In reply to Philippe Mathieu-DaudéUse the size of a MR / AS to decide how many address chars need to be used.
For example, using 'qemu-system-x86_64 -M q35 -S -monitor stdio' to run 'info mtree' displays before:
address-space: I/O
0000000000000000-000000000000ffff (prio 0, i/o): io
0000000000000000-0000000000000003 (prio 0, i/o): acpi-evt
0000000000000004-0000000000000005 (prio 0, i/o): acpi-cnt
0000000000000008-000000000000000b (prio 0, i/o): acpi-tmr
0000000000000020-000000000000002f (prio 0, i/o): acpi-gpe0
0000000000000030-0000000000000037 (prio 0, i/o): acpi-smi
0000000000000060-000000000000007f (prio 0, i/o): sm-tco
0000000000000000-0000000000000007 (prio 0, i/o): dma-chan
0000000000000008-000000000000000f (prio 0, i/o): dma-cont
0000000000000020-0000000000000021 (prio 0, i/o): pic
0000000000000040-0000000000000043 (prio 0, i/o): pit
...
memory-region: pc.ram
0000000000000000-0000000007ffffff (prio 0, ram): pc.ram
memory-region: pc.bios
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios
memory-region: pci
0000000000000000-ffffffffffffffff (prio -1, i/o): pci
00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem
00000000000c0000-00000000000dffff (prio 1, rom): pc.rom
00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios...
and after:
address-space: I/O
0000-ffff (prio 0, container): io
0000-0003 (prio 0, i/o): acpi-evt
0004-0005 (prio 0, i/o): acpi-cnt
0008-000b (prio 0, i/o): acpi-tmr
0020-002f (prio 0, i/o): acpi-gpe0
0030-0037 (prio 0, i/o): acpi-smi
0060-007f (prio 0, i/o): sm-tco
0000-0007 (prio 0, i/o): dma-chan
0008-000f (prio 0, i/o): dma-cont
0020-0021 (prio 0, i/o): pic
0040-0043 (prio 0, i/o): pit
...
memory-region: pc.ram
00000000-07ffffff (prio 0, ram): pc.ram
memory-region: pc.bios
fffc0000-ffffffff (prio 0, rom): pc.bios
memory-region: pci
0000000000000000-ffffffffffffffff (prio -1, i/o): pci
00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem
00000000000c0000-00000000000dffff (prio 1, rom): pc.rom
00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios...
--- system/memory.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
system/memory.c +23 -4
@@ -3321,7 +3321,26 @@ typedef QTAILQ_HEAD(, MemoryRegionList) MemoryRegionListHead;#define MR_SIZE (size) (int128_nz(size) ? (hwaddr)int128_get64( \ int128_sub((size), int128_one())) : 0) -#define MR_ADDR_WIDTH 16 + +static unsigned mr_addr_fmt_width (const MemoryRegion *mr) +{ +const unsigned int bits =127 -clz128 (mr->size); +unsigned int width; + +if (bits <=8 ) { + width =2 ; + }else if (bits <=16 ) { + width =4 ; + }else if (bits <=32 ) { + width =8 ; + }else if (bits <=64 ) { + width =16 ; + }else { + width =20 ; + } +return width; +} +#define MTREE_INDENT " "static void mtree_expand_owner (const char *label,Object *obj)
@@ -3513,7 +3532,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,return ; } - width =MR_ADDR_WIDTH ; + width =mr_addr_fmt_width (view->root);while (n--) {const MemoryRegion *mr = range->mr;
@@ -3643,7 +3662,7 @@ static void mtree_print_as(gpointer key, gpointer value, gpointer user_data)MemoryRegion *mr = key;GSList *as_same_root_mr_list = value;struct AddressSpaceInfo *asi = user_data; -const unsigned int width =MR_ADDR_WIDTH ; +const unsigned int width =mr_addr_fmt_width (mr);g_slist_foreach (as_same_root_mr_list, mtree_print_as_name,NULL ); mtree_print_mr(mr, 1, width, -mr->addr, false,
@@ -3692,7 +3711,7 @@ static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled)/* print aliased regions */ QTAILQ_FOREACH(ml, &ml_head, mrqueue) {const MemoryRegion *mr = ml->mr; -const unsigned int width =MR_ADDR_WIDTH ; +const unsigned int width =mr_addr_fmt_width (mr);qemu_printf ("memory-region: %s\n" ,memory_region_name (mr));mtree_print_mr (mr,1 , width,0 , false, &ml_head, owner, disabled);
Signature · 1 line
2.52.0
Re: [PATCH 7/7] system/memory: Have 'info mtree' display addresses nicely
Quoted 114 lines · Philippe Mathieu-Daudé
Use the size of a MR / AS to decide how many address chars need to be used.
For example, using 'qemu-system-x86_64 -M q35 -S -monitor stdio' to run 'info mtree' displays before:
address-space: I/O 0000000000000000-000000000000ffff (prio 0, i/o): io 0000000000000000-0000000000000003 (prio 0, i/o): acpi-evt 0000000000000004-0000000000000005 (prio 0, i/o): acpi-cnt 0000000000000008-000000000000000b (prio 0, i/o): acpi-tmr 0000000000000020-000000000000002f (prio 0, i/o): acpi-gpe0 0000000000000030-0000000000000037 (prio 0, i/o): acpi-smi 0000000000000060-000000000000007f (prio 0, i/o): sm-tco 0000000000000000-0000000000000007 (prio 0, i/o): dma-chan 0000000000000008-000000000000000f (prio 0, i/o): dma-cont 0000000000000020-0000000000000021 (prio 0, i/o): pic 0000000000000040-0000000000000043 (prio 0, i/o): pit ... memory-region: pc.ram 0000000000000000-0000000007ffffff (prio 0, ram): pc.ram memory-region: pc.bios 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios memory-region: pci 0000000000000000-ffffffffffffffff (prio -1, i/o): pci 00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem 00000000000c0000-00000000000dffff (prio 1, rom): pc.rom 00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios ...and after:
address-space: I/O 0000-ffff (prio 0, container): io 0000-0003 (prio 0, i/o): acpi-evt 0004-0005 (prio 0, i/o): acpi-cnt 0008-000b (prio 0, i/o): acpi-tmr 0020-002f (prio 0, i/o): acpi-gpe0 0030-0037 (prio 0, i/o): acpi-smi 0060-007f (prio 0, i/o): sm-tco 0000-0007 (prio 0, i/o): dma-chan 0008-000f (prio 0, i/o): dma-cont 0020-0021 (prio 0, i/o): pic 0040-0043 (prio 0, i/o): pit ... memory-region: pc.ram 00000000-07ffffff (prio 0, ram): pc.ram memory-region: pc.bios fffc0000-ffffffff (prio 0, rom): pc.bios memory-region: pci 0000000000000000-ffffffffffffffff (prio -1, i/o): pci 00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem 00000000000c0000-00000000000dffff (prio 1, rom): pc.rom 00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios ...Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- system/memory.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)system/memory.c +22
-3@@ -3321,7 +3321,26 @@ typedef QTAILQ_HEAD(, MemoryRegionList) MemoryRegionListHead;#define MR_SIZE (size) (int128_nz(size) ? (hwaddr)int128_get64( \ int128_sub((size), int128_one())) : 0) -#define MR_ADDR_WIDTH 16 + +static unsigned mr_addr_fmt_width (const MemoryRegion *mr) +{ +const unsigned int bits =127 -clz128 (mr->size); +unsigned int width; + +if (bits <=8 ) { + width =2 ; + }else if (bits <=16 ) { + width =4 ; + }else if (bits <=32 ) { + width =8 ; + }else if (bits <=64 ) { + width =16 ; + }else { + width =20 ; + } +return width; +} +#define MTREE_INDENT " "static void mtree_expand_owner (const char *label,Object *obj)@@ -3513,7 +3532,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,return ; } - width =MR_ADDR_WIDTH ; + width =mr_addr_fmt_width (view->root);while (n--) {const MemoryRegion *mr = range->mr;@@ -3643,7 +3662,7 @@ static void mtree_print_as(gpointer key, gpointer value, gpointer user_data)MemoryRegion *mr = key;GSList *as_same_root_mr_list = value;struct AddressSpaceInfo *asi = user_data; -const unsigned int width =MR_ADDR_WIDTH ; +const unsigned int width =mr_addr_fmt_width (mr);g_slist_foreach (as_same_root_mr_list, mtree_print_as_name,NULL ); mtree_print_mr(mr, 1, width, -mr->addr, false,
system/memory.c static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled) · line 3717
Quoted 8 lines
system/memory.c +1
-1@@ -3692,7 +3711,7 @@ static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled)/* print aliased regions */ QTAILQ_FOREACH(ml, &ml_head, mrqueue) {const MemoryRegion *mr = ml->mr; -const unsigned int width =MR_ADDR_WIDTH ; +const unsigned int width =mr_addr_fmt_width (mr);qemu_printf ("memory-region: %s\n" ,memory_region_name (mr));mtree_print_mr (mr,1 , width,0 , false, &ml_head, owner, disabled);
That is so neat!
Re: [PATCH 7/7] system/memory: Have 'info mtree' display addresses nicely
In reply to Philippe Mathieu-DaudéQuoted 78 lines · Philippe Mathieu-Daudé
Use the size of a MR / AS to decide how many address chars need to be used.
For example, using 'qemu-system-x86_64 -M q35 -S -monitor stdio' to run 'info mtree' displays before:
address-space: I/O
0000000000000000-000000000000ffff (prio 0, i/o): io0000000000000000-0000000000000003 (prio 0, i/o): acpi-evt 0000000000000004-0000000000000005 (prio 0, i/o): acpi-cnt 0000000000000008-000000000000000b (prio 0, i/o): acpi-tmr 0000000000000020-000000000000002f (prio 0, i/o): acpi-gpe0 0000000000000030-0000000000000037 (prio 0, i/o): acpi-smi 0000000000000060-000000000000007f (prio 0, i/o): sm-tco 0000000000000000-0000000000000007 (prio 0, i/o): dma-chan 0000000000000008-000000000000000f (prio 0, i/o): dma-cont 0000000000000020-0000000000000021 (prio 0, i/o): pic 0000000000000040-0000000000000043 (prio 0, i/o): pit ... memory-region: pc.ram 0000000000000000-0000000007ffffff (prio 0, ram): pc.ram memory-region: pc.bios 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios memory-region: pci 0000000000000000-ffffffffffffffff (prio -1, i/o): pci 00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem 00000000000c0000-00000000000dffff (prio 1, rom): pc.rom 00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios...
and after:
address-space: I/O
0000-ffff (prio 0, container): io0000-0003 (prio 0, i/o): acpi-evt 0004-0005 (prio 0, i/o): acpi-cnt 0008-000b (prio 0, i/o): acpi-tmr 0020-002f (prio 0, i/o): acpi-gpe0 0030-0037 (prio 0, i/o): acpi-smi 0060-007f (prio 0, i/o): sm-tco 0000-0007 (prio 0, i/o): dma-chan 0008-000f (prio 0, i/o): dma-cont 0020-0021 (prio 0, i/o): pic 0040-0043 (prio 0, i/o): pit ... memory-region: pc.ram 00000000-07ffffff (prio 0, ram): pc.ram memory-region: pc.bios fffc0000-ffffffff (prio 0, rom): pc.bios memory-region: pci 0000000000000000-ffffffffffffffff (prio -1, i/o): pci 00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem 00000000000c0000-00000000000dffff (prio 1, rom): pc.rom 00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios...
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
system/memory.c| 27 +++++++++++++++++++++++----1 file changed, 23 insertions(+), 4 deletions(-)system/memory.c +6
-1@@ -3321,7 +3321,26 @@ typedef QTAILQ_HEAD(, MemoryRegionList) MemoryRegionListHead;#define MR_SIZE (size) (int128_nz(size) ? (hwaddr)int128_get64( \ int128_sub((size), int128_one())) : 0) -#define MR_ADDR_WIDTH 16 + +static unsigned mr_addr_fmt_width (const MemoryRegion *mr) +{ +const unsigned int bits =127 -clz128 (mr->size); +unsigned int width; +
system/memory.c typedef QTAILQ_HEAD(, MemoryRegionList) MemoryRegionListHead; · line 3339
Quoted 10 lines
system/memory.c +10
-0+if (bits <=8 ) { + width =2 ; + }else if (bits <=16 ) { + width =4 ; + }else if (bits <=32 ) { + width =8 ; + }else if (bits <=64 ) { + width =16 ; + }else { + width =20 ;
Why 20? HWADDR_FMT_plx this seems to replace is "%016" PRIx64
Regards,
BALATON Zoltan
Quoted 35 lines
system/memory.c +7
-3+ } +return width; +} +#define MTREE_INDENT " "static void mtree_expand_owner (const char *label,Object *obj)@@ -3513,7 +3532,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,return ; } - width =MR_ADDR_WIDTH ; + width =mr_addr_fmt_width (view->root);while (n--) {const MemoryRegion *mr = range->mr;@@ -3643,7 +3662,7 @@ static void mtree_print_as(gpointer key, gpointer value, gpointer user_data)MemoryRegion *mr = key;GSList *as_same_root_mr_list = value;struct AddressSpaceInfo *asi = user_data; -const unsigned int width =MR_ADDR_WIDTH ; +const unsigned int width =mr_addr_fmt_width (mr);g_slist_foreach (as_same_root_mr_list, mtree_print_as_name,NULL ); mtree_print_mr(mr, 1, width, -mr->addr, false,@@ -3692,7 +3711,7 @@ static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled)/* print aliased regions */ QTAILQ_FOREACH(ml, &ml_head, mrqueue) {const MemoryRegion *mr = ml->mr; -const unsigned int width =MR_ADDR_WIDTH ; +const unsigned int width =mr_addr_fmt_width (mr);qemu_printf ("memory-region: %s\n" ,memory_region_name (mr));mtree_print_mr (mr,1 , width,0 , false, &ml_head, owner, disabled);
Re: [PATCH 7/7] system/memory: Have 'info mtree' display addresses nicely
Hi Zoltan,
Quoted 86 lines · BALATON Zoltan
Quoted 85 lines · Philippe Mathieu-Daudé
Use the size of a MR / AS to decide how many address chars need to be used.
For example, using 'qemu-system-x86_64 -M q35 -S -monitor stdio' to run 'info mtree' displays before:
address-space: I/O
0000000000000000-000000000000ffff (prio 0, i/o): io 0000000000000000-0000000000000003 (prio 0, i/o): acpi-evt 0000000000000004-0000000000000005 (prio 0, i/o): acpi-cnt 0000000000000008-000000000000000b (prio 0, i/o): acpi-tmr 0000000000000020-000000000000002f (prio 0, i/o): acpi-gpe0 0000000000000030-0000000000000037 (prio 0, i/o): acpi-smi 0000000000000060-000000000000007f (prio 0, i/o): sm-tco 0000000000000000-0000000000000007 (prio 0, i/o): dma-chan 0000000000000008-000000000000000f (prio 0, i/o): dma-cont 0000000000000020-0000000000000021 (prio 0, i/o): pic 0000000000000040-0000000000000043 (prio 0, i/o): pit
...
memory-region: pc.ram
0000000000000000-0000000007ffffff (prio 0, ram): pc.ram
memory-region: pc.bios
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios
memory-region: pci
0000000000000000-ffffffffffffffff (prio -1, i/o): pci 00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem 00000000000c0000-00000000000dffff (prio 1, rom): pc.rom 00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios
...and after:
address-space: I/O
0000-ffff (prio 0, container): io
0000-0003 (prio 0, i/o): acpi-evt
0004-0005 (prio 0, i/o): acpi-cnt
0008-000b (prio 0, i/o): acpi-tmr
0020-002f (prio 0, i/o): acpi-gpe0
0030-0037 (prio 0, i/o): acpi-smi
0060-007f (prio 0, i/o): sm-tco
0000-0007 (prio 0, i/o): dma-chan
0008-000f (prio 0, i/o): dma-cont
0020-0021 (prio 0, i/o): pic
0040-0043 (prio 0, i/o): pit
...
memory-region: pc.ram
00000000-07ffffff (prio 0, ram): pc.ram
memory-region: pc.bios
fffc0000-ffffffff (prio 0, rom): pc.bios
memory-region: pci
0000000000000000-ffffffffffffffff (prio -1, i/o): pci 00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem 00000000000c0000-00000000000dffff (prio 1, rom): pc.rom 00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios
...Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
system/memory.c| 27 +++++++++++++++++++++++----1 file changed, 23 insertions(+), 4 deletions(-)system/memory.c +10
-1@@ -3321,7 +3321,26 @@ typedef QTAILQ_HEAD(, MemoryRegionList) MemoryRegionListHead;#define MR_SIZE (size) (int128_nz(size) ? (hwaddr)int128_get64( \ int128_sub((size), int128_one())) : 0) -#define MR_ADDR_WIDTH 16 + +static unsigned mr_addr_fmt_width (const MemoryRegion *mr) +{ + const unsigned int bits = 127 - clz128(mr->size); + unsigned int width; + + if (bits <= 8) { + width = 2; + } else if (bits <= 16) { + width = 4;
Quoted 8 lines
system/memory.c typedef QTAILQ_HEAD(, MemoryRegionList) MemoryRegionListHead; · line 3339
Quoted 6 lines
system/memory.c +6
-0+ } else if (bits <= 32) { + width = 8; + } else if (bits <= 64) { + width = 16; + } else { + width = 20;Why 20?
HWADDR_FMT_plxthis seems to replace is "%016" PRIx64
HWADDR_FMT_plx predates support for int128_t and 128-bit wide addresses. Using 20 chars is sufficient to align our current uses.
I'll precise that in the patch description.
Regards,
Phil.
Quoted 3 lines
Regards,
BALATON Zoltan
Re: [PATCH 7/7] system/memory: Have 'info mtree' display addresses nicely
In reply to Philippe Mathieu-DaudéQuoted 78 lines · Philippe Mathieu-Daudé
Use the size of a MR / AS to decide how many address chars need to be used.
For example, using 'qemu-system-x86_64 -M q35 -S -monitor stdio' to run 'info mtree' displays before:
address-space: I/O
0000000000000000-000000000000ffff (prio 0, i/o): io 0000000000000000-0000000000000003 (prio 0, i/o): acpi-evt 0000000000000004-0000000000000005 (prio 0, i/o): acpi-cnt 0000000000000008-000000000000000b (prio 0, i/o): acpi-tmr 0000000000000020-000000000000002f (prio 0, i/o): acpi-gpe0 0000000000000030-0000000000000037 (prio 0, i/o): acpi-smi 0000000000000060-000000000000007f (prio 0, i/o): sm-tco 0000000000000000-0000000000000007 (prio 0, i/o): dma-chan 0000000000000008-000000000000000f (prio 0, i/o): dma-cont 0000000000000020-0000000000000021 (prio 0, i/o): pic 0000000000000040-0000000000000043 (prio 0, i/o): pit ... memory-region: pc.ram 0000000000000000-0000000007ffffff (prio 0, ram): pc.ram memory-region: pc.bios 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios memory-region: pci 0000000000000000-ffffffffffffffff (prio -1, i/o): pci 00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem 00000000000c0000-00000000000dffff (prio 1, rom): pc.rom 00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios...
and after:
address-space: I/O
0000-ffff (prio 0, container): io 0000-0003 (prio 0, i/o): acpi-evt 0004-0005 (prio 0, i/o): acpi-cnt 0008-000b (prio 0, i/o): acpi-tmr 0020-002f (prio 0, i/o): acpi-gpe0 0030-0037 (prio 0, i/o): acpi-smi 0060-007f (prio 0, i/o): sm-tco 0000-0007 (prio 0, i/o): dma-chan 0008-000f (prio 0, i/o): dma-cont 0020-0021 (prio 0, i/o): pic 0040-0043 (prio 0, i/o): pit ... memory-region: pc.ram 00000000-07ffffff (prio 0, ram): pc.ram memory-region: pc.bios fffc0000-ffffffff (prio 0, rom): pc.bios memory-region: pci 0000000000000000-ffffffffffffffff (prio -1, i/o): pci 00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem 00000000000c0000-00000000000dffff (prio 1, rom): pc.rom 00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios...
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- system/memory.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)system/memory.c +6
-1@@ -3321,7 +3321,26 @@ typedef QTAILQ_HEAD(, MemoryRegionList) MemoryRegionListHead;#define MR_SIZE (size) (int128_nz(size) ? (hwaddr)int128_get64( \ int128_sub((size), int128_one())) : 0) -#define MR_ADDR_WIDTH 16 + +static unsigned mr_addr_fmt_width (const MemoryRegion *mr) +{ +const unsigned int bits =127 -clz128 (mr->size); +unsigned int width; +
system/memory.c typedef QTAILQ_HEAD(, MemoryRegionList) MemoryRegionListHead; · line 3339
Quoted 10 lines
system/memory.c +10
-0+if (bits <=8 ) { + width =2 ; + }else if (bits <=16 ) { + width =4 ; + }else if (bits <=32 ) { + width =8 ; + }else if (bits <=64 ) { + width =16 ; + }else { + width =20 ;
Is there any case this can happen? I thought we don't have MR larger than 1<<64. Not a huge deal, though.
Quoted 37 lines
system/memory.c +7
-3+ } +return width; +} +#define MTREE_INDENT " "static void mtree_expand_owner (const char *label,Object *obj)@@ -3513,7 +3532,7 @@ static void mtree_print_flatview(gpointer key, gpointer value,return ; } - width =MR_ADDR_WIDTH ; + width =mr_addr_fmt_width (view->root);while (n--) {const MemoryRegion *mr = range->mr;@@ -3643,7 +3662,7 @@ static void mtree_print_as(gpointer key, gpointer value, gpointer user_data)MemoryRegion *mr = key;GSList *as_same_root_mr_list = value;struct AddressSpaceInfo *asi = user_data; -const unsigned int width =MR_ADDR_WIDTH ; +const unsigned int width =mr_addr_fmt_width (mr);g_slist_foreach (as_same_root_mr_list, mtree_print_as_name,NULL ); mtree_print_mr(mr, 1, width, -mr->addr, false,@@ -3692,7 +3711,7 @@ static void mtree_info_as(bool dispatch_tree, bool owner, bool disabled)/* print aliased regions */ QTAILQ_FOREACH(ml, &ml_head, mrqueue) {const MemoryRegion *mr = ml->mr; -const unsigned int width =MR_ADDR_WIDTH ; +const unsigned int width =mr_addr_fmt_width (mr);qemu_printf ("memory-region: %s\n" ,memory_region_name (mr));mtree_print_mr (mr,1 , width,0 , false, &ml_head, owner, disabled);Signature · 1 line
2.52.0
Signature · 1 line
Peter Xu
Re: [PATCH 7/7] system/memory: Have 'info mtree' display addresses nicely
Quoted 93 lines · Peter Xu
Quoted 78 lines · Philippe Mathieu-Daudé
Use the size of a MR / AS to decide how many address chars need to be used.
For example, using 'qemu-system-x86_64 -M q35 -S -monitor stdio' to run 'info mtree' displays before:
address-space: I/O 0000000000000000-000000000000ffff (prio 0, i/o): io 0000000000000000-0000000000000003 (prio 0, i/o): acpi-evt 0000000000000004-0000000000000005 (prio 0, i/o): acpi-cnt 0000000000000008-000000000000000b (prio 0, i/o): acpi-tmr 0000000000000020-000000000000002f (prio 0, i/o): acpi-gpe0 0000000000000030-0000000000000037 (prio 0, i/o): acpi-smi 0000000000000060-000000000000007f (prio 0, i/o): sm-tco 0000000000000000-0000000000000007 (prio 0, i/o): dma-chan 0000000000000008-000000000000000f (prio 0, i/o): dma-cont 0000000000000020-0000000000000021 (prio 0, i/o): pic 0000000000000040-0000000000000043 (prio 0, i/o): pit ... memory-region: pc.ram 0000000000000000-0000000007ffffff (prio 0, ram): pc.ram memory-region: pc.bios 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios memory-region: pci 0000000000000000-ffffffffffffffff (prio -1, i/o): pci 00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem 00000000000c0000-00000000000dffff (prio 1, rom): pc.rom 00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios ...and after:
address-space: I/O 0000-ffff (prio 0, container): io 0000-0003 (prio 0, i/o): acpi-evt 0004-0005 (prio 0, i/o): acpi-cnt 0008-000b (prio 0, i/o): acpi-tmr 0020-002f (prio 0, i/o): acpi-gpe0 0030-0037 (prio 0, i/o): acpi-smi 0060-007f (prio 0, i/o): sm-tco 0000-0007 (prio 0, i/o): dma-chan 0008-000f (prio 0, i/o): dma-cont 0020-0021 (prio 0, i/o): pic 0040-0043 (prio 0, i/o): pit ... memory-region: pc.ram 00000000-07ffffff (prio 0, ram): pc.ram memory-region: pc.bios fffc0000-ffffffff (prio 0, rom): pc.bios memory-region: pci 0000000000000000-ffffffffffffffff (prio -1, i/o): pci 00000000000a0000-00000000000bffff (prio 1, i/o): vga-lowmem 00000000000c0000-00000000000dffff (prio 1, rom): pc.rom 00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 0000000000020000-000000000003ffff 00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios ...Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- system/memory.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)system/memory.c +6
-1@@ -3321,7 +3321,26 @@ typedef QTAILQ_HEAD(, MemoryRegionList) MemoryRegionListHead;#define MR_SIZE (size) (int128_nz(size) ? (hwaddr)int128_get64( \ int128_sub((size), int128_one())) : 0) -#define MR_ADDR_WIDTH 16 + +static unsigned mr_addr_fmt_width (const MemoryRegion *mr) +{ +const unsigned int bits =127 -clz128 (mr->size); +unsigned int width; +system/memory.c typedef QTAILQ_HEAD(, MemoryRegionList) MemoryRegionListHead; · line 3339
Quoted 10 lines
system/memory.c +10
-0+if (bits <=8 ) { + width =2 ; + }else if (bits <=16 ) { + width =4 ; + }else if (bits <=32 ) { + width =8 ; + }else if (bits <=64 ) { + width =16 ; + }else { + width =20 ;Is there any case this can happen? I thought we don't have MR larger than 1<<64. Not a huge deal, though.
Quoted 1 line
Reviewed-by Peter Xu <[email protected]>
There are few uses of 0x1.0000.0000.0000.0000:
$ git grep int128_2_64
hw/vfio/container-legacy.c:184: Int128 llsize = int128_rshift(int128_2_64(), 1);
hw/vfio/listener.c:727: if (int128_eq(llsize, int128_2_64())) {
hw/virtio/vhost-vdpa.c:469: if (int128_eq(llsize, int128_2_64())) {
system/memory.c:757: addrrange_make(int128_zero(), int128_2_64()),
system/memory.c:1226: mr->size = int128_2_64();
system/memory.c:1809: if (int128_eq(mr->size, int128_2_64())) {
system/memory.c:2649: s = int128_2_64();
system/physmem.c:2996: .size = int128_2_64(),include/qemu/int128.h:55:static inline Int128 int128_2_64(void) include/qemu/int128.h-56-{include/qemu/int128.h-57- return (Int128)1 << 64;include/qemu/int128.h-58-}
Re: [PATCH 7/7] system/memory: Have 'info mtree' display addresses nicely
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Peter Xu
Quoted 9 lines · Philippe Mathieu-Daudé
#define MR_SIZE(size) (int128_nz(size) ? (hwaddr)int128_get64( \ int128_sub((size), int128_one())) : 0)system/memory.c +6
-1-#define MR_ADDR_WIDTH 16 + +static unsigned mr_addr_fmt_width (const MemoryRegion *mr) +{ +const unsigned int bits =127 -clz128 (mr->size); +unsigned int width; +system/memory.c typedef QTAILQ_HEAD(, MemoryRegionList) MemoryRegionListHead; · line 3339
Quoted 10 lines
system/memory.c +10
-0+if (bits <=8 ) { + width =2 ; + }else if (bits <=16 ) { + width =4 ; + }else if (bits <=32 ) { + width =8 ; + }else if (bits <=64 ) { + width =16 ; + }else { + width =20 ;Is there any case this can happen? I thought we don't have MR larger than 1<<64. Not a huge deal, though.
Quoted 3 lines
Quoted 1 line
Reviewed-by Peter Xu <[email protected]>There are few uses of 0x1.0000.0000.0000.0000:
Yes; that's the largest possible MR size: exactly 2^64. Inside MemoryRegion we keep the size in an Int128; in some APIs (e.g. the ones for creating an MR, and the return value of memory_region_size()) we represent a size as a uint64_t, with UINT64_MAX being a special case meaning "actually 2^64". So here the largest possible value of 'bits' is 64: anything else would mean some bug elsewhere in QEMU resulting in an invalid mr->size somehow, I think.
-- PMM