Improve Decrementor Implementation v2
Subsystems (3)
cover Improve Decrementor Implementation v2
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(-)
A message that is not in the archive (sent off-list or not yet received): 1261423285-12715-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org
PATCH 1/3 Move vector to irqprio resolving to separate function
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.
--- arch/powerpc/kvm/book3s.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)
arch/powerpc/kvm/book3s.c +10 -3
@@ -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
Signature · 1 line
1.6.0.2
PATCH 2/3 Improve DEC handling
In reply to a message not in the archiveWe 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.
---
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(-)
arch/powerpc/include/asm/kvm_ppc.h +1 -0
@@ -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);
arch/powerpc/kvm/book3s.c +15 -1
@@ -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 ; }
arch/powerpc/kvm/booke.c +5 -0
@@ -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) {
arch/powerpc/kvm/emulate.c +3 -0
@@ -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);
Signature · 1 line
1.6.0.2
PATCH 3/3 Remove AGGRESSIVE_DEC
In reply to a message not in the archiveBecause 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.
--- arch/powerpc/kvm/book3s.c | 16 +--------------- 1 files changed, 1 insertions(+), 15 deletions(-)
arch/powerpc/kvm/book3s.c +1 -15
@@ -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);
Signature · 1 line
1.6.0.2
Avi Kivity
AppliedQuoted 6 lines · Alexander Graf
We currently have an ugly hack called
AGGRESSIVE_DECthat 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.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 16 lines · Alexander Graf
We currently have an ugly hack called
AGGRESSIVE_DECthat 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 -> dequeueAlexander Graf (3):
Move vector to irqprio resolving to separate function Improve DEC handling
RemoveAGGRESSIVE_DEC
Quoted 5 lines
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(-)