From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] Cleanup cpu loop Date: Mon, 22 Jun 2009 16:30:51 +0300 Message-ID: <4A3F878B.9080406@redhat.com> References: <20090618122228.GE20289@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: Gleb Natapov Return-path: Received: from mx2.redhat.com ([66.187.237.31]:51668 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750936AbZFVNaH (ORCPT ); Mon, 22 Jun 2009 09:30:07 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5MDU9BU023347 for ; Mon, 22 Jun 2009 09:30:09 -0400 In-Reply-To: <20090618122228.GE20289@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 06/18/2009 03:22 PM, Gleb Natapov wrote: > Rearrange cpu loop to be (hopefully) more readable. Put difference > between kernel/userspace irqchip in one place. > > > static void flush_queued_work(CPUState *env) > @@ -1877,6 +1871,8 @@ static void update_regs_for_init(CPUState *env) > #endif > > cpu_reset(env); > + /* cpu_reset() clears env->halted, cpu should be halted after init */ > + env->halted = 1; > How does that work for the boot cpu? > static int kvm_main_loop_cpu(CPUState *env) > { > setup_kernel_sigmask(env); > @@ -1935,19 +1941,14 @@ static int kvm_main_loop_cpu(CPUState *env) > kvm_arch_load_regs(env); > > while (1) { > - while (!has_work(env)) > - kvm_main_loop_wait(env, 1000); > - if (env->interrupt_request& (CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI)) > - env->halted = 0; > - if (!kvm_irqchip_in_kernel(kvm_context)) { > - if (env->kvm_cpu_state.init) > - update_regs_for_init(env); > - if (env->kvm_cpu_state.sipi_needed) > - update_regs_for_sipi(env); > + int run_cpu = is_cpu_stopped(env) ? 0 : 1; > run_cpu = !is_cpu_stopped() > + if (run_cpu&& !kvm_irqchip_in_kernel(kvm_context)) { > + process_irqchip_events(env); > + run_cpu = !env->halted; > } > - if (!env->halted || kvm_irqchip_in_kernel(kvm_context)) > - kvm_cpu_exec(env); > - kvm_main_loop_wait(env, 0); > + kvm_main_loop_wait(env, run_cpu ? 0 : 1000); > + if (run_cpu) > + kvm_cpu_exec(env); > } > A single conditional may be clearer: if (run_cpu) kvm_main_loop_wait(0) kvm_cpu_exec() else kvm_main_loop_wait(1000) -- error compiling committee.c: too many arguments to function