[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 30/31] plugins: add time control API
From: |
Alex Bennée |
Subject: |
[RFC PATCH 30/31] plugins: add time control API |
Date: |
Mon, 25 Sep 2023 15:48:53 +0100 |
Expose the ability to control time through the plugin API. Only one
plugin can control time so it has to request control when loaded.
There are probably more corner cases to catch here.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20230519170454.2353945-8-alex.bennee@linaro.org>
---
v2
- ifdef for SOFTMMU only
- fix checkpatch warnings
---
include/qemu/qemu-plugin.h | 19 +++++++++++++++++++
plugins/api.c | 28 ++++++++++++++++++++++++++++
plugins/qemu-plugins.symbols | 2 ++
3 files changed, 49 insertions(+)
diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
index 50a9957279..898385d92d 100644
--- a/include/qemu/qemu-plugin.h
+++ b/include/qemu/qemu-plugin.h
@@ -536,7 +536,26 @@ void qemu_plugin_register_vcpu_mem_inline(struct
qemu_plugin_insn *insn,
enum qemu_plugin_op op, void *ptr,
uint64_t imm);
+/**
+ * qemu_plugin_request_time_control() - request the ability to control time
+ *
+ * This grants the plugin the ability to control system time. Only one
+ * plugin can control time so if multiple plugins request the ability
+ * all but the first will fail.
+ *
+ * Returns an opaque handle or NULL if fails
+ */
+const void *qemu_plugin_request_time_control(void);
+/**
+ * qemu_plugin_update_ns() - update system emulation time
+ * @handle: opaque handle returned by qemu_plugin_request_time_control()
+ * @new_time_ns: time in nanoseconds
+ *
+ * This allows an appropriately authorised plugin (i.e. holding the
+ * time control handle) to move system time forward to @new_time_ns.
+ */
+void qemu_plugin_update_ns(const void *handle, int64_t new_time_ns);
typedef void
(*qemu_plugin_vcpu_syscall_cb_t)(qemu_plugin_id_t id, unsigned int vcpu_index,
diff --git a/plugins/api.c b/plugins/api.c
index 5521b0ad36..a1d413dc2d 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -37,6 +37,7 @@
#include "qemu/osdep.h"
#include "qemu/plugin.h"
#include "qemu/log.h"
+#include "qemu/timer.h"
#include "tcg/tcg.h"
#include "exec/exec-all.h"
#include "exec/ram_addr.h"
@@ -427,3 +428,30 @@ uint64_t qemu_plugin_entry_code(void)
#endif
return entry;
}
+
+/*
+ * Time control
+ */
+#ifdef CONFIG_SOFTMMU
+static bool has_control;
+#endif
+
+const void *qemu_plugin_request_time_control(void)
+{
+#ifdef CONFIG_SOFTMMU
+ if (!has_control) {
+ has_control = true;
+ return &has_control;
+ }
+#endif
+ return NULL;
+}
+
+void qemu_plugin_update_ns(const void *handle, int64_t new_time)
+{
+#ifdef CONFIG_SOFTMMU
+ if (handle == &has_control) {
+ qemu_clock_advance_virtual_time(new_time);
+ }
+#endif
+}
diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols
index 71f6c90549..91b882fecc 100644
--- a/plugins/qemu-plugins.symbols
+++ b/plugins/qemu-plugins.symbols
@@ -35,11 +35,13 @@
qemu_plugin_register_vcpu_tb_exec_cb;
qemu_plugin_register_vcpu_tb_exec_inline;
qemu_plugin_register_vcpu_tb_trans_cb;
+ qemu_plugin_request_time_control;
qemu_plugin_reset;
qemu_plugin_start_code;
qemu_plugin_tb_get_insn;
qemu_plugin_tb_n_insns;
qemu_plugin_tb_vaddr;
qemu_plugin_uninstall;
+ qemu_plugin_update_ns;
qemu_plugin_vcpu_for_each;
};
--
2.39.2
- [PATCH 19/31] gdbstub: Remove gdb_has_xml variable, (continued)
- [PATCH 19/31] gdbstub: Remove gdb_has_xml variable, Alex Bennée, 2023/09/25
- [PATCH 21/31] accel/tcg: Add plugin_enabled to DisasContextBase, Alex Bennée, 2023/09/25
- [RFC PATCH 27/31] sysemu: add set_virtual_time to accel ops, Alex Bennée, 2023/09/25
- [PATCH 25/31] contrib/plugins: fix coverity warning in lockstep, Alex Bennée, 2023/09/25
- [RFC PATCH 31/31] contrib/plugins: add iops plugin example for cost modelling, Alex Bennée, 2023/09/25
- [PATCH 22/31] target/sh4: Disable decode_gusa when plugins enabled, Alex Bennée, 2023/09/25
- [PATCH 18/31] target/ppc: Remove references to gdb_has_xml, Alex Bennée, 2023/09/25
- [PATCH 16/31] gdbstub: Use g_markup_printf_escaped(), Alex Bennée, 2023/09/25
- [RFC PATCH 29/31] sysemu: generalise qtest_warp_clock as qemu_clock_advance_virtual_time, Alex Bennée, 2023/09/25
- [PATCH 24/31] contrib/plugins: fix coverity warning in cache, Alex Bennée, 2023/09/25
- [RFC PATCH 30/31] plugins: add time control API,
Alex Bennée <=
- [RFC PATCH 28/31] qtest: use cpu interface in qtest_clock_warp, Alex Bennée, 2023/09/25
- [PATCH 26/31] contrib/plugins: fix coverity warning in hotblocks, Alex Bennée, 2023/09/25
- [PATCH 20/31] gdbstub: Replace gdb_regs with an array, Alex Bennée, 2023/09/25
- [PATCH 17/31] target/arm: Remove references to gdb_has_xml, Alex Bennée, 2023/09/25