From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:33605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QkDvM-0003lb-Ir for qemu-devel@nongnu.org; Fri, 22 Jul 2011 07:29:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QkDvL-0007cV-A5 for qemu-devel@nongnu.org; Fri, 22 Jul 2011 07:29:44 -0400 Received: from goliath.siemens.de ([192.35.17.28]:23317) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QkDvL-0007cA-1H for qemu-devel@nongnu.org; Fri, 22 Jul 2011 07:29:43 -0400 Message-ID: <4E295F23.8060508@siemens.com> Date: Fri, 22 Jul 2011 13:29:39 +0200 From: Jan Kiszka MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] Replace qemu_system_cond with VCPU stop mechanism List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel , Anthony Liguori Cc: Paolo Bonzini , Gleb Natapov We can express the VCPU thread wakeup with the stop mechanism, saving both qemu_system_ready and the qemu_system_cond. For KVM threads, we can just enter the main loop as long as the thread is stopped. The central TCG thread is better held back before the loop as there can be side effects of the services called even when all CPUs are stopped. Creating VCPUs in stopped state will also be required for proper CPU hotplugging support. Signed-off-by: Jan Kiszka --- cpus.c | 18 +++++------------- 1 files changed, 5 insertions(+), 13 deletions(-) diff --git a/cpus.c b/cpus.c index 0e54d6b..7a83bdf 100644 --- a/cpus.c +++ b/cpus.c @@ -643,11 +643,9 @@ static QemuThread io_thread; static QemuThread *tcg_cpu_thread; static QemuCond *tcg_halt_cond; -static int qemu_system_ready; /* cpu creation */ static QemuCond qemu_cpu_cond; /* system init */ -static QemuCond qemu_system_cond; static QemuCond qemu_pause_cond; static QemuCond qemu_work_cond; @@ -669,7 +667,6 @@ int qemu_init_main_loop(void) } qemu_cond_init(&qemu_cpu_cond); - qemu_cond_init(&qemu_system_cond); qemu_cond_init(&qemu_pause_cond); qemu_cond_init(&qemu_work_cond); qemu_mutex_init(&qemu_fair_mutex); @@ -683,8 +680,7 @@ int qemu_init_main_loop(void) void qemu_main_loop_start(void) { - qemu_system_ready = 1; - qemu_cond_broadcast(&qemu_system_cond); + resume_all_vcpus(); } void run_on_cpu(CPUState *env, void (*func)(void *data), void *data) @@ -803,11 +799,6 @@ static void *qemu_kvm_cpu_thread_fn(void *arg) env->created = 1; qemu_cond_signal(&qemu_cpu_cond); - /* and wait for machine initialization */ - while (!qemu_system_ready) { - qemu_cond_wait(&qemu_system_cond, &qemu_global_mutex); - } - while (1) { if (cpu_can_run(env)) { r = kvm_cpu_exec(env); @@ -836,9 +827,9 @@ static void *qemu_tcg_cpu_thread_fn(void *arg) } qemu_cond_signal(&qemu_cpu_cond); - /* and wait for machine initialization */ - while (!qemu_system_ready) { - qemu_cond_wait(&qemu_system_cond, &qemu_global_mutex); + /* wait for initial kick-off after machine start */ + while (!first_cpu->stopped) { + qemu_cond_wait(tcg_halt_cond, &qemu_global_mutex); } while (1) { @@ -1006,6 +997,7 @@ void qemu_init_vcpu(void *_env) env->nr_cores = smp_cores; env->nr_threads = smp_threads; + env->stopped = 1; if (kvm_enabled()) { qemu_kvm_start_vcpu(env); } else { -- 1.7.3.4