xref: /openbmc/qemu/docs/about/emulation.rst (revision a5dd9ee060b0ad65239889a62e93a33276055981)
1a0a6754bSAlex BennéeEmulation
2a0a6754bSAlex Bennée=========
3a0a6754bSAlex Bennée
4a0a6754bSAlex BennéeQEMU's Tiny Code Generator (TCG) provides the ability to emulate a
5a0a6754bSAlex Bennéenumber of CPU architectures on any supported host platform. Both
6a0a6754bSAlex Bennée:ref:`System Emulation` and :ref:`User Mode Emulation` are supported
7a0a6754bSAlex Bennéedepending on the guest architecture.
8a0a6754bSAlex Bennée
9a0a6754bSAlex Bennée.. list-table:: Supported Guest Architectures for Emulation
10a0a6754bSAlex Bennée  :widths: 30 10 10 50
11a0a6754bSAlex Bennée  :header-rows: 1
12a0a6754bSAlex Bennée
13a0a6754bSAlex Bennée  * - Architecture (qemu name)
14a0a6754bSAlex Bennée    - System
15a0a6754bSAlex Bennée    - User
16a0a6754bSAlex Bennée    - Notes
17a0a6754bSAlex Bennée  * - Alpha
18a0a6754bSAlex Bennée    - Yes
19a0a6754bSAlex Bennée    - Yes
20a0a6754bSAlex Bennée    - Legacy 64 bit RISC ISA developed by DEC
21a0a6754bSAlex Bennée  * - Arm (arm, aarch64)
22a0a6754bSAlex Bennée    - :ref:`Yes<ARM-System-emulator>`
23a0a6754bSAlex Bennée    - Yes
24a0a6754bSAlex Bennée    - Wide range of features, see :ref:`Arm Emulation` for details
25a0a6754bSAlex Bennée  * - AVR
26a0a6754bSAlex Bennée    - :ref:`Yes<AVR-System-emulator>`
27a0a6754bSAlex Bennée    - No
28a0a6754bSAlex Bennée    - 8 bit micro controller, often used in maker projects
29a0a6754bSAlex Bennée  * - Hexagon
30a0a6754bSAlex Bennée    - No
31a0a6754bSAlex Bennée    - Yes
32a0a6754bSAlex Bennée    - Family of DSPs by Qualcomm
33a0a6754bSAlex Bennée  * - PA-RISC (hppa)
34a0a6754bSAlex Bennée    - Yes
35a0a6754bSAlex Bennée    - Yes
36a0a6754bSAlex Bennée    - A legacy RISC system used in HP's old minicomputers
37a0a6754bSAlex Bennée  * - x86 (i386, x86_64)
38a0a6754bSAlex Bennée    - :ref:`Yes<QEMU-PC-System-emulator>`
39a0a6754bSAlex Bennée    - Yes
40a0a6754bSAlex Bennée    - The ubiquitous desktop PC CPU architecture, 32 and 64 bit.
419ea0f206SPhilippe Mathieu-Daudé  * - LoongArch
42a0a6754bSAlex Bennée    - Yes
43a0a6754bSAlex Bennée    - Yes
44a0a6754bSAlex Bennée    - A MIPS-like 64bit RISC architecture developed in China
45a0a6754bSAlex Bennée  * - m68k
46a0a6754bSAlex Bennée    - :ref:`Yes<ColdFire-System-emulator>`
47a0a6754bSAlex Bennée    - Yes
48a0a6754bSAlex Bennée    - Motorola 68000 variants and ColdFire
49a0a6754bSAlex Bennée  * - Microblaze
50a0a6754bSAlex Bennée    - Yes
51a0a6754bSAlex Bennée    - Yes
52a0a6754bSAlex Bennée    - RISC based soft-core by Xilinx
53a0a6754bSAlex Bennée  * - MIPS (mips*)
54a0a6754bSAlex Bennée    - :ref:`Yes<MIPS-System-emulator>`
55a0a6754bSAlex Bennée    - Yes
56a0a6754bSAlex Bennée    - Venerable RISC architecture originally out of Stanford University
57a0a6754bSAlex Bennée  * - OpenRISC
58a0a6754bSAlex Bennée    - :ref:`Yes<OpenRISC-System-emulator>`
59a0a6754bSAlex Bennée    - Yes
60a0a6754bSAlex Bennée    - Open source RISC architecture developed by the OpenRISC community
61a0a6754bSAlex Bennée  * - Power (ppc, ppc64)
62a0a6754bSAlex Bennée    - :ref:`Yes<PowerPC-System-emulator>`
63a0a6754bSAlex Bennée    - Yes
64a0a6754bSAlex Bennée    - A general purpose RISC architecture now managed by IBM
65a0a6754bSAlex Bennée  * - RISC-V
66a0a6754bSAlex Bennée    - :ref:`Yes<RISC-V-System-emulator>`
67a0a6754bSAlex Bennée    - Yes
68a0a6754bSAlex Bennée    - An open standard RISC ISA maintained by RISC-V International
69a0a6754bSAlex Bennée  * - RX
70a0a6754bSAlex Bennée    - :ref:`Yes<RX-System-emulator>`
71a0a6754bSAlex Bennée    - No
72a0a6754bSAlex Bennée    - A 32 bit micro controller developed by Renesas
73a0a6754bSAlex Bennée  * - s390x
74a0a6754bSAlex Bennée    - :ref:`Yes<s390x-System-emulator>`
75a0a6754bSAlex Bennée    - Yes
76a0a6754bSAlex Bennée    - A 64 bit CPU found in IBM's System Z mainframes
77a0a6754bSAlex Bennée  * - sh4
78a0a6754bSAlex Bennée    - Yes
79a0a6754bSAlex Bennée    - Yes
80a0a6754bSAlex Bennée    - A 32 bit RISC embedded CPU developed by Hitachi
81a0a6754bSAlex Bennée  * - SPARC (sparc, sparc64)
82a0a6754bSAlex Bennée    - :ref:`Yes<Sparc32-System-emulator>`
83a0a6754bSAlex Bennée    - Yes
84a0a6754bSAlex Bennée    - A RISC ISA originally developed by Sun Microsystems
85a0a6754bSAlex Bennée  * - Tricore
86a0a6754bSAlex Bennée    - Yes
87a0a6754bSAlex Bennée    - No
88a0a6754bSAlex Bennée    - A 32 bit RISC/uController/DSP developed by Infineon
89a0a6754bSAlex Bennée  * - Xtensa
90a0a6754bSAlex Bennée    - :ref:`Yes<Xtensa-System-emulator>`
91a0a6754bSAlex Bennée    - Yes
92a0a6754bSAlex Bennée    - A configurable 32 bit soft core now owned by Cadence
93a0a6754bSAlex Bennée
942da9d213SAlex Bennée.. _Semihosting:
952da9d213SAlex Bennée
962da9d213SAlex BennéeSemihosting
972da9d213SAlex Bennée-----------
982da9d213SAlex Bennée
992da9d213SAlex BennéeSemihosting is a feature defined by the owner of the architecture to
1002da9d213SAlex Bennéeallow programs to interact with a debugging host system. On real
1012da9d213SAlex Bennéehardware this is usually provided by an In-circuit emulator (ICE)
1022da9d213SAlex Bennéehooked directly to the board. QEMU's implementation allows for
1032da9d213SAlex Bennéesemihosting calls to be passed to the host system or via the
1042da9d213SAlex Bennée``gdbstub``.
1052da9d213SAlex Bennée
1062da9d213SAlex BennéeGenerally semihosting makes it easier to bring up low level code before a
1072da9d213SAlex Bennéemore fully functional operating system has been enabled. On QEMU it
1082da9d213SAlex Bennéealso allows for embedded micro-controller code which typically doesn't
1092da9d213SAlex Bennéehave a full libc to be run as "bare-metal" code under QEMU's user-mode
1102da9d213SAlex Bennéeemulation. It is also useful for writing test cases and indeed a
1112da9d213SAlex Bennéenumber of compiler suites as well as QEMU itself use semihosting calls
1122da9d213SAlex Bennéeto exit test code while reporting the success state.
1132da9d213SAlex Bennée
1142da9d213SAlex BennéeSemihosting is only available using TCG emulation. This is because the
1152da9d213SAlex Bennéeinstructions to trigger a semihosting call are typically reserved
1162da9d213SAlex Bennéecausing most hypervisors to trap and fault on them.
1172da9d213SAlex Bennée
1182da9d213SAlex Bennée.. warning::
1192da9d213SAlex Bennée   Semihosting inherently bypasses any isolation there may be between
1202da9d213SAlex Bennée   the guest and the host. As a result a program using semihosting can
121ef073ebdSAlex Bennée   happily trash your host system. Some semihosting calls (e.g.
122ef073ebdSAlex Bennée   ``SYS_READC``) can block execution indefinitely. You should only
123ef073ebdSAlex Bennée   ever run trusted code with semihosting enabled.
1242da9d213SAlex Bennée
1252da9d213SAlex BennéeRedirection
1262da9d213SAlex Bennée~~~~~~~~~~~
1272da9d213SAlex Bennée
1282da9d213SAlex BennéeSemihosting calls can be re-directed to a (potentially remote) gdb
1292da9d213SAlex Bennéeduring debugging via the :ref:`gdbstub<GDB usage>`. Output to the
1302da9d213SAlex Bennéesemihosting console is configured as a ``chardev`` so can be
1312da9d213SAlex Bennéeredirected to a file, pipe or socket like any other ``chardev``
1322da9d213SAlex Bennéedevice.
1332da9d213SAlex Bennée
1342da9d213SAlex BennéeSupported Targets
1352da9d213SAlex Bennée~~~~~~~~~~~~~~~~~
1362da9d213SAlex Bennée
1372da9d213SAlex BennéeMost targets offer similar semihosting implementations with some
1382da9d213SAlex Bennéeminor changes to define the appropriate instruction to encode the
1392da9d213SAlex Bennéesemihosting call and which registers hold the parameters. They tend to
1402da9d213SAlex Bennéepresents a simple POSIX-like API which allows your program to read and
1412da9d213SAlex Bennéewrite files, access the console and some other basic interactions.
1422da9d213SAlex Bennée
1432da9d213SAlex BennéeFor full details of the ABI for a particular target, and the set of
1442da9d213SAlex Bennéecalls it provides, you should consult the semihosting specification
1452da9d213SAlex Bennéefor that architecture.
1462da9d213SAlex Bennée
1472da9d213SAlex Bennée.. note::
1482da9d213SAlex Bennée   QEMU makes an implementation decision to implement all file
1492da9d213SAlex Bennée   access in ``O_BINARY`` mode. The user-visible effect of this is
1502da9d213SAlex Bennée   regardless of the text/binary mode the program sets QEMU will
1512da9d213SAlex Bennée   always select a binary mode ensuring no line-terminator conversion
1522da9d213SAlex Bennée   is performed on input or output. This is because gdb semihosting
1532da9d213SAlex Bennée   support doesn't make the distinction between the modes and
1542da9d213SAlex Bennée   magically processing line endings can be confusing.
1552da9d213SAlex Bennée
1562da9d213SAlex Bennée.. list-table:: Guest Architectures supporting Semihosting
1572da9d213SAlex Bennée  :widths: 10 10 80
1582da9d213SAlex Bennée  :header-rows: 1
1592da9d213SAlex Bennée
1602da9d213SAlex Bennée  * - Architecture
1612da9d213SAlex Bennée    - Modes
1622da9d213SAlex Bennée    - Specification
1632da9d213SAlex Bennée  * - Arm
1642da9d213SAlex Bennée    - System and User-mode
1652da9d213SAlex Bennée    - https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst
1662da9d213SAlex Bennée  * - m68k
1672da9d213SAlex Bennée    - System
1682da9d213SAlex Bennée    - https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=libgloss/m68k/m68k-semi.txt;hb=HEAD
1692da9d213SAlex Bennée  * - MIPS
1702da9d213SAlex Bennée    - System
1712da9d213SAlex Bennée    - Unified Hosting Interface (MD01069)
1722da9d213SAlex Bennée  * - RISC-V
1732da9d213SAlex Bennée    - System and User-mode
1742da9d213SAlex Bennée    - https://github.com/riscv/riscv-semihosting-spec/blob/main/riscv-semihosting-spec.adoc
1752da9d213SAlex Bennée  * - Xtensa
1762da9d213SAlex Bennée    - System
1772da9d213SAlex Bennée    - Tensilica ISS SIMCALL
1786484a3e5SAlex Bennée
1796484a3e5SAlex BennéeTCG Plugins
1806484a3e5SAlex Bennée-----------
1816484a3e5SAlex Bennée
1826484a3e5SAlex BennéeQEMU TCG plugins provide a way for users to run experiments taking
1836484a3e5SAlex Bennéeadvantage of the total system control emulation can have over a guest.
1846484a3e5SAlex BennéeIt provides a mechanism for plugins to subscribe to events during
1856484a3e5SAlex Bennéetranslation and execution and optionally callback into the plugin
1866484a3e5SAlex Bennéeduring these events. TCG plugins are unable to change the system state
1876484a3e5SAlex Bennéeonly monitor it passively. However they can do this down to an
1886484a3e5SAlex Bennéeindividual instruction granularity including potentially subscribing
1896484a3e5SAlex Bennéeto all load and store operations.
1906484a3e5SAlex Bennée
1916484a3e5SAlex BennéeSee the developer section of the manual for details about
1926484a3e5SAlex Bennée:ref:`writing plugins<TCG Plugins>`.
1936484a3e5SAlex Bennée
1946484a3e5SAlex BennéeUsage
1956484a3e5SAlex Bennée~~~~~
1966484a3e5SAlex Bennée
1976484a3e5SAlex BennéeAny QEMU binary with TCG support has plugins enabled by default.
1986484a3e5SAlex BennéeEarlier releases needed to be explicitly enabled with::
1996484a3e5SAlex Bennée
2006484a3e5SAlex Bennée  configure --enable-plugins
2016484a3e5SAlex Bennée
2026484a3e5SAlex BennéeOnce built a program can be run with multiple plugins loaded each with
2036484a3e5SAlex Bennéetheir own arguments::
2046484a3e5SAlex Bennée
2056484a3e5SAlex Bennée  $QEMU $OTHER_QEMU_ARGS \
2063f9f9a37SPierrick Bouvier      -plugin contrib/plugins/libhowvec.so,inline=on,count=hint \
2073f9f9a37SPierrick Bouvier      -plugin contrib/plugins/libhotblocks.so
2086484a3e5SAlex Bennée
2096484a3e5SAlex BennéeArguments are plugin specific and can be used to modify their
2106484a3e5SAlex Bennéebehaviour. In this case the howvec plugin is being asked to use inline
2116484a3e5SAlex Bennéeops to count and break down the hint instructions by type.
2126484a3e5SAlex Bennée
2136484a3e5SAlex BennéeLinux user-mode emulation also evaluates the environment variable
2146484a3e5SAlex Bennée``QEMU_PLUGIN``::
2156484a3e5SAlex Bennée
2166484a3e5SAlex Bennée  QEMU_PLUGIN="file=contrib/plugins/libhowvec.so,inline=on,count=hint" $QEMU
2176484a3e5SAlex Bennée
2183f9f9a37SPierrick BouvierQEMU plugins avoid to write directly to stdin/stderr, and use the log provided
2193f9f9a37SPierrick Bouvierby the API (see function ``qemu_plugin_outs``).
2203f9f9a37SPierrick BouvierTo show output, you may use this additional parameter::
2213f9f9a37SPierrick Bouvier
2223f9f9a37SPierrick Bouvier  $QEMU $OTHER_QEMU_ARGS \
2233f9f9a37SPierrick Bouvier    -d plugin \
2243f9f9a37SPierrick Bouvier    -plugin contrib/plugins/libhowvec.so,inline=on,count=hint
2253f9f9a37SPierrick Bouvier
2266484a3e5SAlex BennéeExample Plugins
2276484a3e5SAlex Bennée~~~~~~~~~~~~~~~
2286484a3e5SAlex Bennée
2296484a3e5SAlex BennéeThere are a number of plugins included with QEMU and you are
2306484a3e5SAlex Bennéeencouraged to contribute your own plugins plugins upstream. There is a
2316484a3e5SAlex Bennée``contrib/plugins`` directory where they can go. There are also some
2326484a3e5SAlex Bennéebasic plugins that are used to test and exercise the API during the
2336484a3e5SAlex Bennée``make check-tcg`` target in ``tests/tcg/plugins`` that are never the
2346484a3e5SAlex Bennéeless useful for basic analysis.
2356484a3e5SAlex Bennée
2366484a3e5SAlex BennéeEmpty
2376484a3e5SAlex Bennée.....
2386484a3e5SAlex Bennée
2396484a3e5SAlex Bennée``tests/tcg/plugins/empty.c``
2406484a3e5SAlex Bennée
2416484a3e5SAlex BennéePurely a test plugin for measuring the overhead of the plugins system
2426484a3e5SAlex Bennéeitself. Does no instrumentation.
2436484a3e5SAlex Bennée
2446484a3e5SAlex BennéeBasic Blocks
2456484a3e5SAlex Bennée............
2466484a3e5SAlex Bennée
2476484a3e5SAlex Bennée``tests/tcg/plugins/bb.c``
2486484a3e5SAlex Bennée
2496484a3e5SAlex BennéeA very basic plugin which will measure execution in coarse terms as
2506484a3e5SAlex Bennéeeach basic block is executed. By default the results are shown once
2516484a3e5SAlex Bennéeexecution finishes::
2526484a3e5SAlex Bennée
2536484a3e5SAlex Bennée  $ qemu-aarch64 -plugin tests/plugin/libbb.so \
2546484a3e5SAlex Bennée      -d plugin ./tests/tcg/aarch64-linux-user/sha1
2556484a3e5SAlex Bennée  SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
2566484a3e5SAlex Bennée  bb's: 2277338, insns: 158483046
2576484a3e5SAlex Bennée
2586484a3e5SAlex BennéeBehaviour can be tweaked with the following arguments:
2596484a3e5SAlex Bennée
2606484a3e5SAlex Bennée.. list-table:: Basic Block plugin arguments
2616484a3e5SAlex Bennée  :widths: 20 80
2626484a3e5SAlex Bennée  :header-rows: 1
2636484a3e5SAlex Bennée
2646484a3e5SAlex Bennée  * - Option
2656484a3e5SAlex Bennée    - Description
2666484a3e5SAlex Bennée  * - inline=true|false
2673f9f9a37SPierrick Bouvier    - Use faster inline addition of a single counter.
2686484a3e5SAlex Bennée  * - idle=true|false
2696484a3e5SAlex Bennée    - Dump the current execution stats whenever the guest vCPU idles
2706484a3e5SAlex Bennée
2710d279becSAkihiko OdakiBasic Block Vectors
2720d279becSAkihiko Odaki...................
2730d279becSAkihiko Odaki
2740d279becSAkihiko Odaki``contrib/plugins/bbv.c``
2750d279becSAkihiko Odaki
2760d279becSAkihiko OdakiThe bbv plugin allows you to generate basic block vectors for use with the
2770d279becSAkihiko Odaki`SimPoint <https://cseweb.ucsd.edu/~calder/simpoint/>`__ analysis tool.
2780d279becSAkihiko Odaki
2790d279becSAkihiko Odaki.. list-table:: Basic block vectors arguments
2800d279becSAkihiko Odaki  :widths: 20 80
2810d279becSAkihiko Odaki  :header-rows: 1
2820d279becSAkihiko Odaki
2830d279becSAkihiko Odaki  * - Option
2840d279becSAkihiko Odaki    - Description
2850d279becSAkihiko Odaki  * - interval=N
2860d279becSAkihiko Odaki    - The interval to generate a basic block vector specified by the number of
2870d279becSAkihiko Odaki      instructions (Default: N = 100000000)
2880d279becSAkihiko Odaki  * - outfile=PATH
2890d279becSAkihiko Odaki    - The path to output files.
2900d279becSAkihiko Odaki      It will be suffixed with ``.N.bb`` where ``N`` is a vCPU index.
2910d279becSAkihiko Odaki
2920d279becSAkihiko OdakiExample::
2930d279becSAkihiko Odaki
2940d279becSAkihiko Odaki  $ qemu-aarch64 \
2950d279becSAkihiko Odaki    -plugin contrib/plugins/libbbv.so,interval=100,outfile=sha1 \
2960d279becSAkihiko Odaki    tests/tcg/aarch64-linux-user/sha1
2970d279becSAkihiko Odaki  SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
2980d279becSAkihiko Odaki  $ du sha1.0.bb
2990d279becSAkihiko Odaki  23128   sha1.0.bb
3000d279becSAkihiko Odaki
3016484a3e5SAlex BennéeInstruction
3026484a3e5SAlex Bennée...........
3036484a3e5SAlex Bennée
3046484a3e5SAlex Bennée``tests/tcg/plugins/insn.c``
3056484a3e5SAlex Bennée
3066484a3e5SAlex BennéeThis is a basic instruction level instrumentation which can count the
3076484a3e5SAlex Bennéenumber of instructions executed on each core/thread::
3086484a3e5SAlex Bennée
3096484a3e5SAlex Bennée  $ qemu-aarch64 -plugin tests/plugin/libinsn.so \
3106484a3e5SAlex Bennée      -d plugin ./tests/tcg/aarch64-linux-user/threadcount
3116484a3e5SAlex Bennée  Created 10 threads
3126484a3e5SAlex Bennée  Done
3136484a3e5SAlex Bennée  cpu 0 insns: 46765
3146484a3e5SAlex Bennée  cpu 1 insns: 3694
3156484a3e5SAlex Bennée  cpu 2 insns: 3694
3166484a3e5SAlex Bennée  cpu 3 insns: 2994
3176484a3e5SAlex Bennée  cpu 4 insns: 1497
3186484a3e5SAlex Bennée  cpu 5 insns: 1497
3196484a3e5SAlex Bennée  cpu 6 insns: 1497
3206484a3e5SAlex Bennée  cpu 7 insns: 1497
3216484a3e5SAlex Bennée  total insns: 63135
3226484a3e5SAlex Bennée
3236484a3e5SAlex BennéeBehaviour can be tweaked with the following arguments:
3246484a3e5SAlex Bennée
3256484a3e5SAlex Bennée.. list-table:: Instruction plugin arguments
3266484a3e5SAlex Bennée  :widths: 20 80
3276484a3e5SAlex Bennée  :header-rows: 1
3286484a3e5SAlex Bennée
3296484a3e5SAlex Bennée  * - Option
3306484a3e5SAlex Bennée    - Description
3316484a3e5SAlex Bennée  * - inline=true|false
3326484a3e5SAlex Bennée    - Use faster inline addition of a single counter.
3336484a3e5SAlex Bennée  * - sizes=true|false
3346484a3e5SAlex Bennée    - Give a summary of the instruction sizes for the execution
3356484a3e5SAlex Bennée  * - match=<string>
3366484a3e5SAlex Bennée    - Only instrument instructions matching the string prefix
3376484a3e5SAlex Bennée
3386484a3e5SAlex BennéeThe ``match`` option will show some basic stats including how many
3396484a3e5SAlex Bennéeinstructions have executed since the last execution. For
3406484a3e5SAlex Bennéeexample::
3416484a3e5SAlex Bennée
3426484a3e5SAlex Bennée   $ qemu-aarch64 -plugin tests/plugin/libinsn.so,match=bl \
3436484a3e5SAlex Bennée       -d plugin ./tests/tcg/aarch64-linux-user/sha512-vector
3446484a3e5SAlex Bennée   ...
3456484a3e5SAlex Bennée   0x40069c, 'bl #0x4002b0', 10 hits, 1093 match hits, Δ+1257 since last match, 98 avg insns/match
3466484a3e5SAlex Bennée   0x4006ac, 'bl #0x403690', 10 hits, 1094 match hits, Δ+47 since last match, 98 avg insns/match
3476484a3e5SAlex Bennée   0x4037fc, 'bl #0x4002b0', 18 hits, 1095 match hits, Δ+22 since last match, 98 avg insns/match
3486484a3e5SAlex Bennée   0x400720, 'bl #0x403690', 10 hits, 1096 match hits, Δ+58 since last match, 98 avg insns/match
3496484a3e5SAlex Bennée   0x4037fc, 'bl #0x4002b0', 19 hits, 1097 match hits, Δ+22 since last match, 98 avg insns/match
3506484a3e5SAlex Bennée   0x400730, 'bl #0x403690', 10 hits, 1098 match hits, Δ+33 since last match, 98 avg insns/match
3516484a3e5SAlex Bennée   0x4037ac, 'bl #0x4002b0', 12 hits, 1099 match hits, Δ+20 since last match, 98 avg insns/match
3526484a3e5SAlex Bennée   ...
3536484a3e5SAlex Bennée
3546484a3e5SAlex BennéeFor more detailed execution tracing see the ``execlog`` plugin for
3556484a3e5SAlex Bennéeother options.
3566484a3e5SAlex Bennée
3576484a3e5SAlex BennéeMemory
3586484a3e5SAlex Bennée......
3596484a3e5SAlex Bennée
3606484a3e5SAlex Bennée``tests/tcg/plugins/mem.c``
3616484a3e5SAlex Bennée
3626484a3e5SAlex BennéeBasic instruction level memory instrumentation::
3636484a3e5SAlex Bennée
3646484a3e5SAlex Bennée  $ qemu-aarch64 -plugin tests/plugin/libmem.so,inline=true \
3656484a3e5SAlex Bennée      -d plugin ./tests/tcg/aarch64-linux-user/sha1
3666484a3e5SAlex Bennée  SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
3676484a3e5SAlex Bennée  inline mem accesses: 79525013
3686484a3e5SAlex Bennée
3696484a3e5SAlex BennéeBehaviour can be tweaked with the following arguments:
3706484a3e5SAlex Bennée
3716484a3e5SAlex Bennée.. list-table:: Memory plugin arguments
3726484a3e5SAlex Bennée  :widths: 20 80
3736484a3e5SAlex Bennée  :header-rows: 1
3746484a3e5SAlex Bennée
3756484a3e5SAlex Bennée  * - Option
3766484a3e5SAlex Bennée    - Description
3776484a3e5SAlex Bennée  * - inline=true|false
3786484a3e5SAlex Bennée    - Use faster inline addition of a single counter
3796484a3e5SAlex Bennée  * - callback=true|false
3806484a3e5SAlex Bennée    - Use callbacks on each memory instrumentation.
3816484a3e5SAlex Bennée  * - hwaddr=true|false
3826484a3e5SAlex Bennée    - Count IO accesses (only for system emulation)
3836484a3e5SAlex Bennée
3846484a3e5SAlex BennéeSystem Calls
3856484a3e5SAlex Bennée............
3866484a3e5SAlex Bennée
3876484a3e5SAlex Bennée``tests/tcg/plugins/syscall.c``
3886484a3e5SAlex Bennée
3896484a3e5SAlex BennéeA basic syscall tracing plugin. This only works for user-mode. By
3906484a3e5SAlex Bennéedefault it will give a summary of syscall stats at the end of the
3916484a3e5SAlex Bennéerun::
3926484a3e5SAlex Bennée
3936484a3e5SAlex Bennée  $ qemu-aarch64 -plugin tests/plugin/libsyscall \
3946484a3e5SAlex Bennée      -d plugin ./tests/tcg/aarch64-linux-user/threadcount
3956484a3e5SAlex Bennée  Created 10 threads
3966484a3e5SAlex Bennée  Done
3976484a3e5SAlex Bennée  syscall no.  calls  errors
3986484a3e5SAlex Bennée  226          12     0
3996484a3e5SAlex Bennée  99           11     11
4006484a3e5SAlex Bennée  115          11     0
4016484a3e5SAlex Bennée  222          11     0
4026484a3e5SAlex Bennée  93           10     0
4036484a3e5SAlex Bennée  220          10     0
4046484a3e5SAlex Bennée  233          10     0
4056484a3e5SAlex Bennée  215          8      0
4066484a3e5SAlex Bennée  214          4      0
4076484a3e5SAlex Bennée  134          2      0
4086484a3e5SAlex Bennée  64           2      0
4096484a3e5SAlex Bennée  96           1      0
4106484a3e5SAlex Bennée  94           1      0
4116484a3e5SAlex Bennée  80           1      0
4126484a3e5SAlex Bennée  261          1      0
4136484a3e5SAlex Bennée  78           1      0
4146484a3e5SAlex Bennée  160          1      0
4156484a3e5SAlex Bennée  135          1      0
4166484a3e5SAlex Bennée
417*f2505260SRowan HartBehaviour can be tweaked with the following arguments:
418*f2505260SRowan Hart
419*f2505260SRowan Hart.. list-table:: Syscall plugin arguments
420*f2505260SRowan Hart  :widths: 20 80
421*f2505260SRowan Hart  :header-rows: 1
422*f2505260SRowan Hart
423*f2505260SRowan Hart  * - Option
424*f2505260SRowan Hart    - Description
425*f2505260SRowan Hart  * - print=true|false
426*f2505260SRowan Hart    - Print the number of times each syscall is called
427*f2505260SRowan Hart  * - log_writes=true|false
428*f2505260SRowan Hart    - Log the buffer of each write syscall in hexdump format
429*f2505260SRowan Hart
4303f9f9a37SPierrick BouvierTest inline operations
4313f9f9a37SPierrick Bouvier......................
4323f9f9a37SPierrick Bouvier
4333f9f9a37SPierrick Bouvier``tests/plugins/inline.c``
4343f9f9a37SPierrick Bouvier
4353f9f9a37SPierrick BouvierThis plugin is used for testing all inline operations, conditional callbacks and
4363f9f9a37SPierrick Bouvierscoreboard. It prints a per-cpu summary of all events.
4373f9f9a37SPierrick Bouvier
4383f9f9a37SPierrick Bouvier
4396484a3e5SAlex BennéeHot Blocks
4406484a3e5SAlex Bennée..........
4416484a3e5SAlex Bennée
4426484a3e5SAlex Bennée``contrib/plugins/hotblocks.c``
4436484a3e5SAlex Bennée
4446484a3e5SAlex BennéeThe hotblocks plugin allows you to examine the where hot paths of
4456484a3e5SAlex Bennéeexecution are in your program. Once the program has finished you will
4466484a3e5SAlex Bennéeget a sorted list of blocks reporting the starting PC, translation
4476484a3e5SAlex Bennéecount, number of instructions and execution count. This will work best
4486484a3e5SAlex Bennéewith linux-user execution as system emulation tends to generate
4496484a3e5SAlex Bennéere-translations as blocks from different programs get swapped in and
4506484a3e5SAlex Bennéeout of system memory.
4516484a3e5SAlex Bennée
4526484a3e5SAlex BennéeExample::
4536484a3e5SAlex Bennée
4546484a3e5SAlex Bennée  $ qemu-aarch64 \
4556484a3e5SAlex Bennée    -plugin contrib/plugins/libhotblocks.so -d plugin \
4566484a3e5SAlex Bennée    ./tests/tcg/aarch64-linux-user/sha1
4576484a3e5SAlex Bennée  SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
4586484a3e5SAlex Bennée  collected 903 entries in the hash table
4596484a3e5SAlex Bennée  pc, tcount, icount, ecount
4606484a3e5SAlex Bennée  0x0000000041ed10, 1, 5, 66087
4616484a3e5SAlex Bennée  0x000000004002b0, 1, 4, 66087
4626484a3e5SAlex Bennée  ...
4636484a3e5SAlex Bennée
4646484a3e5SAlex Bennée
4656484a3e5SAlex BennéeHot Pages
4666484a3e5SAlex Bennée.........
4676484a3e5SAlex Bennée
4686484a3e5SAlex Bennée``contrib/plugins/hotpages.c``
4696484a3e5SAlex Bennée
4706484a3e5SAlex BennéeSimilar to hotblocks but this time tracks memory accesses::
4716484a3e5SAlex Bennée
4726484a3e5SAlex Bennée  $ qemu-aarch64 \
4736484a3e5SAlex Bennée    -plugin contrib/plugins/libhotpages.so -d plugin \
4746484a3e5SAlex Bennée    ./tests/tcg/aarch64-linux-user/sha1
4756484a3e5SAlex Bennée  SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
4766484a3e5SAlex Bennée  Addr, RCPUs, Reads, WCPUs, Writes
4776484a3e5SAlex Bennée  0x000055007fe000, 0x0001, 31747952, 0x0001, 8835161
4786484a3e5SAlex Bennée  0x000055007ff000, 0x0001, 29001054, 0x0001, 8780625
4796484a3e5SAlex Bennée  0x00005500800000, 0x0001, 687465, 0x0001, 335857
4806484a3e5SAlex Bennée  0x0000000048b000, 0x0001, 130594, 0x0001, 355
4816484a3e5SAlex Bennée  0x0000000048a000, 0x0001, 1826, 0x0001, 11
4826484a3e5SAlex Bennée
4836484a3e5SAlex BennéeThe hotpages plugin can be configured using the following arguments:
4846484a3e5SAlex Bennée
4856484a3e5SAlex Bennée.. list-table:: Hot pages arguments
4866484a3e5SAlex Bennée  :widths: 20 80
4876484a3e5SAlex Bennée  :header-rows: 1
4886484a3e5SAlex Bennée
4896484a3e5SAlex Bennée  * - Option
4906484a3e5SAlex Bennée    - Description
4916484a3e5SAlex Bennée  * - sortby=reads|writes|address
4926484a3e5SAlex Bennée    - Log the data sorted by either the number of reads, the number of writes, or
4936484a3e5SAlex Bennée      memory address. (Default: entries are sorted by the sum of reads and writes)
4946484a3e5SAlex Bennée  * - io=on
4956484a3e5SAlex Bennée    - Track IO addresses. Only relevant to full system emulation. (Default: off)
4966484a3e5SAlex Bennée  * - pagesize=N
4976484a3e5SAlex Bennée    - The page size used. (Default: N = 4096)
4986484a3e5SAlex Bennée
4996484a3e5SAlex BennéeInstruction Distribution
5006484a3e5SAlex Bennée........................
5016484a3e5SAlex Bennée
5026484a3e5SAlex Bennée``contrib/plugins/howvec.c``
5036484a3e5SAlex Bennée
5046484a3e5SAlex BennéeThis is an instruction classifier so can be used to count different
5056484a3e5SAlex Bennéetypes of instructions. It has a number of options to refine which get
5066484a3e5SAlex Bennéecounted. You can give a value to the ``count`` argument for a class of
5076484a3e5SAlex Bennéeinstructions to break it down fully, so for example to see all the system
5086484a3e5SAlex Bennéeregisters accesses::
5096484a3e5SAlex Bennée
5106484a3e5SAlex Bennée  $ qemu-system-aarch64 $(QEMU_ARGS) \
5116484a3e5SAlex Bennée    -append "root=/dev/sda2 systemd.unit=benchmark.service" \
5126484a3e5SAlex Bennée    -smp 4 -plugin ./contrib/plugins/libhowvec.so,count=sreg -d plugin
5136484a3e5SAlex Bennée
5146484a3e5SAlex Bennéewhich will lead to a sorted list after the class breakdown::
5156484a3e5SAlex Bennée
5166484a3e5SAlex Bennée  Instruction Classes:
5176484a3e5SAlex Bennée  Class:   UDEF                   not counted
5186484a3e5SAlex Bennée  Class:   SVE                    (68 hits)
5196484a3e5SAlex Bennée  Class:   PCrel addr             (47789483 hits)
5206484a3e5SAlex Bennée  Class:   Add/Sub (imm)          (192817388 hits)
5216484a3e5SAlex Bennée  Class:   Logical (imm)          (93852565 hits)
5226484a3e5SAlex Bennée  Class:   Move Wide (imm)        (76398116 hits)
5236484a3e5SAlex Bennée  Class:   Bitfield               (44706084 hits)
5246484a3e5SAlex Bennée  Class:   Extract                (5499257 hits)
5256484a3e5SAlex Bennée  Class:   Cond Branch (imm)      (147202932 hits)
5266484a3e5SAlex Bennée  Class:   Exception Gen          (193581 hits)
5276484a3e5SAlex Bennée  Class:     NOP                  not counted
5286484a3e5SAlex Bennée  Class:   Hints                  (6652291 hits)
5296484a3e5SAlex Bennée  Class:   Barriers               (8001661 hits)
5306484a3e5SAlex Bennée  Class:   PSTATE                 (1801695 hits)
5316484a3e5SAlex Bennée  Class:   System Insn            (6385349 hits)
5326484a3e5SAlex Bennée  Class:   System Reg             counted individually
5336484a3e5SAlex Bennée  Class:   Branch (reg)           (69497127 hits)
5346484a3e5SAlex Bennée  Class:   Branch (imm)           (84393665 hits)
5356484a3e5SAlex Bennée  Class:   Cmp & Branch           (110929659 hits)
5366484a3e5SAlex Bennée  Class:   Tst & Branch           (44681442 hits)
5376484a3e5SAlex Bennée  Class:   AdvSimd ldstmult       (736 hits)
5386484a3e5SAlex Bennée  Class:   ldst excl              (9098783 hits)
5396484a3e5SAlex Bennée  Class:   Load Reg (lit)         (87189424 hits)
5406484a3e5SAlex Bennée  Class:   ldst noalloc pair      (3264433 hits)
5416484a3e5SAlex Bennée  Class:   ldst pair              (412526434 hits)
5426484a3e5SAlex Bennée  Class:   ldst reg (imm)         (314734576 hits)
5436484a3e5SAlex Bennée  Class: Loads & Stores           (2117774 hits)
5446484a3e5SAlex Bennée  Class: Data Proc Reg            (223519077 hits)
5456484a3e5SAlex Bennée  Class: Scalar FP                (31657954 hits)
5466484a3e5SAlex Bennée  Individual Instructions:
5476484a3e5SAlex Bennée  Instr: mrs x0, sp_el0           (2682661 hits)  (op=0xd5384100/  System Reg)
5486484a3e5SAlex Bennée  Instr: mrs x1, tpidr_el2        (1789339 hits)  (op=0xd53cd041/  System Reg)
5496484a3e5SAlex Bennée  Instr: mrs x2, tpidr_el2        (1513494 hits)  (op=0xd53cd042/  System Reg)
5506484a3e5SAlex Bennée  Instr: mrs x0, tpidr_el2        (1490823 hits)  (op=0xd53cd040/  System Reg)
5516484a3e5SAlex Bennée  Instr: mrs x1, sp_el0           (933793 hits)   (op=0xd5384101/  System Reg)
5526484a3e5SAlex Bennée  Instr: mrs x2, sp_el0           (699516 hits)   (op=0xd5384102/  System Reg)
5536484a3e5SAlex Bennée  Instr: mrs x4, tpidr_el2        (528437 hits)   (op=0xd53cd044/  System Reg)
5546484a3e5SAlex Bennée  Instr: mrs x30, ttbr1_el1       (480776 hits)   (op=0xd538203e/  System Reg)
5556484a3e5SAlex Bennée  Instr: msr ttbr1_el1, x30       (480713 hits)   (op=0xd518203e/  System Reg)
5566484a3e5SAlex Bennée  Instr: msr vbar_el1, x30        (480671 hits)   (op=0xd518c01e/  System Reg)
5576484a3e5SAlex Bennée  ...
5586484a3e5SAlex Bennée
5596484a3e5SAlex BennéeTo find the argument shorthand for the class you need to examine the
5606484a3e5SAlex Bennéesource code of the plugin at the moment, specifically the ``*opt``
5616484a3e5SAlex Bennéeargument in the InsnClassExecCount tables.
5626484a3e5SAlex Bennée
5636484a3e5SAlex BennéeLockstep Execution
5646484a3e5SAlex Bennée..................
5656484a3e5SAlex Bennée
5666484a3e5SAlex Bennée``contrib/plugins/lockstep.c``
5676484a3e5SAlex Bennée
5686484a3e5SAlex BennéeThis is a debugging tool for developers who want to find out when and
5696484a3e5SAlex Bennéewhere execution diverges after a subtle change to TCG code generation.
5706484a3e5SAlex BennéeIt is not an exact science and results are likely to be mixed once
5716484a3e5SAlex Bennéeasynchronous events are introduced. While the use of -icount can
5726484a3e5SAlex Bennéeintroduce determinism to the execution flow it doesn't always follow
5736484a3e5SAlex Bennéethe translation sequence will be exactly the same. Typically this is
5746484a3e5SAlex Bennéecaused by a timer firing to service the GUI causing a block to end
5756484a3e5SAlex Bennéeearly. However in some cases it has proved to be useful in pointing
5766484a3e5SAlex Bennéepeople at roughly where execution diverges. The only argument you need
5776484a3e5SAlex Bennéefor the plugin is a path for the socket the two instances will
5786484a3e5SAlex Bennéecommunicate over::
5796484a3e5SAlex Bennée
5806484a3e5SAlex Bennée
5816484a3e5SAlex Bennée  $ qemu-system-sparc -monitor none -parallel none \
5826484a3e5SAlex Bennée    -net none -M SS-20 -m 256 -kernel day11/zImage.elf \
5836484a3e5SAlex Bennée    -plugin ./contrib/plugins/liblockstep.so,sockpath=lockstep-sparc.sock \
5846484a3e5SAlex Bennée    -d plugin,nochain
5856484a3e5SAlex Bennée
5866484a3e5SAlex Bennéewhich will eventually report::
5876484a3e5SAlex Bennée
5886484a3e5SAlex Bennée  qemu-system-sparc: warning: nic lance.0 has no peer
5896484a3e5SAlex Bennée  @ 0x000000ffd06678 vs 0x000000ffd001e0 (2/1 since last)
5906484a3e5SAlex Bennée  @ 0x000000ffd07d9c vs 0x000000ffd06678 (3/1 since last)
5916484a3e5SAlex Bennée  Δ insn_count @ 0x000000ffd07d9c (809900609) vs 0x000000ffd06678 (809900612)
5926484a3e5SAlex Bennée    previously @ 0x000000ffd06678/10 (809900609 insns)
5936484a3e5SAlex Bennée    previously @ 0x000000ffd001e0/4 (809900599 insns)
5946484a3e5SAlex Bennée    previously @ 0x000000ffd080ac/2 (809900595 insns)
5956484a3e5SAlex Bennée    previously @ 0x000000ffd08098/5 (809900593 insns)
5966484a3e5SAlex Bennée    previously @ 0x000000ffd080c0/1 (809900588 insns)
5976484a3e5SAlex Bennée
5986484a3e5SAlex Bennée
5996484a3e5SAlex BennéeHardware Profile
6006484a3e5SAlex Bennée................
6016484a3e5SAlex Bennée
6026484a3e5SAlex Bennée``contrib/plugins/hwprofile.c``
6036484a3e5SAlex Bennée
6046484a3e5SAlex BennéeThe hwprofile tool can only be used with system emulation and allows
6056484a3e5SAlex Bennéethe user to see what hardware is accessed how often. It has a number of options:
6066484a3e5SAlex Bennée
6076484a3e5SAlex Bennée.. list-table:: Hardware Profile arguments
6086484a3e5SAlex Bennée  :widths: 20 80
6096484a3e5SAlex Bennée  :header-rows: 1
6106484a3e5SAlex Bennée
6116484a3e5SAlex Bennée  * - Option
6126484a3e5SAlex Bennée    - Description
6136484a3e5SAlex Bennée  * - track=[read|write]
6146484a3e5SAlex Bennée    - By default the plugin tracks both reads and writes. You can use
6156484a3e5SAlex Bennée      this option to limit the tracking to just one class of accesses.
6166484a3e5SAlex Bennée  * - source
6176484a3e5SAlex Bennée    - Will include a detailed break down of what the guest PC that made the
6186484a3e5SAlex Bennée      access was. Not compatible with the pattern option. Example output::
6196484a3e5SAlex Bennée
6206484a3e5SAlex Bennée        cirrus-low-memory @ 0xfffffd00000a0000
6216484a3e5SAlex Bennée         pc:fffffc0000005cdc, 1, 256
6226484a3e5SAlex Bennée         pc:fffffc0000005ce8, 1, 256
6236484a3e5SAlex Bennée         pc:fffffc0000005cec, 1, 256
6246484a3e5SAlex Bennée
6256484a3e5SAlex Bennée  * - pattern
6266484a3e5SAlex Bennée    - Instead break down the accesses based on the offset into the HW
6276484a3e5SAlex Bennée      region. This can be useful for seeing the most used registers of
6286484a3e5SAlex Bennée      a device. Example output::
6296484a3e5SAlex Bennée
6306484a3e5SAlex Bennée        pci0-conf @ 0xfffffd01fe000000
6316484a3e5SAlex Bennée          off:00000004, 1, 1
6326484a3e5SAlex Bennée          off:00000010, 1, 3
6336484a3e5SAlex Bennée          off:00000014, 1, 3
6346484a3e5SAlex Bennée          off:00000018, 1, 2
6356484a3e5SAlex Bennée          off:0000001c, 1, 2
6366484a3e5SAlex Bennée          off:00000020, 1, 2
6376484a3e5SAlex Bennée          ...
6386484a3e5SAlex Bennée
6396484a3e5SAlex Bennée
6406484a3e5SAlex BennéeExecution Log
6416484a3e5SAlex Bennée.............
6426484a3e5SAlex Bennée
6436484a3e5SAlex Bennée``contrib/plugins/execlog.c``
6446484a3e5SAlex Bennée
6456484a3e5SAlex BennéeThe execlog tool traces executed instructions with memory access. It can be used
6466484a3e5SAlex Bennéefor debugging and security analysis purposes.
6476484a3e5SAlex BennéePlease be aware that this will generate a lot of output.
6486484a3e5SAlex Bennée
6496484a3e5SAlex BennéeThe plugin needs default argument::
6506484a3e5SAlex Bennée
6516484a3e5SAlex Bennée  $ qemu-system-arm $(QEMU_ARGS) \
6526484a3e5SAlex Bennée    -plugin ./contrib/plugins/libexeclog.so -d plugin
6536484a3e5SAlex Bennée
6546484a3e5SAlex Bennéewhich will output an execution trace following this structure::
6556484a3e5SAlex Bennée
6566484a3e5SAlex Bennée  # vCPU, vAddr, opcode, disassembly[, load/store, memory addr, device]...
6576484a3e5SAlex Bennée  0, 0xa12, 0xf8012400, "movs r4, #0"
6586484a3e5SAlex Bennée  0, 0xa14, 0xf87f42b4, "cmp r4, r6"
6596484a3e5SAlex Bennée  0, 0xa16, 0xd206, "bhs #0xa26"
6606484a3e5SAlex Bennée  0, 0xa18, 0xfff94803, "ldr r0, [pc, #0xc]", load, 0x00010a28, RAM
6616484a3e5SAlex Bennée  0, 0xa1a, 0xf989f000, "bl #0xd30"
6626484a3e5SAlex Bennée  0, 0xd30, 0xfff9b510, "push {r4, lr}", store, 0x20003ee0, RAM, store, 0x20003ee4, RAM
6636484a3e5SAlex Bennée  0, 0xd32, 0xf9893014, "adds r0, #0x14"
6646484a3e5SAlex Bennée  0, 0xd34, 0xf9c8f000, "bl #0x10c8"
6656484a3e5SAlex Bennée  0, 0x10c8, 0xfff96c43, "ldr r3, [r0, #0x44]", load, 0x200000e4, RAM
6666484a3e5SAlex Bennée
6676484a3e5SAlex BennéePlease note that you need to configure QEMU with Capstone support to get disassembly.
6686484a3e5SAlex Bennée
6696484a3e5SAlex BennéeThe output can be filtered to only track certain instructions or
6706484a3e5SAlex Bennéeaddresses using the ``ifilter`` or ``afilter`` options. You can stack the
6716484a3e5SAlex Bennéearguments if required::
6726484a3e5SAlex Bennée
6736484a3e5SAlex Bennée  $ qemu-system-arm $(QEMU_ARGS) \
6746484a3e5SAlex Bennée    -plugin ./contrib/plugins/libexeclog.so,ifilter=st1w,afilter=0x40001808 -d plugin
6756484a3e5SAlex Bennée
6766484a3e5SAlex BennéeThis plugin can also dump registers when they change value. Specify the name of the
6776484a3e5SAlex Bennéeregisters with multiple ``reg`` options. You can also use glob style matching if you wish::
6786484a3e5SAlex Bennée
6796484a3e5SAlex Bennée  $ qemu-system-arm $(QEMU_ARGS) \
6806484a3e5SAlex Bennée    -plugin ./contrib/plugins/libexeclog.so,reg=\*_el2,reg=sp -d plugin
6816484a3e5SAlex Bennée
6826484a3e5SAlex BennéeBe aware that each additional register to check will slow down
6836484a3e5SAlex Bennéeexecution quite considerably. You can optimise the number of register
6846484a3e5SAlex Bennéechecks done by using the rdisas option. This will only instrument
6856484a3e5SAlex Bennéeinstructions that mention the registers in question in disassembly.
6866484a3e5SAlex BennéeThis is not foolproof as some instructions implicitly change
6876484a3e5SAlex Bennéeinstructions. You can use the ifilter to catch these cases::
6886484a3e5SAlex Bennée
6896484a3e5SAlex Bennée  $ qemu-system-arm $(QEMU_ARGS) \
6906484a3e5SAlex Bennée    -plugin ./contrib/plugins/libexeclog.so,ifilter=msr,ifilter=blr,reg=x30,reg=\*_el1,rdisas=on
6916484a3e5SAlex Bennée
6926484a3e5SAlex BennéeCache Modelling
6936484a3e5SAlex Bennée...............
6946484a3e5SAlex Bennée
6956484a3e5SAlex Bennée``contrib/plugins/cache.c``
6966484a3e5SAlex Bennée
6976484a3e5SAlex BennéeCache modelling plugin that measures the performance of a given L1 cache
6986484a3e5SAlex Bennéeconfiguration, and optionally a unified L2 per-core cache when a given working
6996484a3e5SAlex Bennéeset is run::
7006484a3e5SAlex Bennée
7016484a3e5SAlex Bennée  $ qemu-x86_64 -plugin ./contrib/plugins/libcache.so \
7026484a3e5SAlex Bennée      -d plugin -D cache.log ./tests/tcg/x86_64-linux-user/float_convs
7036484a3e5SAlex Bennée
7046484a3e5SAlex Bennéewill report the following::
7056484a3e5SAlex Bennée
7066484a3e5SAlex Bennée    core #, data accesses, data misses, dmiss rate, insn accesses, insn misses, imiss rate
7076484a3e5SAlex Bennée    0       996695         508             0.0510%  2642799        18617           0.7044%
7086484a3e5SAlex Bennée
7096484a3e5SAlex Bennée    address, data misses, instruction
7106484a3e5SAlex Bennée    0x424f1e (_int_malloc), 109, movq %rax, 8(%rcx)
7116484a3e5SAlex Bennée    0x41f395 (_IO_default_xsputn), 49, movb %dl, (%rdi, %rax)
7126484a3e5SAlex Bennée    0x42584d (ptmalloc_init.part.0), 33, movaps %xmm0, (%rax)
7136484a3e5SAlex Bennée    0x454d48 (__tunables_init), 20, cmpb $0, (%r8)
7146484a3e5SAlex Bennée    ...
7156484a3e5SAlex Bennée
7166484a3e5SAlex Bennée    address, fetch misses, instruction
7176484a3e5SAlex Bennée    0x4160a0 (__vfprintf_internal), 744, movl $1, %ebx
7186484a3e5SAlex Bennée    0x41f0a0 (_IO_setb), 744, endbr64
7196484a3e5SAlex Bennée    0x415882 (__vfprintf_internal), 744, movq %r12, %rdi
7206484a3e5SAlex Bennée    0x4268a0 (__malloc), 696, andq $0xfffffffffffffff0, %rax
7216484a3e5SAlex Bennée    ...
7226484a3e5SAlex Bennée
7236484a3e5SAlex BennéeThe plugin has a number of arguments, all of them are optional:
7246484a3e5SAlex Bennée
7256484a3e5SAlex Bennée.. list-table:: Cache modelling arguments
7266484a3e5SAlex Bennée  :widths: 20 80
7276484a3e5SAlex Bennée  :header-rows: 1
7286484a3e5SAlex Bennée
7296484a3e5SAlex Bennée  * - Option
7306484a3e5SAlex Bennée    - Description
7316484a3e5SAlex Bennée  * - limit=N
7326484a3e5SAlex Bennée    - Print top N icache and dcache thrashing instructions along with
7336484a3e5SAlex Bennée      their address, number of misses, and its disassembly. (default: 32)
7346484a3e5SAlex Bennée  * - icachesize=N
7356484a3e5SAlex Bennée      iblksize=B
7366484a3e5SAlex Bennée      iassoc=A
7376484a3e5SAlex Bennée    - Instruction cache configuration arguments. They specify the
7386484a3e5SAlex Bennée      cache size, block size, and associativity of the instruction
7396484a3e5SAlex Bennée      cache, respectively. (default: N = 16384, B = 64, A = 8)
7406484a3e5SAlex Bennée  * - dcachesize=N
7416484a3e5SAlex Bennée    - Data cache size (default: 16834)
7426484a3e5SAlex Bennée  * - dblksize=B
7436484a3e5SAlex Bennée    - Data cache block size (default: 64)
7446484a3e5SAlex Bennée  * - dassoc=A
7456484a3e5SAlex Bennée    - Data cache associativity (default: 8)
7466484a3e5SAlex Bennée  * - evict=POLICY
7476484a3e5SAlex Bennée    - Sets the eviction policy to POLICY. Available policies are:
7486484a3e5SAlex Bennée      ``lru``, ``fifo``, and ``rand``. The plugin will use
7496484a3e5SAlex Bennée      the specified policy for both instruction and data caches.
7506484a3e5SAlex Bennée      (default: POLICY = ``lru``)
7516484a3e5SAlex Bennée  * - cores=N
7526484a3e5SAlex Bennée    - Sets the number of cores for which we maintain separate icache
7536484a3e5SAlex Bennée      and dcache. (default: for linux-user, N = 1, for full system
7546484a3e5SAlex Bennée      emulation: N = cores available to guest)
7556484a3e5SAlex Bennée  * - l2=on
7566484a3e5SAlex Bennée    - Simulates a unified L2 cache (stores blocks for both
7576484a3e5SAlex Bennée      instructions and data) using the default L2 configuration (cache
7586484a3e5SAlex Bennée      size = 2MB, associativity = 16-way, block size = 64B).
7596484a3e5SAlex Bennée  * - l2cachesize=N
7606484a3e5SAlex Bennée    - L2 cache size (default: 2097152 (2MB)), implies ``l2=on``
7616484a3e5SAlex Bennée  * - l2blksize=B
7626484a3e5SAlex Bennée    - L2 cache block size (default: 64), implies ``l2=on``
7636484a3e5SAlex Bennée  * - l2assoc=A
7646484a3e5SAlex Bennée    - L2 cache associativity (default: 16), implies ``l2=on``
7656484a3e5SAlex Bennée
7666484a3e5SAlex BennéeStop on Trigger
7676484a3e5SAlex Bennée...............
7686484a3e5SAlex Bennée
7696484a3e5SAlex Bennée``contrib/plugins/stoptrigger.c``
7706484a3e5SAlex Bennée
7716484a3e5SAlex BennéeThe stoptrigger plugin allows to setup triggers to stop emulation.
7726484a3e5SAlex BennéeIt can be used for research purposes to launch some code and precisely stop it
7736484a3e5SAlex Bennéeand understand where its execution flow went.
7746484a3e5SAlex Bennée
7756484a3e5SAlex BennéeTwo types of triggers can be configured: a count of instructions to stop at,
7766484a3e5SAlex Bennéeor an address to stop at. Multiple triggers can be set at once.
7776484a3e5SAlex Bennée
7786484a3e5SAlex BennéeBy default, QEMU will exit with return code 0. A custom return code can be
7796484a3e5SAlex Bennéeconfigured for each trigger using ``:CODE`` syntax.
7806484a3e5SAlex Bennée
7816484a3e5SAlex BennéeFor example, to stop at the 20-th instruction with return code 41, at address
7826484a3e5SAlex Bennée0xd4 with return code 0 or at address 0xd8 with return code 42::
7836484a3e5SAlex Bennée
7846484a3e5SAlex Bennée  $ qemu-system-aarch64 $(QEMU_ARGS) \
7856484a3e5SAlex Bennée    -plugin ./contrib/plugins/libstoptrigger.so,icount=20:41,addr=0xd4,addr=0xd8:42 -d plugin
7866484a3e5SAlex Bennée
7876484a3e5SAlex BennéeThe plugin will log the reason of exit, for example::
7886484a3e5SAlex Bennée
7896484a3e5SAlex Bennée  0xd4 reached, exiting
7906484a3e5SAlex Bennée
7913f9f9a37SPierrick BouvierLimit instructions per second
7923f9f9a37SPierrick Bouvier.............................
7933f9f9a37SPierrick Bouvier
7943f9f9a37SPierrick BouvierThis plugin can limit the number of Instructions Per Second that are executed::
7953f9f9a37SPierrick Bouvier
7963f9f9a37SPierrick Bouvier    # get number of instructions
7973f9f9a37SPierrick Bouvier    $ num_insn=$(./build/qemu-x86_64 -plugin ./build/tests/plugin/libinsn.so -d plugin /bin/true |& grep total | sed -e 's/.*: //')
7983f9f9a37SPierrick Bouvier    # limit speed to execute in 10 seconds
7993f9f9a37SPierrick Bouvier    $ time ./build/qemu-x86_64 -plugin ./build/contrib/plugins/libips.so,ips=$(($num_insn/10)) /bin/true
8003f9f9a37SPierrick Bouvier    real 10.000s
8013f9f9a37SPierrick Bouvier
8023f9f9a37SPierrick Bouvier
8033f9f9a37SPierrick Bouvier.. list-table:: IPS arguments
8043f9f9a37SPierrick Bouvier  :widths: 20 80
8053f9f9a37SPierrick Bouvier  :header-rows: 1
8063f9f9a37SPierrick Bouvier
8073f9f9a37SPierrick Bouvier  * - Option
8083f9f9a37SPierrick Bouvier    - Description
8093f9f9a37SPierrick Bouvier  * - ips=N
8103f9f9a37SPierrick Bouvier    - Maximum number of instructions per cpu that can be executed in one second.
8113f9f9a37SPierrick Bouvier      The plugin will sleep when the given number of instructions is reached.
8123f9f9a37SPierrick Bouvier
8136484a3e5SAlex BennéeOther emulation features
8146484a3e5SAlex Bennée------------------------
8156484a3e5SAlex Bennée
8166484a3e5SAlex BennéeWhen running system emulation you can also enable deterministic
8176484a3e5SAlex Bennéeexecution which allows for repeatable record/replay debugging. See
8186484a3e5SAlex Bennée:ref:`Record/Replay<replay>` for more details.
819