[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v15 16/19] plugins: Introduce CPU flags
From: |
Akihiko Odaki |
Subject: |
[PATCH v15 16/19] plugins: Introduce CPU flags |
Date: |
Wed, 25 Oct 2023 14:27:38 +0900 |
The capability to read registers is being added to plugins. Whether the
capability is enabled affects TCG translation.
Introduce "CPU flags" to represent a condition affecting TCG
translation.
The CPU flags replaces the plugin event bitmap held by CPUState; the
plugin event bitmap was needed because the presence of a
QEMU_PLUGIN_EV_VCPU_TB_TRANS callback affected TCG translation. We now
have a dedicated CPU flag for this, QEMU_PLUGIN_CPU_FLAG_CB_TRANS.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
include/hw/core/cpu.h | 4 ++--
include/qemu/plugin.h | 2 ++
plugins/plugin.h | 1 +
accel/tcg/plugin-gen.c | 2 +-
plugins/core.c | 26 ++++++++++++++++----------
plugins/loader.c | 6 ------
6 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index d2e70643f2..dbdca8b105 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -437,7 +437,7 @@ struct qemu_work_item;
* @trace_dstate_delayed: Delayed changes to trace_dstate (includes all changes
* to @trace_dstate).
* @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask).
- * @plugin_mask: Plugin event bitmap. Modified only via async work.
+ * @plugin_flags: Plugin flags. Modified only via async work.
* @ignore_memory_transaction_failures: Cached copy of the MachineState
* flag of the same name: allows the board to suppress calling of the
* CPU do_transaction_failed hook function.
@@ -529,7 +529,7 @@ struct CPUState {
/* Use by accel-block: CPU is executing an ioctl() */
QemuLockCnt in_ioctl_lock;
- DECLARE_BITMAP(plugin_mask, QEMU_PLUGIN_EV_MAX);
+ unsigned long plugin_flags;
#ifdef CONFIG_PLUGIN
GArray *plugin_mem_cbs;
diff --git a/include/qemu/plugin.h b/include/qemu/plugin.h
index 7fdc3a4849..b15fee39fd 100644
--- a/include/qemu/plugin.h
+++ b/include/qemu/plugin.h
@@ -16,6 +16,8 @@
#include "exec/memopidx.h"
#include "hw/core/cpu.h"
+#define QEMU_PLUGIN_CPU_FLAG_CB_TB_TRANS BIT(0)
+
/*
* Option parsing/processing.
* Note that we can load an arbitrary number of plugins.
diff --git a/plugins/plugin.h b/plugins/plugin.h
index 5eb2fdbc85..db25e2650d 100644
--- a/plugins/plugin.h
+++ b/plugins/plugin.h
@@ -31,6 +31,7 @@ struct qemu_plugin_state {
* but with the HT we avoid adding a field to CPUState.
*/
GHashTable *cpu_ht;
+ unsigned long cpu_flags;
DECLARE_BITMAP(mask, QEMU_PLUGIN_EV_MAX);
/*
* @lock protects the struct as well as ctx->uninstalling.
diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c
index 78b331b251..4870433f3a 100644
--- a/accel/tcg/plugin-gen.c
+++ b/accel/tcg/plugin-gen.c
@@ -796,7 +796,7 @@ bool plugin_gen_tb_start(CPUState *cpu, const
DisasContextBase *db,
{
bool ret = false;
- if (test_bit(QEMU_PLUGIN_EV_VCPU_TB_TRANS, cpu->plugin_mask)) {
+ if (cpu->plugin_flags & QEMU_PLUGIN_CPU_FLAG_CB_TB_TRANS) {
struct qemu_plugin_tb *ptb = tcg_ctx->plugin_tb;
int i;
diff --git a/plugins/core.c b/plugins/core.c
index fcd33a2bff..368e2d1f54 100644
--- a/plugins/core.c
+++ b/plugins/core.c
@@ -55,19 +55,19 @@ struct qemu_plugin_ctx
*plugin_id_to_ctx_locked(qemu_plugin_id_t id)
static void plugin_cpu_update__async(CPUState *cpu, run_on_cpu_data data)
{
- bitmap_copy(cpu->plugin_mask, &data.host_ulong, QEMU_PLUGIN_EV_MAX);
+ cpu->plugin_flags = data.host_ulong;
tcg_flush_jmp_cache(cpu);
}
static void plugin_cpu_update__locked(gpointer k, gpointer v, gpointer udata)
{
CPUState *cpu = container_of(k, CPUState, cpu_index);
- run_on_cpu_data mask = RUN_ON_CPU_HOST_ULONG(*plugin.mask);
+ run_on_cpu_data flags = RUN_ON_CPU_HOST_ULONG(plugin.cpu_flags);
if (DEVICE(cpu)->realized) {
- async_run_on_cpu(cpu, plugin_cpu_update__async, mask);
+ async_run_on_cpu(cpu, plugin_cpu_update__async, flags);
} else {
- plugin_cpu_update__async(cpu, mask);
+ plugin_cpu_update__async(cpu, flags);
}
}
@@ -84,7 +84,11 @@ void plugin_unregister_cb__locked(struct qemu_plugin_ctx
*ctx,
ctx->callbacks[ev] = NULL;
if (QLIST_EMPTY_RCU(&plugin.cb_lists[ev])) {
clear_bit(ev, plugin.mask);
- g_hash_table_foreach(plugin.cpu_ht, plugin_cpu_update__locked, NULL);
+ if (ev == QEMU_PLUGIN_EV_VCPU_TB_TRANS) {
+ plugin.cpu_flags &= ~QEMU_PLUGIN_CPU_FLAG_CB_TB_TRANS;
+ g_hash_table_foreach(plugin.cpu_ht, plugin_cpu_update__locked,
+ NULL);
+ }
}
}
@@ -186,8 +190,10 @@ do_plugin_register_cb(qemu_plugin_id_t id, enum
qemu_plugin_event ev,
cb->udata = udata;
ctx->callbacks[ev] = cb;
QLIST_INSERT_HEAD_RCU(&plugin.cb_lists[ev], cb, entry);
- if (!test_bit(ev, plugin.mask)) {
- set_bit(ev, plugin.mask);
+ set_bit(ev, plugin.mask);
+ if (ev == QEMU_PLUGIN_EV_VCPU_TB_TRANS &&
+ !(plugin.cpu_flags & QEMU_PLUGIN_CPU_FLAG_CB_TB_TRANS)) {
+ plugin.cpu_flags |= QEMU_PLUGIN_CPU_FLAG_CB_TB_TRANS;
g_hash_table_foreach(plugin.cpu_ht, plugin_cpu_update__locked,
NULL);
}
@@ -334,7 +340,7 @@ void qemu_plugin_tb_trans_cb(CPUState *cpu, struct
qemu_plugin_tb *tb)
struct qemu_plugin_cb *cb, *next;
enum qemu_plugin_event ev = QEMU_PLUGIN_EV_VCPU_TB_TRANS;
- /* no plugin_mask check here; caller should have checked */
+ /* no plugin.mask check here; caller should have checked */
QLIST_FOREACH_SAFE_RCU(cb, &plugin.cb_lists[ev], entry, next) {
qemu_plugin_vcpu_tb_trans_cb_t func = cb->f.vcpu_tb_trans;
@@ -357,7 +363,7 @@ qemu_plugin_vcpu_syscall(CPUState *cpu, int64_t num,
uint64_t a1, uint64_t a2,
struct qemu_plugin_cb *cb, *next;
enum qemu_plugin_event ev = QEMU_PLUGIN_EV_VCPU_SYSCALL;
- if (!test_bit(ev, cpu->plugin_mask)) {
+ if (!test_bit(ev, plugin.mask)) {
return;
}
@@ -379,7 +385,7 @@ void qemu_plugin_vcpu_syscall_ret(CPUState *cpu, int64_t
num, int64_t ret)
struct qemu_plugin_cb *cb, *next;
enum qemu_plugin_event ev = QEMU_PLUGIN_EV_VCPU_SYSCALL_RET;
- if (!test_bit(ev, cpu->plugin_mask)) {
+ if (!test_bit(ev, plugin.mask)) {
return;
}
diff --git a/plugins/loader.c b/plugins/loader.c
index 734c11cae0..2c6e60c5d0 100644
--- a/plugins/loader.c
+++ b/plugins/loader.c
@@ -37,12 +37,6 @@
#include "plugin.h"
-/*
- * For convenience we use a bitmap for plugin.mask, but really all we need is a
- * u32, which is what we store in TranslationBlock.
- */
-QEMU_BUILD_BUG_ON(QEMU_PLUGIN_EV_MAX > 32);
-
struct qemu_plugin_desc {
char *path;
char **argv;
--
2.42.0
- [PATCH v15 06/19] target/riscv: Use GDBFeature for dynamic XML, (continued)
- [PATCH v15 06/19] target/riscv: Use GDBFeature for dynamic XML, Akihiko Odaki, 2023/10/25
- [PATCH v15 07/19] gdbstub: Use GDBFeature for gdb_register_coprocessor, Akihiko Odaki, 2023/10/25
- [PATCH v15 08/19] gdbstub: Use GDBFeature for GDBRegisterState, Akihiko Odaki, 2023/10/25
- [PATCH v15 10/19] gdbstub: Simplify XML lookup, Akihiko Odaki, 2023/10/25
- [PATCH v15 09/19] gdbstub: Change gdb_get_reg_cb and gdb_set_reg_cb, Akihiko Odaki, 2023/10/25
- [PATCH v15 11/19] gdbstub: Infer number of core registers from XML, Akihiko Odaki, 2023/10/25
- [PATCH v15 12/19] hw/core/cpu: Remove gdb_get_dynamic_xml member, Akihiko Odaki, 2023/10/25
- [PATCH v15 13/19] gdbstub: Add members to identify registers to GDBFeature, Akihiko Odaki, 2023/10/25
- [PATCH v15 14/19] gdbstub: Expose functions to read registers, Akihiko Odaki, 2023/10/25
- [PATCH v15 15/19] cpu: Call plugin hooks only when ready, Akihiko Odaki, 2023/10/25
- [PATCH v15 16/19] plugins: Introduce CPU flags,
Akihiko Odaki <=
- [PATCH v15 18/19] plugins: Allow to read registers, Akihiko Odaki, 2023/10/25
- [PATCH v15 17/19] plugins: Use different helpers when reading registers, Akihiko Odaki, 2023/10/25
- [PATCH v15 19/19] contrib/plugins: Allow to log registers, Akihiko Odaki, 2023/10/25