From patchwork Wed Feb 9 15:29:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 82478 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 07D7BB70EA for ; Thu, 10 Feb 2011 02:32:29 +1100 (EST) Received: from localhost ([127.0.0.1]:39310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PnC1p-00010w-Ro for incoming@patchwork.ozlabs.org; Wed, 09 Feb 2011 10:32:25 -0500 Received: from [140.186.70.92] (port=49586 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PnBzC-0008Py-Ux for qemu-devel@nongnu.org; Wed, 09 Feb 2011 10:29:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PnBzB-00083a-JI for qemu-devel@nongnu.org; Wed, 09 Feb 2011 10:29:42 -0500 Received: from thoth.sbs.de ([192.35.17.2]:16410) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PnBzB-000834-7k for qemu-devel@nongnu.org; Wed, 09 Feb 2011 10:29:41 -0500 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.13.6/8.13.6) with ESMTP id p19FTc3s014724; Wed, 9 Feb 2011 16:29:38 +0100 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id p19FTcg3015473; Wed, 9 Feb 2011 16:29:38 +0100 Message-ID: <4D52B2E1.70806@siemens.com> Date: Wed, 09 Feb 2011 16:29:37 +0100 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: Avi Kivity , Marcelo Tosatti References: <1e7a4f5097aafb5da844c1b9ff8661539d0d10e8.1297077506.git.jan.kiszka@siemens.com> In-Reply-To: <1e7a4f5097aafb5da844c1b9ff8661539d0d10e8.1297077506.git.jan.kiszka@siemens.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.35.17.2 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH v2 02/15] Refactor cpu_has_work/any_cpu_has_work in cpus.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Avoid duplicate use of the function name cpu_has_work, it's confusing, also their scope. Refactor cpu_has_work to cpu_thread_is_idle and do the same with any_cpu_has_work. Signed-off-by: Jan Kiszka --- Changes in v2: - renaming: cpu_thread_is_idle and all_cpu_threads_idle cpus.c | 43 +++++++++++++++++++++++-------------------- 1 files changed, 23 insertions(+), 20 deletions(-) diff --git a/cpus.c b/cpus.c index d54ec7d..e963208 100644 --- a/cpus.c +++ b/cpus.c @@ -137,29 +137,30 @@ static int cpu_can_run(CPUState *env) return 1; } -static int cpu_has_work(CPUState *env) +static bool cpu_thread_is_idle(CPUState *env) { - if (env->stop) - return 1; - if (env->queued_work_first) - return 1; - if (env->stopped || !vm_running) - return 0; - if (!env->halted) - return 1; - if (qemu_cpu_has_work(env)) - return 1; - return 0; + if (env->stop || env->queued_work_first) { + return false; + } + if (env->stopped || !vm_running) { + return true; + } + if (!env->halted || qemu_cpu_has_work(env)) { + return false; + } + return true; } -static int any_cpu_has_work(void) +static bool all_cpu_threads_idle(void) { CPUState *env; - for (env = first_cpu; env != NULL; env = env->next_cpu) - if (cpu_has_work(env)) - return 1; - return 0; + for (env = first_cpu; env != NULL; env = env->next_cpu) { + if (!cpu_thread_is_idle(env)) { + return false; + } + } + return true; } static void cpu_debug_handler(CPUState *env) @@ -743,8 +744,9 @@ static void qemu_tcg_wait_io_event(void) { CPUState *env; - while (!any_cpu_has_work()) + while (all_cpu_threads_idle()) { qemu_cond_timedwait(tcg_halt_cond, &qemu_global_mutex, 1000); + } qemu_mutex_unlock(&qemu_global_mutex); @@ -765,8 +767,9 @@ static void qemu_tcg_wait_io_event(void) static void qemu_kvm_wait_io_event(CPUState *env) { - while (!cpu_has_work(env)) + while (cpu_thread_is_idle(env)) { qemu_cond_timedwait(env->halt_cond, &qemu_global_mutex, 1000); + } qemu_kvm_eat_signals(env); qemu_wait_io_event_common(env); @@ -1070,7 +1073,7 @@ bool cpu_exec_all(void) } } exit_request = 0; - return any_cpu_has_work(); + return !all_cpu_threads_idle(); } void set_numa_modes(void)