public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] Improve Decrementor Implementation v2
@ 2009-12-21 19:21 Alexander Graf
       [not found] ` <1261423285-12715-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
  2009-12-21 23:21 ` Hollis Blanchard
  0 siblings, 2 replies; 6+ messages in thread
From: Alexander Graf @ 2009-12-21 19:21 UTC (permalink / raw)
  To: kvm-ppc; +Cc: kvm, hollis

We currently have an ugly hack called AGGRESSIVE_DEC that makes the Decrementor
either work well for PPC32 or PPC64 targets.

This patchset removes that hack, bringing the decrementor implementation closer
to real hardware.

V1 -> V2:

  - make DEC clearing code on mtdec book3s specific
  - rename stop -> dequeue

Alexander Graf (3):
  Move vector to irqprio resolving to separate function
  Improve DEC handling
  Remove AGGRESSIVE_DEC

 arch/powerpc/include/asm/kvm_ppc.h |    1 +
 arch/powerpc/kvm/book3s.c          |   45 ++++++++++++++++++++---------------
 arch/powerpc/kvm/booke.c           |    5 ++++
 arch/powerpc/kvm/emulate.c         |    3 ++
 4 files changed, 35 insertions(+), 19 deletions(-)


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] Move vector to irqprio resolving to separate function
       [not found] ` <1261423285-12715-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
@ 2009-12-21 19:21   ` Alexander Graf
  2009-12-21 19:21   ` [PATCH 2/3] Improve DEC handling Alexander Graf
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Alexander Graf @ 2009-12-21 19:21 UTC (permalink / raw)
  To: kvm-ppc-u79uwXL29TY76Z2rM5mHXA
  Cc: kvm-u79uwXL29TY76Z2rM5mHXA, hollis-yUx37fBWTUITNcAmw9vGhQ

We're using a switch table to find the irqprio that belongs to a specific
interrupt vector. This table is part of the interrupt inject logic.

Since we'll add a new function to stop interrupts, let's move this table
out of the injection logic into a separate function.

Signed-off-by: Alexander Graf <agraf-l3A5Bk7waGM@public.gmane.org>
---
 arch/powerpc/kvm/book3s.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 3e294bd..241795b 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -125,11 +125,10 @@ void kvmppc_inject_interrupt(struct kvm_vcpu *vcpu, int vec, u64 flags)
 	vcpu->arch.mmu.reset_msr(vcpu);
 }
 
-void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec)
+static int kvmppc_book3s_vec2irqprio(unsigned int vec)
 {
 	unsigned int prio;
 
-	vcpu->stat.queue_intr++;
 	switch (vec) {
 	case 0x100: prio = BOOK3S_IRQPRIO_SYSTEM_RESET;		break;
 	case 0x200: prio = BOOK3S_IRQPRIO_MACHINE_CHECK;	break;
@@ -149,7 +148,15 @@ void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec)
 	default:    prio = BOOK3S_IRQPRIO_MAX;			break;
 	}
 
-	set_bit(prio, &vcpu->arch.pending_exceptions);
+	return prio;
+}
+
+void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec)
+{
+	vcpu->stat.queue_intr++;
+
+	set_bit(kvmppc_book3s_vec2irqprio(vec),
+		&vcpu->arch.pending_exceptions);
 #ifdef EXIT_DEBUG
 	printk(KERN_INFO "Queueing interrupt %x\n", vec);
 #endif
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] Improve DEC handling
       [not found] ` <1261423285-12715-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
  2009-12-21 19:21   ` [PATCH 1/3] Move vector to irqprio resolving to separate function Alexander Graf
@ 2009-12-21 19:21   ` Alexander Graf
  2009-12-21 19:21   ` [PATCH 3/3] Remove AGGRESSIVE_DEC Alexander Graf
  2009-12-22 10:04   ` [PATCH 0/3] Improve Decrementor Implementation v2 Avi Kivity
  3 siblings, 0 replies; 6+ messages in thread
From: Alexander Graf @ 2009-12-21 19:21 UTC (permalink / raw)
  To: kvm-ppc-u79uwXL29TY76Z2rM5mHXA
  Cc: kvm-u79uwXL29TY76Z2rM5mHXA, hollis-yUx37fBWTUITNcAmw9vGhQ

We treated the DEC interrupt like an edge based one. This is not true for
Book3s. The DEC keeps firing until mtdec is issued again and thus clears
the interrupt line.

So let's implement this logic in KVM too. This patch moves the line clearing
from the firing of the interrupt to the mtdec emulation.

This makes PPC64 guests work without AGGRESSIVE_DEC defined.

Signed-off-by: Alexander Graf <agraf-l3A5Bk7waGM@public.gmane.org>

---

V1 -> V2:

  - make DEC clearing code on mtdec book3s specific
  - rename stop -> dequeue
---
 arch/powerpc/include/asm/kvm_ppc.h |    1 +
 arch/powerpc/kvm/book3s.c          |   16 +++++++++++++++-
 arch/powerpc/kvm/booke.c           |    5 +++++
 arch/powerpc/kvm/emulate.c         |    3 +++
 4 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
index 269ee46..abfd0c4 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -82,6 +82,7 @@ extern void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu);
 extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu);
 extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu);
 extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu);
+extern void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu);
 extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
                                        struct kvm_interrupt *irq);
 
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 241795b..fd3ad6c 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -151,6 +151,13 @@ static int kvmppc_book3s_vec2irqprio(unsigned int vec)
 	return prio;
 }
 
+static void kvmppc_book3s_dequeue_irqprio(struct kvm_vcpu *vcpu,
+					  unsigned int vec)
+{
+	clear_bit(kvmppc_book3s_vec2irqprio(vec),
+		  &vcpu->arch.pending_exceptions);
+}
+
 void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec)
 {
 	vcpu->stat.queue_intr++;
@@ -178,6 +185,11 @@ int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu)
 	return test_bit(BOOK3S_INTERRUPT_DECREMENTER >> 7, &vcpu->arch.pending_exceptions);
 }
 
+void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu)
+{
+	kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_DECREMENTER);
+}
+
 void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
                                 struct kvm_interrupt *irq)
 {
@@ -275,7 +287,9 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
 #endif
 	priority = __ffs(*pending);
 	while (priority <= (sizeof(unsigned int) * 8)) {
-		if (kvmppc_book3s_irqprio_deliver(vcpu, priority)) {
+		if (kvmppc_book3s_irqprio_deliver(vcpu, priority) &&
+		    (priority != BOOK3S_IRQPRIO_DECREMENTER)) {
+			/* DEC interrupts get cleared by mtdec */
 			clear_bit(priority, &vcpu->arch.pending_exceptions);
 			break;
 		}
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 06f5a9e..d8b6342 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -97,6 +97,11 @@ int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu)
 	return test_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
 }
 
+void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu)
+{
+	clear_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
+}
+
 void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
                                 struct kvm_interrupt *irq)
 {
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 4a9ac66..303457b 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -83,6 +83,9 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
 
 	pr_debug("mtDEC: %x\n", vcpu->arch.dec);
 #ifdef CONFIG_PPC64
+	/* mtdec lowers the interrupt line when positive. */
+	kvmppc_core_dequeue_dec(vcpu);
+
 	/* POWER4+ triggers a dec interrupt if the value is < 0 */
 	if (vcpu->arch.dec & 0x80000000) {
 		hrtimer_try_to_cancel(&vcpu->arch.dec_timer);
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] Remove AGGRESSIVE_DEC
       [not found] ` <1261423285-12715-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
  2009-12-21 19:21   ` [PATCH 1/3] Move vector to irqprio resolving to separate function Alexander Graf
  2009-12-21 19:21   ` [PATCH 2/3] Improve DEC handling Alexander Graf
@ 2009-12-21 19:21   ` Alexander Graf
  2009-12-22 10:04   ` [PATCH 0/3] Improve Decrementor Implementation v2 Avi Kivity
  3 siblings, 0 replies; 6+ messages in thread
From: Alexander Graf @ 2009-12-21 19:21 UTC (permalink / raw)
  To: kvm-ppc-u79uwXL29TY76Z2rM5mHXA
  Cc: kvm-u79uwXL29TY76Z2rM5mHXA, hollis-yUx37fBWTUITNcAmw9vGhQ

Because we now emulate the DEC interrupt according to real life behavior,
there's no need to keep the AGGRESSIVE_DEC hack around.

Let's just remove it.

Signed-off-by: Alexander Graf <agraf-l3A5Bk7waGM@public.gmane.org>
---
 arch/powerpc/kvm/book3s.c |   16 +---------------
 1 files changed, 1 insertions(+), 15 deletions(-)

diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index fd3ad6c..803505d 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -34,12 +34,6 @@
 /* #define EXIT_DEBUG */
 /* #define EXIT_DEBUG_SIMPLE */
 
-/* Without AGGRESSIVE_DEC we only fire off a DEC interrupt when DEC turns 0.
- * When set, we retrigger a DEC interrupt after that if DEC <= 0.
- * PPC32 Linux runs faster without AGGRESSIVE_DEC, PPC64 Linux requires it. */
-
-/* #define AGGRESSIVE_DEC */
-
 struct kvm_stats_debugfs_item debugfs_entries[] = {
 	{ "exits",       VCPU_STAT(sum_exits) },
 	{ "mmio",        VCPU_STAT(mmio_exits) },
@@ -81,7 +75,7 @@ void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
 	to_book3s(vcpu)->slb_shadow_max = get_paca()->kvm_slb_max;
 }
 
-#if defined(AGGRESSIVE_DEC) || defined(EXIT_DEBUG)
+#if defined(EXIT_DEBUG)
 static u32 kvmppc_get_dec(struct kvm_vcpu *vcpu)
 {
 	u64 jd = mftb() - vcpu->arch.dec_jiffies;
@@ -273,14 +267,6 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
 	unsigned long *pending = &vcpu->arch.pending_exceptions;
 	unsigned int priority;
 
-	/* XXX be more clever here - no need to mftb() on every entry */
-	/* Issue DEC again if it's still active */
-#ifdef AGGRESSIVE_DEC
-	if (vcpu->arch.msr & MSR_EE)
-		if (kvmppc_get_dec(vcpu) & 0x80000000)
-			kvmppc_core_queue_dec(vcpu);
-#endif
-
 #ifdef EXIT_DEBUG
 	if (vcpu->arch.pending_exceptions)
 		printk(KERN_EMERG "KVM: Check pending: %lx\n", vcpu->arch.pending_exceptions);
-- 
1.6.0.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Improve Decrementor Implementation v2
  2009-12-21 19:21 [PATCH 0/3] Improve Decrementor Implementation v2 Alexander Graf
       [not found] ` <1261423285-12715-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
@ 2009-12-21 23:21 ` Hollis Blanchard
  1 sibling, 0 replies; 6+ messages in thread
From: Hollis Blanchard @ 2009-12-21 23:21 UTC (permalink / raw)
  To: Alexander Graf; +Cc: kvm-ppc, kvm

On Mon, Dec 21, 2009 at 11:21 AM, Alexander Graf <agraf@suse.de> wrote:
> We currently have an ugly hack called AGGRESSIVE_DEC that makes the Decrementor
> either work well for PPC32 or PPC64 targets.
>
> This patchset removes that hack, bringing the decrementor implementation closer
> to real hardware.
>
> V1 -> V2:
>
>  - make DEC clearing code on mtdec book3s specific
>  - rename stop -> dequeue
>
> Alexander Graf (3):
>  Move vector to irqprio resolving to separate function
>  Improve DEC handling
>  Remove AGGRESSIVE_DEC
>
>  arch/powerpc/include/asm/kvm_ppc.h |    1 +
>  arch/powerpc/kvm/book3s.c          |   45 ++++++++++++++++++++---------------
>  arch/powerpc/kvm/booke.c           |    5 ++++
>  arch/powerpc/kvm/emulate.c         |    3 ++
>  4 files changed, 35 insertions(+), 19 deletions(-)

Acked-by: Hollis Blanchard <hollis@penguinppc.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] Improve Decrementor Implementation v2
       [not found] ` <1261423285-12715-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
                     ` (2 preceding siblings ...)
  2009-12-21 19:21   ` [PATCH 3/3] Remove AGGRESSIVE_DEC Alexander Graf
@ 2009-12-22 10:04   ` Avi Kivity
  3 siblings, 0 replies; 6+ messages in thread
From: Avi Kivity @ 2009-12-22 10:04 UTC (permalink / raw)
  To: Alexander Graf
  Cc: kvm-ppc-u79uwXL29TY76Z2rM5mHXA, kvm-u79uwXL29TY76Z2rM5mHXA,
	hollis-yUx37fBWTUITNcAmw9vGhQ

On 12/21/2009 09:21 PM, Alexander Graf wrote:
> We currently have an ugly hack called AGGRESSIVE_DEC that makes the Decrementor
> either work well for PPC32 or PPC64 targets.
>
> This patchset removes that hack, bringing the decrementor implementation closer
> to real hardware.
>    

Applied, thanks.

-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-12-22 10:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-21 19:21 [PATCH 0/3] Improve Decrementor Implementation v2 Alexander Graf
     [not found] ` <1261423285-12715-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
2009-12-21 19:21   ` [PATCH 1/3] Move vector to irqprio resolving to separate function Alexander Graf
2009-12-21 19:21   ` [PATCH 2/3] Improve DEC handling Alexander Graf
2009-12-21 19:21   ` [PATCH 3/3] Remove AGGRESSIVE_DEC Alexander Graf
2009-12-22 10:04   ` [PATCH 0/3] Improve Decrementor Implementation v2 Avi Kivity
2009-12-21 23:21 ` Hollis Blanchard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox