From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LkJpF-0007s5-Sj for qemu-devel@nongnu.org; Thu, 19 Mar 2009 11:06:29 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LkJpB-0007pk-8Y for qemu-devel@nongnu.org; Thu, 19 Mar 2009 11:06:29 -0400 Received: from [199.232.76.173] (port=51967 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LkJpA-0007pf-Vg for qemu-devel@nongnu.org; Thu, 19 Mar 2009 11:06:25 -0400 Received: from mx2.redhat.com ([66.187.237.31]:36011) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LkJpA-0005vu-AY for qemu-devel@nongnu.org; Thu, 19 Mar 2009 11:06:24 -0400 Message-Id: <20090319150538.014041718@localhost.localdomain> References: <20090319145705.988576615@localhost.localdomain> Date: Thu, 19 Mar 2009 11:57:08 -0300 From: mtosatti@redhat.com Content-Disposition: inline; filename=vcpus-on-thread Subject: [Qemu-devel] [patch 3/7] qemu: main thread does io and cpu thread is spawned Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Index: qemu/vl.c =================================================================== --- qemu.orig/vl.c +++ qemu/vl.c @@ -3623,12 +3623,13 @@ static int wait_signal(int timeout) static int has_work(CPUState *env) { - int r = 0; + if (!vm_running) + return 0; if (!env->halted) - r = 1; + return 1; if (env->interrupt_request & (CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI)) - r = 1; - return r; + return 1; + return 0; } static void qemu_wait_io_event(CPUState *env, int timeout) @@ -3737,14 +3738,6 @@ void main_loop_break(void) qemu_thread_signal(&io_thread, SIG_IPI); } -static void *io_thread_fn(void *arg) -{ - unblock_io_signals(); - qemu_mutex_lock(&qemu_global_mutex); - while (1) - main_loop_wait(1000); -} - static void qemu_signal_lock(unsigned int msecs) { qemu_mutex_lock(&qemu_fair_mutex); @@ -3842,9 +3835,11 @@ void main_loop_wait(int timeout) #endif /* vm time timers */ - if (vm_running && likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER))) - qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL], - qemu_get_clock(vm_clock)); + if (vm_running) { + if (cur_cpu && likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER))) + qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL], + qemu_get_clock(vm_clock)); + } /* real time timers */ qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME], @@ -3856,7 +3851,7 @@ void main_loop_wait(int timeout) } -static int main_loop(void) +static void *cpu_main_loop(void *arg) { int ret, timeout; #ifdef CONFIG_PROFILER @@ -3864,15 +3859,11 @@ static int main_loop(void) #endif CPUState *env; - qemu_mutex_init(&qemu_fair_mutex); - qemu_mutex_init(&qemu_global_mutex); - qemu_mutex_lock(&qemu_global_mutex); - - qemu_thread_create(&io_thread, io_thread_fn, NULL); block_io_signals(); - qemu_thread_self(&cpus_thread); + qemu_mutex_lock(&qemu_global_mutex); + cur_cpu = first_cpu; next_cpu = cur_cpu->next_cpu ?: first_cpu; for(;;) { @@ -4011,7 +4002,23 @@ static int main_loop(void) #endif } cpu_disable_ticks(); - return ret; + return NULL; +} + +static void main_loop(void) +{ + qemu_mutex_init(&qemu_fair_mutex); + qemu_mutex_init(&qemu_global_mutex); + qemu_mutex_lock(&qemu_global_mutex); + + qemu_thread_self(&io_thread); + + unblock_io_signals(); + + qemu_thread_create(&cpus_thread, cpu_main_loop, NULL); + + while (1) + main_loop_wait(1000); } static void help(int exitcode) --