fix conflicts when merging no-thread to master
This commit is contained in:
77
qemu/cpus.c
77
qemu/cpus.c
@ -39,17 +39,13 @@ static void cpu_handle_guest_debug(CPUState *cpu);
|
||||
static int tcg_cpu_exec(struct uc_struct *uc, CPUArchState *env);
|
||||
static bool tcg_exec_all(struct uc_struct* uc);
|
||||
static int qemu_tcg_init_vcpu(CPUState *cpu);
|
||||
static void *qemu_tcg_cpu_thread_fn(void *arg);
|
||||
static void *qemu_tcg_cpu_loop(struct uc_struct *uc);
|
||||
|
||||
int vm_start(struct uc_struct* uc)
|
||||
{
|
||||
if (resume_all_vcpus(uc)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// kick off TCG thread
|
||||
qemu_mutex_unlock_iothread(uc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -60,30 +56,9 @@ bool cpu_is_stopped(CPUState *cpu)
|
||||
|
||||
void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data)
|
||||
{
|
||||
if (qemu_cpu_is_self(cpu)) {
|
||||
func(data);
|
||||
return;
|
||||
}
|
||||
func(data);
|
||||
}
|
||||
|
||||
// send halt_cond/tcg_halt_cond to @cpu
|
||||
bool qemu_cpu_is_self(CPUState *cpu)
|
||||
{
|
||||
return qemu_thread_is_self(cpu->thread);
|
||||
}
|
||||
|
||||
void pause_all_vcpus(struct uc_struct *uc)
|
||||
{
|
||||
CPUState *cpu;
|
||||
|
||||
CPU_FOREACH(cpu) {
|
||||
qemu_thread_join(uc, cpu->thread);
|
||||
free(cpu->thread);
|
||||
cpu->thread = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int resume_all_vcpus(struct uc_struct *uc)
|
||||
{
|
||||
CPUState *cpu;
|
||||
@ -102,7 +77,6 @@ int resume_all_vcpus(struct uc_struct *uc)
|
||||
if (qemu_init_vcpu(cpu))
|
||||
return -1;
|
||||
}
|
||||
qemu_mutex_lock_iothread(uc);
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,6 +84,7 @@ int resume_all_vcpus(struct uc_struct *uc)
|
||||
CPU_FOREACH(cpu) {
|
||||
cpu_resume(cpu);
|
||||
}
|
||||
qemu_tcg_cpu_loop(uc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -119,7 +94,6 @@ int qemu_init_vcpu(CPUState *cpu)
|
||||
cpu->nr_cores = smp_cores;
|
||||
cpu->nr_threads = smp_threads;
|
||||
cpu->stopped = true;
|
||||
cpu->uc->tcg_cpu_thread = NULL;
|
||||
|
||||
if (tcg_enabled(cpu->uc))
|
||||
return qemu_tcg_init_vcpu(cpu);
|
||||
@ -128,40 +102,27 @@ int qemu_init_vcpu(CPUState *cpu)
|
||||
}
|
||||
|
||||
|
||||
static void *qemu_tcg_cpu_thread_fn(void *arg)
|
||||
static void *qemu_tcg_cpu_loop(struct uc_struct *uc)
|
||||
{
|
||||
CPUState *cpu = arg;
|
||||
struct uc_struct *uc = cpu->uc;
|
||||
CPUState *cpu;
|
||||
|
||||
//qemu_tcg_init_cpu_signals();
|
||||
qemu_thread_get_self(uc, cpu->thread);
|
||||
|
||||
qemu_mutex_lock(&uc->qemu_global_mutex);
|
||||
CPU_FOREACH(cpu) {
|
||||
cpu->thread_id = qemu_get_thread_id();
|
||||
cpu->created = true;
|
||||
}
|
||||
qemu_cond_signal(&uc->qemu_cpu_cond);
|
||||
|
||||
/* wait for initial kick-off after machine start */
|
||||
while (QTAILQ_FIRST(&uc->cpus)->stopped) {
|
||||
qemu_cond_wait(uc->tcg_halt_cond, &uc->qemu_global_mutex);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
if (tcg_exec_all(uc))
|
||||
break;
|
||||
}
|
||||
|
||||
CPU_FOREACH(cpu) {
|
||||
cpu->thread_id = 0;
|
||||
cpu->created = false;
|
||||
qemu_cond_destroy(cpu->halt_cond);
|
||||
free(cpu->halt_cond);
|
||||
#ifdef _WIN32
|
||||
if (cpu->hThread)
|
||||
CloseHandle(cpu->hThread);
|
||||
#endif
|
||||
cpu->halt_cond = NULL;
|
||||
}
|
||||
|
||||
@ -172,38 +133,16 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
|
||||
|
||||
|
||||
|
||||
/* For temporary buffers for forming a name */
|
||||
#define VCPU_THREAD_NAME_SIZE 16
|
||||
|
||||
static int qemu_tcg_init_vcpu(CPUState *cpu)
|
||||
{
|
||||
struct uc_struct *uc = cpu->uc;
|
||||
char thread_name[VCPU_THREAD_NAME_SIZE];
|
||||
|
||||
tcg_cpu_address_space_init(cpu, cpu->as);
|
||||
|
||||
/* share a single thread for all cpus with TCG */
|
||||
if (!uc->tcg_cpu_thread) {
|
||||
cpu->thread = g_malloc0(sizeof(QemuThread));
|
||||
cpu->halt_cond = g_malloc0(sizeof(QemuCond));
|
||||
qemu_cond_init(cpu->halt_cond);
|
||||
uc->tcg_halt_cond = cpu->halt_cond;
|
||||
snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
|
||||
cpu->cpu_index);
|
||||
if (qemu_thread_create(uc, cpu->thread, thread_name, qemu_tcg_cpu_thread_fn,
|
||||
cpu, QEMU_THREAD_JOINABLE))
|
||||
return -1;
|
||||
#ifdef _WIN32
|
||||
cpu->hThread = qemu_thread_get_handle(cpu->thread);
|
||||
#endif
|
||||
while (!cpu->created) {
|
||||
qemu_cond_wait(&uc->qemu_cpu_cond, &uc->qemu_global_mutex);
|
||||
}
|
||||
uc->tcg_cpu_thread = cpu->thread;
|
||||
} else {
|
||||
cpu->thread = uc->tcg_cpu_thread;
|
||||
cpu->halt_cond = uc->tcg_halt_cond;
|
||||
}
|
||||
cpu->halt_cond = g_malloc0(sizeof(QemuCond));
|
||||
qemu_cond_init(cpu->halt_cond);
|
||||
uc->tcg_halt_cond = cpu->halt_cond;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user