@@ -38,9 +38,27 @@
typedef uint64_t qemu_plugin_id_t;
+typedef struct {
+ /* string describing architecture */
+ const char *target_name;
+ /* is this a full system emulation? */
+ bool system_emulation;
+ union {
+ /*
+ * smp_vcpus may change if vCPUs can be hot-plugged, max_vcpus
+ * is the system-wide limit.
+ */
+ struct {
+ int smp_vcpus;
+ int max_vcpus;
+ } system;
+ };
+} qemu_info_t;
+
/**
* qemu_plugin_install() - Install a plugin
* @id: this plugin's opaque ID
+ * @info: a block describing some details about the guest
* @argc: number of arguments
* @argv: array of arguments (@argc elements)
*
@@ -49,10 +67,14 @@ typedef uint64_t qemu_plugin_id_t;
* Note: Calling qemu_plugin_uninstall() from this function is a bug. To raise
* an error during install, return !0.
*
+ * Note: @info is only live during the call. Copy any information we
+ * want to keep.
+ *
* Note: @argv remains valid throughout the lifetime of the loaded plugin.
*/
-QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc,
- char **argv);
+QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
+ const qemu_info_t *info,
+ int argc, char **argv);
/*
* Prototypes for the various callback styles we will be registering
@@ -29,6 +29,9 @@
#include "hw/core/cpu.h"
#include "cpu.h"
#include "exec/exec-all.h"
+#ifndef CONFIG_USER_ONLY
+#include "hw/boards.h"
+#endif
#include "plugin.h"
@@ -60,7 +63,7 @@ QemuOptsList qemu_plugin_opts = {
},
};
-typedef int (*qemu_plugin_install_func_t)(qemu_plugin_id_t, int, char **);
+typedef int (*qemu_plugin_install_func_t)(qemu_plugin_id_t, const qemu_info_t *, int, char **);
extern struct qemu_plugin_state plugin;
@@ -147,7 +150,7 @@ static uint64_t xorshift64star(uint64_t x)
return x * UINT64_C(2685821657736338717);
}
-static int plugin_load(struct qemu_plugin_desc *desc)
+static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info)
{
qemu_plugin_install_func_t install;
struct qemu_plugin_ctx *ctx;
@@ -198,7 +201,7 @@ static int plugin_load(struct qemu_plugin_desc *desc)
}
QTAILQ_INSERT_TAIL(&plugin.ctxs, ctx, entry);
ctx->installing = true;
- rc = install(ctx->id, desc->argc, desc->argv);
+ rc = install(ctx->id, info, desc->argc, desc->argv);
ctx->installing = false;
if (rc) {
error_report("%s: qemu_plugin_install returned error code %d",
@@ -249,11 +252,22 @@ static void plugin_desc_free(struct qemu_plugin_desc *desc)
int qemu_plugin_load_list(QemuPluginList *head)
{
struct qemu_plugin_desc *desc, *next;
+ g_autofree qemu_info_t *info = g_new0(qemu_info_t, 1);
+
+ info->target_name = TARGET_NAME;
+#ifndef CONFIG_USER_ONLY
+ MachineState * ms = MACHINE(qdev_get_machine());
+ info->system_emulation = true;
+ info->system.smp_vcpus = ms->smp.cpus;
+ info->system.max_vcpus = ms->smp.max_cpus;
+#else
+ info->system_emulation = false;
+#endif
QTAILQ_FOREACH_SAFE(desc, head, entry, next) {
int err;
- err = plugin_load(desc);
+ err = plugin_load(desc, info);
if (err) {
return err;
}
@@ -48,8 +48,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
}
}
-QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc,
- char **argv)
+QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
+ const qemu_info_t *info,
+ int argc, char **argv)
{
if (argc && strcmp(argv[0], "inline") == 0) {
do_inline = true;
@@ -21,8 +21,9 @@
static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
{ }
-QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc,
- char **argv)
+QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
+ const qemu_info_t *info,
+ int argc, char **argv)
{
qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
return 0;
@@ -129,8 +129,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
}
}
-QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc,
- char **argv)
+QEMU_PLUGIN_EXPORT
+int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,
+ int argc, char **argv)
{
if (argc && strcmp(argv[0], "inline") == 0) {
do_inline = true;
@@ -148,8 +148,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
}
}
-QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc,
- char **argv)
+QEMU_PLUGIN_EXPORT
+int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,
+ int argc, char **argv)
{
int i;
@@ -264,8 +264,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
}
}
-QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc,
- char **argv)
+QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
+ const qemu_info_t *info,
+ int argc, char **argv)
{
int i;
@@ -45,8 +45,9 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
dprintf(stdout_fd, "insns: %" PRIu64 "\n", insn_count);
}
-QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc,
- char **argv)
+QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
+ const qemu_info_t *info,
+ int argc, char **argv)
{
if (argc && !strcmp(argv[0], "inline")) {
do_inline = true;
@@ -64,8 +64,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
}
}
-QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc,
- char **argv)
+QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
+ const qemu_info_t *info,
+ int argc, char **argv)
{
if (argc) {
if (argc >= 3) {
This provides a limited amount of info to plugins about the guest system that will allow them to make some additional decisions on setup. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> --- include/qemu/qemu-plugin.h | 26 ++++++++++++++++++++++++-- plugins/loader.c | 22 ++++++++++++++++++---- tests/plugin/bb.c | 5 +++-- tests/plugin/empty.c | 5 +++-- tests/plugin/hotblocks.c | 5 +++-- tests/plugin/hotpages.c | 5 +++-- tests/plugin/howvec.c | 5 +++-- tests/plugin/insn.c | 5 +++-- tests/plugin/mem.c | 5 +++-- 9 files changed, 63 insertions(+), 20 deletions(-) -- 2.20.1