[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC 48/48] plugin: add a couple of very simple example
From: |
Pavel Dovgalyuk |
Subject: |
Re: [Qemu-devel] [RFC 48/48] plugin: add a couple of very simple examples |
Date: |
Mon, 29 Oct 2018 13:59:03 +0300 |
> From: Emilio G. Cota [mailto:address@hidden
> Signed-off-by: Emilio G. Cota <address@hidden>
> ---
> plugin-examples/bbcount_avgsize_racy.c | 50 ++++++++++++++++++++++
> plugin-examples/mem_count_racy_both.c | 58 ++++++++++++++++++++++++++
> plugin-examples/Makefile | 31 ++++++++++++++
> 3 files changed, 139 insertions(+)
> create mode 100644 plugin-examples/bbcount_avgsize_racy.c
> create mode 100644 plugin-examples/mem_count_racy_both.c
> create mode 100644 plugin-examples/Makefile
>
<snip>
> diff --git a/plugin-examples/mem_count_racy_both.c
> b/plugin-examples/mem_count_racy_both.c
> new file mode 100644
> index 0000000000..a47f2025bf
> --- /dev/null
> +++ b/plugin-examples/mem_count_racy_both.c
> @@ -0,0 +1,58 @@
> +#include <inttypes.h>
> +#include <assert.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <stdio.h>
> +
> +#include <qemu-plugin.h>
> +
> +static uint64_t mem_count;
> +static int stdout_fd;
> +static bool do_inline;
> +
> +static void plugin_exit(qemu_plugin_id_t id, void *p)
> +{
> + dprintf(stdout_fd, "accesses: %" PRIu64 "\n", mem_count);
> +}
> +
> +static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo,
> + uint64_t vaddr, void *udata)
> +{
> + mem_count++;
> +}
> +
> +static void vcpu_tb_trans(qemu_plugin_id_t id, unsigned int cpu_index,
> + struct qemu_plugin_tb *tb)
> +{
> + size_t n = qemu_plugin_tb_n_insns(tb);
> + size_t i;
> +
> + for (i = 0; i < n; i++) {
> + struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i);
> +
> + if (do_inline) {
> + qemu_plugin_register_vcpu_mem_inline(insn,
> + QEMU_PLUGIN_INLINE_ADD_U64,
> + &mem_count, 1);
> + } else {
> + qemu_plugin_register_vcpu_mem_cb(insn, vcpu_mem,
> + QEMU_PLUGIN_CB_NO_REGS, NULL);
> + }
> + }
> +}
> +
> +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc,
> + char **argv)
> +{
> + if (argc && strcmp(argv[0], "inline") == 0) {
> + do_inline = true;
> + }
> + /* plugin_exit might write to stdout after stdout has been closed */
> + stdout_fd = dup(STDOUT_FILENO);
> + assert(stdout_fd);
> +
> + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
> + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);
> + return 0;
> +}
Thanks for the series.
Can you provide more plugin examples for better understanding of
double-translate idea?
E.g., plugins that hook specific instructions or addresses.
Pavel Dovgalyuk
- [Qemu-devel] [RFC 23/48] translator: add plugin_insn argument to translate_insn, (continued)
- [Qemu-devel] [RFC 23/48] translator: add plugin_insn argument to translate_insn, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 39/48] plugin: add API symbols to qemu-plugins.symbols, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 18/48] tcg: add memory callbacks for plugins (WIP), Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 10/48] exec: export do_tb_flush, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 19/48] translate-all: notify plugin code of tb_flush, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 09/48] tcg: reset runtime helpers when flushing the code cache, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 01/48] cpu: introduce run_on_cpu_no_bql, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 20/48] *-user: notify plugin of exit, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 13/48] xxhash: add qemu_xxhash8, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 48/48] plugin: add a couple of very simple examples, Emilio G. Cota, 2018/10/25
- Re: [Qemu-devel] [RFC 48/48] plugin: add a couple of very simple examples,
Pavel Dovgalyuk <=
- [Qemu-devel] [RFC 12/48] atomic_template: define pre/post macros, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 07/48] tcg: export TCGHelperInfo, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 08/48] tcg: export tcg_gen_runtime_helper, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 04/48] exec: introduce qemu_xxhash{2,4,5,6,7}, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 31/48] target/mips: prepare for 2-pass translation (WIP), Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 34/48] target/s390x: prepare for 2-pass translation, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 32/48] target/alpha: prepare for 2-pass translation, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 40/48] plugin: let plugins control the virtual clock, Emilio G. Cota, 2018/10/25
- [Qemu-devel] [RFC 24/48] translator: add .ctx_base_offset and .ctx_size to TranslatorOps, Emilio G. Cota, 2018/10/25