From patchwork Sat Jul 23 10:40:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 106430 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6DECCB6F70 for ; Sat, 23 Jul 2011 20:40:20 +1000 (EST) Received: from localhost ([::1]:34624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QkZcy-00061D-QE for incoming@patchwork.ozlabs.org; Sat, 23 Jul 2011 06:40:12 -0400 Received: from eggs.gnu.org ([140.186.70.92]:51001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QkZct-0005zF-74 for qemu-devel@nongnu.org; Sat, 23 Jul 2011 06:40:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QkZcr-00047V-OD for qemu-devel@nongnu.org; Sat, 23 Jul 2011 06:40:07 -0400 Received: from fmmailgate02.web.de ([217.72.192.227]:46504) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QkZcr-00046D-C6 for qemu-devel@nongnu.org; Sat, 23 Jul 2011 06:40:05 -0400 Received: from smtp02.web.de ( [172.20.0.184]) by fmmailgate02.web.de (Postfix) with ESMTP id 971641A7095E3; Sat, 23 Jul 2011 12:40:04 +0200 (CEST) Received: from [88.64.2.82] (helo=mchn199C.mchp.siemens.de) by smtp02.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #2) id 1QkZcq-0006Fa-00; Sat, 23 Jul 2011 12:40:04 +0200 Message-ID: <4E2AA504.9000205@web.de> Date: Sat, 23 Jul 2011 12:40:04 +0200 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: qemu-devel , Anthony Liguori References: <4E295F23.8060508@siemens.com> In-Reply-To: <4E295F23.8060508@siemens.com> X-Enigmail-Version: 1.2 X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX1+cURrolQwZZNxrHPovP8VAfipcsPyw/wFfSyNG +xBcq9Loa/6yCTjX471V1k0GIUt2+Jn7wYwrpF4L2Zmw67OqRe yoaf5bL0s= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 217.72.192.227 Cc: Paolo Bonzini , Gleb Natapov Subject: [Qemu-devel] [PATCH v2] Replace qemu_system_cond with VCPU stop mechanism X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jan Kiszka 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 --- Changes in v2: - move tcg_halt_cond initialization to avoid crash in tcg mode cpus.c | 20 ++++++-------------- 1 files changed, 6 insertions(+), 14 deletions(-) diff --git a/cpus.c b/cpus.c index 0e54d6b..04c1278 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) { @@ -977,12 +968,12 @@ static void qemu_tcg_init_vcpu(void *_env) env->thread = qemu_mallocz(sizeof(QemuThread)); env->halt_cond = qemu_mallocz(sizeof(QemuCond)); qemu_cond_init(env->halt_cond); + tcg_halt_cond = env->halt_cond; qemu_thread_create(env->thread, qemu_tcg_cpu_thread_fn, env); while (env->created == 0) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); } tcg_cpu_thread = env->thread; - tcg_halt_cond = env->halt_cond; } else { env->thread = tcg_cpu_thread; env->halt_cond = tcg_halt_cond; @@ -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 {