public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] Cleanup cpu loop
Date: Mon, 22 Jun 2009 16:30:51 +0300	[thread overview]
Message-ID: <4A3F878B.9080406@redhat.com> (raw)
In-Reply-To: <20090618122228.GE20289@redhat.com>

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


  reply	other threads:[~2009-06-22 13:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-18 12:22 [PATCH] Cleanup cpu loop Gleb Natapov
2009-06-22 13:30 ` Avi Kivity [this message]
2009-06-22 13:41   ` Gleb Natapov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A3F878B.9080406@redhat.com \
    --to=avi@redhat.com \
    --cc=gleb@redhat.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox