cpus: extract out hvf-specific code to target/i386/hvf/

register a "CpusAccel" interface for HVF as well.

Signed-off-by: Claudio Fontana <cfontana@suse.de>
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
[added const]
Signed-off-by: Claudio Fontana <cfontana@suse.de>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Claudio Fontana 2020-07-07 11:50:13 +02:00 committed by Paolo Bonzini
parent 8ef39ecfa6
commit b52bcba7bd
5 changed files with 152 additions and 66 deletions

View file

@ -33,7 +33,6 @@
#include "exec/gdbstub.h"
#include "sysemu/hw_accel.h"
#include "sysemu/kvm.h"
#include "sysemu/hvf.h"
#include "exec/exec-all.h"
#include "qemu/thread.h"
#include "qemu/plugin.h"
@ -198,9 +197,6 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu)
if (cpus_accel && cpus_accel->synchronize_pre_loadvm) {
cpus_accel->synchronize_pre_loadvm(cpu);
}
if (hvf_enabled()) {
hvf_cpu_synchronize_pre_loadvm(cpu);
}
}
int64_t cpus_get_virtual_clock(void)
@ -390,48 +386,6 @@ void qemu_wait_io_event(CPUState *cpu)
qemu_wait_io_event_common(cpu);
}
/* The HVF-specific vCPU thread function. This one should only run when the host
* CPU supports the VMX "unrestricted guest" feature. */
static void *qemu_hvf_cpu_thread_fn(void *arg)
{
CPUState *cpu = arg;
int r;
assert(hvf_enabled());
rcu_register_thread();
qemu_mutex_lock_iothread();
qemu_thread_get_self(cpu->thread);
cpu->thread_id = qemu_get_thread_id();
cpu->can_do_io = 1;
current_cpu = cpu;
hvf_init_vcpu(cpu);
/* signal CPU creation */
cpu_thread_signal_created(cpu);
qemu_guest_random_seed_thread_part2(cpu->random_seed);
do {
if (cpu_can_run(cpu)) {
r = hvf_vcpu_exec(cpu);
if (r == EXCP_DEBUG) {
cpu_handle_guest_debug(cpu);
}
}
qemu_wait_io_event(cpu);
} while (!cpu->unplug || cpu_can_run(cpu));
hvf_vcpu_destroy(cpu);
cpu_thread_signal_destroyed(cpu);
qemu_mutex_unlock_iothread();
rcu_unregister_thread();
return NULL;
}
void cpus_kick_thread(CPUState *cpu)
{
#ifndef _WIN32
@ -602,24 +556,6 @@ void cpu_remove_sync(CPUState *cpu)
qemu_mutex_lock_iothread();
}
static void qemu_hvf_start_vcpu(CPUState *cpu)
{
char thread_name[VCPU_THREAD_NAME_SIZE];
/* HVF currently does not support TCG, and only runs in
* unrestricted-guest mode. */
assert(hvf_enabled());
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/HVF",
cpu->cpu_index);
qemu_thread_create(cpu->thread, thread_name, qemu_hvf_cpu_thread_fn,
cpu, QEMU_THREAD_JOINABLE);
}
void cpus_register_accel(const CpusAccel *ca)
{
assert(ca != NULL);
@ -647,8 +583,6 @@ void qemu_init_vcpu(CPUState *cpu)
if (cpus_accel) {
/* accelerator already implements the CpusAccel interface */
cpus_accel->create_vcpu_thread(cpu);
} else if (hvf_enabled()) {
qemu_hvf_start_vcpu(cpu);
} else {
g_assert_not_reached();
}