From 32ba75adc009763db8a9686a57c268b82e774f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Wed, 15 Mar 2023 17:43:05 +0000 Subject: include/qemu: add documentation for memory callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some API documentation was missed, rectify that. Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1497 Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Reviewed-by: Thomas Huth Message-Id: <20230315174331.2959-7-alex.bennee@linaro.org> --- include/qemu/qemu-plugin.h | 47 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index d0e9d03..50a9957 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -481,17 +481,56 @@ uint64_t qemu_plugin_hwaddr_phys_addr(const struct qemu_plugin_hwaddr *haddr); */ const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h); -typedef void -(*qemu_plugin_vcpu_mem_cb_t)(unsigned int vcpu_index, - qemu_plugin_meminfo_t info, uint64_t vaddr, - void *userdata); +/** + * typedef qemu_plugin_vcpu_mem_cb_t - memory callback function type + * @vcpu_index: the executing vCPU + * @info: an opaque handle for further queries about the memory + * @vaddr: the virtual address of the transaction + * @userdata: any user data attached to the callback + */ +typedef void (*qemu_plugin_vcpu_mem_cb_t) (unsigned int vcpu_index, + qemu_plugin_meminfo_t info, + uint64_t vaddr, + void *userdata); +/** + * qemu_plugin_register_vcpu_mem_cb() - register memory access callback + * @insn: handle for instruction to instrument + * @cb: callback of type qemu_plugin_vcpu_mem_cb_t + * @flags: (currently unused) callback flags + * @rw: monitor reads, writes or both + * @userdata: opaque pointer for userdata + * + * This registers a full callback for every memory access generated by + * an instruction. If the instruction doesn't access memory no + * callback will be made. + * + * The callback reports the vCPU the access took place on, the virtual + * address of the access and a handle for further queries. The user + * can attach some userdata to the callback for additional purposes. + * + * Other execution threads will continue to execute during the + * callback so the plugin is responsible for ensuring it doesn't get + * confused by making appropriate use of locking if required. + */ void qemu_plugin_register_vcpu_mem_cb(struct qemu_plugin_insn *insn, qemu_plugin_vcpu_mem_cb_t cb, enum qemu_plugin_cb_flags flags, enum qemu_plugin_mem_rw rw, void *userdata); +/** + * qemu_plugin_register_vcpu_mem_inline() - register an inline op to any memory access + * @insn: handle for instruction to instrument + * @rw: apply to reads, writes or both + * @op: the op, of type qemu_plugin_op + * @ptr: pointer memory for the op + * @imm: immediate data for @op + * + * This registers a inline op every memory access generated by the + * instruction. This provides for a lightweight but not thread-safe + * way of counting the number of operations done. + */ void qemu_plugin_register_vcpu_mem_inline(struct qemu_plugin_insn *insn, enum qemu_plugin_mem_rw rw, enum qemu_plugin_op op, void *ptr, -- cgit v1.1 From e8956e0c6c2f61a235d896eb5b9941f474b6a57d Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Wed, 15 Mar 2023 17:43:12 +0000 Subject: include/qemu/plugin: Remove QEMU_PLUGIN_ASSERT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This macro is no longer used. Signed-off-by: Richard Henderson Message-Id: <20230310195252.210956-4-richard.henderson@linaro.org> Signed-off-by: Alex Bennée Message-Id: <20230315174331.2959-14-alex.bennee@linaro.org> Reviewed-by: Emilio Cota --- include/qemu/plugin.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index fb338ba..e0ebede 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -59,8 +59,6 @@ get_plugin_meminfo_rw(qemu_plugin_meminfo_t i) #ifdef CONFIG_PLUGIN extern QemuOptsList qemu_plugin_opts; -#define QEMU_PLUGIN_ASSERT(cond) g_assert(cond) - static inline void qemu_plugin_add_opts(void) { qemu_add_opts(&qemu_plugin_opts); @@ -252,8 +250,6 @@ void qemu_plugin_user_postfork(bool is_child); #else /* !CONFIG_PLUGIN */ -#define QEMU_PLUGIN_ASSERT(cond) - static inline void qemu_plugin_add_opts(void) { } -- cgit v1.1 From aa4cf6eb82954fa9d4bb7c5dfee9bad830bfa91d Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Wed, 15 Mar 2023 17:43:15 +0000 Subject: include/qemu: Split out plugin-event.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The usage in hw/core/cpu.h only requires QEMU_PLUGIN_EV_MAX. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20230310195252.210956-7-richard.henderson@linaro.org> Signed-off-by: Alex Bennée Message-Id: <20230315174331.2959-17-alex.bennee@linaro.org> Reviewed-by: Emilio Cota --- include/qemu/plugin-event.h | 26 ++++++++++++++++++++++++++ include/qemu/plugin.h | 17 +---------------- 2 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 include/qemu/plugin-event.h (limited to 'include/qemu') diff --git a/include/qemu/plugin-event.h b/include/qemu/plugin-event.h new file mode 100644 index 0000000..7056d84 --- /dev/null +++ b/include/qemu/plugin-event.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2017, Emilio G. Cota + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ +#ifndef QEMU_PLUGIN_EVENT_H +#define QEMU_PLUGIN_EVENT_H + +/* + * Events that plugins can subscribe to. + */ +enum qemu_plugin_event { + QEMU_PLUGIN_EV_VCPU_INIT, + QEMU_PLUGIN_EV_VCPU_EXIT, + QEMU_PLUGIN_EV_VCPU_TB_TRANS, + QEMU_PLUGIN_EV_VCPU_IDLE, + QEMU_PLUGIN_EV_VCPU_RESUME, + QEMU_PLUGIN_EV_VCPU_SYSCALL, + QEMU_PLUGIN_EV_VCPU_SYSCALL_RET, + QEMU_PLUGIN_EV_FLUSH, + QEMU_PLUGIN_EV_ATEXIT, + QEMU_PLUGIN_EV_MAX, /* total number of plugin events we support */ +}; + +#endif /* QEMU_PLUGIN_EVENT_H */ diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index e0ebede..6bf4bce 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -12,25 +12,10 @@ #include "qemu/error-report.h" #include "qemu/queue.h" #include "qemu/option.h" +#include "qemu/plugin-event.h" #include "exec/memopidx.h" /* - * Events that plugins can subscribe to. - */ -enum qemu_plugin_event { - QEMU_PLUGIN_EV_VCPU_INIT, - QEMU_PLUGIN_EV_VCPU_EXIT, - QEMU_PLUGIN_EV_VCPU_TB_TRANS, - QEMU_PLUGIN_EV_VCPU_IDLE, - QEMU_PLUGIN_EV_VCPU_RESUME, - QEMU_PLUGIN_EV_VCPU_SYSCALL, - QEMU_PLUGIN_EV_VCPU_SYSCALL_RET, - QEMU_PLUGIN_EV_FLUSH, - QEMU_PLUGIN_EV_ATEXIT, - QEMU_PLUGIN_EV_MAX, /* total number of plugin events we support */ -}; - -/* * Option parsing/processing. * Note that we can load an arbitrary number of plugins. */ -- cgit v1.1 From 507271d4680d1c3b6041b6c65d975824624b149a Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Wed, 15 Mar 2023 17:43:16 +0000 Subject: include/qemu/plugin: Inline qemu_plugin_disable_mem_helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that we've broken the include loop with cpu.h, we can bring this inline. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20230310195252.210956-8-richard.henderson@linaro.org> Signed-off-by: Alex Bennée Message-Id: <20230315174331.2959-18-alex.bennee@linaro.org> Reviewed-by: Emilio Cota --- include/qemu/plugin.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include/qemu') diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h index 6bf4bce..bc0781c 100644 --- a/include/qemu/plugin.h +++ b/include/qemu/plugin.h @@ -14,6 +14,7 @@ #include "qemu/option.h" #include "qemu/plugin-event.h" #include "exec/memopidx.h" +#include "hw/core/cpu.h" /* * Option parsing/processing. @@ -204,7 +205,10 @@ void qemu_plugin_atexit_cb(void); void qemu_plugin_add_dyn_cb_arr(GArray *arr); -void qemu_plugin_disable_mem_helpers(CPUState *cpu); +static inline void qemu_plugin_disable_mem_helpers(CPUState *cpu) +{ + cpu->plugin_mem_cbs = NULL; +} /** * qemu_plugin_user_exit(): clean-up callbacks before calling exit callbacks -- cgit v1.1