18ea6abf0SAlex Bennée.. 28ea6abf0SAlex Bennée Copyright (C) 2017, Emilio G. Cota <cota@braap.org> 38ea6abf0SAlex Bennée Copyright (c) 2019, Linaro Limited 48ea6abf0SAlex Bennée Written by Emilio Cota and Alex Bennée 58ea6abf0SAlex Bennée 68ea6abf0SAlex BennéeQEMU TCG Plugins 78ea6abf0SAlex Bennée================ 88ea6abf0SAlex Bennée 98ea6abf0SAlex BennéeQEMU TCG plugins provide a way for users to run experiments taking 108ea6abf0SAlex Bennéeadvantage of the total system control emulation can have over a guest. 118ea6abf0SAlex BennéeIt provides a mechanism for plugins to subscribe to events during 128ea6abf0SAlex Bennéetranslation and execution and optionally callback into the plugin 138ea6abf0SAlex Bennéeduring these events. TCG plugins are unable to change the system state 148ea6abf0SAlex Bennéeonly monitor it passively. However they can do this down to an 158ea6abf0SAlex Bennéeindividual instruction granularity including potentially subscribing 168ea6abf0SAlex Bennéeto all load and store operations. 178ea6abf0SAlex Bennée 188ea6abf0SAlex BennéeUsage 19*e9adb4acSPaolo Bonzini----- 208ea6abf0SAlex Bennée 21ba4dd2aaSAlex BennéeAny QEMU binary with TCG support has plugins enabled by default. 22ba4dd2aaSAlex BennéeEarlier releases needed to be explicitly enabled with:: 238ea6abf0SAlex Bennée 248ea6abf0SAlex Bennée configure --enable-plugins 258ea6abf0SAlex Bennée 268ea6abf0SAlex BennéeOnce built a program can be run with multiple plugins loaded each with 275c6ecbdcSAlex Bennéetheir own arguments:: 288ea6abf0SAlex Bennée 298ea6abf0SAlex Bennée $QEMU $OTHER_QEMU_ARGS \ 30d8525358SMahmoud Mandour -plugin tests/plugin/libhowvec.so,inline=on,count=hint \ 318ea6abf0SAlex Bennée -plugin tests/plugin/libhotblocks.so 328ea6abf0SAlex Bennée 338ea6abf0SAlex BennéeArguments are plugin specific and can be used to modify their 348ea6abf0SAlex Bennéebehaviour. In this case the howvec plugin is being asked to use inline 358ea6abf0SAlex Bennéeops to count and break down the hint instructions by type. 368ea6abf0SAlex Bennée 37*e9adb4acSPaolo BonziniWriting plugins 38*e9adb4acSPaolo Bonzini--------------- 39*e9adb4acSPaolo Bonzini 40*e9adb4acSPaolo BonziniAPI versioning 41*e9adb4acSPaolo Bonzini~~~~~~~~~~~~~~ 42*e9adb4acSPaolo Bonzini 43*e9adb4acSPaolo BonziniThis is a new feature for QEMU and it does allow people to develop 44*e9adb4acSPaolo Bonziniout-of-tree plugins that can be dynamically linked into a running QEMU 45*e9adb4acSPaolo Bonziniprocess. However the project reserves the right to change or break the 46*e9adb4acSPaolo BonziniAPI should it need to do so. The best way to avoid this is to submit 47*e9adb4acSPaolo Bonziniyour plugin upstream so they can be updated if/when the API changes. 48*e9adb4acSPaolo Bonzini 49*e9adb4acSPaolo BonziniAll plugins need to declare a symbol which exports the plugin API 50*e9adb4acSPaolo Bonziniversion they were built against. This can be done simply by:: 51*e9adb4acSPaolo Bonzini 52*e9adb4acSPaolo Bonzini QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION; 53*e9adb4acSPaolo Bonzini 54*e9adb4acSPaolo BonziniThe core code will refuse to load a plugin that doesn't export a 55*e9adb4acSPaolo Bonzini``qemu_plugin_version`` symbol or if plugin version is outside of QEMU's 56*e9adb4acSPaolo Bonzinisupported range of API versions. 57*e9adb4acSPaolo Bonzini 58*e9adb4acSPaolo BonziniAdditionally the ``qemu_info_t`` structure which is passed to the 59*e9adb4acSPaolo Bonzini``qemu_plugin_install`` method of a plugin will detail the minimum and 60*e9adb4acSPaolo Bonzinicurrent API versions supported by QEMU. The API version will be 61*e9adb4acSPaolo Bonziniincremented if new APIs are added. The minimum API version will be 62*e9adb4acSPaolo Bonziniincremented if existing APIs are changed or removed. 63*e9adb4acSPaolo Bonzini 64*e9adb4acSPaolo BonziniLifetime of the query handle 65*e9adb4acSPaolo Bonzini~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 66*e9adb4acSPaolo Bonzini 67*e9adb4acSPaolo BonziniEach callback provides an opaque anonymous information handle which 68*e9adb4acSPaolo Bonzinican usually be further queried to find out information about a 69*e9adb4acSPaolo Bonzinitranslation, instruction or operation. The handles themselves are only 70*e9adb4acSPaolo Bonzinivalid during the lifetime of the callback so it is important that any 71*e9adb4acSPaolo Bonziniinformation that is needed is extracted during the callback and saved 72*e9adb4acSPaolo Bonziniby the plugin. 73*e9adb4acSPaolo Bonzini 74*e9adb4acSPaolo BonziniPlugin life cycle 75*e9adb4acSPaolo Bonzini~~~~~~~~~~~~~~~~~ 768ea6abf0SAlex Bennée 778ea6abf0SAlex BennéeFirst the plugin is loaded and the public qemu_plugin_install function 788ea6abf0SAlex Bennéeis called. The plugin will then register callbacks for various plugin 798ea6abf0SAlex Bennéeevents. Generally plugins will register a handler for the *atexit* 808ea6abf0SAlex Bennéeif they want to dump a summary of collected information once the 818ea6abf0SAlex Bennéeprogram/system has finished running. 828ea6abf0SAlex Bennée 838ea6abf0SAlex BennéeWhen a registered event occurs the plugin callback is invoked. The 848ea6abf0SAlex Bennéecallbacks may provide additional information. In the case of a 858ea6abf0SAlex Bennéetranslation event the plugin has an option to enumerate the 868ea6abf0SAlex Bennéeinstructions in a block of instructions and optionally register 878ea6abf0SAlex Bennéecallbacks to some or all instructions when they are executed. 888ea6abf0SAlex Bennée 898ea6abf0SAlex BennéeThere is also a facility to add an inline event where code to 908ea6abf0SAlex Bennéeincrement a counter can be directly inlined with the translation. 918ea6abf0SAlex BennéeCurrently only a simple increment is supported. This is not atomic so 928ea6abf0SAlex Bennéecan miss counts. If you want absolute precision you should use a 938ea6abf0SAlex Bennéecallback which can then ensure atomicity itself. 948ea6abf0SAlex Bennée 958ea6abf0SAlex BennéeFinally when QEMU exits all the registered *atexit* callbacks are 968ea6abf0SAlex Bennéeinvoked. 978ea6abf0SAlex Bennée 98*e9adb4acSPaolo BonziniExposure of QEMU internals 99*e9adb4acSPaolo Bonzini~~~~~~~~~~~~~~~~~~~~~~~~~~ 100*e9adb4acSPaolo Bonzini 101*e9adb4acSPaolo BonziniThe plugin architecture actively avoids leaking implementation details 102*e9adb4acSPaolo Bonziniabout how QEMU's translation works to the plugins. While there are 103*e9adb4acSPaolo Bonziniconceptions such as translation time and translation blocks the 104*e9adb4acSPaolo Bonzinidetails are opaque to plugins. The plugin is able to query select 105*e9adb4acSPaolo Bonzinidetails of instructions and system configuration only through the 106*e9adb4acSPaolo Bonziniexported *qemu_plugin* functions. 107*e9adb4acSPaolo Bonzini 108*e9adb4acSPaolo BonziniAPI 109*e9adb4acSPaolo Bonzini~~~ 110*e9adb4acSPaolo Bonzini 111*e9adb4acSPaolo Bonzini.. kernel-doc:: include/qemu/qemu-plugin.h 112*e9adb4acSPaolo Bonzini 1138ea6abf0SAlex BennéeInternals 114*e9adb4acSPaolo Bonzini--------- 1158ea6abf0SAlex Bennée 1168ea6abf0SAlex BennéeLocking 117*e9adb4acSPaolo Bonzini~~~~~~~ 1188ea6abf0SAlex Bennée 1198ea6abf0SAlex BennéeWe have to ensure we cannot deadlock, particularly under MTTCG. For 1208ea6abf0SAlex Bennéethis we acquire a lock when called from plugin code. We also keep the 1218ea6abf0SAlex Bennéelist of callbacks under RCU so that we do not have to hold the lock 1228ea6abf0SAlex Bennéewhen calling the callbacks. This is also for performance, since some 1238ea6abf0SAlex Bennéecallbacks (e.g. memory access callbacks) might be called very 1248ea6abf0SAlex Bennéefrequently. 1258ea6abf0SAlex Bennée 1268ea6abf0SAlex Bennée * A consequence of this is that we keep our own list of CPUs, so that 1278ea6abf0SAlex Bennée we do not have to worry about locking order wrt cpu_list_lock. 1288ea6abf0SAlex Bennée * Use a recursive lock, since we can get registration calls from 1298ea6abf0SAlex Bennée callbacks. 1308ea6abf0SAlex Bennée 1318ea6abf0SAlex BennéeAs a result registering/unregistering callbacks is "slow", since it 1328ea6abf0SAlex Bennéetakes a lock. But this is very infrequent; we want performance when 1338ea6abf0SAlex Bennéecalling (or not calling) callbacks, not when registering them. Using 1348ea6abf0SAlex BennéeRCU is great for this. 1358ea6abf0SAlex Bennée 1368ea6abf0SAlex BennéeWe support the uninstallation of a plugin at any time (e.g. from 1378ea6abf0SAlex Bennéeplugin callbacks). This allows plugins to remove themselves if they no 1388ea6abf0SAlex Bennéelonger want to instrument the code. This operation is asynchronous 1398ea6abf0SAlex Bennéewhich means callbacks may still occur after the uninstall operation is 1408ea6abf0SAlex Bennéerequested. The plugin isn't completely uninstalled until the safe work 1418ea6abf0SAlex Bennéehas executed while all vCPUs are quiescent. 142c17a386bSAlex Bennée 143c17a386bSAlex BennéeExample Plugins 144*e9adb4acSPaolo Bonzini--------------- 145c17a386bSAlex Bennée 146c17a386bSAlex BennéeThere are a number of plugins included with QEMU and you are 147c17a386bSAlex Bennéeencouraged to contribute your own plugins plugins upstream. There is a 1481e235edaSPeter Maydell``contrib/plugins`` directory where they can go. 149c17a386bSAlex Bennée 150c17a386bSAlex Bennée- tests/plugins 151c17a386bSAlex Bennée 152c17a386bSAlex BennéeThese are some basic plugins that are used to test and exercise the 1531e235edaSPeter MaydellAPI during the ``make check-tcg`` target. 154c17a386bSAlex Bennée 155c17a386bSAlex Bennée- contrib/plugins/hotblocks.c 156c17a386bSAlex Bennée 157c17a386bSAlex BennéeThe hotblocks plugin allows you to examine the where hot paths of 158c17a386bSAlex Bennéeexecution are in your program. Once the program has finished you will 159c17a386bSAlex Bennéeget a sorted list of blocks reporting the starting PC, translation 160c17a386bSAlex Bennéecount, number of instructions and execution count. This will work best 161c17a386bSAlex Bennéewith linux-user execution as system emulation tends to generate 162c17a386bSAlex Bennéere-translations as blocks from different programs get swapped in and 163c17a386bSAlex Bennéeout of system memory. 164c17a386bSAlex Bennée 1651e235edaSPeter MaydellIf your program is single-threaded you can use the ``inline`` option for 166c17a386bSAlex Bennéeslightly faster (but not thread safe) counters. 167c17a386bSAlex Bennée 168c17a386bSAlex BennéeExample:: 169c17a386bSAlex Bennée 170c17a386bSAlex Bennée ./aarch64-linux-user/qemu-aarch64 \ 171c17a386bSAlex Bennée -plugin contrib/plugins/libhotblocks.so -d plugin \ 172c17a386bSAlex Bennée ./tests/tcg/aarch64-linux-user/sha1 173c17a386bSAlex Bennée SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6 174c17a386bSAlex Bennée collected 903 entries in the hash table 175c17a386bSAlex Bennée pc, tcount, icount, ecount 176c17a386bSAlex Bennée 0x0000000041ed10, 1, 5, 66087 177c17a386bSAlex Bennée 0x000000004002b0, 1, 4, 66087 178c17a386bSAlex Bennée ... 179c17a386bSAlex Bennée 180c17a386bSAlex Bennée- contrib/plugins/hotpages.c 181c17a386bSAlex Bennée 182c17a386bSAlex BennéeSimilar to hotblocks but this time tracks memory accesses:: 183c17a386bSAlex Bennée 184c17a386bSAlex Bennée ./aarch64-linux-user/qemu-aarch64 \ 185c17a386bSAlex Bennée -plugin contrib/plugins/libhotpages.so -d plugin \ 186c17a386bSAlex Bennée ./tests/tcg/aarch64-linux-user/sha1 187c17a386bSAlex Bennée SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6 188c17a386bSAlex Bennée Addr, RCPUs, Reads, WCPUs, Writes 189c17a386bSAlex Bennée 0x000055007fe000, 0x0001, 31747952, 0x0001, 8835161 190c17a386bSAlex Bennée 0x000055007ff000, 0x0001, 29001054, 0x0001, 8780625 191c17a386bSAlex Bennée 0x00005500800000, 0x0001, 687465, 0x0001, 335857 192c17a386bSAlex Bennée 0x0000000048b000, 0x0001, 130594, 0x0001, 355 193c17a386bSAlex Bennée 0x0000000048a000, 0x0001, 1826, 0x0001, 11 194c17a386bSAlex Bennée 195f698d5efSMahmoud MandourThe hotpages plugin can be configured using the following arguments: 196f698d5efSMahmoud Mandour 197f698d5efSMahmoud Mandour * sortby=reads|writes|address 198f698d5efSMahmoud Mandour 199f698d5efSMahmoud Mandour Log the data sorted by either the number of reads, the number of writes, or 200f698d5efSMahmoud Mandour memory address. (Default: entries are sorted by the sum of reads and writes) 201f698d5efSMahmoud Mandour 202f698d5efSMahmoud Mandour * io=on 203f698d5efSMahmoud Mandour 204f698d5efSMahmoud Mandour Track IO addresses. Only relevant to full system emulation. (Default: off) 205f698d5efSMahmoud Mandour 206f698d5efSMahmoud Mandour * pagesize=N 207f698d5efSMahmoud Mandour 208f698d5efSMahmoud Mandour The page size used. (Default: N = 4096) 209f698d5efSMahmoud Mandour 210c17a386bSAlex Bennée- contrib/plugins/howvec.c 211c17a386bSAlex Bennée 212c17a386bSAlex BennéeThis is an instruction classifier so can be used to count different 213c17a386bSAlex Bennéetypes of instructions. It has a number of options to refine which get 214d8525358SMahmoud Mandourcounted. You can give a value to the `count` argument for a class of 215d8525358SMahmoud Mandourinstructions to break it down fully, so for example to see all the system 216d8525358SMahmoud Mandourregisters accesses:: 217c17a386bSAlex Bennée 218c17a386bSAlex Bennée ./aarch64-softmmu/qemu-system-aarch64 $(QEMU_ARGS) \ 219c17a386bSAlex Bennée -append "root=/dev/sda2 systemd.unit=benchmark.service" \ 220d8525358SMahmoud Mandour -smp 4 -plugin ./contrib/plugins/libhowvec.so,count=sreg -d plugin 221c17a386bSAlex Bennée 222c17a386bSAlex Bennéewhich will lead to a sorted list after the class breakdown:: 223c17a386bSAlex Bennée 224c17a386bSAlex Bennée Instruction Classes: 225c17a386bSAlex Bennée Class: UDEF not counted 226c17a386bSAlex Bennée Class: SVE (68 hits) 227c17a386bSAlex Bennée Class: PCrel addr (47789483 hits) 228c17a386bSAlex Bennée Class: Add/Sub (imm) (192817388 hits) 229c17a386bSAlex Bennée Class: Logical (imm) (93852565 hits) 230c17a386bSAlex Bennée Class: Move Wide (imm) (76398116 hits) 231c17a386bSAlex Bennée Class: Bitfield (44706084 hits) 232c17a386bSAlex Bennée Class: Extract (5499257 hits) 233c17a386bSAlex Bennée Class: Cond Branch (imm) (147202932 hits) 234c17a386bSAlex Bennée Class: Exception Gen (193581 hits) 235c17a386bSAlex Bennée Class: NOP not counted 236c17a386bSAlex Bennée Class: Hints (6652291 hits) 237c17a386bSAlex Bennée Class: Barriers (8001661 hits) 238c17a386bSAlex Bennée Class: PSTATE (1801695 hits) 239c17a386bSAlex Bennée Class: System Insn (6385349 hits) 240c17a386bSAlex Bennée Class: System Reg counted individually 241c17a386bSAlex Bennée Class: Branch (reg) (69497127 hits) 242c17a386bSAlex Bennée Class: Branch (imm) (84393665 hits) 243c17a386bSAlex Bennée Class: Cmp & Branch (110929659 hits) 244c17a386bSAlex Bennée Class: Tst & Branch (44681442 hits) 245c17a386bSAlex Bennée Class: AdvSimd ldstmult (736 hits) 246c17a386bSAlex Bennée Class: ldst excl (9098783 hits) 247c17a386bSAlex Bennée Class: Load Reg (lit) (87189424 hits) 248c17a386bSAlex Bennée Class: ldst noalloc pair (3264433 hits) 249c17a386bSAlex Bennée Class: ldst pair (412526434 hits) 250c17a386bSAlex Bennée Class: ldst reg (imm) (314734576 hits) 251c17a386bSAlex Bennée Class: Loads & Stores (2117774 hits) 252c17a386bSAlex Bennée Class: Data Proc Reg (223519077 hits) 253c17a386bSAlex Bennée Class: Scalar FP (31657954 hits) 254c17a386bSAlex Bennée Individual Instructions: 255c17a386bSAlex Bennée Instr: mrs x0, sp_el0 (2682661 hits) (op=0xd5384100/ System Reg) 256c17a386bSAlex Bennée Instr: mrs x1, tpidr_el2 (1789339 hits) (op=0xd53cd041/ System Reg) 257c17a386bSAlex Bennée Instr: mrs x2, tpidr_el2 (1513494 hits) (op=0xd53cd042/ System Reg) 258c17a386bSAlex Bennée Instr: mrs x0, tpidr_el2 (1490823 hits) (op=0xd53cd040/ System Reg) 259c17a386bSAlex Bennée Instr: mrs x1, sp_el0 (933793 hits) (op=0xd5384101/ System Reg) 260c17a386bSAlex Bennée Instr: mrs x2, sp_el0 (699516 hits) (op=0xd5384102/ System Reg) 261c17a386bSAlex Bennée Instr: mrs x4, tpidr_el2 (528437 hits) (op=0xd53cd044/ System Reg) 262c17a386bSAlex Bennée Instr: mrs x30, ttbr1_el1 (480776 hits) (op=0xd538203e/ System Reg) 263c17a386bSAlex Bennée Instr: msr ttbr1_el1, x30 (480713 hits) (op=0xd518203e/ System Reg) 264c17a386bSAlex Bennée Instr: msr vbar_el1, x30 (480671 hits) (op=0xd518c01e/ System Reg) 265c17a386bSAlex Bennée ... 266c17a386bSAlex Bennée 267c17a386bSAlex BennéeTo find the argument shorthand for the class you need to examine the 2681e235edaSPeter Maydellsource code of the plugin at the moment, specifically the ``*opt`` 269c17a386bSAlex Bennéeargument in the InsnClassExecCount tables. 270c17a386bSAlex Bennée 271c17a386bSAlex Bennée- contrib/plugins/lockstep.c 272c17a386bSAlex Bennée 273c17a386bSAlex BennéeThis is a debugging tool for developers who want to find out when and 274c17a386bSAlex Bennéewhere execution diverges after a subtle change to TCG code generation. 275c17a386bSAlex BennéeIt is not an exact science and results are likely to be mixed once 276c17a386bSAlex Bennéeasynchronous events are introduced. While the use of -icount can 277c17a386bSAlex Bennéeintroduce determinism to the execution flow it doesn't always follow 278c17a386bSAlex Bennéethe translation sequence will be exactly the same. Typically this is 279c17a386bSAlex Bennéecaused by a timer firing to service the GUI causing a block to end 280c17a386bSAlex Bennéeearly. However in some cases it has proved to be useful in pointing 281c17a386bSAlex Bennéepeople at roughly where execution diverges. The only argument you need 282c17a386bSAlex Bennéefor the plugin is a path for the socket the two instances will 283c17a386bSAlex Bennéecommunicate over:: 284c17a386bSAlex Bennée 285c17a386bSAlex Bennée 286c17a386bSAlex Bennée ./sparc-softmmu/qemu-system-sparc -monitor none -parallel none \ 287c17a386bSAlex Bennée -net none -M SS-20 -m 256 -kernel day11/zImage.elf \ 288b18a0cadSMahmoud Mandour -plugin ./contrib/plugins/liblockstep.so,sockpath=lockstep-sparc.sock \ 289c17a386bSAlex Bennée -d plugin,nochain 290c17a386bSAlex Bennée 291c17a386bSAlex Bennéewhich will eventually report:: 292c17a386bSAlex Bennée 293c17a386bSAlex Bennée qemu-system-sparc: warning: nic lance.0 has no peer 294c17a386bSAlex Bennée @ 0x000000ffd06678 vs 0x000000ffd001e0 (2/1 since last) 295c17a386bSAlex Bennée @ 0x000000ffd07d9c vs 0x000000ffd06678 (3/1 since last) 296c17a386bSAlex Bennée Δ insn_count @ 0x000000ffd07d9c (809900609) vs 0x000000ffd06678 (809900612) 297c17a386bSAlex Bennée previously @ 0x000000ffd06678/10 (809900609 insns) 298c17a386bSAlex Bennée previously @ 0x000000ffd001e0/4 (809900599 insns) 299c17a386bSAlex Bennée previously @ 0x000000ffd080ac/2 (809900595 insns) 300c17a386bSAlex Bennée previously @ 0x000000ffd08098/5 (809900593 insns) 301c17a386bSAlex Bennée previously @ 0x000000ffd080c0/1 (809900588 insns) 302c17a386bSAlex Bennée 303a35af836SMahmoud Mandour- contrib/plugins/hwprofile.c 304a622d64eSAlex Bennée 305a622d64eSAlex BennéeThe hwprofile tool can only be used with system emulation and allows 306a622d64eSAlex Bennéethe user to see what hardware is accessed how often. It has a number of options: 307a622d64eSAlex Bennée 30860753843SMahmoud Mandour * track=read or track=write 309a622d64eSAlex Bennée 310a622d64eSAlex Bennée By default the plugin tracks both reads and writes. You can use one 311a622d64eSAlex Bennée of these options to limit the tracking to just one class of accesses. 312a622d64eSAlex Bennée 31360753843SMahmoud Mandour * source 314a622d64eSAlex Bennée 315a622d64eSAlex Bennée Will include a detailed break down of what the guest PC that made the 31660753843SMahmoud Mandour access was. Not compatible with the pattern option. Example output:: 317a622d64eSAlex Bennée 318a622d64eSAlex Bennée cirrus-low-memory @ 0xfffffd00000a0000 319a622d64eSAlex Bennée pc:fffffc0000005cdc, 1, 256 320a622d64eSAlex Bennée pc:fffffc0000005ce8, 1, 256 321a622d64eSAlex Bennée pc:fffffc0000005cec, 1, 256 322a622d64eSAlex Bennée 32360753843SMahmoud Mandour * pattern 324a622d64eSAlex Bennée 325a622d64eSAlex Bennée Instead break down the accesses based on the offset into the HW 326a622d64eSAlex Bennée region. This can be useful for seeing the most used registers of a 327a622d64eSAlex Bennée device. Example output:: 328a622d64eSAlex Bennée 329a622d64eSAlex Bennée pci0-conf @ 0xfffffd01fe000000 330a622d64eSAlex Bennée off:00000004, 1, 1 331a622d64eSAlex Bennée off:00000010, 1, 3 332a622d64eSAlex Bennée off:00000014, 1, 3 333a622d64eSAlex Bennée off:00000018, 1, 2 334a622d64eSAlex Bennée off:0000001c, 1, 2 335a622d64eSAlex Bennée off:00000020, 1, 2 336a622d64eSAlex Bennée ... 337307ce0aaSAlexandre Iooss 338307ce0aaSAlexandre Iooss- contrib/plugins/execlog.c 339307ce0aaSAlexandre Iooss 340307ce0aaSAlexandre IoossThe execlog tool traces executed instructions with memory access. It can be used 341307ce0aaSAlexandre Ioossfor debugging and security analysis purposes. 342307ce0aaSAlexandre IoossPlease be aware that this will generate a lot of output. 343307ce0aaSAlexandre Iooss 344307ce0aaSAlexandre IoossThe plugin takes no argument:: 345307ce0aaSAlexandre Iooss 346307ce0aaSAlexandre Iooss qemu-system-arm $(QEMU_ARGS) \ 347307ce0aaSAlexandre Iooss -plugin ./contrib/plugins/libexeclog.so -d plugin 348307ce0aaSAlexandre Iooss 349307ce0aaSAlexandre Ioosswhich will output an execution trace following this structure:: 350307ce0aaSAlexandre Iooss 351307ce0aaSAlexandre Iooss # vCPU, vAddr, opcode, disassembly[, load/store, memory addr, device]... 352307ce0aaSAlexandre Iooss 0, 0xa12, 0xf8012400, "movs r4, #0" 353307ce0aaSAlexandre Iooss 0, 0xa14, 0xf87f42b4, "cmp r4, r6" 354307ce0aaSAlexandre Iooss 0, 0xa16, 0xd206, "bhs #0xa26" 355307ce0aaSAlexandre Iooss 0, 0xa18, 0xfff94803, "ldr r0, [pc, #0xc]", load, 0x00010a28, RAM 356307ce0aaSAlexandre Iooss 0, 0xa1a, 0xf989f000, "bl #0xd30" 357307ce0aaSAlexandre Iooss 0, 0xd30, 0xfff9b510, "push {r4, lr}", store, 0x20003ee0, RAM, store, 0x20003ee4, RAM 358307ce0aaSAlexandre Iooss 0, 0xd32, 0xf9893014, "adds r0, #0x14" 359307ce0aaSAlexandre Iooss 0, 0xd34, 0xf9c8f000, "bl #0x10c8" 360307ce0aaSAlexandre Iooss 0, 0x10c8, 0xfff96c43, "ldr r3, [r0, #0x44]", load, 0x200000e4, RAM 3614c125f3bSMahmoud Mandour 362a35af836SMahmoud Mandour- contrib/plugins/cache.c 3634c125f3bSMahmoud Mandour 3644c125f3bSMahmoud MandourCache modelling plugin that measures the performance of a given cache 3654c125f3bSMahmoud Mandourconfiguration when a given working set is run:: 3664c125f3bSMahmoud Mandour 3674c125f3bSMahmoud Mandour qemu-x86_64 -plugin ./contrib/plugins/libcache.so \ 3684c125f3bSMahmoud Mandour -d plugin -D cache.log ./tests/tcg/x86_64-linux-user/float_convs 3694c125f3bSMahmoud Mandour 3704c125f3bSMahmoud Mandourwill report the following:: 3714c125f3bSMahmoud Mandour 3725397acb8SMahmoud Mandour core #, data accesses, data misses, dmiss rate, insn accesses, insn misses, imiss rate 3735397acb8SMahmoud Mandour 0 996695 508 0.0510% 2642799 18617 0.7044% 3744c125f3bSMahmoud Mandour 3754c125f3bSMahmoud Mandour address, data misses, instruction 3764c125f3bSMahmoud Mandour 0x424f1e (_int_malloc), 109, movq %rax, 8(%rcx) 3774c125f3bSMahmoud Mandour 0x41f395 (_IO_default_xsputn), 49, movb %dl, (%rdi, %rax) 3784c125f3bSMahmoud Mandour 0x42584d (ptmalloc_init.part.0), 33, movaps %xmm0, (%rax) 3794c125f3bSMahmoud Mandour 0x454d48 (__tunables_init), 20, cmpb $0, (%r8) 3804c125f3bSMahmoud Mandour ... 3814c125f3bSMahmoud Mandour 3824c125f3bSMahmoud Mandour address, fetch misses, instruction 3834c125f3bSMahmoud Mandour 0x4160a0 (__vfprintf_internal), 744, movl $1, %ebx 3844c125f3bSMahmoud Mandour 0x41f0a0 (_IO_setb), 744, endbr64 3854c125f3bSMahmoud Mandour 0x415882 (__vfprintf_internal), 744, movq %r12, %rdi 3864c125f3bSMahmoud Mandour 0x4268a0 (__malloc), 696, andq $0xfffffffffffffff0, %rax 3874c125f3bSMahmoud Mandour ... 3884c125f3bSMahmoud Mandour 3894c125f3bSMahmoud MandourThe plugin has a number of arguments, all of them are optional: 3904c125f3bSMahmoud Mandour 3912dd3fef8SMahmoud Mandour * limit=N 3924c125f3bSMahmoud Mandour 3934c125f3bSMahmoud Mandour Print top N icache and dcache thrashing instructions along with their 3944c125f3bSMahmoud Mandour address, number of misses, and its disassembly. (default: 32) 3954c125f3bSMahmoud Mandour 3962dd3fef8SMahmoud Mandour * icachesize=N 3972dd3fef8SMahmoud Mandour * iblksize=B 3982dd3fef8SMahmoud Mandour * iassoc=A 3994c125f3bSMahmoud Mandour 4004c125f3bSMahmoud Mandour Instruction cache configuration arguments. They specify the cache size, block 4014c125f3bSMahmoud Mandour size, and associativity of the instruction cache, respectively. 4024c125f3bSMahmoud Mandour (default: N = 16384, B = 64, A = 8) 4034c125f3bSMahmoud Mandour 4042dd3fef8SMahmoud Mandour * dcachesize=N 4052dd3fef8SMahmoud Mandour * dblksize=B 4062dd3fef8SMahmoud Mandour * dassoc=A 4074c125f3bSMahmoud Mandour 4084c125f3bSMahmoud Mandour Data cache configuration arguments. They specify the cache size, block size, 4094c125f3bSMahmoud Mandour and associativity of the data cache, respectively. 4104c125f3bSMahmoud Mandour (default: N = 16384, B = 64, A = 8) 4114c125f3bSMahmoud Mandour 4122dd3fef8SMahmoud Mandour * evict=POLICY 4134c125f3bSMahmoud Mandour 4144c125f3bSMahmoud Mandour Sets the eviction policy to POLICY. Available policies are: :code:`lru`, 4154c125f3bSMahmoud Mandour :code:`fifo`, and :code:`rand`. The plugin will use the specified policy for 4164c125f3bSMahmoud Mandour both instruction and data caches. (default: POLICY = :code:`lru`) 4175397acb8SMahmoud Mandour 4182dd3fef8SMahmoud Mandour * cores=N 4195397acb8SMahmoud Mandour 4205397acb8SMahmoud Mandour Sets the number of cores for which we maintain separate icache and dcache. 4215397acb8SMahmoud Mandour (default: for linux-user, N = 1, for full system emulation: N = cores 4225397acb8SMahmoud Mandour available to guest) 423