Skip to contentSkip to conversation

plugins/next (disas, monitor, docs, execlog)

PATCH In review Alex Bennée 5 participants 21 messages Sep 21, 2022 – Sep 28, 2022 Block layer

lore
Share & tools
lore
#0 lore raw

cover plugins/next (disas, monitor, docs, execlog)

Hi,

It has been a while since I last posted the state of my plugins queue. These are mostly small cleanups and documentation tweaks. I also did a little bit of tidying up in the disas interface.

The following still need review:

- docs/devel: document the test plugins
- contrib/plugins: reset skip when matching in execlog
- docs/devel: move API to end of tcg-plugins.rst
- docs/devel: clean-up qemu invocations in tcg-plugins
- tests/tcg: add memory-sve test for aarch64

Alex Bennée (9):
monitor: expose monitor_puts to rest of code
disas: generalise plugin_printf and use for monitor_disas
disas: use result of ->read_memory_func tests/tcg: add memory-sve test for aarch64
plugins: extend execlog to filter matches docs/devel: clean-up qemu invocations in tcg-plugins docs/devel: move API to end of tcg-plugins.rst contrib/plugins: reset skip when matching in execlog docs/devel: document the test plugins

Richard Henderson (1):
plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr

 docs/devel/tcg-plugins.rst                | 175 +++++++++++++++++++---
 docs/devel/writing-monitor-commands.rst   |   2 +-
 include/monitor/monitor.h                 |   1 +
 monitor/monitor-internal.h                |   1 -
 block/monitor/block-hmp-cmds.c            |  10 +-
 contrib/plugins/execlog.c                 |  99 ++++++++++--
 disas.c                                   |  43 +++---
 disas/capstone.c                          |  73 +++++----
 hw/misc/mos6522.c                         |   2 +-
 monitor/hmp-cmds.c                        |   8 +-
 monitor/hmp.c                             |   2 +-
 plugins/api.c                             |   2 +
 target/i386/helper.c                      |   2 +-
 tests/tcg/aarch64/Makefile.softmmu-target |   7 +
 tests/tcg/aarch64/system/boot.S           |   3 +-
 15 files changed, 336 insertions(+), 94 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/10 monitor: expose monitor_puts to rest of code

This helps us construct strings elsewhere before echoing to the monitor. It avoids having to jump through hoops like:

  monitor_printf(mon, "%s", s->str);

It will be useful in following patches but for now convert all existing plain "%s" printfs to use the _puts api.

---
v2
- s/monitor_printf(mon, "%s"/monitor_puts(mon, /

---
 docs/devel/writing-monitor-commands.rst |  2 +-
 include/monitor/monitor.h               |  1 +
 monitor/monitor-internal.h              |  1 -
 block/monitor/block-hmp-cmds.c          | 10 +++++-----
 hw/misc/mos6522.c                       |  2 +-
 monitor/hmp-cmds.c                      |  8 ++++----
 monitor/hmp.c                           |  2 +-
 target/i386/helper.c                    |  2 +-
 8 files changed, 14 insertions(+), 14 deletions(-)
docs/devel/writing-monitor-commands.rst +1 -1
index 4aa2bb904d..2fefedcd98 100644
@@ -716,7 +716,7 @@ message. Here's the implementation of the "info roms" HMP command::
      if (hmp_handle_error(mon, err)) {
          return;
      }
-     monitor_printf(mon, "%s", info->human_readable_text);
+     monitor_puts(mon, info->human_readable_text);
  }
 
 Also, you have to add the function's prototype to the hmp.h file.
include/monitor/monitor.h +1 -0
index a4b40e8391..737e750670 100644
@@ -31,6 +31,7 @@ void monitor_resume(Monitor *mon);
 int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp);
 int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp);
 
+int monitor_puts(Monitor *mon, const char *str);
 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
     G_GNUC_PRINTF(2, 0);
 int monitor_printf(Monitor *mon, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
monitor/monitor-internal.h +0 -1
index caa2e90ef2..a2cdbbf646 100644
@@ -174,7 +174,6 @@ extern int mon_refcount;
 
 extern HMPCommand hmp_cmds[];
 
-int monitor_puts(Monitor *mon, const char *str);
 void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
                        bool use_io_thread);
 void monitor_data_destroy(Monitor *mon);
block/monitor/block-hmp-cmds.c +5 -5
index bfb3c043a0..939a520d17 100644
@@ -638,16 +638,16 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
     assert(!info || !info->has_inserted || info->inserted == inserted);
 
     if (info && *info->device) {
-        monitor_printf(mon, "%s", info->device);
+        monitor_puts(mon, info->device);
         if (inserted && inserted->has_node_name) {
             monitor_printf(mon, " (%s)", inserted->node_name);
         }
     } else {
         assert(info || inserted);
-        monitor_printf(mon, "%s",
-                       inserted && inserted->has_node_name ? inserted->node_name
-                       : info && info->has_qdev ? info->qdev
-                       : "<anonymous>");
+        monitor_puts(mon,
+                     inserted && inserted->has_node_name ? inserted->node_name
+                     : info && info->has_qdev ? info->qdev
+                     : "<anonymous>");
     }
 
     if (inserted) {
hw/misc/mos6522.c +1 -1
index f9e646350e..fe38c44426 100644
@@ -595,7 +595,7 @@ void hmp_info_via(Monitor *mon, const QDict *qdict)
     if (hmp_handle_error(mon, err)) {
         return;
     }
-    monitor_printf(mon, "%s", info->human_readable_text);
+    monitor_puts(mon, info->human_readable_text);
 }
 
 static const MemoryRegionOps mos6522_ops = {
monitor/hmp-cmds.c +4 -4
index c6cd6f91dd..f90eea8d01 100644
@@ -730,7 +730,7 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
     monitor_printf(mon, "    ");
 
     if (dev->class_info->has_desc) {
-        monitor_printf(mon, "%s", dev->class_info->desc);
+        monitor_puts(mon, dev->class_info->desc);
     } else {
         monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
     }
@@ -2258,12 +2258,12 @@ static void print_stats_schema_value(Monitor *mon, StatsSchemaValue *value)
     if (unit && value->base == 10 &&
         value->exponent >= -18 && value->exponent <= 18 &&
         value->exponent % 3 == 0) {
-        monitor_printf(mon, "%s", si_prefix(value->exponent));
+        monitor_puts(mon, si_prefix(value->exponent));
     } else if (unit && value->base == 2 &&
                value->exponent >= 0 && value->exponent <= 60 &&
                value->exponent % 10 == 0) {
 
-        monitor_printf(mon, "%s", iec_binary_prefix(value->exponent));
+        monitor_puts(mon, iec_binary_prefix(value->exponent));
     } else if (value->exponent) {
         /* Use exponential notation and write the unit's English name */
         monitor_printf(mon, "* %d^%d%s",
@@ -2273,7 +2273,7 @@ static void print_stats_schema_value(Monitor *mon, StatsSchemaValue *value)
     }
 
     if (value->has_unit) {
-        monitor_printf(mon, "%s", unit ? unit : StatsUnit_str(value->unit));
+        monitor_puts(mon, unit ? unit : StatsUnit_str(value->unit));
     }
 
     /* Print bucket size for linear histograms */
monitor/hmp.c +1 -1
index a3375d0341..43fd69f984 100644
@@ -1094,7 +1094,7 @@ static void hmp_info_human_readable_text(Monitor *mon,
         return;
     }
 
-    monitor_printf(mon, "%s", info->human_readable_text);
+    monitor_puts(mon, info->human_readable_text);
 }
 
 static void handle_hmp_command_exec(Monitor *mon,
target/i386/helper.c +1 -1
index fa409e9c44..b954ccda50 100644
@@ -415,7 +415,7 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
         if (need_reset) {
             emit_guest_memory_failure(MEMORY_FAILURE_ACTION_RESET, ar,
                                       recursive);
-            monitor_printf(params->mon, "%s", msg);
+            monitor_puts(params->mon, msg);
             qemu_log_mask(CPU_LOG_RESET, "%s\n", msg);
             qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
             return;
Signature · 1 line
2.34.1
Reviewed-by Philippe Mathieu-Daudé on v1 1/10
#2 lore raw

Re: [PATCH v1 01/10] monitor: expose monitor_puts to rest of code

Quoted 14 lines · Alex Bennée

This helps us construct strings elsewhere before echoing to the monitor. It avoids having to jump through hoops like:

   monitor_printf(mon, "%s", s->str);

It will be useful in following patches but for now convert all existing plain "%s" printfs to use the _puts api.

---
v2
- s/monitor_printf(mon, "%s"/monitor_puts(mon, /

Quoted 10 lines
---
  docs/devel/writing-monitor-commands.rst |  2 +-
  include/monitor/monitor.h               |  1 +
  monitor/monitor-internal.h              |  1 -
  block/monitor/block-hmp-cmds.c          | 10 +++++-----
  hw/misc/mos6522.c                       |  2 +-
  monitor/hmp-cmds.c                      |  8 ++++----
  monitor/hmp.c                           |  2 +-
  target/i386/helper.c                    |  2 +-
  8 files changed, 14 insertions(+), 14 deletions(-)
Reviewed-by on v1 1/10
#3 lore raw

Re: [PATCH v1 01/10] monitor: expose monitor_puts to rest of code

In reply to Alex Bennée
Quoted 10 lines · Alex Bennée

This helps us construct strings elsewhere before echoing to the monitor. It avoids having to jump through hoops like:

  monitor_printf(mon, "%s", s->str);

It will be useful in following patches but for now convert all existing plain "%s" printfs to use the _puts api.

Reviewed-by on v1 1/10
#4 lore raw

Re: [PATCH v1 01/10] monitor: expose monitor_puts to rest of code

In reply to Alex Bennée

Am 21.09.2022 um 18:07 hat Alex Bennée geschrieben:

Quoted 10 lines

This helps us construct strings elsewhere before echoing to the monitor. It avoids having to jump through hoops like:

  monitor_printf(mon, "%s", s->str);

It will be useful in following patches but for now convert all existing plain "%s" printfs to use the _puts api.

#5 lore raw

PATCH 2/10 disas: generalise plugin_printf and use for monitor_disas

In reply to Alex Bennée

Rather than assembling our output piecemeal lets use the same approach as the plugin disas interface to build the disassembly string before printing it.

---
 disas.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
disas.c +15 -8
index e31438f349..f07b6e760b 100644
@@ -239,7 +239,7 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
     }
 }
 
-static int plugin_printf(FILE *stream, const char *fmt, ...)
+static int gstring_printf(FILE *stream, const char *fmt, ...)
 {
     /* We abuse the FILE parameter to pass a GString. */
     GString *s = (GString *)stream;
@@ -270,7 +270,7 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size)
     GString *ds = g_string_new(NULL);
 
     initialize_debug_target(&s, cpu);
-    s.info.fprintf_func = plugin_printf;
+    s.info.fprintf_func = gstring_printf;
     s.info.stream = (FILE *)ds;  /* abuse this slot */
     s.info.buffer_vma = addr;
     s.info.buffer_length = size;
@@ -358,15 +358,19 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
 {
     int count, i;
     CPUDebug s;
+    g_autoptr(GString) ds = g_string_new("");
 
     initialize_debug_target(&s, cpu);
-    s.info.fprintf_func = qemu_fprintf;
+    s.info.fprintf_func = gstring_printf;
+    s.info.stream = (FILE *)ds;  /* abuse this slot */
+
     if (is_physical) {
         s.info.read_memory_func = physical_read_memory;
     }
     s.info.buffer_vma = pc;
 
     if (s.info.cap_arch >= 0 && cap_disas_monitor(&s.info, pc, nb_insn)) {
+        monitor_puts(mon, ds->str);
         return;
     }
 
@@ -376,13 +380,16 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
         return;
     }
 
-    for(i = 0; i < nb_insn; i++) {
-	monitor_printf(mon, "0x" TARGET_FMT_lx ":  ", pc);
+    for (i = 0; i < nb_insn; i++) {
+        g_string_append_printf(ds, "0x" TARGET_FMT_lx ":  ", pc);
         count = s.info.print_insn(pc, &s.info);
-	monitor_printf(mon, "\n");
-	if (count < 0)
-	    break;
+        g_string_append_c(ds, '\n');
+        if (count < 0) {
+            break;
+        }
         pc += count;
     }
+
+    monitor_puts(mon, ds->str);
 }
 #endif
Signature · 1 line
2.34.1
#6 lore raw

PATCH 3/10 disas: use result of ->read_memory_func

In reply to Alex Bennée

This gets especially confusing if you start plugging in host addresses from a trace and you wonder why the output keeps changing. Report when read_memory_func fails instead of blindly disassembling the buffer contents.

---
 disas.c          | 20 ++++++-------
 disas/capstone.c | 73 ++++++++++++++++++++++++++++--------------------
 2 files changed, 53 insertions(+), 40 deletions(-)
disas.c +10 -10
index f07b6e760b..94d3b45042 100644
@@ -83,18 +83,18 @@ static int print_insn_objdump(bfd_vma pc, disassemble_info *info,
                               const char *prefix)
 {
     int i, n = info->buffer_length;
-    uint8_t *buf = g_malloc(n);
-
-    info->read_memory_func(pc, buf, n, info);
-
-    for (i = 0; i < n; ++i) {
-        if (i % 32 == 0) {
-            info->fprintf_func(info->stream, "\n%s: ", prefix);
+    g_autofree uint8_t *buf = g_malloc(n);
+
+    if (info->read_memory_func(pc, buf, n, info) == 0) {
+        for (i = 0; i < n; ++i) {
+            if (i % 32 == 0) {
+                info->fprintf_func(info->stream, "\n%s: ", prefix);
+            }
+            info->fprintf_func(info->stream, "%02x", buf[i]);
         }
-        info->fprintf_func(info->stream, "%02x", buf[i]);
+    } else {
+        info->fprintf_func(info->stream, "unable to read memory");
     }
-
-    g_free(buf);
     return n;
 }
 
disas/capstone.c +43 -30

96 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by Philippe Mathieu-Daudé on v1 3/10
#7 lore raw

Re: [PATCH v1 03/10] disas: use result of ->read_memory_func

Quoted 11 lines · Alex Bennée

This gets especially confusing if you start plugging in host addresses from a trace and you wonder why the output keeps changing. Report when read_memory_func fails instead of blindly disassembling the buffer contents.

---
  disas.c          | 20 ++++++-------
  disas/capstone.c | 73 ++++++++++++++++++++++++++++--------------------
  2 files changed, 53 insertions(+), 40 deletions(-)
#8 lore raw

PATCH 4/10 tests/tcg: add memory-sve test for aarch64

In reply to Alex Bennée

This will be helpful in debugging problems with tracking SVE memory accesses via the TCG plugins system.

Cc Robert Henry <[email protected]>
Cc Aaron Lindsay <[email protected]>
---
 tests/tcg/aarch64/Makefile.softmmu-target | 7 +++++++
 tests/tcg/aarch64/system/boot.S           | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)
tests/tcg/aarch64/Makefile.softmmu-target +7 -0
index f6fcd4829e..26701b718c 100644
@@ -31,6 +31,13 @@ LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc
 
 memory: CFLAGS+=-DCHECK_UNALIGNED=1
 
+memory-sve: memory.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS)
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
+
+memory-sve: CFLAGS+=-DCHECK_UNALIGNED=1 -march=armv8.1-a+sve -O3 -fno-tree-loop-distribute-patterns
+
+TESTS+=memory-sve
+
 # Running
 QEMU_BASE_MACHINE=-M virt -cpu max -display none
 QEMU_OPTS+=$(QEMU_BASE_MACHINE) -semihosting-config enable=on,target=native,chardev=output -kernel
tests/tcg/aarch64/system/boot.S +2 -1
index e190b1efa6..f136363d2a 100644
@@ -179,12 +179,13 @@ __start:
 	isb
 
 	/*
-	 * Enable FP registers. The standard C pre-amble will be
+	 * Enable FP/SVE registers. The standard C pre-amble will be
 	 * saving these and A-profile compilers will use AdvSIMD
 	 * registers unless we tell it not to.
 	*/
 	mrs	x0, cpacr_el1
 	orr	x0, x0, #(3 << 20)
+	orr	x0, x0, #(3 << 16)
 	msr	cpacr_el1, x0
 
 	/* Setup some stack space and enter the test code.
Signature · 1 line
2.34.1
Reviewed-by on v1 4/10
#9 lore raw

Re: [PATCH v1 04/10] tests/tcg: add memory-sve test for aarch64

Quoted 10 lines · Alex Bennée

This will be helpful in debugging problems with tracking SVE memory accesses via the TCG plugins system.

Cc Robert Henry <[email protected]>
Cc Aaron Lindsay <[email protected]>
---
  tests/tcg/aarch64/Makefile.softmmu-target | 7 +++++++
  tests/tcg/aarch64/system/boot.S           | 3 ++-
  2 files changed, 9 insertions(+), 1 deletion(-)

r~

#10 lore raw

PATCH 5/10 plugins: extend execlog to filter matches

In reply to Alex Bennée

Sometimes the whole execlog is just two much so add the ability to filter by instruction opcode or address.

[AJB: this shows for example

.qemu-system-aarch64 -display none -serial mon:stdio \
-M virt -cpu max \
-semihosting-config enable=on \
-kernel ./tests/tcg/aarch64-softmmu/memory-sve \
-plugin ./contrib/plugins/libexeclog.so,ifilter=st1w,afilter=0x40001808 -d plugin -D plugin.out

the st1w SVE instruction is not instrumenting its stores.]

---
 docs/devel/tcg-plugins.rst |  9 +++-
 contrib/plugins/execlog.c  | 96 ++++++++++++++++++++++++++++++++------
 2 files changed, 90 insertions(+), 15 deletions(-)
docs/devel/tcg-plugins.rst +8 -1
index a7cc44aa20..a503d44cee 100644
@@ -346,7 +346,7 @@ The execlog tool traces executed instructions with memory access. It can be used
 for debugging and security analysis purposes.
 Please be aware that this will generate a lot of output.
 
-The plugin takes no argument::
+The plugin needs default argument::
 
   qemu-system-arm $(QEMU_ARGS) \
     -plugin ./contrib/plugins/libexeclog.so -d plugin
@@ -364,6 +364,13 @@ which will output an execution trace following this structure::
   0, 0xd34, 0xf9c8f000, "bl #0x10c8"
   0, 0x10c8, 0xfff96c43, "ldr r3, [r0, #0x44]", load, 0x200000e4, RAM
 
+the output can be filtered to only track certain instructions or
+addresses using the `ifilter` or `afilter` options. You can stack the
+arguments if required::
+
+  qemu-system-arm $(QEMU_ARGS) \
+    -plugin ./contrib/plugins/libexeclog.so,ifilter=st1w,afilter=0x40001808 -d plugin
+
 - contrib/plugins/cache.c
 
 Cache modelling plugin that measures the performance of a given L1 cache
contrib/plugins/execlog.c +82 -14

132 lines not on this page · raw message

Signature · 1 line
2.34.1
#11 lore raw

PATCH 6/10 plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr

In reply to Alex Bennée

From: Richard Henderson <[email protected]>

Coverity reports out-of-bound accesses here. This should be a false positive due to how the index is decoded from MemOpIdx.

Fixes Coverity CID 1487201

Message-Id: <[email protected]>

---
 plugins/api.c | 2 ++
 1 file changed, 2 insertions(+)
plugins/api.c +2 -0
index 7bf71b189d..2078b16edb 100644
@@ -289,6 +289,8 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
     enum qemu_plugin_mem_rw rw = get_plugin_meminfo_rw(info);
     hwaddr_info.is_store = (rw & QEMU_PLUGIN_MEM_W) != 0;
 
+    assert(mmu_idx < NB_MMU_MODES);
+
     if (!tlb_plugin_lookup(cpu, vaddr, mmu_idx,
                            hwaddr_info.is_store, &hwaddr_info)) {
         error_report("invalid use of qemu_plugin_get_hwaddr");
Signature · 1 line
2.34.1
Reviewed-by Philippe Mathieu-Daudé on v1 6/10
#12 lore raw

Re: [PATCH v1 06/10] plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr

Quoted 5 lines · Alex Bennée

From: Richard Henderson <[email protected]>

Coverity reports out-of-bound accesses here. This should be a false positive due to how the index is decoded from MemOpIdx.

Quoted 8 lines
Fixes Coverity CID 1487201

Message-Id: <[email protected]>

---
  plugins/api.c | 2 ++
  1 file changed, 2 insertions(+)
#13 lore raw

PATCH 7/10 docs/devel: clean-up qemu invocations in tcg-plugins

In reply to Alex Bennée

We currently have the final binaries in the root of the build dir so the build prefix is superfluous. Additionally add a shell prompt to be more in line with the rest of the code.

---
 docs/devel/tcg-plugins.rst | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
docs/devel/tcg-plugins.rst +9 -9
index a503d44cee..a6fdde01f8 100644
@@ -172,7 +172,7 @@ slightly faster (but not thread safe) counters.
 
 Example::
 
-  ./aarch64-linux-user/qemu-aarch64 \
+  $ qemu-aarch64 \
     -plugin contrib/plugins/libhotblocks.so -d plugin \
     ./tests/tcg/aarch64-linux-user/sha1
   SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
@@ -186,7 +186,7 @@ Example::
 
 Similar to hotblocks but this time tracks memory accesses::
 
-  ./aarch64-linux-user/qemu-aarch64 \
+  $ qemu-aarch64 \
     -plugin contrib/plugins/libhotpages.so -d plugin \
     ./tests/tcg/aarch64-linux-user/sha1
   SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
@@ -220,7 +220,7 @@ counted. You can give a value to the ``count`` argument for a class of
 instructions to break it down fully, so for example to see all the system
 registers accesses::
 
-  ./aarch64-softmmu/qemu-system-aarch64 $(QEMU_ARGS) \
+  $ qemu-system-aarch64 $(QEMU_ARGS) \
     -append "root=/dev/sda2 systemd.unit=benchmark.service" \
     -smp 4 -plugin ./contrib/plugins/libhowvec.so,count=sreg -d plugin
 
@@ -288,10 +288,10 @@ for the plugin is a path for the socket the two instances will
 communicate over::
 
 
-  ./sparc-softmmu/qemu-system-sparc -monitor none -parallel none \
+  $ qemu-system-sparc -monitor none -parallel none \
     -net none -M SS-20 -m 256 -kernel day11/zImage.elf \
     -plugin ./contrib/plugins/liblockstep.so,sockpath=lockstep-sparc.sock \
-  -d plugin,nochain
+    -d plugin,nochain
 
 which will eventually report::
 
@@ -348,7 +348,7 @@ Please be aware that this will generate a lot of output.
 
 The plugin needs default argument::
 
-  qemu-system-arm $(QEMU_ARGS) \
+  $ qemu-system-arm $(QEMU_ARGS) \
     -plugin ./contrib/plugins/libexeclog.so -d plugin
 
 which will output an execution trace following this structure::
@@ -365,10 +365,10 @@ which will output an execution trace following this structure::
   0, 0x10c8, 0xfff96c43, "ldr r3, [r0, #0x44]", load, 0x200000e4, RAM
 
 the output can be filtered to only track certain instructions or
-addresses using the `ifilter` or `afilter` options. You can stack the
+addresses using the ``ifilter`` or ``afilter`` options. You can stack the
 arguments if required::
 
-  qemu-system-arm $(QEMU_ARGS) \
+  $ qemu-system-arm $(QEMU_ARGS) \
     -plugin ./contrib/plugins/libexeclog.so,ifilter=st1w,afilter=0x40001808 -d plugin
 
 - contrib/plugins/cache.c
@@ -377,7 +377,7 @@ Cache modelling plugin that measures the performance of a given L1 cache
 configuration, and optionally a unified L2 per-core cache when a given working
 set is run::
 
-    qemu-x86_64 -plugin ./contrib/plugins/libcache.so \
+  $ qemu-x86_64 -plugin ./contrib/plugins/libcache.so \
       -d plugin -D cache.log ./tests/tcg/x86_64-linux-user/float_convs
 
 will report the following::
Signature · 1 line
2.34.1
Reviewed-by Philippe Mathieu-Daudé on v1 7/10
#14 lore raw

Re: [PATCH v1 07/10] docs/devel: clean-up qemu invocations in tcg-plugins

Quoted 8 lines · Alex Bennée

We currently have the final binaries in the root of the build dir so the build prefix is superfluous. Additionally add a shell prompt to be more in line with the rest of the code.

---
  docs/devel/tcg-plugins.rst | 18 +++++++++---------
  1 file changed, 9 insertions(+), 9 deletions(-)
#15 lore raw

PATCH 8/10 docs/devel: move API to end of tcg-plugins.rst

In reply to Alex Bennée

The API documentation is quite dry and doesn't flow nicely with the rest of the document. Move it to its own section at the bottom along with a little leader text to remind people to update it.

---
 docs/devel/tcg-plugins.rst | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
docs/devel/tcg-plugins.rst +10 -5
index a6fdde01f8..8b40b2a606 100644
@@ -110,11 +110,6 @@ details are opaque to plugins. The plugin is able to query select
 details of instructions and system configuration only through the
 exported *qemu_plugin* functions.
 
-API
-~~~
-
-.. kernel-doc:: include/qemu/qemu-plugin.h
-
 Internals
 ---------
 
@@ -448,3 +443,13 @@ The plugin has a number of arguments, all of them are optional:
   associativity of the L2 cache, respectively. Setting any of the L2
   configuration arguments implies ``l2=on``.
   (default: N = 2097152 (2MB), B = 64, A = 16)
+
+API
+---
+
+The following API is generated from the inline documentation in
+``include/qemu/qemu-plugin.h``. Please ensure any updates to the API
+include the full kernel-doc annotations.
+
+.. kernel-doc:: include/qemu/qemu-plugin.h
+
Signature · 1 line
2.34.1
Reviewed-by Philippe Mathieu-Daudé on v1 8/10
#16 lore raw

Re: [PATCH v1 08/10] docs/devel: move API to end of tcg-plugins.rst

Quoted 8 lines · Alex Bennée

The API documentation is quite dry and doesn't flow nicely with the rest of the document. Move it to its own section at the bottom along with a little leader text to remind people to update it.

---
  docs/devel/tcg-plugins.rst | 15 ++++++++++-----
  1 file changed, 10 insertions(+), 5 deletions(-)
#17 lore raw

PATCH 9/10 contrib/plugins: reset skip when matching in execlog

In reply to Alex Bennée

The purpose of the matches was to only track the execution of instructions we care about. Without resetting skip to the value at the start of the block we end up dumping all instructions after the match with the consequent load on the instrumentation.

Cc Alexandre Iooss <[email protected]>
---
 contrib/plugins/execlog.c | 3 +++
 1 file changed, 3 insertions(+)
contrib/plugins/execlog.c +3 -0
index e659ac9cbb..b5360f2c8e 100644
@@ -147,6 +147,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
             /* Register callback on instruction */
             qemu_plugin_register_vcpu_insn_exec_cb(insn, vcpu_insn_exec,
                                                    QEMU_PLUGIN_CB_NO_REGS, output);
+
+            /* reset skip */
+            skip = (imatches || amatches) ? true : false;
         }
 
     }
Signature · 1 line
2.34.1
Reviewed-by Philippe Mathieu-Daudé on v1 9/10
#18 lore raw

Re: [PATCH v1 09/10] contrib/plugins: reset skip when matching in execlog

Quoted 10 lines · Alex Bennée

The purpose of the matches was to only track the execution of instructions we care about. Without resetting skip to the value at the start of the block we end up dumping all instructions after the match with the consequent load on the instrumentation.

Cc Alexandre Iooss <[email protected]>
---
  contrib/plugins/execlog.c | 3 +++
  1 file changed, 3 insertions(+)
Reviewed-by on v1 9/10
#19 lore raw

Re: [PATCH v1 09/10] contrib/plugins: reset skip when matching in execlog

In reply to Alex Bennée
Quoted 16 lines · Alex Bennée

The purpose of the matches was to only track the execution of instructions we care about. Without resetting skip to the value at the start of the block we end up dumping all instructions after the match with the consequent load on the instrumentation.

Cc Alexandre Iooss <[email protected]>
---
  contrib/plugins/execlog.c | 3 +++
  1 file changed, 3 insertions(+)
contrib/plugins/execlog.c +0 -0
index e659ac9cbb..b5360f2c8e 100644

contrib/plugins/execlog.c static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) · line 152

Quoted 6 lines
contrib/plugins/execlog.c +3 -0
@@ -147,6 +147,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
              /* Register callback on instruction */
              qemu_plugin_register_vcpu_insn_exec_cb(insn, vcpu_insn_exec,
                                                     QEMU_PLUGIN_CB_NO_REGS, output);
+
+            /* reset skip */
+            skip = (imatches || amatches) ? true : false;

Drop the redundant ?:. Otherwise,

r~

#20 lore raw

PATCH 10/10 docs/devel: document the test plugins

In reply to Alex Bennée

Although the test plugins are fairly basic they are still useful for some things so we should document their existence.

---
 docs/devel/tcg-plugins.rst | 137 +++++++++++++++++++++++++++++++++++--
 1 file changed, 133 insertions(+), 4 deletions(-)
docs/devel/tcg-plugins.rst +133 -4
index 8b40b2a606..9740a70406 100644
@@ -145,12 +145,141 @@ Example Plugins
 
 There are a number of plugins included with QEMU and you are
 encouraged to contribute your own plugins plugins upstream. There is a
-``contrib/plugins`` directory where they can go.
+``contrib/plugins`` directory where they can go. There are also some
+basic plugins that are used to test and exercise the API during the
+``make check-tcg`` target in ``tests\plugins``.
 
-- tests/plugins
+- tests/plugins/empty.c
 
-These are some basic plugins that are used to test and exercise the
-API during the ``make check-tcg`` target.
+Purely a test plugin for measuring the overhead of the plugins system
+itself. Does no instrumentation.
+
+- tests/plugins/bb.c
+
+A very basic plugin which will measure execution in course terms as
+each basic block is executed. By default the results are shown once
+execution finishes::
+
+  $ qemu-aarch64 -plugin tests/plugin/libbb.so \
+      -d plugin ./tests/tcg/aarch64-linux-user/sha1
+  SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
+  bb's: 2277338, insns: 158483046
+
+Behaviour can be tweaked with the following arguments:
+
+ * inline=true|false
+
+ Use faster inline addition of a single counter. Not per-cpu and not
+ thread safe.
+
+ * idle=true|false
+
+ Dump the current execution stats whenever the guest vCPU idles
+
+- tests/plugins/insn.c
+
+This is a basic instruction level instrumentation which can count the
+number of instructions executed on each core/thread::
+
+  $ qemu-aarch64 -plugin tests/plugin/libinsn.so \
+      -d plugin ./tests/tcg/aarch64-linux-user/threadcount
+  Created 10 threads
+  Done
+  cpu 0 insns: 46765
+  cpu 1 insns: 3694
+  cpu 2 insns: 3694
+  cpu 3 insns: 2994
+  cpu 4 insns: 1497
+  cpu 5 insns: 1497
+  cpu 6 insns: 1497
+  cpu 7 insns: 1497
+  total insns: 63135
+
+Behaviour can be tweaked with the following arguments:
+
+ * inline=true|false
+
+ Use faster inline addition of a single counter. Not per-cpu and not
+ thread safe.
+
+ * sizes=true|false
+
+ Give a summary of the instruction sizes for the execution
+
+ * match=<string>
+
+ Only instrument instructions matching the string prefix. Will show
+ some basic stats including how many instructions have executed since
+ the last execution. For example::
+
+   $ qemu-aarch64 -plugin tests/plugin/libinsn.so,match=bl \
+       -d plugin ./tests/tcg/aarch64-linux-user/sha512-vector
+   ...
+   0x40069c, 'bl #0x4002b0', 10 hits, 1093 match hits, Δ+1257 since last match, 98 avg insns/match
+   0x4006ac, 'bl #0x403690', 10 hits, 1094 match hits, Δ+47 since last match, 98 avg insns/match 
+   0x4037fc, 'bl #0x4002b0', 18 hits, 1095 match hits, Δ+22 since last match, 98 avg insns/match 
+   0x400720, 'bl #0x403690', 10 hits, 1096 match hits, Δ+58 since last match, 98 avg insns/match 
+   0x4037fc, 'bl #0x4002b0', 19 hits, 1097 match hits, Δ+22 since last match, 98 avg insns/match 
+   0x400730, 'bl #0x403690', 10 hits, 1098 match hits, Δ+33 since last match, 98 avg insns/match 
+   0x4037ac, 'bl #0x4002b0', 12 hits, 1099 match hits, Δ+20 since last match, 98 avg insns/match 
+   ...
+
+For more detailed execution tracing see the ``execlog`` plugin for
+other options.
+
+- tests/plugins/mem.c
+
+Basic instruction level memory instrumentation::
+
+  $ qemu-aarch64 -plugin tests/plugin/libmem.so,inline=true \
+      -d plugin ./tests/tcg/aarch64-linux-user/sha1
+  SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
+  inline mem accesses: 79525013
+
+Behaviour can be tweaked with the following arguments:
+
+ * inline=true|false
+
+ Use faster inline addition of a single counter. Not per-cpu and not
+ thread safe.
+
+ * callback=true|false
+
+ Use callbacks on each memory instrumentation.
+
+ * hwaddr=true|false
+
+ Count IO accesses (only for system emulation)
+
+- tests/plugins/syscall.c
+
+A basic syscall tracing plugin. This only works for user-mode. By
+default it will give a summary of syscall stats at the end of the
+run::
+
+  $ qemu-aarch64 -plugin tests/plugin/libsyscall \
+      -d plugin ./tests/tcg/aarch64-linux-user/threadcount
+  Created 10 threads
+  Done
+  syscall no.  calls  errors
+  226          12     0
+  99           11     11
+  115          11     0
+  222          11     0
+  93           10     0
+  220          10     0
+  233          10     0
+  215          8      0
+  214          4      0
+  134          2      0
+  64           2      0
+  96           1      0
+  94           1      0
+  80           1      0
+  261          1      0
+  78           1      0
+  160          1      0
+  135          1      0
 
 - contrib/plugins/hotblocks.c
 
Signature · 1 line
2.34.1