From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33414) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gW4uF-0001SZ-A1 for qemu-devel@nongnu.org; Sun, 09 Dec 2018 14:38:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gW4uD-0005sd-71 for qemu-devel@nongnu.org; Sun, 09 Dec 2018 14:38:23 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:43325) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gW4uC-00052M-QL for qemu-devel@nongnu.org; Sun, 09 Dec 2018 14:38:21 -0500 From: "Emilio G. Cota" Date: Sun, 9 Dec 2018 14:37:30 -0500 Message-Id: <20181209193749.12277-20-cota@braap.org> In-Reply-To: <20181209193749.12277-1-cota@braap.org> References: <20181209193749.12277-1-cota@braap.org> Subject: [Qemu-devel] [RFC v2 19/38] cpu: hook plugin vcpu events List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson , Pavel Dovgalyuk Signed-off-by: Emilio G. Cota --- cpus.c | 10 ++++++++++ exec.c | 2 ++ qom/cpu.c | 2 ++ 3 files changed, 14 insertions(+) diff --git a/cpus.c b/cpus.c index c9acef73e4..e3844c69c8 100644 --- a/cpus.c +++ b/cpus.c @@ -43,6 +43,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" @@ -1322,12 +1323,21 @@ static void qemu_tcg_rr_wait_io_event(CPUState *cpu) static void qemu_wait_io_event(CPUState *cpu) { + bool slept = false; + g_assert(cpu_mutex_locked(cpu)); g_assert(!qemu_mutex_iothread_locked()); while (cpu_thread_is_idle(cpu)) { + if (!slept) { + slept = true; + qemu_plugin_vcpu_idle_cb(cpu); + } qemu_cond_wait(&cpu->halt_cond, &cpu->lock); } + if (slept) { + qemu_plugin_vcpu_resume_cb(cpu); + } #ifdef _WIN32 /* Eat dummy APC queued by qemu_cpu_kick_thread. */ diff --git a/exec.c b/exec.c index 04d505500b..bdafb0e71a 100644 --- a/exec.c +++ b/exec.c @@ -967,6 +967,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); diff --git a/qom/cpu.c b/qom/cpu.c index b33d182c4c..6233a98a84 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -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; @@ -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); } -- 2.17.1