misc rc0 fixes (docs, plugins, docker)
cover misc rc0 fixes (docs, plugins, docker)
Hi,
These are some candidate patches for rc0 along with a few plugin patches that haven't yet gotten review. The new functionality won't get added to the PR but I'd like to get the cputlb fix in.
Alongside the plugin stuff there are some documentation updates which are worth adding and some tweaks to the docker cache handling that I only discovered after I sent the last PR.
Based on:
Message-Id: <[email protected]>
https://github.com/stsquad/qemu.git tags/pull-testing-and-misc-070720-1
The following need review:
- configure: remove all dependencies on a (re)configure
- tests/docker: fall back more gracefully when pull fails
- tests/plugins: add -Wno-unknown-warning-option to handle -Wpsabi
- target/sh4: revert to using cpu_lduw_code to decode gusa
- plugins: expand the bb plugin to be thread safe and track per-cpu
- cputlb: ensure we save the IOTLB data in case of reset
Alex Bennée (11):
docs/devel: convert and update MTTCG design document docs/devel: add some notes on tcg-icount for developers
cputlb: ensure we save the IOTLB data in case of reset hw/virtio/pci: include vdev name in registered PCI sections
plugins: add API to return a name for a IO device
plugins: new hwprofile plugin
plugins: expand the bb plugin to be thread safe and track per-cpu target/sh4: revert to using cpu_lduw_code to decode gusa tests/plugins: add -Wno-unknown-warning-option to handle -Wpsabi tests/docker: fall back more gracefully when pull fails
configure: remove all dependencies on a (re)configure
Jon Doron (1):
docs: Add to gdbstub documentation the PhyMemMode
Max Filippov (1):
tests/docker: update toolchain set in debian-xtensa-cross
docs/devel/index.rst | 2 +
...ti-thread-tcg.txt => multi-thread-tcg.rst} | 52 +--
docs/devel/tcg-icount.rst | 97 ++++++
docs/system/gdb.rst | 20 ++
configure | 15 +-
include/hw/core/cpu.h | 4 +
include/qemu/qemu-plugin.h | 6 +
include/qemu/typedefs.h | 1 +
accel/tcg/cputlb.c | 57 +++-
hw/virtio/virtio-pci.c | 22 +-
plugins/api.c | 20 ++
target/sh4/translate.c | 8 +-
tests/plugin/bb.c | 96 +++++-
tests/plugin/hwprofile.c | 305 ++++++++++++++++++
tests/docker/docker.py | 11 +-
.../dockerfiles/debian-xtensa-cross.docker | 6 +-
tests/plugin/Makefile | 3 +-
tests/tcg/Makefile.target | 12 +-
18 files changed, 673 insertions(+), 64 deletions(-)
rename docs/devel/{multi-thread-tcg.txt => multi-thread-tcg.rst} (90%)
create mode 100644 docs/devel/tcg-icount.rst
create mode 100644 tests/plugin/hwprofile.cSignature · 1 line
2.20.1
PATCH 1/13 docs/devel: convert and update MTTCG design document
Do a light conversion to .rst and clean-up some of the language at the start now MTTCG has been merged for a while.
---
docs/devel/index.rst | 1 +
...ti-thread-tcg.txt => multi-thread-tcg.rst} | 52 ++++++++++++-------
2 files changed, 34 insertions(+), 19 deletions(-)
rename docs/devel/{multi-thread-tcg.txt => multi-thread-tcg.rst} (90%)docs/devel/index.rst +1 -0
@@ -23,6 +23,7 @@ Contents: decodetree secure-coding-practices tcg + multi-thread-tcg tcg-plugins bitops reset
docs/devel/multi-thread-tcg.rst renamed from docs/devel/multi-thread-tcg.txt +33 -19
94 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH v1 01/13] docs/devel: convert and update MTTCG design document
docs/devel/multi-thread-tcg.rst including: · line 110
Quoted 5 lines · Alex Bennée
docs/devel/multi-thread-tcg.rst renamed from docs/devel/multi-thread-tcg.txt +1
-0@@ -92,6 +107,7 @@ including: - debugging operations (breakpoint insertion/removal) - some CPU helper functions + - linux-user spawning it's first thread
s/it's/its/
Thanks,
E.
PATCH 2/13 docs/devel: add some notes on tcg-icount for developers
In reply to Alex BennéeThis attempts to bring together my understanding of the requirements for icount behaviour into one reference document for our developer notes.
Message-Id: <[email protected]>
---
v2
- fix copyright date
- it's -> its
- drop mentioned of gen_io_end()
- remove and correct original conjecture
v3
- include link in index
v4
- Grammar fixes from Peter
- re-worded final section
--- docs/devel/index.rst | 1 + docs/devel/tcg-icount.rst | 97 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 docs/devel/tcg-icount.rst
docs/devel/index.rst +1 -0
@@ -23,6 +23,7 @@ Contents: decodetree secure-coding-practices tcg + tcg-icount multi-thread-tcg tcg-plugins bitops
docs/devel/tcg-icount.rst new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH v1 02/13] docs/devel: add some notes on tcg-icount for developers
Quoted 6 lines · Alex Bennée
This attempts to bring together my understanding of the requirements for icount behaviour into one reference document for our developer notes.
Signed-off-by Alex Bennée <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Thanks,
Emilio
PATCH 3/13 docs: Add to gdbstub documentation the PhyMemMode
In reply to Alex BennéeFrom: Jon Doron <[email protected]>
The PhyMemMode gdb extension command was missing from the gdb.rst document.
Message-Id: <[email protected]>
--- docs/system/gdb.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
docs/system/gdb.rst +20 -0
@@ -87,3 +87,23 @@ three commands you can query and set the single step behavior: (gdb) maintenance packet Qqemu.sstep=0x5 sending: "qemu.sstep=0x5" received: "OK" + + +Another feature that QEMU gdbstub provides is to toggle the memory GDB +works with, by default GDB will show the current process memory respecting +the virtual address translation. + +If you want to examine/change the physical memory you can set the gdbstub +to work with the physical memory rather with the virtual one. + +The memory mode can be checked by sending the following command: + +``maintenance packet qqemu.PhyMemMode`` + This will return either 0 or 1, 1 indicates you are currently in the + physical memory mode. + +``maintenance packet Qqemu.PhyMemMode:1`` + This will change the memory mode to physical memory. + +``maintenance packet Qqemu.PhyMemMode:0`` + This will change it back to normal memory mode.
Signature · 1 line
2.20.1
Re: [PATCH v1 03/13] docs: Add to gdbstub documentation the PhyMemMode
Quoted 17 lines · Alex Bennée
From: Jon Doron <[email protected]>
The PhyMemMode gdb extension command was missing from the
gdb.rstdocument.Signed-off-by Jon Doron <[email protected]>Signed-off-by Alex Bennée <[email protected]>Message-Id: <[email protected]>
--- docs/system/gdb.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)docs/system/gdb.rst +0
-0
docs/system/gdb.rst three commands you can query and set the single step behavior: · line 93
Quoted 7 lines
docs/system/gdb.rst +4
-0@@ -87,3 +87,23 @@ three commands you can query and set the single step behavior: (gdb) maintenance packet Qqemu.sstep=0x5 sending: "qemu.sstep=0x5" received: "OK" + + +Another feature that QEMU gdbstub provides is to toggle the memory GDB +works with,
Maybe start a new sentence?
Otherwise looks good:
Quoted 18 lines
by default GDB will show the current process memory respecting
docs/system/gdb.rst +16
-0+the virtual address translation. + +If you want to examine/change the physical memory you can set the gdbstub +to work with the physical memory rather with the virtual one. + +The memory mode can be checked by sending the following command: + +``maintenance packet qqemu.PhyMemMode`` + This will return either 0 or 1, 1 indicates you are currently in the + physical memory mode. + +``maintenance packet Qqemu.PhyMemMode:1`` + This will change the memory mode to physical memory. + +``maintenance packet Qqemu.PhyMemMode:0`` + This will change it back to normal memory mode.
PATCH 4/13 cputlb: ensure we save the IOTLB data in case of reset
In reply to Alex BennéeAny write to a device might cause a re-arrangement of memory triggering a TLB flush and potential re-size of the TLB invalidating previous entries. This would cause users of qemu_plugin_get_hwaddr() to see the warning:
invalid use of qemu_plugin_get_hwaddr
because of the failed tlb_lookup which should always succeed. To prevent this we save the IOTLB data in case it is later needed by a plugin doing a lookup.
---
v2
- save the entry instead of re-running the tlb_fill.
v3
- don't abuse TLS, use CPUState to store data
- just use g_free_rcu() to avoid ugliness
- verify addr matches before returning data
- ws fix
--- include/hw/core/cpu.h | 4 +++ include/qemu/typedefs.h | 1 + accel/tcg/cputlb.c | 57 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 2 deletions(-)
include/hw/core/cpu.h +4 -0
@@ -417,7 +417,11 @@ struct CPUState {DECLARE_BITMAP (plugin_mask,QEMU_PLUGIN_EV_MAX ); +#ifdef CONFIG_PLUGIN GArray *plugin_mem_cbs; +/* saved iotlb data from io_writex */ +SavedIOTLB *saved_iotlb; +#endif /* TODO Move common fields from CPUArchState here. */ int cpu_index;
include/qemu/typedefs.h +1 -0
@@ -116,6 +116,7 @@ typedef struct QObject QObject;typedef struct QString QString ;typedef struct RAMBlock RAMBlock ;typedef struct Range Range ; +typedef struct SavedIOTLB SavedIOTLB ;typedef struct SHPCDevice SHPCDevice ;typedef struct SSIBus SSIBus ;typedef struct VirtIODevice VirtIODevice ;
accel/tcg/cputlb.c +55 -2
81 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH v1 04/13] cputlb: ensure we save the IOTLB data in case of reset
Quoted 70 lines · Alex Bennée
Any write to a device might cause a re-arrangement of memory triggering a TLB flush and potential re-size of the TLB invalidating previous entries. This would cause users of
qemu_plugin_get_hwaddr()to see the warning:invalid use of
qemu_plugin_get_hwaddrbecause of the failed
tlb_lookupwhich should always succeed. To prevent this we save the IOTLB data in case it is later needed by a plugin doing a lookup.Signed-off-by Alex Bennée <[email protected]>---
v2
- save the entry instead of re-running thetlb_fill.
v3
- don't abuse TLS, use CPUState to store data
- just useg_free_rcu()to avoid ugliness
- verify addr matches before returning data
- ws fix--- include/hw/core/cpu.h | 4 +++ include/qemu/typedefs.h | 1 + accel/tcg/cputlb.c | 57 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 2 deletions(-)include/hw/core/cpu.h +4
-0@@ -417,7 +417,11 @@ struct CPUState {DECLARE_BITMAP (plugin_mask,QEMU_PLUGIN_EV_MAX ); +#ifdef CONFIG_PLUGIN GArray *plugin_mem_cbs; +/* saved iotlb data from io_writex */ +SavedIOTLB *saved_iotlb; +#endif /* TODO Move common fields from CPUArchState here. */ int cpu_index;include/qemu/typedefs.h +1
-0@@ -116,6 +116,7 @@ typedef struct QObject QObject;typedef struct QString QString ;typedef struct RAMBlock RAMBlock ;typedef struct Range Range ; +typedef struct SavedIOTLB SavedIOTLB ;typedef struct SHPCDevice SHPCDevice ;typedef struct SSIBus SSIBus ;typedef struct VirtIODevice VirtIODevice ;accel/tcg/cputlb.c +7
-0@@ -1073,6 +1073,42 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry,return val; } +#ifdef CONFIG_PLUGIN + +typedef struct SavedIOTLB { + struct rcu_head rcu; + hwaddr addr; + MemoryRegionSection *section; + hwaddr mr_offset;
accel/tcg/cputlb.c static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, · line 1092
Quoted 10 lines
accel/tcg/cputlb.c +10
-0+} SavedIOTLB; + +/* +* Save a potentially trashed IOTLB entry for later lookup by plugin. +* +* We also need to track the thread storage address because the RCU +* cleanup that runs when we leave the critical region (the current +* execution) is actually in a different thread. +*/ +static void save_iotlb_data (CPUState *cs,hwaddr addr,MemoryRegionSection *section,hwaddr mr_offset)
Overlong line.
accel/tcg/cputlb.c static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, · line 1103
Quoted 11 lines
accel/tcg/cputlb.c +11
-0+{ +SavedIOTLB *old, *new =g_new (SavedIOTLB,1 ); + new->addr = addr; + new->section = section; + new->mr_offset = mr_offset; + old =atomic_rcu_read (&cs->saved_iotlb); +atomic_rcu_set (&cs->saved_iotlb, new); +if (old) { +g_free_rcu (old, rcu); + } +}
I'm a bit confused by this. Why all the multiple allocation? How many consumers are you expecting, and more are you expecting multiple memory operations in flight at once?
If multiple memory operations in flight, then why aren't we chaining them together, so that you can search through multiple alternatives.
If only one memory operation in flight, why are you allocating memory at all, much less managing it with rcu? Just put one structure (or a collection of fields) into CPUState and be done.
accel/tcg/cputlb.c static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, · line 1110
Quoted 7 lines
accel/tcg/cputlb.c +7
-0+ +#else +static void save_iotlb_data (CPUState *cs,hwaddr addr,MemoryRegionSection *section,hwaddr mr_offset) +{ +/* do nothing */ +} +#endif
Surely better to move the ifdef inside the function so that you don't have to replicate the definition?
accel/tcg/cputlb.c bool tlb_plugin_lookup(CPUState *cpu, target_ulong addr, int mmu_idx, · line 1461
Quoted 7 lines
accel/tcg/cputlb.c +7
-0+SavedIOTLB *saved =atomic_rcu_read (&cpu->saved_iotlb); +if (saved && saved->addr == tlb_addr) { + data->is_io = true; + data->v.io.section = saved->section; + data->v.io.offset = saved->mr_offset; +return true; + }
Should that test in fact be an assert? Why would this fail?
r~
Re: [PATCH v1 04/13] cputlb: ensure we save the IOTLB data in case of reset
Quoted 100 lines · Richard Henderson
Quoted 70 lines · Alex Bennée
Any write to a device might cause a re-arrangement of memory triggering a TLB flush and potential re-size of the TLB invalidating previous entries. This would cause users of
qemu_plugin_get_hwaddr()to see the warning:invalid use of
qemu_plugin_get_hwaddrbecause of the failed
tlb_lookupwhich should always succeed. To prevent this we save the IOTLB data in case it is later needed by a plugin doing a lookup.Signed-off-by Alex Bennée <[email protected]>---
v2
- save the entry instead of re-running thetlb_fill.
v3
- don't abuse TLS, use CPUState to store data
- just useg_free_rcu()to avoid ugliness
- verify addr matches before returning data
- ws fix--- include/hw/core/cpu.h | 4 +++ include/qemu/typedefs.h | 1 + accel/tcg/cputlb.c | 57 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 2 deletions(-)include/hw/core/cpu.h +4
-0@@ -417,7 +417,11 @@ struct CPUState {DECLARE_BITMAP (plugin_mask,QEMU_PLUGIN_EV_MAX ); +#ifdef CONFIG_PLUGIN GArray *plugin_mem_cbs; +/* saved iotlb data from io_writex */ +SavedIOTLB *saved_iotlb; +#endif /* TODO Move common fields from CPUArchState here. */ int cpu_index;include/qemu/typedefs.h +1
-0@@ -116,6 +116,7 @@ typedef struct QObject QObject;typedef struct QString QString ;typedef struct RAMBlock RAMBlock ;typedef struct Range Range ; +typedef struct SavedIOTLB SavedIOTLB ;typedef struct SHPCDevice SHPCDevice ;typedef struct SSIBus SSIBus ;typedef struct VirtIODevice VirtIODevice ;accel/tcg/cputlb.c +7
-0@@ -1073,6 +1073,42 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry,return val; } +#ifdef CONFIG_PLUGIN + +typedef struct SavedIOTLB { + struct rcu_head rcu; + hwaddr addr; + MemoryRegionSection *section; + hwaddr mr_offset;accel/tcg/cputlb.c static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, · line 1092
Quoted 10 lines
accel/tcg/cputlb.c +10
-0+} SavedIOTLB; + +/* +* Save a potentially trashed IOTLB entry for later lookup by plugin. +* +* We also need to track the thread storage address because the RCU +* cleanup that runs when we leave the critical region (the current +* execution) is actually in a different thread. +*/ +static void save_iotlb_data (CPUState *cs,hwaddr addr,MemoryRegionSection *section,hwaddr mr_offset)Overlong line.
accel/tcg/cputlb.c static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, · line 1103
Quoted 11 lines
accel/tcg/cputlb.c +11
-0+{ +SavedIOTLB *old, *new =g_new (SavedIOTLB,1 ); + new->addr = addr; + new->section = section; + new->mr_offset = mr_offset; + old =atomic_rcu_read (&cs->saved_iotlb); +atomic_rcu_set (&cs->saved_iotlb, new); +if (old) { +g_free_rcu (old, rcu); + } +}I'm a bit confused by this. Why all the multiple allocation? How many consumers are you expecting, and more are you expecting multiple memory operations in flight at once?
Quoted 6 lines
If multiple memory operations in flight, then why aren't we chaining them together, so that you can search through multiple alternatives.
If only one memory operation in flight, why are you allocating memory at all, much less managing it with rcu? Just put one structure (or a collection of fields) into CPUState and be done.
Oh I just saw this reply. I subscribe all of the above, please shelve my R-b tag until these are resolved.
An alternative is to emit the hwaddr directly in the mem_cb -- IIRC this is how I did it originally. The API is a larger/uglier (plugins can subscribe to either hwaddr or vaddr callbacks) but there is no state to keep and no overhead of calling several functions in a hot path.
Thanks,
E.
Re: [PATCH v1 04/13] cputlb: ensure we save the IOTLB data in case of reset
Quoted 104 lines · Emilio G. Cota
Quoted 103 lines · Richard Henderson
Quoted 70 lines · Alex Bennée
Any write to a device might cause a re-arrangement of memory triggering a TLB flush and potential re-size of the TLB invalidating previous entries. This would cause users of
qemu_plugin_get_hwaddr()to see the warning:invalid use of
qemu_plugin_get_hwaddrbecause of the failed
tlb_lookupwhich should always succeed. To prevent this we save the IOTLB data in case it is later needed by a plugin doing a lookup.Signed-off-by Alex Bennée <[email protected]>---
v2
- save the entry instead of re-running thetlb_fill.
v3
- don't abuse TLS, use CPUState to store data
- just useg_free_rcu()to avoid ugliness
- verify addr matches before returning data
- ws fix--- include/hw/core/cpu.h | 4 +++ include/qemu/typedefs.h | 1 + accel/tcg/cputlb.c | 57 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 2 deletions(-)include/hw/core/cpu.h +4
-0@@ -417,7 +417,11 @@ struct CPUState {DECLARE_BITMAP (plugin_mask,QEMU_PLUGIN_EV_MAX ); +#ifdef CONFIG_PLUGIN GArray *plugin_mem_cbs; +/* saved iotlb data from io_writex */ +SavedIOTLB *saved_iotlb; +#endif /* TODO Move common fields from CPUArchState here. */ int cpu_index;include/qemu/typedefs.h +1
-0@@ -116,6 +116,7 @@ typedef struct QObject QObject;typedef struct QString QString ;typedef struct RAMBlock RAMBlock ;typedef struct Range Range ; +typedef struct SavedIOTLB SavedIOTLB ;typedef struct SHPCDevice SHPCDevice ;typedef struct SSIBus SSIBus ;typedef struct VirtIODevice VirtIODevice ;accel/tcg/cputlb.c +7
-0@@ -1073,6 +1073,42 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry,return val; } +#ifdef CONFIG_PLUGIN + +typedef struct SavedIOTLB { + struct rcu_head rcu; + hwaddr addr; + MemoryRegionSection *section; + hwaddr mr_offset;accel/tcg/cputlb.c static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, · line 1092
Quoted 10 lines
accel/tcg/cputlb.c +10
-0+} SavedIOTLB; + +/* +* Save a potentially trashed IOTLB entry for later lookup by plugin. +* +* We also need to track the thread storage address because the RCU +* cleanup that runs when we leave the critical region (the current +* execution) is actually in a different thread. +*/ +static void save_iotlb_data (CPUState *cs,hwaddr addr,MemoryRegionSection *section,hwaddr mr_offset)Overlong line.
accel/tcg/cputlb.c static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, · line 1103
Quoted 11 lines
accel/tcg/cputlb.c +11
-0+{ +SavedIOTLB *old, *new =g_new (SavedIOTLB,1 ); + new->addr = addr; + new->section = section; + new->mr_offset = mr_offset; + old =atomic_rcu_read (&cs->saved_iotlb); +atomic_rcu_set (&cs->saved_iotlb, new); +if (old) { +g_free_rcu (old, rcu); + } +}I'm a bit confused by this. Why all the multiple allocation? How many consumers are you expecting, and more are you expecting multiple memory operations in flight at once?
If multiple memory operations in flight, then why aren't we chaining them together, so that you can search through multiple alternatives.
Quoted 6 lines
Quoted 3 lines
If only one memory operation in flight, why are you allocating memory at all, much less managing it with rcu? Just put one structure (or a collection of fields) into CPUState and be done.
Oh I just saw this reply. I subscribe all of the above, please shelve my R-b tag until these are resolved.
I was just conscious the data is not always valid - clearing it up with RCU at least ensured it went away eventually. However we could certainly just park it in the general CPUState and assert the match on the fall through case of tlb_plugin_lookup.
My only worry is do we ever see us storing data that is valid but the re-filled data in the real TLB could still match and be incorrect?
Quoted 4 lines
An alternative is to emit the hwaddr directly in the
mem_cb-- IIRC this is how I did it originally. The API is a larger/uglier (plugins can subscribe to either hwaddr or vaddr callbacks) but there is no state to keep and no overhead of calling several functions in a hot path.
I think that is certainly an option for evolving the API but I'd rather just get this fix in for now while we ponder what else will be in v2 of the API.
So far my proposal for qemu_plugin_hwaddr_device_name has some mild push back from Peter which I'd like to resolve first:
Date: Wed, 3 Jun 2020 16:48:33 +0100
Message-ID: <CAFEAcA-kPZoumxfLgjxPfCPDmPgsAFCjB-zdicsiGeqSOPOH7Q@mail.gmail.com>
So far I've been adding stuff to solve any particular problems I've had and I'd like to see what other API/hooks are being proposed so we don't have browser style version ticks ;-)
Quoted 3 lines
Thanks,
E.
Signature · 1 line
Alex Bennée
Re: [PATCH v1 04/13] cputlb: ensure we save the IOTLB data in case of reset
In reply to Alex BennéeQuoted 5 lines · Alex Bennée
Any write to a device might cause a re-arrangement of memory triggering a TLB flush and potential re-size of the TLB invalidating previous entries. This would cause users of
qemu_plugin_get_hwaddr()to see the warning:
Quoted 7 lines
invalid use of
qemu_plugin_get_hwaddrbecause of the failed
tlb_lookupwhich should always succeed. To prevent this we save the IOTLB data in case it is later needed by a plugin doing a lookup.Signed-off-by Alex Bennée <[email protected]>
Some minor comments below.
Quoted 11 lines
accel/tcg/cputlb.c +5
-0@@ -1073,6 +1073,42 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry,return val; } +#ifdef CONFIG_PLUGIN + +typedef struct SavedIOTLB { + struct rcu_head rcu; + hwaddr addr;
accel/tcg/cputlb.c static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, · line 1090
Quoted 10 lines
accel/tcg/cputlb.c +10
-0+MemoryRegionSection *section; +hwaddr mr_offset; +} SavedIOTLB; + +/* +* Save a potentially trashed IOTLB entry for later lookup by plugin. +* +* We also need to track the thread storage address because the RCU +* cleanup that runs when we leave the critical region (the current +* execution) is actually in a different thread.
Mentioning the thread storage is now outdated -- I think this comment (starting from 'We') can be removed.
accel/tcg/cputlb.c static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, · line 1102
Quoted 12 lines
accel/tcg/cputlb.c +12
-0+*/ +static void save_iotlb_data (CPUState *cs,hwaddr addr,MemoryRegionSection *section,hwaddr mr_offset) +{ +SavedIOTLB *old, *new =g_new (SavedIOTLB,1 ); + new->addr = addr; + new->section = section; + new->mr_offset = mr_offset; + old =atomic_rcu_read (&cs->saved_iotlb); +atomic_rcu_set (&cs->saved_iotlb, new); +if (old) { +g_free_rcu (old, rcu); + }
Using atomic_rcu_read here is not necessary (only this thread ever writes to this field) and might confuse a reader when trying to find the atomic_rcu_read that matches the atomic_rcu_set (that read is in tlb_plugin_lookup).
Consider doing
old = cs->saved_iotlb;
instead.
Thanks,
Emilio
PATCH 5/13 hw/virtio/pci: include vdev name in registered PCI sections
In reply to Alex BennéeWhen viewing/debugging memory regions it is sometimes hard to figure out which PCI device something belongs to. Make the names unique by including the vdev name in the name string.
---
v2
- swap ()'s for an extra -
--- hw/virtio/virtio-pci.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
hw/virtio/virtio-pci.c +14 -8
@@ -1406,7 +1406,8 @@ static void virtio_pci_device_write(void *opaque, hwaddr addr, } } -static void virtio_pci_modern_regions_init (VirtIOPCIProxy *proxy) +static void virtio_pci_modern_regions_init (VirtIOPCIProxy *proxy, +const char *vdev_name) {static const MemoryRegionOps common_ops = { .read = virtio_pci_common_read,
@@ -1453,36 +1454,41 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy) }, .endianness = DEVICE_LITTLE_ENDIAN, }; +g_autoptr (GString) name =g_string_new (NULL ); - +g_string_printf (name,"virtio-pci-common-%s" , vdev_name);memory_region_init_io (&proxy->common.mr,OBJECT (proxy), &common_ops, proxy, -"virtio-pci-common" , + name->str, proxy->common.size); +g_string_printf (name,"virtio-pci-isr-%s" , vdev_name);memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), &isr_ops, proxy, -"virtio-pci-isr" , + name->str, proxy->isr.size); +g_string_printf (name,"virtio-pci-device-%s" , vdev_name);memory_region_init_io (&proxy->device.mr,OBJECT (proxy), &device_ops,virtio_bus_get_device (&proxy->bus), -"virtio-pci-device" , + name->str, proxy->device.size); +g_string_printf (name,"virtio-pci-notify-%s" , vdev_name);memory_region_init_io (&proxy->notify.mr,OBJECT (proxy), ¬ify_ops,virtio_bus_get_device (&proxy->bus), -"virtio-pci-notify" , + name->str, proxy->notify.size); +g_string_printf (name,"virtio-pci-notify-pio-%s" , vdev_name);memory_region_init_io (&proxy->notify_pio.mr,OBJECT (proxy), ¬ify_pio_ops,virtio_bus_get_device (&proxy->bus), -"virtio-pci-notify-pio" , + name->str, proxy->notify_pio.size); }
@@ -1623,7 +1629,7 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)struct virtio_pci_cfg_cap *cfg_mask; -virtio_pci_modern_regions_init (proxy); +virtio_pci_modern_regions_init (proxy, vdev->name);virtio_pci_modern_mem_region_map (proxy, &proxy->common, &cap);virtio_pci_modern_mem_region_map (proxy, &proxy->isr, &cap);
Signature · 1 line
2.20.1
Re: [PATCH v1 05/13] hw/virtio/pci: include vdev name in registered PCI sections
Quoted 7 lines · Alex Bennée
When viewing/debugging memory regions it is sometimes hard to figure out which PCI device something belongs to. Make the names unique by including the vdev name in the name string.
Signed-off-by Alex Bennée <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Michael S. Tsirkin <[email protected]>
So I don't know what's the plan here. I think ideally core would just do it for us automatically. Why not?
If it can't my ack stands, anyway, pls
merge with rest of the patches if that is deemed appropriate.
Quoted 80 lines
---
v2
- swap ()'s for an extra ---- hw/virtio/virtio-pci.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)hw/virtio/virtio-pci.c +14
-8@@ -1406,7 +1406,8 @@ static void virtio_pci_device_write(void *opaque, hwaddr addr, } } -static void virtio_pci_modern_regions_init (VirtIOPCIProxy *proxy) +static void virtio_pci_modern_regions_init (VirtIOPCIProxy *proxy, +const char *vdev_name) {static const MemoryRegionOps common_ops = { .read = virtio_pci_common_read,@@ -1453,36 +1454,41 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy) }, .endianness = DEVICE_LITTLE_ENDIAN, }; +g_autoptr (GString) name =g_string_new (NULL ); - +g_string_printf (name,"virtio-pci-common-%s" , vdev_name);memory_region_init_io (&proxy->common.mr,OBJECT (proxy), &common_ops, proxy, -"virtio-pci-common" , + name->str, proxy->common.size); +g_string_printf (name,"virtio-pci-isr-%s" , vdev_name);memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), &isr_ops, proxy, -"virtio-pci-isr" , + name->str, proxy->isr.size); +g_string_printf (name,"virtio-pci-device-%s" , vdev_name);memory_region_init_io (&proxy->device.mr,OBJECT (proxy), &device_ops,virtio_bus_get_device (&proxy->bus), -"virtio-pci-device" , + name->str, proxy->device.size); +g_string_printf (name,"virtio-pci-notify-%s" , vdev_name);memory_region_init_io (&proxy->notify.mr,OBJECT (proxy), ¬ify_ops,virtio_bus_get_device (&proxy->bus), -"virtio-pci-notify" , + name->str, proxy->notify.size); +g_string_printf (name,"virtio-pci-notify-pio-%s" , vdev_name);memory_region_init_io (&proxy->notify_pio.mr,OBJECT (proxy), ¬ify_pio_ops,virtio_bus_get_device (&proxy->bus), -"virtio-pci-notify-pio" , + name->str, proxy->notify_pio.size); }@@ -1623,7 +1629,7 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)struct virtio_pci_cfg_cap *cfg_mask; -virtio_pci_modern_regions_init (proxy); +virtio_pci_modern_regions_init (proxy, vdev->name);virtio_pci_modern_mem_region_map (proxy, &proxy->common, &cap);virtio_pci_modern_mem_region_map (proxy, &proxy->isr, &cap);Signature · 1 line
2.20.1
Re: [PATCH v1 05/13] hw/virtio/pci: include vdev name in registered PCI sections
Quoted 10 lines · Michael S. Tsirkin
Quoted 7 lines · Alex Bennée
When viewing/debugging memory regions it is sometimes hard to figure out which PCI device something belongs to. Make the names unique by including the vdev name in the name string.
Signed-off-by Alex Bennée <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Michael S. Tsirkin <[email protected]>
Quoted 4 lines
So I don't know what's the plan here. I think ideally core would just do it for us automatically. Why not?
If it can't my ack stands, anyway, pls
merge with rest of the patches if that is deemed appropriate.
Yeah currently it's sitting in my plugins/next queue which isn't targeting 5.1. As the hwprofile plugin is the only one I know using it I figured I'd keep it with those.
Quoted 81 lines
Quoted 81 lines
---
v2
- swap ()'s for an extra ---- hw/virtio/virtio-pci.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)hw/virtio/virtio-pci.c +14
-8@@ -1406,7 +1406,8 @@ static void virtio_pci_device_write(void *opaque, hwaddr addr, } } -static void virtio_pci_modern_regions_init (VirtIOPCIProxy *proxy) +static void virtio_pci_modern_regions_init (VirtIOPCIProxy *proxy, +const char *vdev_name) {static const MemoryRegionOps common_ops = { .read = virtio_pci_common_read,@@ -1453,36 +1454,41 @@ static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy) }, .endianness = DEVICE_LITTLE_ENDIAN, }; +g_autoptr (GString) name =g_string_new (NULL ); - +g_string_printf (name,"virtio-pci-common-%s" , vdev_name);memory_region_init_io (&proxy->common.mr,OBJECT (proxy), &common_ops, proxy, -"virtio-pci-common" , + name->str, proxy->common.size); +g_string_printf (name,"virtio-pci-isr-%s" , vdev_name);memory_region_init_io (&proxy->isr.mr,OBJECT (proxy), &isr_ops, proxy, -"virtio-pci-isr" , + name->str, proxy->isr.size); +g_string_printf (name,"virtio-pci-device-%s" , vdev_name);memory_region_init_io (&proxy->device.mr,OBJECT (proxy), &device_ops,virtio_bus_get_device (&proxy->bus), -"virtio-pci-device" , + name->str, proxy->device.size); +g_string_printf (name,"virtio-pci-notify-%s" , vdev_name);memory_region_init_io (&proxy->notify.mr,OBJECT (proxy), ¬ify_ops,virtio_bus_get_device (&proxy->bus), -"virtio-pci-notify" , + name->str, proxy->notify.size); +g_string_printf (name,"virtio-pci-notify-pio-%s" , vdev_name);memory_region_init_io (&proxy->notify_pio.mr,OBJECT (proxy), ¬ify_pio_ops,virtio_bus_get_device (&proxy->bus), -"virtio-pci-notify-pio" , + name->str, proxy->notify_pio.size); }@@ -1623,7 +1629,7 @@ static void virtio_pci_device_plugged(DeviceState *d, Error **errp)struct virtio_pci_cfg_cap *cfg_mask; -virtio_pci_modern_regions_init (proxy); +virtio_pci_modern_regions_init (proxy, vdev->name);virtio_pci_modern_mem_region_map (proxy, &proxy->common, &cap);virtio_pci_modern_mem_region_map (proxy, &proxy->isr, &cap);Signature · 1 line
2.20.1
Signature · 1 line
Alex Bennée
PATCH 6/13 plugins: add API to return a name for a IO device
In reply to Alex BennéeThis may well end up being anonymous but it should always be unique.
---
v3
- return a non-freeable const g_intern_string()
- checkpatch cleanups
--- include/qemu/qemu-plugin.h | 6 ++++++ plugins/api.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+)
include/qemu/qemu-plugin.h +6 -0
@@ -335,6 +335,12 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,bool qemu_plugin_hwaddr_is_io (const struct qemu_plugin_hwaddr *haddr);uint64_t qemu_plugin_hwaddr_device_offset (const struct qemu_plugin_hwaddr *haddr); +/* +* Returns a string representing the device. The string is valid for +* the lifetime of the plugin. +*/ +const char *qemu_plugin_hwaddr_device_name (const struct qemu_plugin_hwaddr *h); +typedef void (*qemu_plugin_vcpu_mem_cb_t)(unsigned int vcpu_index, qemu_plugin_meminfo_t info, uint64_t vaddr,
plugins/api.c +20 -0
@@ -303,6 +303,26 @@ uint64_t qemu_plugin_hwaddr_device_offset(const struct qemu_plugin_hwaddr *haddrreturn 0 ; } +const char *qemu_plugin_hwaddr_device_name (const struct qemu_plugin_hwaddr *h) +{ +#ifdef CONFIG_SOFTMMU +if (h && h->is_io) { +MemoryRegionSection *mrs = h->v.io.section; +if (!mrs->mr->name) { +unsigned long maddr =0xffffffff & (uintptr_t ) mrs->mr; + g_autofree char *temp = g_strdup_printf("anon%08lx", maddr); +return g_intern_string (temp); + }else { +return g_intern_string (mrs->mr->name); + } + }else { +return g_intern_string ("RAM" ); + } +#else +return g_intern_string ("Invalid" ); +#endif +} +/* * Queries to the number and potential maximum number of vCPUs there * will be. This helps the plugin dimension per-vcpu arrays.
Signature · 1 line
2.20.1
Re: [PATCH v1 06/13] plugins: add API to return a name for a IO device
Quoted 38 lines · Alex Bennée
This may well end up being anonymous but it should always be unique.
Signed-off-by Alex Bennée <[email protected]>[r-b provisional given change to g_intern_string]Reviewed-by Clement Deschamps <[email protected]>Reviewed-by Emilio G. Cota <[email protected]>---
v3
- return a non-freeable constg_intern_string()
- checkpatch cleanups--- include/qemu/qemu-plugin.h | 6 ++++++ plugins/api.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+)include/qemu/qemu-plugin.h +6
-0@@ -335,6 +335,12 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,bool qemu_plugin_hwaddr_is_io (const struct qemu_plugin_hwaddr *haddr);uint64_t qemu_plugin_hwaddr_device_offset (const struct qemu_plugin_hwaddr *haddr); +/* +* Returns a string representing the device. The string is valid for +* the lifetime of the plugin. +*/ +const char *qemu_plugin_hwaddr_device_name (const struct qemu_plugin_hwaddr *h); +typedef void (*qemu_plugin_vcpu_mem_cb_t)(unsigned int vcpu_index, qemu_plugin_meminfo_t info, uint64_t vaddr,plugins/api.c +0
-0
plugins/api.c uint64_t qemu_plugin_hwaddr_device_offset(const struct qemu_plugin_hwaddr *haddr · line 312
Quoted 10 lines
plugins/api.c +7
-0@@ -303,6 +303,26 @@ uint64_t qemu_plugin_hwaddr_device_offset(const struct qemu_plugin_hwaddr *haddrreturn 0 ; } +const char *qemu_plugin_hwaddr_device_name (const struct qemu_plugin_hwaddr *h) +{ +#ifdef CONFIG_SOFTMMU +if (h && h->is_io) { +MemoryRegionSection *mrs = h->v.io.section; +if (!mrs->mr->name) { +unsigned long maddr =0xffffffff & (uintptr_t ) mrs->mr;
Why not use uint32_t & PRIx32?
uint32_t maddr = (uintptr_t) mrs->mr;
plugins/api.c uint64_t qemu_plugin_hwaddr_device_offset(const struct qemu_plugin_hwaddr *haddr · line 314
Quoted 2 lines
plugins/api.c +2
-0+ g_autofree char *temp = g_strdup_printf("anon%08lx", maddr); +return g_intern_string (temp);
Isn't this illegal? temp is definitively not const...
Quoted 15 lines
plugins/api.c +11
-0+ } else { +return g_intern_string (mrs->mr->name); + } + }else { +return g_intern_string ("RAM" ); + } +#else +return g_intern_string ("Invalid" ); +#endif +} +/* * Queries to the number and potential maximum number of vCPUs there * will be. This helps the plugin dimension per-vcpu arrays.
Re: [PATCH v1 06/13] plugins: add API to return a name for a IO device
Quoted 52 lines · Philippe Mathieu-Daudé
Quoted 38 lines · Alex Bennée
This may well end up being anonymous but it should always be unique.
Signed-off-by Alex Bennée <[email protected]>[r-b provisional given change to g_intern_string]Reviewed-by Clement Deschamps <[email protected]>Reviewed-by Emilio G. Cota <[email protected]>---
v3
- return a non-freeable constg_intern_string()
- checkpatch cleanups--- include/qemu/qemu-plugin.h | 6 ++++++ plugins/api.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+)include/qemu/qemu-plugin.h +6
-0@@ -335,6 +335,12 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,bool qemu_plugin_hwaddr_is_io (const struct qemu_plugin_hwaddr *haddr);uint64_t qemu_plugin_hwaddr_device_offset (const struct qemu_plugin_hwaddr *haddr); +/* +* Returns a string representing the device. The string is valid for +* the lifetime of the plugin. +*/ +const char *qemu_plugin_hwaddr_device_name (const struct qemu_plugin_hwaddr *h); +typedef void (*qemu_plugin_vcpu_mem_cb_t)(unsigned int vcpu_index, qemu_plugin_meminfo_t info, uint64_t vaddr,plugins/api.c +0
-0plugins/api.c uint64_t qemu_plugin_hwaddr_device_offset(const struct qemu_plugin_hwaddr *haddr · line 312
Quoted 10 lines
plugins/api.c +7
-0@@ -303,6 +303,26 @@ uint64_t qemu_plugin_hwaddr_device_offset(const struct qemu_plugin_hwaddr *haddrreturn 0 ; } +const char *qemu_plugin_hwaddr_device_name (const struct qemu_plugin_hwaddr *h) +{ +#ifdef CONFIG_SOFTMMU +if (h && h->is_io) { +MemoryRegionSection *mrs = h->v.io.section; +if (!mrs->mr->name) { +unsigned long maddr =0xffffffff & (uintptr_t ) mrs->mr;Why not use
uint32_t& PRIx32?
Quoted 6 lines
uint32_t maddr = (uintptr_t) mrs->mr;plugins/api.c uint64_t qemu_plugin_hwaddr_device_offset(const struct qemu_plugin_hwaddr *haddr · line 314
Quoted 2 lines
plugins/api.c +2
-0+ g_autofree char *temp = g_strdup_printf("anon%08lx", maddr); +return g_intern_string (temp);Isn't this illegal? temp is definitively not const...
We don't mess with it, we return a new string which is the canonical form.
Quoted 16 lines
Quoted 16 lines
plugins/api.c +11
-0+ } else { +return g_intern_string (mrs->mr->name); + } + }else { +return g_intern_string ("RAM" ); + } +#else +return g_intern_string ("Invalid" ); +#endif +} +/* * Queries to the number and potential maximum number of vCPUs there * will be. This helps the plugin dimension per-vcpu arrays.
Signature · 1 line
Alex Bennée
PATCH 7/13 plugins: new hwprofile plugin
In reply to Alex BennéeThis is a plugin intended to help with profiling access to various bits of system hardware. It only really makes sense for system emulation.
It takes advantage of the recently exposed helper API that allows us to see the device name (memory region name) associated with a device.
You can specify arg=read or arg=write to limit the tracking to just reads or writes (by default it does both).
The pattern option:
-plugin ./tests/plugin/libhwprofile.so,arg=pattern
will allow you to see the access pattern to devices, eg:
gic_cpu @ 0xffffffc010040000
off:00000000, 8, 1, 8, 1
off:00000000, 4, 1, 4, 1
off:00000000, 2, 1, 2, 1
off:00000000, 1, 1, 1, 1The source option:
-plugin ./tests/plugin/libhwprofile.so,arg=source
will track the virtual source address of the instruction making the access:
pl011 @ 0xffffffc010031000
pc:ffffffc0104c785c, 1, 4, 0, 0
pc:ffffffc0104c7898, 1, 4, 0, 0
pc:ffffffc010512bcc, 2, 1867, 0, 0You cannot mix source and pattern.
Finally the match option allow you to limit the tracking to just the devices you care about.
---
v2
- use 64 bit cpu masks
- warn if we will exceed cpu mask capability
- don't run in linux-user mode
- skip in check-tcg for linux-user test
v3
- update device name API
- re-factor and clean-up
- add source tracking
- use direct hash for source/pattern
- add match function
- expand the commit message
- checkpatch cleanups
--- tests/plugin/hwprofile.c | 305 ++++++++++++++++++++++++++++++++++++++ tests/plugin/Makefile | 1 + tests/tcg/Makefile.target | 12 +- 3 files changed, 316 insertions(+), 2 deletions(-) create mode 100644 tests/plugin/hwprofile.c
tests/plugin/hwprofile.c new file +305 -0
@@ -0,0 +1,305 @@ +/* +* Copyright (C) 2020, Alex Bennée <[email protected]> +* +* HW Profile - breakdown access patterns for IO to devices +* +* License: GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include <inttypes.h> +#include <assert.h> +#include <stdlib.h> +#include <inttypes.h> +#include <string.h> +#include <unistd.h> +#include <stdio.h> +#include <glib.h> + +#include <qemu-plugin.h> + +QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; + +#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0])) + +typedef struct { +uint64_t cpu_read; +uint64_t cpu_write; +uint64_t reads; +uint64_t writes; +}IOCounts ; + +typedef struct { +uint64_t off_or_pc; +IOCounts counts; +}IOLocationCounts ; + +typedef struct { +const char *name; +uint64_t base; +IOCounts totals; +GHashTable *detail; +}DeviceCounts ; + +static GMutex lock; +static GHashTable *devices; + +/* track the access pattern to a piece of HW */ +static bool pattern; +/* track the source address of access to HW */ +static bool source; +/* track only matched regions of HW */ +static bool check_match; +static gchar **matches; + +static enum qemu_plugin_mem_rw rw =QEMU_PLUGIN_MEM_RW ; + +static inline bool track_reads (void ) +{ +return rw ==QEMU_PLUGIN_MEM_RW || rw ==QEMU_PLUGIN_MEM_R ; +} + +static inline bool track_writes (void ) +{ +return rw ==QEMU_PLUGIN_MEM_RW || rw ==QEMU_PLUGIN_MEM_W ; +} + +static void plugin_init (void ) +{ + devices =g_hash_table_new (NULL ,NULL ); +} + +static gint sort_cmp (gconstpointer a,gconstpointer b) +{ +DeviceCounts *ea = (DeviceCounts *) a; +DeviceCounts *eb = (DeviceCounts *) b; +return ea->totals.reads + ea->totals.writes > + eb->totals.reads + eb->totals.writes ?-1 :1 ; +} + +static gint sort_loc (gconstpointer a,gconstpointer b) +{ +IOLocationCounts *ea = (IOLocationCounts *) a; +IOLocationCounts *eb = (IOLocationCounts *) b; +return ea->off_or_pc > eb->off_or_pc; +} + +static void fmt_iocount_record (GString *s,IOCounts *rec) +{ +if (track_reads ()) { +g_string_append_printf (s,", %" PRIx64", %" PRId64, + rec->cpu_read, rec->reads); + } +if (track_writes ()) { +g_string_append_printf (s,", %" PRIx64", %" PRId64, + rec->cpu_write, rec->writes); + } +} + +static void fmt_dev_record (GString *s,DeviceCounts *rec) +{ +g_string_append_printf (s,"%s, 0x%" PRIx64, + rec->name, rec->base); +fmt_iocount_record (s, &rec->totals); +g_string_append_c (s,'\n' ); +} + +static void plugin_exit (qemu_plugin_id_t id,void *p) +{ +g_autoptr (GString) report =g_string_new ("" ); +GList *counts; + +if (!(pattern || source)) { +g_string_printf (report,"Device, Address" ); +if (track_reads ()) { +g_string_append_printf (report,", RCPUs, Reads" ); + } +if (track_writes ()) { +g_string_append_printf (report,", WCPUs, Writes" ); + } +g_string_append_c (report,'\n' ); + } + + counts =g_hash_table_get_values (devices); +if (counts &&g_list_next (counts)) { +GList *it; + + it =g_list_sort (counts, sort_cmp); + +while (it) { +DeviceCounts *rec = (DeviceCounts *) it->data; +if (rec->detail) { +GList *accesses =g_hash_table_get_values (rec->detail); +GList *io_it =g_list_sort (accesses, sort_loc); +const char *prefix = pattern ?"off" :"pc" ; +g_string_append_printf (report,"%s @ 0x%" PRIx64"\n" , + rec->name, rec->base); +while (io_it) { +IOLocationCounts *loc = (IOLocationCounts *) io_it->data; +g_string_append_printf (report," %s:%08" PRIx64, + prefix, loc->off_or_pc); +fmt_iocount_record (report, &loc->counts); +g_string_append_c (report,'\n' ); + io_it = io_it->next; + } + }else { +fmt_dev_record (report, rec); + } + it = it->next; + }; +g_list_free (it); + } + +qemu_plugin_outs (report->str); +} + +static DeviceCounts *new_count (const char *name,uint64_t base) +{ +DeviceCounts *count =g_new0 (DeviceCounts,1 ); + count->name = name; + count->base = base; +if (pattern || source) { + count->detail =g_hash_table_new (NULL ,NULL ); + } +g_hash_table_insert (devices, (gpointer ) name, count); +return count; +} + +static IOLocationCounts *new_location (GHashTable *table,uint64_t off_or_pc) +{ +IOLocationCounts *loc =g_new0 (IOLocationCounts,1 ); + loc->off_or_pc = off_or_pc; +g_hash_table_insert (table, (gpointer ) off_or_pc, loc); +return loc; +} + +static void hwprofile_match_hit (DeviceCounts *rec,uint64_t off) +{ +g_autoptr (GString) report =g_string_new ("hwprofile: match @ offset" ); +g_string_append_printf (report,"%" PRIx64", previous hits\n" , off); +fmt_dev_record (report, rec); +qemu_plugin_outs (report->str); +} + +static void inc_count (IOCounts *count,bool is_write,unsigned int cpu_index) +{ +if (is_write) { + count->writes++; + count->cpu_write |= (1 << cpu_index); + }else { + count->reads++; + count->cpu_read |= (1 << cpu_index); + } +} + +static void vcpu_haddr (unsigned int cpu_index,qemu_plugin_meminfo_t meminfo, +uint64_t vaddr,void *udata) +{ +struct qemu_plugin_hwaddr *hwaddr =qemu_plugin_get_hwaddr (meminfo, vaddr); + +if (!hwaddr || !qemu_plugin_hwaddr_is_io (hwaddr)) { +return ; + }else { +const char *name =qemu_plugin_hwaddr_device_name (hwaddr); +uint64_t off =qemu_plugin_hwaddr_device_offset (hwaddr); +bool is_write =qemu_plugin_mem_is_store (meminfo); +DeviceCounts *counts; + +g_mutex_lock (&lock); + counts = (DeviceCounts *)g_hash_table_lookup (devices, name); + +if (!counts) { +uint64_t base = vaddr - off; + counts =new_count (name, base); + } + +if (check_match) { +if (g_strv_contains ((const char *const *)matches, counts->name)) { +hwprofile_match_hit (counts, off); +inc_count (&counts->totals, is_write, cpu_index); + } + }else { +inc_count (&counts->totals, is_write, cpu_index); + } + +/* either track offsets or source of access */ +if (source) { + off = (uint64_t ) udata; + } + +if (pattern || source) { +IOLocationCounts *io_count =g_hash_table_lookup (counts->detail, + (gpointer ) off); +if (!io_count) { + io_count =new_location (counts->detail, off); + } +inc_count (&io_count->counts, is_write, cpu_index); + } + +g_mutex_unlock (&lock); + } +} + +static void vcpu_tb_trans (qemu_plugin_id_t id,struct qemu_plugin_tb *tb) +{ +size_t n =qemu_plugin_tb_n_insns (tb); +size_t i; + +for (i =0 ; i < n; i++) { +struct qemu_plugin_insn *insn =qemu_plugin_tb_get_insn (tb, i); +gpointer udata = (gpointer) (source ?qemu_plugin_insn_vaddr (insn) :0 ); +qemu_plugin_register_vcpu_mem_cb (insn, vcpu_haddr, +QEMU_PLUGIN_CB_NO_REGS , + rw, udata); + } +} + +QEMU_PLUGIN_EXPORT +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, +int argc,char **argv) +{ +int i; + +for (i =0 ; i < argc; i++) { +char *opt = argv[i]; +if (g_strcmp0 (opt,"read" ) ==0 ) { + rw =QEMU_PLUGIN_MEM_R ; + }else if (g_strcmp0 (opt,"write" ) ==0 ) { + rw =QEMU_PLUGIN_MEM_W ; + }else if (g_strcmp0 (opt,"pattern" ) ==0 ) { + pattern = true; + }else if (g_strcmp0 (opt,"source" ) ==0 ) { + source = true; + }else if (g_str_has_prefix (opt,"match" )) { +gchar **parts =g_strsplit (opt,"=" ,2 ); + check_match = true; + matches =g_strsplit (parts[1 ],"," ,-1 ); +g_strfreev (parts); + }else { +fprintf (stderr,"option parsing failed: %s\n" , opt); +return -1 ; + } + } + +if (source && pattern) { +fprintf (stderr,"can only currently track either source or pattern.\n" ); +return -1 ; + } + +if (!info->system_emulation) { +fprintf (stderr,"hwprofile: plugin only useful for system emulation\n" ); +return -1 ; + } + +/* Just warn about overflow */ +if (info->system.smp_vcpus >64 || + info->system.max_vcpus >64 ) { +fprintf (stderr,"hwprofile: can only track up to 64 CPUs\n" ); + } + +plugin_init (); + +qemu_plugin_register_vcpu_tb_trans_cb (id, vcpu_tb_trans); +qemu_plugin_register_atexit_cb (id, plugin_exit,NULL ); +return 0 ; +}
tests/plugin/Makefile +1 -0
@@ -14,6 +14,7 @@ NAMES += hotblocks NAMES += howvec NAMES += hotpages NAMES += lockstep +NAMES += hwprofile SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
tests/tcg/Makefile.target +10 -2
@@ -129,8 +129,16 @@ ifeq ($(CONFIG_PLUGIN),y) PLUGIN_SRC=$(SRC_PATH)/tests/plugin PLUGIN_LIB=../../plugin VPATH+=$(PLUGIN_LIB) -PLUGINS=$(filter-out liblockstep.so,\ - $(patsubst %.c, lib%.so, $(notdir $(wildcard $(PLUGIN_SRC)/*.c)))) + +# Some plugins aren't testable automatically +SKIP_PLUGINS=liblockstep.so +ifdef CONFIG_USER_ONLY +SKIP_PLUGINS+=libhwprofile.so +endif + +PLUGINS=$(filter-out $(SKIP_PLUGINS),\ + $(patsubst %.c, lib%.so, \ + $(notdir $(wildcard $(PLUGIN_SRC)/*.c)))) # We need to ensure expand the run-plugin-TEST-with-PLUGIN # pre-requistes manually here as we can't use stems to handle it. We
Signature · 1 line
2.20.1
PATCH 8/13 plugins: expand the bb plugin to be thread safe and track per-cpu
In reply to Alex BennéeWhile there isn't any easy way to make the inline counts thread safe we can ensure the callback based ones are. While we are at it we can reduce introduce a new option ("idle") to dump a report of the current bb and insn count each time a vCPU enters the idle state.
---
v2
- fixup for non-inline linux-user case
- minor cleanup and re-factor
--- tests/plugin/bb.c | 96 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 13 deletions(-)
tests/plugin/bb.c +83 -13
@@ -16,24 +16,67 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; -static uint64_t bb_count; -static uint64_t insn_count; +typedef struct { +GMutex lock; +int index; +uint64_t bb_count; +uint64_t insn_count; +}CPUCount ; + +/* Used by the inline & linux-user counts */ static bool do_inline; +static CPUCount inline_count; + +/* Dump running CPU total on idle? */ +static bool idle_report; +static GPtrArray *counts; +static int max_cpus; + +static void gen_one_cpu_report (CPUCount *count,GString *report) +{ +if (count->bb_count) { +g_string_append_printf (report,"CPU%d: " +"bb's: %" PRIu64", insns: %" PRIu64"\n" , + count->index, + count->bb_count, count->insn_count); + } +}static void plugin_exit (qemu_plugin_id_t id,void *p) { - g_autofree gchar *out = g_strdup_printf( -"bb's: %" PRIu64", insns: %" PRIu64"\n" , - bb_count, insn_count); -qemu_plugin_outs (out); +g_autoptr (GString) report =g_string_new ("" ); + +if (do_inline || !max_cpus) { +g_string_printf (report,"bb's: %" PRIu64", insns: %" PRIu64"\n" , + inline_count.bb_count, inline_count.insn_count); + }else { +g_ptr_array_foreach (counts, (GFunc ) gen_one_cpu_report, report); + } +qemu_plugin_outs (report->str); +} + +static void vcpu_idle (qemu_plugin_id_t id,unsigned int cpu_index) +{ +CPUCount *count =g_ptr_array_index (counts, cpu_index); +g_autoptr (GString) report =g_string_new ("" ); +gen_one_cpu_report (count, report); + +if (report->len >0 ) { +g_string_prepend (report,"Idling " ); +qemu_plugin_outs (report->str); + } }static void vcpu_tb_exec (unsigned int cpu_index,void *udata) { -unsigned long n_insns = (unsigned long )udata; +CPUCount *count = max_cpus ? +g_ptr_array_index (counts, cpu_index) : &inline_count; - insn_count += n_insns; - bb_count++; +unsigned long n_insns = (unsigned long )udata; +g_mutex_lock (&count->lock); + count->insn_count += n_insns; + count->bb_count++; +g_mutex_unlock (&count->lock); }static void vcpu_tb_trans (qemu_plugin_id_t id,struct qemu_plugin_tb *tb)
@@ -42,9 +85,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)if (do_inline) {qemu_plugin_register_vcpu_tb_exec_inline (tb,QEMU_PLUGIN_INLINE_ADD_U64 , - &bb_count,1 ); + &inline_count.bb_count,1 );qemu_plugin_register_vcpu_tb_exec_inline (tb,QEMU_PLUGIN_INLINE_ADD_U64 , - &insn_count, n_insns); + &inline_count.insn_count, n_insns); }else { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS,
@@ -56,8 +99,35 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,const qemu_info_t *info, int argc, char **argv) { - if (argc && strcmp(argv[0], "inline") == 0) { - do_inline = true; + int i; + +for (i =0 ; i < argc; i++) { +char *opt = argv[i]; +if (g_strcmp0 (opt,"inline" ) ==0 ) { + do_inline = true; + }else if (g_strcmp0 (opt,"idle" ) ==0 ) { + idle_report = true; + }else { +fprintf (stderr,"option parsing failed: %s\n" , opt); +return -1 ; + } + } + +if (info->system_emulation && !do_inline) { + max_cpus = info->system.max_vcpus; + counts =g_ptr_array_new (); +for (i =0 ; i < max_cpus; i++) { +CPUCount *count =g_new0 (CPUCount,1 ); +g_mutex_init (&count->lock); + count->index = i; +g_ptr_array_add (counts, count); + } + }else if (!do_inline) { +g_mutex_init (&inline_count.lock); + } + +if (idle_report) { +qemu_plugin_register_vcpu_idle_cb (id, vcpu_idle); }qemu_plugin_register_vcpu_tb_trans_cb (id, vcpu_tb_trans);
Signature · 1 line
2.20.1
Re: [PATCH v1 08/13] plugins: expand the bb plugin to be thread safe and track per-cpu
Quoted 151 lines · Alex Bennée
While there isn't any easy way to make the inline counts thread safe we can ensure the callback based ones are. While we are at it we can reduce introduce a new option ("idle") to dump a report of the current bb and insn count each time a vCPU enters the idle state.
Signed-off-by Alex Bennée <[email protected]>Cc Dave Bort <[email protected]>---
v2
- fixup for non-inline linux-user case
- minor cleanup and re-factor--- tests/plugin/bb.c | 96 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 13 deletions(-)tests/plugin/bb.c +83
-14@@ -16,24 +16,67 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; -static uint64_t bb_count; -static uint64_t insn_count; +typedef struct { +GMutex lock; +int index; +uint64_t bb_count; +uint64_t insn_count; +}CPUCount ; + +/* Used by the inline & linux-user counts */ static bool do_inline; +static CPUCount inline_count; + +/* Dump running CPU total on idle? */ +static bool idle_report; +static GPtrArray *counts; +static int max_cpus; + +static void gen_one_cpu_report (CPUCount *count,GString *report) +{ +if (count->bb_count) { +g_string_append_printf (report,"CPU%d: " +"bb's: %" PRIu64", insns: %" PRIu64"\n" , + count->index, + count->bb_count, count->insn_count); + } +}static void plugin_exit (qemu_plugin_id_t id,void *p) { - g_autofree gchar *out = g_strdup_printf( -"bb's: %" PRIu64", insns: %" PRIu64"\n" , - bb_count, insn_count); -qemu_plugin_outs (out); +g_autoptr (GString) report =g_string_new ("" ); + +if (do_inline || !max_cpus) { +g_string_printf (report,"bb's: %" PRIu64", insns: %" PRIu64"\n" , + inline_count.bb_count, inline_count.insn_count); + }else { +g_ptr_array_foreach (counts, (GFunc ) gen_one_cpu_report, report); + } +qemu_plugin_outs (report->str); +} + +static void vcpu_idle (qemu_plugin_id_t id,unsigned int cpu_index) +{ +CPUCount *count =g_ptr_array_index (counts, cpu_index); +g_autoptr (GString) report =g_string_new ("" ); +gen_one_cpu_report (count, report); + +if (report->len >0 ) { +g_string_prepend (report,"Idling " ); +qemu_plugin_outs (report->str); + } }static void vcpu_tb_exec (unsigned int cpu_index,void *udata) { -unsigned long n_insns = (unsigned long )udata; +CPUCount *count = max_cpus ? +g_ptr_array_index (counts, cpu_index) : &inline_count; - insn_count += n_insns; - bb_count++; +unsigned long n_insns = (unsigned long )udata; +g_mutex_lock (&count->lock); + count->insn_count += n_insns; + count->bb_count++; +g_mutex_unlock (&count->lock); }static void vcpu_tb_trans (qemu_plugin_id_t id,struct qemu_plugin_tb *tb)@@ -42,9 +85,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)if (do_inline) {qemu_plugin_register_vcpu_tb_exec_inline (tb,QEMU_PLUGIN_INLINE_ADD_U64 , - &bb_count,1 ); + &inline_count.bb_count,1 );qemu_plugin_register_vcpu_tb_exec_inline (tb,QEMU_PLUGIN_INLINE_ADD_U64 , - &insn_count, n_insns); + &inline_count.insn_count, n_insns); }else { qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, QEMU_PLUGIN_CB_NO_REGS,@@ -56,8 +99,35 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,const qemu_info_t *info, int argc, char **argv) { - if (argc && strcmp(argv[0], "inline") == 0) { - do_inline = true; + int i; + +for (i =0 ; i < argc; i++) { +char *opt = argv[i]; +if (g_strcmp0 (opt,"inline" ) ==0 ) { + do_inline = true; + }else if (g_strcmp0 (opt,"idle" ) ==0 ) { + idle_report = true; + }else { +fprintf (stderr,"option parsing failed: %s\n" , opt); +return -1 ; + } + } + +if (info->system_emulation && !do_inline) { + max_cpus = info->system.max_vcpus; + counts =g_ptr_array_new (); +for (i =0 ; i < max_cpus; i++) { +CPUCount *count =g_new0 (CPUCount,1 ); +g_mutex_init (&count->lock); + count->index = i; +g_ptr_array_add (counts, count); + } + }else if (!do_inline) { +g_mutex_init (&inline_count.lock); + } + +if (idle_report) { +qemu_plugin_register_vcpu_idle_cb (id, vcpu_idle); }qemu_plugin_register_vcpu_tb_trans_cb (id, vcpu_tb_trans); --2.20.1
Re: [PATCH v1 08/13] plugins: expand the bb plugin to be thread safe and track per-cpu
In reply to Alex BennéeQuoted 1 line · Alex Bennée
While there isn't any easy way to make the inline counts thread safe
Why not? At least in 64-bit hosts TCG will emit a single write to update the 64-bit counter.
Quoted 2 lines
we can ensure the callback based ones are. While we are at it we can reduce introduce a new option ("idle") to dump a report of the current
s/reduce//
Quoted 19 lines
bb and insn count each time a vCPU enters the idle state.
Signed-off-by Alex Bennée <[email protected]>Cc Dave Bort <[email protected]>---
v2
- fixup for non-inline linux-user case
- minor cleanup and re-factor--- tests/plugin/bb.c | 96 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 13 deletions(-)tests/plugin/bb.c +0
-0@@ -16,24 +16,67 @@
tests/plugin/bb.c line 24
Quoted 10 lines
tests/plugin/bb.c +6
-2QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; -static uint64_t bb_count; -static uint64_t insn_count; +typedef struct { +GMutex lock; +int index; +uint64_t bb_count; +uint64_t insn_count; +}CPUCount ;
Why use a mutex?
Just have a per-vCPU struct that each vCPU thread updates with atomic_write. Then when we want to print a report we just have to collect the counts with atomic_read().
Also, consider just adding a comment to bb.c noting that it is not thread-safe, and having a separate bb-threadsafe.c plugin for patch. The reason is that bb.c is very simple, which is useful to understand the interface.
Thanks,
E.
Re: [PATCH v1 08/13] plugins: expand the bb plugin to be thread safe and track per-cpu
Quoted 5 lines · Emilio G. Cota
Quoted 1 line · Alex Bennée
While there isn't any easy way to make the inline counts thread safe
Why not? At least in 64-bit hosts TCG will emit a single write to update the 64-bit counter.
Well the operation is an add so that is a load/add/store cycle on non-x86. If we want to do it properly we should expose an atomic add operation which may be helper based or maybe generate an atomic operation if the backend can support it easily.
Quoted 48 lines
Quoted 3 lines
we can ensure the callback based ones are. While we are at it we can reduce introduce a new option ("idle") to dump a report of the current
s/reduce//
Quoted 19 lines
bb and insn count each time a vCPU enters the idle state.
Signed-off-by Alex Bennée <[email protected]>Cc Dave Bort <[email protected]>---
v2
- fixup for non-inline linux-user case
- minor cleanup and re-factor--- tests/plugin/bb.c | 96 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 13 deletions(-)tests/plugin/bb.c +0
-0@@ -16,24 +16,67 @@tests/plugin/bb.c line 24
Quoted 10 lines
tests/plugin/bb.c +6
-2QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; -static uint64_t bb_count; -static uint64_t insn_count; +typedef struct { +GMutex lock; +int index; +uint64_t bb_count; +uint64_t insn_count; +}CPUCount ;Why use a mutex?
Just have a per-vCPU struct that each vCPU thread updates with
atomic_write. Then when we want to print a report we just have to collect the counts withatomic_read().Also, consider just adding a comment to
bb.cnoting that it is not thread-safe, and having a separatebb-threadsafe.cplugin for patch. The reason is thatbb.cis very simple, which is useful to understand the interface.Thanks,
E.
Signature · 1 line
Alex Bennée
PATCH 9/13 target/sh4: revert to using cpu_lduw_code to decode gusa
In reply to Alex BennéeThe translator_ld* functions very much expect us to be decoding one instruction at a time. Otherwise we will see weirdness such as:
qemu-sh4: warning: plugin_disas: 6 bytes left over
when we use the disas functions. For what SH4 is doing here (scanning ahead in the instruction stream) this is the right function to use.
--- target/sh4/translate.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
target/sh4/translate.c +6 -2
@@ -1915,9 +1915,13 @@ static void decode_gusa(DisasContext *ctx, CPUSH4State *env) goto fail; } -/* Read all of the insns for the region. */ +/* +* Read all of the insns for the region. We do this directly with +* cpu_lduw_code to avoid confusing the plugins by decoding +* multiple instructions. +*/ for (i =0 ; i < max_insns; ++i) { - insns[i] =translator_lduw (env, pc + i *2 ); + insns[i] =cpu_lduw_code (env, pc + i *2 ); } ld_adr = ld_dst = ld_mop =-1 ;
Signature · 1 line
2.20.1
Re: [PATCH v1 09/13] target/sh4: revert to using cpu_lduw_code to decode gusa
Quoted 21 lines · Alex Bennée
The translator_ld* functions very much expect us to be decoding one instruction at a time. Otherwise we will see weirdness such as:
qemu-sh4: warning:
plugin_disas: 6 bytes left overwhen we use the disas functions. For what SH4 is doing here (scanning ahead in the instruction stream) this is the right function to use.
Reported-by Claudio Fontana <[email protected]>Signed-off-by Alex Bennée <[email protected]>--- target/sh4/translate.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)target/sh4/translate.c +0
-0@@ -1915,9 +1915,13 @@ static void decode_gusa(DisasContext *ctx, CPUSH4State *env) goto fail; }
target/sh4/translate.c static void decode_gusa(DisasContext *ctx, CPUSH4State *env) · line 1924
Quoted 10 lines
target/sh4/translate.c +6
-2-/* Read all of the insns for the region. */ +/* +* Read all of the insns for the region. We do this directly with +* cpu_lduw_code to avoid confusing the plugins by decoding +* multiple instructions. +*/ for (i =0 ; i < max_insns; ++i) { - insns[i] =translator_lduw (env, pc + i *2 ); + insns[i] =cpu_lduw_code (env, pc + i *2 );
Quoted 4 lines
target/sh4/translate.c +0
-0} ld_adr = ld_dst = ld_mop =-1 ;
Re: [PATCH v1 09/13] target/sh4: revert to using cpu_lduw_code to decode gusa
In reply to Alex BennéeQuoted 7 lines · Alex Bennée
The translator_ld* functions very much expect us to be decoding one instruction at a time. Otherwise we will see weirdness such as:
qemu-sh4: warning:
plugin_disas: 6 bytes left overwhen we use the disas functions. For what SH4 is doing here (scanning ahead in the instruction stream) this is the right function to use.
It is not just scanning ahead. It does that, but after having done so it may also commit to translating them all at once.
In the case to which you refer, above, we have translated 4 insns into one operation. Just having plugin_disas see the first one is not really correct either.
r~
Quoted 28 lines
Reported-by Claudio Fontana <[email protected]>Signed-off-by Alex Bennée <[email protected]>--- target/sh4/translate.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)target/sh4/translate.c +6
-2@@ -1915,9 +1915,13 @@ static void decode_gusa(DisasContext *ctx, CPUSH4State *env) goto fail; } -/* Read all of the insns for the region. */ +/* +* Read all of the insns for the region. We do this directly with +* cpu_lduw_code to avoid confusing the plugins by decoding +* multiple instructions. +*/ for (i =0 ; i < max_insns; ++i) { - insns[i] =translator_lduw (env, pc + i *2 ); + insns[i] =cpu_lduw_code (env, pc + i *2 ); } ld_adr = ld_dst = ld_mop =-1 ;
PATCH 10/13 tests/plugins: add -Wno-unknown-warning-option to handle -Wpsabi
In reply to Alex BennéeNot all compilers support the -Wpsabi (clang-9 in my case).
--- tests/plugin/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/plugin/Makefile +1 -1
@@ -18,7 +18,7 @@ NAMES += hwprofile SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) -QEMU_CFLAGS += -fPIC -Wpsabi +QEMU_CFLAGS += -fPIC -Wno-unknown-warning-option -Wpsabi QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu all: $(SONAMES)
Signature · 1 line
2.20.1
Re: [PATCH v1 10/13] tests/plugins: add -Wno-unknown-warning-option to handle -Wpsabi
Quoted 25 lines · Alex Bennée
Not all compilers support the -Wpsabi (clang-9 in my case).
Fixes bac8d222aSigned-off-by Alex Bennée <[email protected]>--- tests/plugin/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/plugin/Makefile +1
-2@@ -18,7 +18,7 @@ NAMES += hwprofile SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) -QEMU_CFLAGS += -fPIC -Wpsabi +QEMU_CFLAGS += -fPIC -Wno-unknown-warning-option -Wpsabi QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu all: $(SONAMES) --2.20.1
Re: [PATCH v1 10/13] tests/plugins: add -Wno-unknown-warning-option to handle -Wpsabi
In reply to Alex BennéeQuoted 13 lines · Alex Bennée
Not all compilers support the -Wpsabi (clang-9 in my case).
Fixes bac8d222aSigned-off-by Alex Bennée <[email protected]>--- tests/plugin/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/plugin/Makefile +0
-0
tests/plugin/Makefile NAMES += hwprofile · line 21
Quoted 5 lines
tests/plugin/Makefile +1
-1@@ -18,7 +18,7 @@ NAMES += hwprofile SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) -QEMU_CFLAGS += -fPIC -Wpsabi +QEMU_CFLAGS += -fPIC -Wno-unknown-warning-option -Wpsabi
Surely -Wno-unknown-warning-option is in the same boat? E.g. I don't see any version of gcc that supports it.
Originally, I tried to grab -Wno-psabi out of the existing QEMU_CFLAGS and transforming it, but I couldn't make that work.
r~
Quoted 4 lines
tests/plugin/Makefile +0
-0QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu all: $(SONAMES)
Re: [PATCH v1 10/13] tests/plugins: add -Wno-unknown-warning-option to handle -Wpsabi
Quoted 15 lines · Richard Henderson
Quoted 14 lines · Alex Bennée
Not all compilers support the -Wpsabi (clang-9 in my case).
Fixes bac8d222aSigned-off-by Alex Bennée <[email protected]>--- tests/plugin/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/plugin/Makefile +0
-0@@ -18,7 +18,7 @@ NAMES += hwprofile
Quoted 7 lines
tests/plugin/Makefile NAMES += hwprofile · line 21
Quoted 4 lines
tests/plugin/Makefile +1
-1SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) -QEMU_CFLAGS += -fPIC -Wpsabi +QEMU_CFLAGS += -fPIC -Wno-unknown-warning-option -WpsabiSurely -Wno-unknown-warning-option is in the same boat? E.g. I don't see any version of gcc that supports it.
GCC doesn't seem to complain about it though.
Quoted 2 lines
Originally, I tried to grab -Wno-psabi out of the existing
QEMU_CFLAGSand transforming it, but I couldn't make that work.
I though the plugin Makefile was meant to be standalone to demonstrate how you build stuff out of tree but I guess we include some of the main make machinery in it. I'll see what I can do.
Quoted 8 lines
r~
Quoted 4 lines
tests/plugin/Makefile +0
-0QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu all: $(SONAMES)
Signature · 1 line
Alex Bennée
Re: [PATCH v1 10/13] tests/plugins: add -Wno-unknown-warning-option to handle -Wpsabi
Quoted 20 lines · Alex Bennée
Quoted 17 lines · Richard Henderson
Quoted 16 lines · Alex Bennée
Not all compilers support the -Wpsabi (clang-9 in my case).
Fixes bac8d222aSigned-off-by Alex Bennée <[email protected]>--- tests/plugin/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/plugin/Makefile +0
-0@@ -18,7 +18,7 @@ NAMES += hwprofile SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
Quoted 7 lines
Quoted 5 lines
tests/plugin/Makefile NAMES += hwprofile · line 21
Quoted 2 lines
tests/plugin/Makefile +1
-1-QEMU_CFLAGS += -fPIC -Wpsabi +QEMU_CFLAGS += -fPIC -Wno-unknown-warning-option -WpsabiSurely -Wno-unknown-warning-option is in the same boat? E.g. I don't see any version of gcc that supports it.
GCC doesn't seem to complain about it though.
Both, GCC and Clang do not complain about unknown -Wno-somthing options as long as there are no other warnings. They only complain for options that do not have a "no-" after the "-W".
Thomas
Re: [PATCH v1 10/13] tests/plugins: add -Wno-unknown-warning-option to handle -Wpsabi
Quoted 27 lines · Thomas Huth
Quoted 26 lines · Alex Bennée
Quoted 22 lines · Richard Henderson
Quoted 13 lines · Alex Bennée
Not all compilers support the -Wpsabi (clang-9 in my case).
Fixes bac8d222aSigned-off-by Alex Bennée <[email protected]>--- tests/plugin/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/plugin/Makefile +0
-0tests/plugin/Makefile NAMES += hwprofile · line 21
Quoted 5 lines
tests/plugin/Makefile +1
-1@@ -18,7 +18,7 @@ NAMES += hwprofile SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) -QEMU_CFLAGS += -fPIC -Wpsabi +QEMU_CFLAGS += -fPIC -Wno-unknown-warning-option -WpsabiSurely -Wno-unknown-warning-option is in the same boat? E.g. I don't see any version of gcc that supports it.
Quoted 5 lines
Quoted 1 line
GCC doesn't seem to complain about it though.
Both, GCC and Clang do not complain about unknown -Wno-somthing options as long as there are no other warnings. They only complain for options that do not have a "no-" after the "-W".
I've done a little minor surgery on the Makefile to both limit the pollution of the plugin build from QEMU flags and to only enable the check if we detect the compiler supports it:
--8<---------------cut here---------------start------------->8--- tests/plugins: don't unconditionally add -Wpsabi
Not all compilers support the -Wpsabi (clang-9 in my case). To handle this gracefully we pare back the shared build machinery so the Makefile is relatively "standalone". We still take advantage of config-host.mak as configure has done a bunch of probing for us but that is it.
---
v2
- separate from main build system and check probe
2 files changed, 21 insertions(+), 4 deletions(-)
configure | 3 +++
tests/plugin/Makefile | 22 ++++++++++++++++++----
modified configure
@@ -7115,6 +7115,9 @@ echo "GIT_UPDATE=$git_update" >> $config_host_mak
echo "ARCH=$ARCH" >> $config_host_mak
+echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
+echo "GLIB_LDFLAGS=$glib_ldflags" >> $config_host_mak
+
if test "$default_devices" = "yes" ; then
echo "CONFIG_MINIKCONF_MODE=--defconfig" >> $config_host_mak
else
modified tests/plugin/Makefile
@@ -1,9 +1,16 @@
+# -*- Mode: makefile -*-
+#
+# This Makefile example is fairly independent from the main makefile +# so users can take and adapt it for their build. We only really +# include config-host.mak so we don't have to repeat probing for +# cflags that the main configure has already done for us. +#
+
BUILD_DIR := $(CURDIR)/../..
include $(BUILD_DIR)/config-host.mak
-include $(SRC_PATH)/rules.mak
-$(call set-vpath, $(SRC_PATH)/tests/plugin)
+VPATH += $(SRC_PATH)/tests/plugin
NAMES :=
NAMES += bb
@@ -18,11 +25,18 @@ NAMES += hwprofile
SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
-QEMU_CFLAGS += -fPIC -Wpsabi
-QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu
+# The main QEMU uses Glib extensively so it's perfectly fine to use it +# in plugins (which many example do).
+CFLAGS = $(GLIB_CFLAGS)
+CFLAGS += -fPIC
+CFLAGS += $(if $(findstring no-psabi,$(QEMU_CFLAGS)),-Wpsabi) +CFLAGS += -I$(SRC_PATH)/include/qemu
all: $(SONAMES)
+%.o: %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
lib%.so: %.o
$(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDLIBS)
--8<---------------cut here---------------end--------------->8---
Signature · 1 line
Alex Bennée
PATCH 11/13 tests/docker: fall back more gracefully when pull fails
In reply to Alex BennéeI only spotted this in the small window between my testing with my registry while waiting for the gitlab PR to go in. As we pre-pull the registry image we know if that fails there isn't any point attempting to use the cache. Fall back to the way we used to do it at that point.
--- tests/docker/docker.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
tests/docker/docker.py +6 -5
@@ -306,13 +306,14 @@ class Docker(object): checksum = _text_checksum(_dockerfile_preprocess(dockerfile)) if registry is not None: - dockerfile = dockerfile.replace("FROM qemu/", - "FROM %s/qemu/" % - (registry)) # see if we can fetch a cache copy, may fail... pull_args = ["pull", "%s/%s" % (registry, tag)] - self._do(pull_args, quiet=quiet) - + if self._do(pull_args, quiet=quiet) == 0: + dockerfile = dockerfile.replace("FROM qemu/", + "FROM %s/qemu/" % + (registry)) + else: + registry = None tmp_df = tempfile.NamedTemporaryFile(mode="w+t", encoding='utf-8',
Signature · 1 line
2.20.1
Re: [PATCH v1 11/13] tests/docker: fall back more gracefully when pull fails
Quoted 16 lines · Alex Bennée
I only spotted this in the small window between my testing with my registry while waiting for the gitlab PR to go in. As we pre-pull the registry image we know if that fails there isn't any point attempting to use the cache. Fall back to the way we used to do it at that point.
Signed-off-by Alex Bennée <[email protected]>--- tests/docker/docker.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)tests/docker/docker.py +0
-0@@ -306,13 +306,14 @@ class Docker(object): checksum = _text_checksum(_dockerfile_preprocess(dockerfile))
tests/docker/docker.py class Docker(object): · line 311
Quoted 10 lines
tests/docker/docker.py +1
-5if registry is not None: - dockerfile = dockerfile.replace("FROM qemu/", - "FROM %s/qemu/" % - (registry)) # see if we can fetch a cache copy, may fail... pull_args = ["pull", "%s/%s" % (registry, tag)] - self._do(pull_args, quiet=quiet) - + if self._do(pull_args, quiet=quiet) == 0:
Maybe worth defining EXIT_SUCCESS = 0. Otherwise:
Quoted 9 lines
tests/docker/docker.py +5
-0+ dockerfile = dockerfile.replace("FROM qemu/", + "FROM %s/qemu/" % + (registry)) + else: + registry = None tmp_df = tempfile.NamedTemporaryFile(mode="w+t", encoding='utf-8',
PATCH 12/13 tests/docker: update toolchain set in debian-xtensa-cross
In reply to Alex BennéeFrom: Max Filippov <[email protected]>
Switch to the prebuilt xtensa toolchains release 2020.07. Drop csp toolchain as the csp core is not a part of QEMU. Add de233_fpu and dsp3400 toolchains to enable DFPU and FPU2000 tests.
Message-Id: <[email protected]>
--- tests/docker/dockerfiles/debian-xtensa-cross.docker | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tests/docker/dockerfiles/debian-xtensa-cross.docker +3 -3
@@ -18,12 +18,12 @@ RUN apt-get update && \ git \ python3-minimal -ENV CPU_LIST csp dc232b dc233c -ENV TOOLCHAIN_RELEASE 2018.02 +ENV CPU_LIST dc232b dc233c de233_fpu dsp3400 +ENV TOOLCHAIN_RELEASE 2020.07 RUN for cpu in $CPU_LIST; do \ curl -#SL http://github.com/foss-xtensa/toolchain/releases/download/$TOOLCHAIN_RELEASE/x86_64-$TOOLCHAIN_RELEASE-xtensa-$cpu-elf.tar.gz \ | tar -xzC /opt; \ done -ENV PATH $PATH:/opt/$TOOLCHAIN_RELEASE/xtensa-dc232b-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-dc233c-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-csp-elf/bin +ENV PATH $PATH:/opt/$TOOLCHAIN_RELEASE/xtensa-dc232b-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-dc233c-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-de233_fpu-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-dsp3400-elf/bin
Signature · 1 line
2.20.1
Re: [PATCH v1 12/13] tests/docker: update toolchain set in debian-xtensa-cross
Quoted 5 lines · Alex Bennée
From: Max Filippov <[email protected]>
Switch to the prebuilt xtensa toolchains release 2020.07. Drop csp toolchain as the csp core is not a part of QEMU. Add
de233_fpuand dsp3400 toolchains to enable DFPU and FPU2000 tests.
Yay thanks Max!
Quoted 29 lines
Signed-off-by Max Filippov <[email protected]>Signed-off-by Alex Bennée <[email protected]>Message-Id: <[email protected]>
--- tests/docker/dockerfiles/debian-xtensa-cross.docker | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)tests/docker/dockerfiles/debian-xtensa-cross.docker +3
-3@@ -18,12 +18,12 @@ RUN apt-get update && \ git \ python3-minimal -ENV CPU_LIST csp dc232b dc233c -ENV TOOLCHAIN_RELEASE 2018.02 +ENV CPU_LIST dc232b dc233c de233_fpu dsp3400 +ENV TOOLCHAIN_RELEASE 2020.07 RUN for cpu in $CPU_LIST; do \ curl -#SL http://github.com/foss-xtensa/toolchain/releases/download/$TOOLCHAIN_RELEASE/x86_64-$TOOLCHAIN_RELEASE-xtensa-$cpu-elf.tar.gz \ | tar -xzC /opt; \ done -ENV PATH $PATH:/opt/$TOOLCHAIN_RELEASE/xtensa-dc232b-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-dc233c-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-csp-elf/bin +ENV PATH $PATH:/opt/$TOOLCHAIN_RELEASE/xtensa-dc232b-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-dc233c-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-de233_fpu-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-dsp3400-elf/bin
PATCH 13/13 configure: remove all dependencies on a (re)configure
In reply to Alex BennéeThe previous code was brittle and missed cases such as the mipn32 variants which for some reason has the 64 bit syscalls. This leads to a number of binary targets having deps lines like:
all.clang-sanitizer/mipsn32el-linux-user/linux-user/signal.d 140: /home/alex/lsrc/qemu.git/linux-user/mips64/syscall_nr.h \ 455:/home/alex/lsrc/qemu.git/linux-user/mips64/syscall_nr.h: all.clang-sanitizer/mipsn32el-linux-user/linux-user/syscall.d 146: /home/alex/lsrc/qemu.git/linux-user/mips64/syscall_nr.h \ 485:/home/alex/lsrc/qemu.git/linux-user/mips64/syscall_nr.h:
which in turn would trigger the re-generation of syscall_nr.h in the source tree (thanks to generic %/syscall_nr.h rules). The previous code attempts to clean it out but misses edge cases but fails.
After spending a day trying to understand how this was happening I'm unconvinced that there are not other such breakages possible with this "caching". As we add more auto-generated code to the build it is likely to trip up again. Apply a hammer to the problem.
--- configure | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
configure +6 -9
@@ -1955,23 +1955,20 @@ EOF exit 0 fi -# Remove old dependency files to make sure that they get properly regenerated -rm -f */config-devices.mak.d - # Remove syscall_nr.h to be sure they will be regenerated in the build # directory, not in the source directory for arch in alpha hppa m68k xtensa sh4 microblaze arm ppc s390x sparc sparc64 \ i386 x86_64 mips mips64 ; do # remove the file if it has been generated in the source directory rm -f "${source_path}/linux-user/${arch}/syscall_nr.h" - # remove the dependency files - for target in ${arch}*-linux-user ; do - test -d "${target}" && find "${target}" -type f -name "*.d" \ - -exec grep -q "${source_path}/linux-user/${arch}/syscall_nr.h" {} \; \ - -print | while read file ; do rm "${file}" "${file%.d}.o" ; done - done done +# Clean out all old dependency files. As more files are generated we +# run the risk of old dependencies triggering generation in the wrong +# places. Previous brittle attempts to be surgical tend to miss edge +# cases leading to wasted time and much confusion. +find -type f -name "*.d" -exec rm -f {} \; + if test -z "$python" then error_exit "Python not found. Use --python=/path/to/python"
Signature · 1 line
2.20.1