mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 14:53:54 -06:00
tcg plugins: expose an API version concept
This is a very simple versioning API which allows the plugin infrastructure to check the API a plugin was built against. We also expose a min/cur API version to the plugin via the info block in case it wants to avoid using old deprecated APIs in the future. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Robert Foley <robert.foley@linaro.org>
This commit is contained in:
parent
05273a43af
commit
3fb356cc86
10 changed files with 56 additions and 0 deletions
|
@ -38,9 +38,28 @@
|
||||||
|
|
||||||
typedef uint64_t qemu_plugin_id_t;
|
typedef uint64_t qemu_plugin_id_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Versioning plugins:
|
||||||
|
*
|
||||||
|
* The plugin API will pass a minimum and current API version that
|
||||||
|
* QEMU currently supports. The minimum API will be incremented if an
|
||||||
|
* API needs to be deprecated.
|
||||||
|
*
|
||||||
|
* The plugins export the API they were built against by exposing the
|
||||||
|
* symbol qemu_plugin_version which can be checked.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern QEMU_PLUGIN_EXPORT int qemu_plugin_version;
|
||||||
|
|
||||||
|
#define QEMU_PLUGIN_VERSION 0
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* string describing architecture */
|
/* string describing architecture */
|
||||||
const char *target_name;
|
const char *target_name;
|
||||||
|
struct {
|
||||||
|
int min;
|
||||||
|
int cur;
|
||||||
|
} version;
|
||||||
/* is this a full system emulation? */
|
/* is this a full system emulation? */
|
||||||
bool system_emulation;
|
bool system_emulation;
|
||||||
union {
|
union {
|
||||||
|
|
|
@ -178,6 +178,25 @@ static int plugin_load(struct qemu_plugin_desc *desc, const qemu_info_t *info)
|
||||||
goto err_symbol;
|
goto err_symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!g_module_symbol(ctx->handle, "qemu_plugin_version", &sym)) {
|
||||||
|
error_report("TCG plugin %s does not declare API version %s",
|
||||||
|
desc->path, g_module_error());
|
||||||
|
goto err_symbol;
|
||||||
|
} else {
|
||||||
|
int version = *(int *)sym;
|
||||||
|
if (version < QEMU_PLUGIN_MIN_VERSION) {
|
||||||
|
error_report("TCG plugin %s requires API version %d, but "
|
||||||
|
"this QEMU supports only a minimum version of %d",
|
||||||
|
desc->path, version, QEMU_PLUGIN_MIN_VERSION);
|
||||||
|
goto err_symbol;
|
||||||
|
} else if (version > QEMU_PLUGIN_VERSION) {
|
||||||
|
error_report("TCG plugin %s requires API version %d, but "
|
||||||
|
"this QEMU supports only up to version %d",
|
||||||
|
desc->path, version, QEMU_PLUGIN_VERSION);
|
||||||
|
goto err_symbol;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
qemu_rec_mutex_lock(&plugin.lock);
|
qemu_rec_mutex_lock(&plugin.lock);
|
||||||
|
|
||||||
/* find an unused random id with &ctx as the seed */
|
/* find an unused random id with &ctx as the seed */
|
||||||
|
@ -248,6 +267,8 @@ int qemu_plugin_load_list(QemuPluginList *head)
|
||||||
g_autofree qemu_info_t *info = g_new0(qemu_info_t, 1);
|
g_autofree qemu_info_t *info = g_new0(qemu_info_t, 1);
|
||||||
|
|
||||||
info->target_name = TARGET_NAME;
|
info->target_name = TARGET_NAME;
|
||||||
|
info->version.min = QEMU_PLUGIN_MIN_VERSION;
|
||||||
|
info->version.cur = QEMU_PLUGIN_VERSION;
|
||||||
#ifndef CONFIG_USER_ONLY
|
#ifndef CONFIG_USER_ONLY
|
||||||
MachineState *ms = MACHINE(qdev_get_machine());
|
MachineState *ms = MACHINE(qdev_get_machine());
|
||||||
info->system_emulation = true;
|
info->system_emulation = true;
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include <gmodule.h>
|
#include <gmodule.h>
|
||||||
|
|
||||||
|
#define QEMU_PLUGIN_MIN_VERSION 0
|
||||||
|
|
||||||
/* global state */
|
/* global state */
|
||||||
struct qemu_plugin_state {
|
struct qemu_plugin_state {
|
||||||
QTAILQ_HEAD(, qemu_plugin_ctx) ctxs;
|
QTAILQ_HEAD(, qemu_plugin_ctx) ctxs;
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include <qemu-plugin.h>
|
#include <qemu-plugin.h>
|
||||||
|
|
||||||
|
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
|
||||||
|
|
||||||
static uint64_t bb_count;
|
static uint64_t bb_count;
|
||||||
static uint64_t insn_count;
|
static uint64_t insn_count;
|
||||||
static bool do_inline;
|
static bool do_inline;
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#include <qemu-plugin.h>
|
#include <qemu-plugin.h>
|
||||||
|
|
||||||
|
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Empty TB translation callback.
|
* Empty TB translation callback.
|
||||||
* This allows us to measure the overhead of injecting and then
|
* This allows us to measure the overhead of injecting and then
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
#include <qemu-plugin.h>
|
#include <qemu-plugin.h>
|
||||||
|
|
||||||
|
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
|
||||||
|
|
||||||
static bool do_inline;
|
static bool do_inline;
|
||||||
|
|
||||||
/* Plugins need to take care of their own locking */
|
/* Plugins need to take care of their own locking */
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
#include <qemu-plugin.h>
|
#include <qemu-plugin.h>
|
||||||
|
|
||||||
|
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
|
||||||
|
|
||||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
static uint64_t page_size = 4096;
|
static uint64_t page_size = 4096;
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include <qemu-plugin.h>
|
#include <qemu-plugin.h>
|
||||||
|
|
||||||
|
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
|
||||||
|
|
||||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include <qemu-plugin.h>
|
#include <qemu-plugin.h>
|
||||||
|
|
||||||
|
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
|
||||||
|
|
||||||
static uint64_t insn_count;
|
static uint64_t insn_count;
|
||||||
static bool do_inline;
|
static bool do_inline;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include <qemu-plugin.h>
|
#include <qemu-plugin.h>
|
||||||
|
|
||||||
|
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
|
||||||
|
|
||||||
static uint64_t mem_count;
|
static uint64_t mem_count;
|
||||||
static uint64_t io_count;
|
static uint64_t io_count;
|
||||||
static bool do_inline;
|
static bool do_inline;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue