public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Jerone Young <jyoung5@us.ibm.com>
To: kvm-devel@lists.sourceforge.net
Cc: kvm-ppc-devel@lists.sourceforge.net
Subject: [PATCH 2 of 2] Add PowerPC KVM guest wait handling support
Date: Fri, 25 Apr 2008 14:19:00 -0500	[thread overview]
Message-ID: <219785bbee06d6f20ec3.1209151140@thinkpadL> (raw)
In-Reply-To: <patchbomb.1209151138@thinkpadL>

2 files changed, 23 insertions(+), 3 deletions(-)
arch/powerpc/kvm/emulate.c |   14 ++++++++++++++
arch/powerpc/kvm/powerpc.c |   12 +++++++++---


This patch handles a guest that is in a wait state & wake up guest that end up being recheduled and go to sleep. This ensures that the guest is not allways eating up 100% cpu when it is idle.

Signed-off-by: Jerone Young <jyoung5@us.ibm.com>

diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -235,6 +235,13 @@ int kvmppc_emulate_instruction(struct kv
 		case 50:                                        /* rfi */
 			kvmppc_emul_rfi(vcpu);
 			advance = 0;
+			
+			/* Handle guest vcpu that is in wait state. 
+ 			 * This will implicitly wake up when it is ready.
+ 			 */
+			if (vcpu->arch.msr & MSR_WE) {
+				kvm_vcpu_block(vcpu);
+			}
 			break;
 
 		default:
@@ -265,6 +272,13 @@ int kvmppc_emulate_instruction(struct kv
 		case 146:                                       /* mtmsr */
 			rs = get_rs(inst);
 			kvmppc_set_msr(vcpu, vcpu->arch.gpr[rs]);
+			
+			/* Handle guest vcpu that is in wait state
+			 * This will implicitly wake up when it is ready.
+ 			 */
+			if (vcpu->arch.msr & MSR_WE) {
+				kvm_vcpu_block(vcpu);
+			}
 			break;
 
 		case 163:                                       /* wrteei */
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
@@ -36,13 +36,12 @@ gfn_t unalias_gfn(struct kvm *kvm, gfn_t
 
 int kvm_cpu_has_interrupt(struct kvm_vcpu *v)
 {
-	/* XXX implement me */
-	return 0;
+	return !!(v->arch.pending_exceptions);
 }
 
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-	return 1;
+	return !(v->arch.msr & MSR_WE);
 }
 
 
@@ -213,6 +212,9 @@ static void kvmppc_decrementer_func(unsi
 {
 	struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
 
+	if (waitqueue_active(&vcpu->wq))
+		wake_up_interruptible(&vcpu->wq);
+
 	kvmppc_queue_exception(vcpu, BOOKE_INTERRUPT_DECREMENTER);
 }
 
@@ -339,6 +341,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_v
 	int r;
 	sigset_t sigsaved;
 
+	vcpu_load(vcpu);
+
 	if (vcpu->sigset_active)
 		sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
 
@@ -362,6 +366,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_v
 
 	if (vcpu->sigset_active)
 		sigprocmask(SIG_SETMASK, &sigsaved, NULL);
+
+	vcpu_put(vcpu);
 
 	return r;
 }

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone

      parent reply	other threads:[~2008-04-25 19:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-25 19:18 [PATCH 0 of 2] [v2] Fix guest eating 100% cpu when guest is idle on PowerPC Jerone Young
2008-04-25 19:18 ` [PATCH 1 of 2] Add idle wait support for 44x platforms Jerone Young
2008-04-25 19:19 ` Jerone Young [this message]

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=219785bbee06d6f20ec3.1209151140@thinkpadL \
    --to=jyoung5@us.ibm.com \
    --cc=kvm-devel@lists.sourceforge.net \
    --cc=kvm-ppc-devel@lists.sourceforge.net \
    /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