execute cpus in same thread as uc_emu_start()

note: I'm sure this makes some dead code
This commit is contained in:
Ryan Hileman 2016-03-23 22:31:23 -07:00
parent 86823f53da
commit f0af8f8282
3 changed files with 8 additions and 37 deletions

View file

@ -38,17 +38,13 @@ static void cpu_handle_guest_debug(CPUState *cpu);
static int tcg_cpu_exec(struct uc_struct *uc, CPUArchState *env); static int tcg_cpu_exec(struct uc_struct *uc, CPUArchState *env);
static bool tcg_exec_all(struct uc_struct* uc); static bool tcg_exec_all(struct uc_struct* uc);
static int qemu_tcg_init_vcpu(CPUState *cpu); 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) int vm_start(struct uc_struct* uc)
{ {
if (resume_all_vcpus(uc)) { if (resume_all_vcpus(uc)) {
return -1; return -1;
} }
// kick off TCG thread
qemu_mutex_unlock_iothread(uc);
return 0; return 0;
} }
@ -99,7 +95,6 @@ int resume_all_vcpus(struct uc_struct *uc)
if (qemu_init_vcpu(cpu)) if (qemu_init_vcpu(cpu))
return -1; return -1;
} }
qemu_mutex_lock_iothread(uc);
} }
} }
@ -107,6 +102,7 @@ int resume_all_vcpus(struct uc_struct *uc)
CPU_FOREACH(cpu) { CPU_FOREACH(cpu) {
cpu_resume(cpu); cpu_resume(cpu);
} }
qemu_tcg_cpu_loop(uc);
return 0; return 0;
} }
@ -125,13 +121,11 @@ 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; CPUState *cpu;
struct uc_struct *uc = cpu->uc;
//qemu_tcg_init_cpu_signals(); //qemu_tcg_init_cpu_signals();
qemu_thread_get_self(uc, cpu->thread);
qemu_mutex_lock(&uc->qemu_global_mutex); qemu_mutex_lock(&uc->qemu_global_mutex);
CPU_FOREACH(cpu) { CPU_FOREACH(cpu) {
@ -140,23 +134,7 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
} }
qemu_cond_signal(&uc->qemu_cpu_cond); 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) { while (1) {
#if 0
int count = 0;
if (count < 10) {
count++;
unsigned int eip = X86_CPU(mycpu)->env.eip;
printf(">>> current EIP = %x\n", eip);
printf(">>> ECX = %x\n", (unsigned int)X86_CPU(mycpu)->env.regs[R_ECX]);
printf(">>> EDX = %x\n", (unsigned int)X86_CPU(mycpu)->env.regs[R_EDX]);
}
#endif
if (tcg_exec_all(uc)) if (tcg_exec_all(uc))
break; break;
} }
@ -191,15 +169,10 @@ static int qemu_tcg_init_vcpu(CPUState *cpu)
uc->tcg_halt_cond = cpu->halt_cond; uc->tcg_halt_cond = cpu->halt_cond;
snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
cpu->cpu_index); cpu->cpu_index);
if (qemu_thread_create(uc, cpu->thread, thread_name, qemu_tcg_cpu_thread_fn, qemu_thread_get_self(uc, cpu->thread);
cpu, QEMU_THREAD_JOINABLE))
return -1;
#ifdef _WIN32 #ifdef _WIN32
cpu->hThread = qemu_thread_get_handle(cpu->thread); cpu->hThread = qemu_thread_get_handle(cpu->thread);
#endif #endif
while (!cpu->created) {
qemu_cond_wait(&uc->qemu_cpu_cond, &uc->qemu_global_mutex);
}
uc->tcg_cpu_thread = cpu->thread; uc->tcg_cpu_thread = cpu->thread;
} else { } else {
cpu->thread = uc->tcg_cpu_thread; cpu->thread = uc->tcg_cpu_thread;

View file

@ -123,7 +123,6 @@ int machine_initialize(struct uc_struct *uc)
configure_accelerator(current_machine); configure_accelerator(current_machine);
qemu_init_cpu_loop(uc); qemu_init_cpu_loop(uc);
qemu_mutex_lock_iothread(uc);
current_machine->cpu_model = NULL; current_machine->cpu_model = NULL;

7
uc.c
View file

@ -559,14 +559,13 @@ uc_err uc_emu_start(uc_engine* uc, uint64_t begin, uint64_t until, uint64_t time
uc->addr_end = until; uc->addr_end = until;
if (timeout)
enable_emu_timer(uc, timeout * 1000); // microseconds -> nanoseconds
if (uc->vm_start(uc)) { if (uc->vm_start(uc)) {
return UC_ERR_RESOURCE; return UC_ERR_RESOURCE;
} }
if (timeout)
enable_emu_timer(uc, timeout * 1000); // microseconds -> nanoseconds
uc->pause_all_vcpus(uc);
// emulation is done // emulation is done
uc->emulation_done = true; uc->emulation_done = true;