Skip to content

Commit

Permalink
cpu: hook plugin vcpu events
Browse files Browse the repository at this point in the history
Signed-off-by: Emilio G. Cota <cota@braap.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
  • Loading branch information
cota authored and stsquad committed Oct 28, 2019
1 parent c36f7a6 commit 30865f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cpus.c
Expand Up @@ -45,6 +45,7 @@
#include "exec/exec-all.h"

#include "qemu/thread.h"
#include "qemu/plugin.h"
#include "sysemu/cpus.h"
#include "sysemu/qtest.h"
#include "qemu/main-loop.h"
Expand Down Expand Up @@ -1264,9 +1265,18 @@ static void qemu_tcg_rr_wait_io_event(void)

static void qemu_wait_io_event(CPUState *cpu)
{
bool slept = false;

while (cpu_thread_is_idle(cpu)) {
if (!slept) {
slept = true;
qemu_plugin_vcpu_idle_cb(cpu);
}
qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex);
}
if (slept) {
qemu_plugin_vcpu_resume_cb(cpu);
}

#ifdef _WIN32
/* Eat dummy APC queued by qemu_cpu_kick_thread. */
Expand Down
2 changes: 2 additions & 0 deletions exec.c
Expand Up @@ -975,6 +975,8 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)
}
tlb_init(cpu);

qemu_plugin_vcpu_init_hook(cpu);

#ifndef CONFIG_USER_ONLY
if (qdev_get_vmsd(DEVICE(cpu)) == NULL) {
vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu);
Expand Down
2 changes: 2 additions & 0 deletions hw/core/cpu.c
Expand Up @@ -32,6 +32,7 @@
#include "hw/boards.h"
#include "hw/qdev-properties.h"
#include "trace-root.h"
#include "qemu/plugin.h"

CPUInterruptHandler cpu_interrupt_handler;

Expand Down Expand Up @@ -352,6 +353,7 @@ static void cpu_common_unrealizefn(DeviceState *dev, Error **errp)
CPUState *cpu = CPU(dev);
/* NOTE: latest generic point before the cpu is fully unrealized */
trace_fini_vcpu(cpu);
qemu_plugin_vcpu_exit_hook(cpu);
cpu_exec_unrealizefn(cpu);
}

Expand Down

0 comments on commit 30865f3

Please sign in to comment.