Skip to content

RFC Trace updates and plugin RFC

Alex Bennée qemu-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest21 patches 48 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/21util/log: allow -dfilter to stackinclude/qemu/log.h tests/test-logging.c util/log.c+32 -61 reply
2/21util/log: add qemu_dfilter_append_range()include/qemu/log.h util/log.c+7 -01 reply
3/21linux-user: add -dfilter progtext shortcutlinux-user/main.c+15 -11 reply
4/21trace: enable the exec_tb trace eventsaccel/tcg/trace-events+5 -43 replies
5/21trace: keep a count of trace-point hitsscripts/tracetool/backend/simple.py trace/event-internal.h+3 -01 reply
6/21trace: show trace point counts in the monitormonitor.c qapi/trace.json trace/qmp.c+6 -33 replies
7/21accel/tcg/cputlb: convert tlb_flush debugging into trace eventsaccel/tcg/cputlb.c accel/tcg/trace-events+58 -303 replies
8/21accel/tcg/cputlb: convert remaining tlb_debug() to trace eventsaccel/tcg/cputlb.c accel/tcg/trace-events+10 -223 replies
9/21trace: suppress log output of trace pointsutil/log.c vl.c+16 -51 reply
10/21qom/cpu: add a cpu_exit trace eventqom/cpu.c qom/trace-events+7 -01 reply
11/21trace: expose a plugin fn pointer in TraceEventtrace/control-internal.h trace/event-internal.h+9 -01 reply
12/21configure: expose a plugin to the trace-backendsconfigure+6 -01 reply
13/21tracetool: generate plugin snippetsscripts/tracetool/backend/plugin.py+79 -01 reply
14/21trace: add support for plugin infrastructureinclude/plugins/plugins.h include/qemu/plugins.h qemu-options.hx +3 more+190 -02 replies
15/21trace: add linux-user plugin supportlinux-user/main.c+15 -01 reply
16/21trace: add infrastructure for building pluginsMakefile trace/Makefile.objs trace/plugins/Makefile.plugins+60 -12 replies
17/21hmp: expose status of plugins to the monitorhmp-commands-info.hx include/qemu/plugins.h monitor.c +1 more+47 -03 replies
18/21linux-user: allow dumping of plugin status at end of runlinux-user/exit.c util/log.c+14 -01 reply
19/21plugins: add an example hotblocks plugintrace/plugins/hotblocks/hotblocks.c+69 -04 replies
20/21plugins: add hotness summary to hotblockstrace/plugins/hotblocks/hotblocks.c+32 -11 reply
21/21plugin: add tlbflush stats plugintrace/plugins/tlbflush/tlbflush.c+283 -00 replies

Reviews trailers per patch

13 of 21 patches have a Reviewed-by or Acked-by.

PatchLaurent VivierRichard HendersonDr. David Alan Gilbert
1/21R-b
2/21R-b
3/21R-b R-b
4/21R-b
5/21
6/21R-b R-b
7/21
8/21
9/21R-b
10/21R-b
11/21R-b
12/21R-b
13/21
14/21R-b
15/21R-b
16/21
17/21R-b R-b
18/21R-b
19/21
20/21
21/21

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v1 thread

Cover letter [Qemu-devel] [RFC PATCH 00/21] Trace updates and plugin RFC

Hi,

This series is a combination of general clean-ups to logging and tracing and a RFC for extending the tracepoint API by the addition of plugins. An example usage would be:

./aarch64-linux-user/qemu-aarch64 -d plugin,nochain -plugin file=trace/plugins/hotblocks.so,args=5 ./aarch64-linux-user/tests/sha1 SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
trace/plugins/hotblocks.so: collected 858d entries in the hash table

    pc: 0x00000000400260 (64004 hits) 4257 ns between returns
    pc: 0x00000000419280 (64004 hits) 4256 ns between returns
    pc: 0x00000000419290 (64003 hits) 4063 ns between returns
    pc: 0x000000004192d4 (64002 hits) 4063 ns between returns
    pc: 0x000000004192f0 (64002 hits) 4062 ns between returns

After reviewing Pavel's series I wondered if we could re-use the trace-point API as potential hooks for a plugin API. Trace points already exist as a series of interesting places in QEMU exposing information that can be used for analysis. By re-using them we avoid potential duplication of concerns. Adding new hook points becomes a simple case of adding a new trace point.

This also allows us to simplify some of the facilities provided to the plugins. I currently envision two types of plugin:

Filter plugins

These are plugins that sit at a trace point and return true/false to the trace code. This would short-circuit the trace from continuing, essentially filtering out unwanted information. The final data is still exported the usual way using trace APIs many output modes.

Analysis plugins

These are plugins that aggregate data in real-time to provide some sort of analysis as they go. They may or may not pass on the trace events to the other trace sub-systems. The example hotblocks plugin is such and example.

While the first set up plugins can re-use the existing trace infrastructure to output information the second type needs a reporting mechanism. As a result I have added a plugin_status() function which can either report on the monitor or in linux-user be called on program exit. In both cases the function simply returns a string and leaves the details of where it gets output to QEMU itself.

=Further Work=

==Known Limitations==

Currently there is only one hook allowed per trace event. We could make this more flexible or simply just error out if two plugins try and hook to the same point. What are the expectations of running multiple plugins hooking into the same point in QEMU?

==TCG Hooks==

Thanks to Lluís' work the trace API already splits up TCG events into translation time and exec time events and provides the machinery for hooking a trace helper into the translation stream. Currently that helper is unconditionally added although perhaps we could expand the call convention a little for TCG events to allow the translation time event to filter out planting the execution time helper?

Any serious analysis tool should allow for us to track all memory accesses so I think the guest_mem_before trace point should probably be split into guest_mem_before_store and guest_mem_after_load. We could go the whole hog and add potential trace points for start/end of all memory operations.

I did start down this road but the code quickly got ugly when dealing with our macrofied access functions. I plan to fish out the de-macrofication of softmmu series I posted earlier this year:

https://lists.gnu.org/archive/html/qemu-devel/2018-04/msg03403.html

And see if that can be applied to all our access functions.

===Instruction Tracing===

Pavel's series had a specific hook for instrumenting individual instructions. I have not yet added it to this series but I think it be done in a slightly cleaner way now we have the ability to insert TCG ops into the instruction stream. If we add a tracepoint for post instruction generation which passes a buffer with the instruction translated and method to insert a helper before or after the instruction. This would avoid exposing the cpu_ldst macros to the plugins.

So what do people think? Could this be a viable way to extend QEMU with plugins?

Alex.

Aaron Lindsay (1):
trace: add linux-user plugin support

Alex Bennée (19):
util/log: allow -dfilter to stack
util/log: add qemu_dfilter_append_range()
linux-user: add -dfilter progtext shortcut
trace: enable the exec_tb trace events
trace: keep a count of trace-point hits
trace: show trace point counts in the monitor accel/tcg/cputlb: convert tlb_flush debugging into trace events accel/tcg/cputlb: convert remaining tlb_debug() to trace events
trace: suppress log output of trace points
qom/cpu: add a cpu_exit trace event
trace: expose a plugin fn pointer in TraceEvent
configure: expose a plugin to the trace-backends
tracetool: generate plugin snippets
trace: add infrastructure for building plugins
hmp: expose status of plugins to the monitor
linux-user: allow dumping of plugin status at end of run
plugins: add an example hotblocks plugin
plugins: add hotness summary to hotblocks
plugin: add tlbflush stats plugin

Pavel Dovgalyuk (1):
trace: add support for plugin infrastructure

 Makefile                            |   5 +-
 accel/tcg/cputlb.c                  |  99 +++++-----
 accel/tcg/trace-events              |  30 ++-
 configure                           |   6 +
 hmp-commands-info.hx                |  17 ++
 include/plugins/plugins.h           |  14 ++
 include/qemu/log.h                  |   2 +
 include/qemu/plugins.h              |  19 ++
 linux-user/exit.c                   |  12 ++
 linux-user/main.c                   |  31 ++-
 monitor.c                           |  19 +-
 qapi/trace.json                     |   3 +-
 qemu-options.hx                     |  10 +
 qom/cpu.c                           |   3 +
 qom/trace-events                    |   4 +
 scripts/tracetool/backend/plugin.py |  79 ++++++++
 scripts/tracetool/backend/simple.py |   2 +
 tests/test-logging.c                |  14 ++
 trace/Makefile.objs                 |  25 +++
 trace/control-internal.h            |   6 +
 trace/event-internal.h              |   4 +
 trace/plugins.c                     | 154 +++++++++++++++
 trace/plugins/Makefile.plugins      |  32 ++++
 trace/plugins/hotblocks/hotblocks.c | 100 ++++++++++
 trace/plugins/tlbflush/tlbflush.c   | 283 ++++++++++++++++++++++++++++
 trace/qmp.c                         |   1 +
 util/log.c                          |  34 +++-
 vl.c                                |  26 ++-
 28 files changed, 962 insertions(+), 72 deletions(-)
 create mode 100644 include/plugins/plugins.h
 create mode 100644 include/qemu/plugins.h
 create mode 100644 scripts/tracetool/backend/plugin.py
 create mode 100644 trace/plugins.c
 create mode 100644 trace/plugins/Makefile.plugins
 create mode 100644 trace/plugins/hotblocks/hotblocks.c
 create mode 100644 trace/plugins/tlbflush/tlbflush.c
Signature · 1 line
2.17.1