From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
Claudio Fontana <cfontana@suse.de>
Subject: [PULL 08/37] cpus: extract out whpx-specific code to target/i386/
Date: Tue, 6 Oct 2020 09:29:18 +0200 [thread overview]
Message-ID: <20201006072947.487729-9-pbonzini@redhat.com> (raw)
In-Reply-To: <20201006072947.487729-1-pbonzini@redhat.com>
From: Claudio Fontana <cfontana@suse.de>
register a "CpusAccel" interface for WHPX as well.
Signed-off-by: Claudio Fontana <cfontana@suse.de>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
MAINTAINERS | 1 +
softmmu/cpus.c | 79 ---------------------------------
target/i386/meson.build | 5 ++-
target/i386/whpx-all.c | 3 ++
target/i386/whpx-cpus.c | 96 +++++++++++++++++++++++++++++++++++++++++
target/i386/whpx-cpus.h | 17 ++++++++
6 files changed, 121 insertions(+), 80 deletions(-)
create mode 100644 target/i386/whpx-cpus.c
create mode 100644 target/i386/whpx-cpus.h
diff --git a/MAINTAINERS b/MAINTAINERS
index ecc45dfac4..231f854437 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -451,6 +451,7 @@ WHPX CPUs
M: Sunil Muthuswamy <sunilmut@microsoft.com>
S: Supported
F: target/i386/whpx-all.c
+F: target/i386/whpx-cpus.c
F: target/i386/whp-dispatch.h
F: accel/stubs/whpx-stub.c
F: include/sysemu/whpx.h
diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index 900fff827a..067dae12eb 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -34,7 +34,6 @@
#include "sysemu/hw_accel.h"
#include "sysemu/kvm.h"
#include "sysemu/hvf.h"
-#include "sysemu/whpx.h"
#include "exec/exec-all.h"
#include "qemu/thread.h"
#include "qemu/plugin.h"
@@ -178,9 +177,6 @@ void cpu_synchronize_state(CPUState *cpu)
if (cpus_accel && cpus_accel->synchronize_state) {
cpus_accel->synchronize_state(cpu);
}
- if (whpx_enabled()) {
- whpx_cpu_synchronize_state(cpu);
- }
}
void cpu_synchronize_post_reset(CPUState *cpu)
@@ -188,9 +184,6 @@ void cpu_synchronize_post_reset(CPUState *cpu)
if (cpus_accel && cpus_accel->synchronize_post_reset) {
cpus_accel->synchronize_post_reset(cpu);
}
- if (whpx_enabled()) {
- whpx_cpu_synchronize_post_reset(cpu);
- }
}
void cpu_synchronize_post_init(CPUState *cpu)
@@ -198,9 +191,6 @@ void cpu_synchronize_post_init(CPUState *cpu)
if (cpus_accel && cpus_accel->synchronize_post_init) {
cpus_accel->synchronize_post_init(cpu);
}
- if (whpx_enabled()) {
- whpx_cpu_synchronize_post_init(cpu);
- }
}
void cpu_synchronize_pre_loadvm(CPUState *cpu)
@@ -211,9 +201,6 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu)
if (hvf_enabled()) {
hvf_cpu_synchronize_pre_loadvm(cpu);
}
- if (whpx_enabled()) {
- whpx_cpu_synchronize_pre_loadvm(cpu);
- }
}
int64_t cpus_get_virtual_clock(void)
@@ -445,48 +432,6 @@ static void *qemu_hvf_cpu_thread_fn(void *arg)
return NULL;
}
-static void *qemu_whpx_cpu_thread_fn(void *arg)
-{
- CPUState *cpu = arg;
- int r;
-
- rcu_register_thread();
-
- qemu_mutex_lock_iothread();
- qemu_thread_get_self(cpu->thread);
- cpu->thread_id = qemu_get_thread_id();
- current_cpu = cpu;
-
- r = whpx_init_vcpu(cpu);
- if (r < 0) {
- fprintf(stderr, "whpx_init_vcpu failed: %s\n", strerror(-r));
- exit(1);
- }
-
- /* signal CPU creation */
- cpu_thread_signal_created(cpu);
- qemu_guest_random_seed_thread_part2(cpu->random_seed);
-
- do {
- if (cpu_can_run(cpu)) {
- r = whpx_vcpu_exec(cpu);
- if (r == EXCP_DEBUG) {
- cpu_handle_guest_debug(cpu);
- }
- }
- while (cpu_thread_is_idle(cpu)) {
- qemu_cond_wait(cpu->halt_cond, &qemu_global_mutex);
- }
- qemu_wait_io_event_common(cpu);
- } while (!cpu->unplug || cpu_can_run(cpu));
-
- whpx_destroy_vcpu(cpu);
- cpu_thread_signal_destroyed(cpu);
- qemu_mutex_unlock_iothread();
- rcu_unregister_thread();
- return NULL;
-}
-
void cpus_kick_thread(CPUState *cpu)
{
#ifndef _WIN32
@@ -501,12 +446,6 @@ void cpus_kick_thread(CPUState *cpu)
fprintf(stderr, "qemu:%s: %s", __func__, strerror(err));
exit(1);
}
-#else /* _WIN32 */
- if (!qemu_cpu_is_self(cpu)) {
- if (whpx_enabled()) {
- whpx_vcpu_kick(cpu);
- }
- }
#endif
}
@@ -681,22 +620,6 @@ static void qemu_hvf_start_vcpu(CPUState *cpu)
cpu, QEMU_THREAD_JOINABLE);
}
-static void qemu_whpx_start_vcpu(CPUState *cpu)
-{
- char thread_name[VCPU_THREAD_NAME_SIZE];
-
- cpu->thread = g_malloc0(sizeof(QemuThread));
- cpu->halt_cond = g_malloc0(sizeof(QemuCond));
- qemu_cond_init(cpu->halt_cond);
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX",
- cpu->cpu_index);
- qemu_thread_create(cpu->thread, thread_name, qemu_whpx_cpu_thread_fn,
- cpu, QEMU_THREAD_JOINABLE);
-#ifdef _WIN32
- cpu->hThread = qemu_thread_get_handle(cpu->thread);
-#endif
-}
-
void cpus_register_accel(const CpusAccel *ca)
{
assert(ca != NULL);
@@ -726,8 +649,6 @@ void qemu_init_vcpu(CPUState *cpu)
cpus_accel->create_vcpu_thread(cpu);
} else if (hvf_enabled()) {
qemu_hvf_start_vcpu(cpu);
- } else if (whpx_enabled()) {
- qemu_whpx_start_vcpu(cpu);
} else {
g_assert_not_reached();
}
diff --git a/target/i386/meson.build b/target/i386/meson.build
index 1db619841c..a1a02f3e99 100644
--- a/target/i386/meson.build
+++ b/target/i386/meson.build
@@ -30,7 +30,10 @@ i386_softmmu_ss.add(files(
))
i386_softmmu_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c'))
i386_softmmu_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'))
-i386_softmmu_ss.add(when: 'CONFIG_WHPX', if_true: files('whpx-all.c'))
+i386_softmmu_ss.add(when: 'CONFIG_WHPX', if_true: files(
+ 'whpx-all.c',
+ 'whpx-cpus.c',
+))
i386_softmmu_ss.add(when: 'CONFIG_HAX', if_true: files(
'hax-all.c',
'hax-mem.c',
diff --git a/target/i386/whpx-all.c b/target/i386/whpx-all.c
index 2a8fcb68fd..91ee2e59f9 100644
--- a/target/i386/whpx-all.c
+++ b/target/i386/whpx-all.c
@@ -24,6 +24,8 @@
#include "migration/blocker.h"
#include "whp-dispatch.h"
+#include "whpx-cpus.h"
+
#include <WinHvPlatform.h>
#include <WinHvEmulation.h>
@@ -1650,6 +1652,7 @@ static int whpx_accel_init(MachineState *ms)
whpx_memory_init();
cpu_interrupt_handler = whpx_handle_interrupt;
+ cpus_register_accel(&whpx_cpus);
printf("Windows Hypervisor Platform accelerator is operational\n");
return 0;
diff --git a/target/i386/whpx-cpus.c b/target/i386/whpx-cpus.c
new file mode 100644
index 0000000000..d9bd5a2d36
--- /dev/null
+++ b/target/i386/whpx-cpus.c
@@ -0,0 +1,96 @@
+/*
+ * QEMU Windows Hypervisor Platform accelerator (WHPX)
+ *
+ * Copyright Microsoft Corp. 2017
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "sysemu/kvm_int.h"
+#include "qemu/main-loop.h"
+#include "sysemu/cpus.h"
+#include "qemu/guest-random.h"
+
+#include "sysemu/whpx.h"
+#include "whpx-cpus.h"
+
+#include <WinHvPlatform.h>
+#include <WinHvEmulation.h>
+
+static void *whpx_cpu_thread_fn(void *arg)
+{
+ CPUState *cpu = arg;
+ int r;
+
+ rcu_register_thread();
+
+ qemu_mutex_lock_iothread();
+ qemu_thread_get_self(cpu->thread);
+ cpu->thread_id = qemu_get_thread_id();
+ current_cpu = cpu;
+
+ r = whpx_init_vcpu(cpu);
+ if (r < 0) {
+ fprintf(stderr, "whpx_init_vcpu failed: %s\n", strerror(-r));
+ exit(1);
+ }
+
+ /* signal CPU creation */
+ cpu_thread_signal_created(cpu);
+ qemu_guest_random_seed_thread_part2(cpu->random_seed);
+
+ do {
+ if (cpu_can_run(cpu)) {
+ r = whpx_vcpu_exec(cpu);
+ if (r == EXCP_DEBUG) {
+ cpu_handle_guest_debug(cpu);
+ }
+ }
+ while (cpu_thread_is_idle(cpu)) {
+ qemu_cond_wait_iothread(cpu->halt_cond);
+ }
+ qemu_wait_io_event_common(cpu);
+ } while (!cpu->unplug || cpu_can_run(cpu));
+
+ whpx_destroy_vcpu(cpu);
+ cpu_thread_signal_destroyed(cpu);
+ qemu_mutex_unlock_iothread();
+ rcu_unregister_thread();
+ return NULL;
+}
+
+static void whpx_start_vcpu_thread(CPUState *cpu)
+{
+ char thread_name[VCPU_THREAD_NAME_SIZE];
+
+ cpu->thread = g_malloc0(sizeof(QemuThread));
+ cpu->halt_cond = g_malloc0(sizeof(QemuCond));
+ qemu_cond_init(cpu->halt_cond);
+ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX",
+ cpu->cpu_index);
+ qemu_thread_create(cpu->thread, thread_name, whpx_cpu_thread_fn,
+ cpu, QEMU_THREAD_JOINABLE);
+#ifdef _WIN32
+ cpu->hThread = qemu_thread_get_handle(cpu->thread);
+#endif
+}
+
+static void whpx_kick_vcpu_thread(CPUState *cpu)
+{
+ if (!qemu_cpu_is_self(cpu)) {
+ whpx_vcpu_kick(cpu);
+ }
+}
+
+const CpusAccel whpx_cpus = {
+ .create_vcpu_thread = whpx_start_vcpu_thread,
+ .kick_vcpu_thread = whpx_kick_vcpu_thread,
+
+ .synchronize_post_reset = whpx_cpu_synchronize_post_reset,
+ .synchronize_post_init = whpx_cpu_synchronize_post_init,
+ .synchronize_state = whpx_cpu_synchronize_state,
+ .synchronize_pre_loadvm = whpx_cpu_synchronize_pre_loadvm,
+};
diff --git a/target/i386/whpx-cpus.h b/target/i386/whpx-cpus.h
new file mode 100644
index 0000000000..2393944954
--- /dev/null
+++ b/target/i386/whpx-cpus.h
@@ -0,0 +1,17 @@
+/*
+ * Accelerator CPUS Interface
+ *
+ * Copyright 2020 SUSE LLC
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef WHPX_CPUS_H
+#define WHPX_CPUS_H
+
+#include "sysemu/cpus.h"
+
+extern const CpusAccel whpx_cpus;
+
+#endif /* WHPX_CPUS_H */
--
2.26.2
next prev parent reply other threads:[~2020-10-06 7:32 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-06 7:29 [PULL 00/37] Build system + accel + record/replay patches for 2020-10-06 Paolo Bonzini
2020-10-06 7:29 ` [PULL 01/37] cpu-timers, icount: new modules Paolo Bonzini
2020-10-06 7:29 ` [PULL 02/37] icount: rename functions to be consistent with the module name Paolo Bonzini
2020-10-06 7:29 ` [PULL 03/37] cpus: prepare new CpusAccel cpu accelerator interface Paolo Bonzini
2020-10-06 7:29 ` [PULL 04/37] cpus: extract out TCG-specific code to accel/tcg Paolo Bonzini
2020-10-06 7:29 ` [PULL 05/37] cpus: extract out qtest-specific code to accel/qtest Paolo Bonzini
2020-10-06 7:29 ` [PULL 06/37] cpus: extract out kvm-specific code to accel/kvm Paolo Bonzini
2020-10-06 7:29 ` [PULL 07/37] cpus: extract out hax-specific code to target/i386/ Paolo Bonzini
2020-10-16 6:48 ` Volker Rümelin
2020-10-16 8:00 ` Claudio Fontana
2020-10-17 7:17 ` Volker Rümelin
2020-10-06 7:29 ` Paolo Bonzini [this message]
2020-10-06 7:29 ` [PULL 09/37] cpus: extract out hvf-specific code to target/i386/hvf/ Paolo Bonzini
2020-10-06 7:29 ` [PULL 10/37] cpus: cleanup now unneeded includes Paolo Bonzini
2020-10-06 7:29 ` [PULL 11/37] cpus: remove checks for non-NULL cpus_accel Paolo Bonzini
2020-10-06 7:29 ` [PULL 12/37] cpus: add handle_interrupt to the CpusAccel interface Paolo Bonzini
2020-10-06 7:29 ` [PULL 13/37] hvf: remove hvf specific functions from global includes Paolo Bonzini
2020-10-06 7:29 ` [PULL 14/37] whpx: remove whpx " Paolo Bonzini
2020-10-06 7:29 ` [PULL 15/37] hax: remove hax " Paolo Bonzini
2020-10-06 7:29 ` [PULL 16/37] kvm: remove kvm " Paolo Bonzini
2020-10-06 7:29 ` [PULL 17/37] kvm: kvm_init_vcpu take Error pointer Paolo Bonzini
2020-10-06 7:29 ` [PULL 18/37] accel/tcg: use current_machine as it is always set for softmmu Paolo Bonzini
2020-10-06 7:29 ` [PULL 19/37] slirp: Convert Makefile bits to meson bits Paolo Bonzini
2020-10-06 7:29 ` [PULL 20/37] dtc: " Paolo Bonzini
2020-10-06 7:29 ` [PULL 21/37] configure: do not clobber environment CFLAGS/CXXFLAGS/LDFLAGS Paolo Bonzini
2020-10-06 7:29 ` [PULL 22/37] configure: consistently pass CFLAGS/CXXFLAGS/LDFLAGS to meson Paolo Bonzini
2020-10-06 7:29 ` [PULL 23/37] configure: don't enable ASLR for --enable-debug Windows builds Paolo Bonzini
2020-10-06 7:29 ` [PULL 24/37] replay: don't record interrupt poll Paolo Bonzini
2020-10-06 7:29 ` [PULL 25/37] replay: provide an accessor for rr filename Paolo Bonzini
2020-10-06 7:29 ` [PULL 26/37] qcow2: introduce icount field for snapshots Paolo Bonzini
2020-10-06 7:29 ` [PULL 27/37] migration: " Paolo Bonzini
2020-10-06 13:44 ` Eric Blake
2020-10-06 7:29 ` [PULL 28/37] qapi: introduce replay.json for record/replay-related stuff Paolo Bonzini
2020-10-06 7:29 ` [PULL 29/37] replay: introduce info hmp/qmp command Paolo Bonzini
2020-10-06 7:29 ` [PULL 30/37] replay: introduce breakpoint at the specified step Paolo Bonzini
2020-10-06 7:29 ` [PULL 31/37] replay: implement replay-seek command Paolo Bonzini
2020-10-06 7:29 ` [PULL 32/37] replay: flush rr queue before loading the vmstate Paolo Bonzini
2020-10-06 7:29 ` [PULL 33/37] gdbstub: add reverse step support in replay mode Paolo Bonzini
2020-10-06 7:29 ` [PULL 34/37] gdbstub: add reverse continue " Paolo Bonzini
2020-10-30 15:15 ` Philippe Mathieu-Daudé
2020-10-06 7:29 ` [PULL 35/37] replay: describe reverse debugging in docs/replay.txt Paolo Bonzini
2020-10-06 7:29 ` [PULL 36/37] replay: create temporary snapshot at debugger connection Paolo Bonzini
2020-10-06 7:29 ` [PULL 37/37] tests/acceptance: add reverse debugging test Paolo Bonzini
2020-10-06 20:13 ` [PULL 00/37] Build system + accel + record/replay patches for 2020-10-06 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201006072947.487729-9-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=cfontana@suse.de \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).