From: Jerone Young Date: Wed, 02 Apr 2008 07:52:02 +0000 Subject: [kvm-ppc-devel] [PATCH 2 of 2] Add PowerPC KVM guest wait handling Message-Id: <37ac8b0137fecb4207ba.1207122722@thinkpadL> List-Id: References: <21179d0ab8a62ecc24d1.1206740047@thinkpadL> In-Reply-To: <21179d0ab8a62ecc24d1.1206740047@thinkpadL> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: kvm-ppc@vger.kernel.org # HG changeset patch # User Jerone Young # Date 1207122433 18000 # Node ID 37ac8b0137fecb4207bac52881b64a3ec5374a03 # Parent 6e9ae9e1e5992339ca1f3efa93f8200cf24cbee5 Add PowerPC KVM guest wait handling support This patch handles a guest that is in a wait state. This ensures that the guest is not allways eating up 100% cpu when it is idle. Signed-off-by: Jerone Young diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -164,13 +164,12 @@ void kvmppc_dump_vcpu(struct kvm_vcpu *v int kvm_cpu_has_interrupt(struct kvm_vcpu *v) { - /* XXX implement me */ - return 0; + return v->arch.pending_exceptions ? 1 : 0; } int kvm_arch_vcpu_runnable(struct kvm_vcpu *v) { - return 1; + return (v->arch.msr & MSR_WE) ? 0 : 1; } /* Check if we are ready to deliver the interrupt */ @@ -214,6 +213,10 @@ static void kvmppc_deliver_interrupt(str vcpu->arch.tsr |= TSR_DIS; break; } + + /* clear guest wait state */ + if (vcpu->arch.msr & MSR_WE) + vcpu->arch.msr &= ~MSR_WE; vcpu->arch.srr0 = vcpu->arch.pc; vcpu->arch.srr1 = vcpu->arch.msr; @@ -452,6 +455,25 @@ int kvmppc_handle_exit(struct kvm_run *r local_irq_disable(); kvmppc_check_and_deliver_interrupts(vcpu); + + /* handle guest vcpu that is in wait state */ + /* XXX eventually replace with kvm_vcpu_block() */ + if (vcpu->arch.msr & MSR_WE) { + DECLARE_WAITQUEUE(wait, current); + + add_wait_queue(&vcpu->wq, &wait); + + while (!kvm_cpu_has_interrupt(vcpu) + && !signal_pending(current) + && !kvm_arch_vcpu_runnable(vcpu)) { + + set_current_state(TASK_INTERRUPTIBLE); + schedule(); + } + + __set_current_state(TASK_RUNNING); + remove_wait_queue(&vcpu->wq, &wait); + } /* Do some exit accounting. */ vcpu->stat.exits++; ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace _______________________________________________ kvm-ppc-devel mailing list kvm-ppc-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/kvm-ppc-devel