kvmppc: optimize irq delivery path
Subsystems (2)
PATCH 1/3 kvmppc: optimize irq delivery path
From: Christian Ehrhardt <[email protected]>
In kvmppc_deliver_interrupt is just one case left in the switch and it is a rare one (less than 8%) when looking at the exit numbers. Therefore we can at least drop the switch/case and if an if. I inserted an unlikely too, but that's open for discussion.
In kvmppc_can_deliver_interrupt all frequent cases are in the default case. I know compilers are smart but we can make it easier for them. By writing down all options and removing the default case combined with the fact that ithe values are constants 0..15 should allow the compiler to write an easy jump table.
Modifying kvmppc_can_deliver_interrupt pointed me to the fact that gcc seems to be unable to reduce priority_exception[x] to a build time constant. Therefore I changed the usage of the translation arrays in the interrupt delivery path completely. It is now using priority without translation to irq on the full irq delivery path.
To be able to do that ivpr regs are stored by their priority now.
---
[diffstat]
arch/powerpc/kvm/booke_guest.c | 144 +++++++++++++++++------------------------ arch/powerpc/kvm/emulate.c | 64 +++++++++--------- arch/powerpc/kvm/powerpc.c | 5 - include/asm-powerpc/kvm_asm.h | 18 +++++ include/asm-powerpc/kvm_ppc.h | 9 +- 5 files changed, 117 insertions(+), 123 deletions(-)
[diff]
arch/powerpc/kvm/booke_guest.c +61 -83
@@ -73,62 +73,42 @@#endif static const u32 interrupt_msr_mask[16 ] = { - [BOOKE_INTERRUPT_CRITICAL ] =MSR_ME , - [BOOKE_INTERRUPT_MACHINE_CHECK ] =0 , - [BOOKE_INTERRUPT_DATA_STORAGE ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_INST_STORAGE ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_EXTERNAL ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_ALIGNMENT ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_PROGRAM ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_FP_UNAVAIL ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_SYSCALL ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_AP_UNAVAIL ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_DECREMENTER ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_FIT ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_WATCHDOG ] =MSR_ME , - [BOOKE_INTERRUPT_DTLB_MISS ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_ITLB_MISS ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_DEBUG ] =MSR_ME , + [BOOKE_INTERRUPT_PRIO_CRITICAL ] =MSR_ME , + [BOOKE_INTERRUPT_PRIO_MACHINE_CHECK ] =0 , + [BOOKE_INTERRUPT_PRIO_DATA_STORAGE ] =MSR_CE |MSR_ME |MSR_DE , + [BOOKE_INTERRUPT_PRIO_INST_STORAGE ] =MSR_CE |MSR_ME |MSR_DE , + [BOOKE_INTERRUPT_PRIO_EXTERNAL ] =MSR_CE |MSR_ME |MSR_DE , + [BOOKE_INTERRUPT_PRIO_ALIGNMENT ] =MSR_CE |MSR_ME |MSR_DE , + [BOOKE_INTERRUPT_PRIO_PROGRAM ] =MSR_CE |MSR_ME |MSR_DE , + [BOOKE_INTERRUPT_PRIO_FP_UNAVAIL ] =MSR_CE |MSR_ME |MSR_DE , + [BOOKE_INTERRUPT_PRIO_SYSCALL ] =MSR_CE |MSR_ME |MSR_DE , + [BOOKE_INTERRUPT_PRIO_AP_UNAVAIL ] =MSR_CE |MSR_ME |MSR_DE , + [BOOKE_INTERRUPT_PRIO_DECREMENTER ] =MSR_CE |MSR_ME |MSR_DE , + [BOOKE_INTERRUPT_PRIO_FIT ] =MSR_CE |MSR_ME |MSR_DE , + [BOOKE_INTERRUPT_PRIO_WATCHDOG ] =MSR_ME , + [BOOKE_INTERRUPT_PRIO_DTLB_MISS ] =MSR_CE |MSR_ME |MSR_DE , + [BOOKE_INTERRUPT_PRIO_ITLB_MISS ] =MSR_CE |MSR_ME |MSR_DE , + [BOOKE_INTERRUPT_PRIO_DEBUG ] =MSR_ME , }; -const unsigned char exception_priority[] = { - [BOOKE_INTERRUPT_DATA_STORAGE ] =0 , - [BOOKE_INTERRUPT_INST_STORAGE ] =1 , - [BOOKE_INTERRUPT_ALIGNMENT ] =2 , - [BOOKE_INTERRUPT_PROGRAM ] =3 , - [BOOKE_INTERRUPT_FP_UNAVAIL ] =4 , - [BOOKE_INTERRUPT_SYSCALL ] =5 , - [BOOKE_INTERRUPT_AP_UNAVAIL ] =6 , - [BOOKE_INTERRUPT_DTLB_MISS ] =7 , - [BOOKE_INTERRUPT_ITLB_MISS ] =8 , - [BOOKE_INTERRUPT_MACHINE_CHECK ] =9 , - [BOOKE_INTERRUPT_DEBUG ] =10 , - [BOOKE_INTERRUPT_CRITICAL ] =11 , - [BOOKE_INTERRUPT_WATCHDOG ] =12 , - [BOOKE_INTERRUPT_EXTERNAL ] =13 , - [BOOKE_INTERRUPT_FIT ] =14 , - [BOOKE_INTERRUPT_DECREMENTER ] =15 , +const unsigned int exception_priority[] = { + [BOOKE_INTERRUPT_DATA_STORAGE ] =BOOKE_INTERRUPT_PRIO_DATA_STORAGE , + [BOOKE_INTERRUPT_INST_STORAGE ] =BOOKE_INTERRUPT_PRIO_INST_STORAGE , + [BOOKE_INTERRUPT_ALIGNMENT ] =BOOKE_INTERRUPT_PRIO_ALIGNMENT , + [BOOKE_INTERRUPT_PROGRAM ] =BOOKE_INTERRUPT_PRIO_PROGRAM , + [BOOKE_INTERRUPT_FP_UNAVAIL ] =BOOKE_INTERRUPT_PRIO_FP_UNAVAIL , + [BOOKE_INTERRUPT_SYSCALL ] =BOOKE_INTERRUPT_PRIO_SYSCALL , + [BOOKE_INTERRUPT_AP_UNAVAIL ] =BOOKE_INTERRUPT_PRIO_AP_UNAVAIL , + [BOOKE_INTERRUPT_DTLB_MISS ] =BOOKE_INTERRUPT_PRIO_DTLB_MISS , + [BOOKE_INTERRUPT_ITLB_MISS ] =BOOKE_INTERRUPT_PRIO_ITLB_MISS , + [BOOKE_INTERRUPT_MACHINE_CHECK ] =BOOKE_INTERRUPT_PRIO_MACHINE_CHECK , + [BOOKE_INTERRUPT_DEBUG ] =BOOKE_INTERRUPT_PRIO_DEBUG , + [BOOKE_INTERRUPT_CRITICAL ] =BOOKE_INTERRUPT_PRIO_CRITICAL , + [BOOKE_INTERRUPT_WATCHDOG ] =BOOKE_INTERRUPT_PRIO_WATCHDOG , + [BOOKE_INTERRUPT_EXTERNAL ] =BOOKE_INTERRUPT_PRIO_EXTERNAL , + [BOOKE_INTERRUPT_FIT ] =BOOKE_INTERRUPT_PRIO_FIT , + [BOOKE_INTERRUPT_DECREMENTER ] =BOOKE_INTERRUPT_PRIO_DECREMENTER , }; - -const unsigned char priority_exception[] = { -BOOKE_INTERRUPT_DATA_STORAGE , -BOOKE_INTERRUPT_INST_STORAGE , -BOOKE_INTERRUPT_ALIGNMENT , -BOOKE_INTERRUPT_PROGRAM , -BOOKE_INTERRUPT_FP_UNAVAIL , -BOOKE_INTERRUPT_SYSCALL , -BOOKE_INTERRUPT_AP_UNAVAIL , -BOOKE_INTERRUPT_DTLB_MISS , -BOOKE_INTERRUPT_ITLB_MISS , -BOOKE_INTERRUPT_MACHINE_CHECK , -BOOKE_INTERRUPT_DEBUG , -BOOKE_INTERRUPT_CRITICAL , -BOOKE_INTERRUPT_WATCHDOG , -BOOKE_INTERRUPT_EXTERNAL , -BOOKE_INTERRUPT_FIT , -BOOKE_INTERRUPT_DECREMENTER , -}; -void kvmppc_dump_tlbs (struct kvm_vcpu *vcpu) {
@@ -187,46 +167,46 @@ }/* Check if we are ready to deliver the interrupt */ -static int kvmppc_can_deliver_interrupt (struct kvm_vcpu *vcpu,int interrupt) +static int kvmppc_can_deliver_interrupt_by_prio (struct kvm_vcpu *vcpu, +unsigned int priority) { -int r; +int r =0 ; -switch (interrupt) { -case BOOKE_INTERRUPT_CRITICAL : +switch (priority) { +case BOOKE_INTERRUPT_PRIO_PROGRAM : +case BOOKE_INTERRUPT_PRIO_DTLB_MISS : +case BOOKE_INTERRUPT_PRIO_ITLB_MISS : +case BOOKE_INTERRUPT_PRIO_SYSCALL : +case BOOKE_INTERRUPT_PRIO_DATA_STORAGE : +case BOOKE_INTERRUPT_PRIO_INST_STORAGE : +case BOOKE_INTERRUPT_PRIO_FP_UNAVAIL : + r =1 ; +break ; +case BOOKE_INTERRUPT_PRIO_CRITICAL : +case BOOKE_INTERRUPT_PRIO_WATCHDOG : r = vcpu->arch.msr &MSR_CE ;break ; -case BOOKE_INTERRUPT_MACHINE_CHECK : +case BOOKE_INTERRUPT_PRIO_MACHINE_CHECK : r = vcpu->arch.msr &MSR_ME ;break ; -case BOOKE_INTERRUPT_EXTERNAL : +case BOOKE_INTERRUPT_PRIO_EXTERNAL : +case BOOKE_INTERRUPT_PRIO_DECREMENTER : +case BOOKE_INTERRUPT_PRIO_FIT : r = vcpu->arch.msr &MSR_EE ;break ; -case BOOKE_INTERRUPT_DECREMENTER : - r = vcpu->arch.msr &MSR_EE ; -break ; -case BOOKE_INTERRUPT_FIT : - r = vcpu->arch.msr &MSR_EE ; -break ; -case BOOKE_INTERRUPT_WATCHDOG : - r = vcpu->arch.msr &MSR_CE ; -break ; -case BOOKE_INTERRUPT_DEBUG : +case BOOKE_INTERRUPT_PRIO_DEBUG : r = vcpu->arch.msr &MSR_DE ;break ; -default : - r =1 ; }return r; } -static void kvmppc_deliver_interrupt (struct kvm_vcpu *vcpu,int interrupt) +static void kvmppc_deliver_interrupt_by_prio (struct kvm_vcpu *vcpu, +unsigned int priority) { -switch (interrupt) { -case BOOKE_INTERRUPT_DECREMENTER : +if (unlikely (priority =BOOKE_INTERRUPT_PRIO_DECREMENTER )) vcpu->arch.tsr |=TSR_DIS ; -break ; - }if (kvmppc_has_pvmem (vcpu)) {kvmppc_set_pvreg (vcpu,KVM_PPCPV_OFFSET_SRR0 , vcpu->arch.pc);
@@ -239,23 +219,21 @@ vcpu->arch.srr1 = vcpu->arch.msr; } - vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[interrupt]; -kvmppc_set_msr (vcpu, vcpu->arch.msr & interrupt_msr_mask[interrupt]); + vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority]; +kvmppc_set_msr (vcpu, vcpu->arch.msr & interrupt_msr_mask[priority]); }/* Check pending exceptions and deliver one, if possible. */ void kvmppc_check_and_deliver_interrupts (struct kvm_vcpu *vcpu) {unsigned long *pending = &vcpu->arch.pending_exceptions; -unsigned int exception;unsigned int priority; priority =find_first_bit (pending,BITS_PER_BYTE *sizeof (*pending));while (priority <=BOOKE_MAX_INTERRUPT ) { - exception = priority_exception[priority]; -if (kvmppc_can_deliver_interrupt (vcpu, exception)) { -kvmppc_clear_exception (vcpu, exception); -kvmppc_deliver_interrupt (vcpu, exception); +if (kvmppc_can_deliver_interrupt_by_prio (vcpu, priority)) { +kvmppc_clear_exception_by_prio (pending, priority); +kvmppc_deliver_interrupt_by_prio (vcpu, priority);break ; }
arch/powerpc/kvm/emulate.c +32 -32
106 lines not on this page · raw message
arch/powerpc/kvm/powerpc.c +2 -3
@@ -222,9 +222,8 @@int kvm_cpu_has_pending_timer (struct kvm_vcpu *vcpu) { -unsigned int priority = exception_priority[BOOKE_INTERRUPT_DECREMENTER ]; - -return test_bit (priority, &vcpu->arch.pending_exceptions); +return test_bit (BOOKE_INTERRUPT_PRIO_DECREMENTER , + &vcpu->arch.pending_exceptions); }static void kvmppc_decrementer_func (unsigned long data)
include/asm-powerpc/kvm_asm.h +18 -0
@@ -44,6 +44,24 @@#define BOOKE_INTERRUPT_DEBUG 15#define BOOKE_MAX_INTERRUPT 15 +/* interrupt priortity ordering */ +#define BOOKE_INTERRUPT_PRIO_DATA_STORAGE 0 +#define BOOKE_INTERRUPT_PRIO_INST_STORAGE 1 +#define BOOKE_INTERRUPT_PRIO_ALIGNMENT 2 +#define BOOKE_INTERRUPT_PRIO_PROGRAM 3 +#define BOOKE_INTERRUPT_PRIO_FP_UNAVAIL 4 +#define BOOKE_INTERRUPT_PRIO_SYSCALL 5 +#define BOOKE_INTERRUPT_PRIO_AP_UNAVAIL 6 +#define BOOKE_INTERRUPT_PRIO_DTLB_MISS 7 +#define BOOKE_INTERRUPT_PRIO_ITLB_MISS 8 +#define BOOKE_INTERRUPT_PRIO_MACHINE_CHECK 9 +#define BOOKE_INTERRUPT_PRIO_DEBUG 10 +#define BOOKE_INTERRUPT_PRIO_CRITICAL 11 +#define BOOKE_INTERRUPT_PRIO_WATCHDOG 12 +#define BOOKE_INTERRUPT_PRIO_EXTERNAL 13 +#define BOOKE_INTERRUPT_PRIO_FIT 14 +#define BOOKE_INTERRUPT_PRIO_DECREMENTER 15 +#define RESUME_FLAG_NV (1<<0)/* Reload guest nonvolatile state? */ #define RESUME_FLAG_HOST (1<<1)/* Resume host? */
include/asm-powerpc/kvm_ppc.h +4 -5
@@ -42,8 +42,7 @@ EMULATE_FAIL, /* can't emulate this instruction */ }; -extern const unsigned char exception_priority[]; -extern const unsigned char priority_exception[]; +extern const unsigned int exception_priority[];extern int __kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu);extern char kvmppc_handlers_start[];
@@ -75,10 +74,10 @@set_bit (priority, &vcpu->arch.pending_exceptions); } -static inline void kvmppc_clear_exception (struct kvm_vcpu *vcpu,int exception) +static inline void kvmppc_clear_exception_by_prio (unsigned long *pending, +unsigned int priority) { -unsigned int priority = exception_priority[exception]; -clear_bit (priority, &vcpu->arch.pending_exceptions); +clear_bit (priority, pending); }/* Helper function for "full" MSR writes. No need to call this if only EE is
Quoted 7 lines · On Fri, 2008-10-10 at 12:59 +0200, [email protected] wrote:
From: Christian Ehrhardt <[email protected]>
In
kvmppc_deliver_interruptis just one case left in the switch and it is a rare one (less than 8%) when looking at the exit numbers. Therefore we can at least drop the switch/case and if an if. I inserted an unlikely too, but that's open for discussion.
Quoted 11 lines
In
kvmppc_can_deliver_interruptall frequent cases are in the default case. I know compilers are smart but we can make it easier for them. By writing down all options and removing the default case combined with the fact that ithe values are constants 0..15 should allow the compiler to write an easy jump table.
Modifyingkvmppc_can_deliver_interruptpointed me to the fact that gcc seems to be unable to reduce priority_exception[x] to a build time constant. Therefore I changed the usage of the translation arrays in the interrupt delivery path completely. It is now using priority without translation to irq on the full irq delivery path.
To be able to do that ivpr regs are stored by their priority now.
I like this, but a few notes:
Why did you convert exception_priority[] to int? AFAICS it still only holds values 0-15, and using chars would shrink it from 2 32-byte cachelines (3 unaligned) to half of one.
It looks like you applied this on top of the pvmem patches. I guess the performance benefit is significant enough to apply those, but I'll have to find the patches again.
I think the IVOR emulation has gotten wide enough that you can add some newlines.
AFAICS the *_PRIO constants aren't used in assembly, so do they need to go into kvm_asm.h?
Signature · 2 lines
Hollis Blanchard IBM Linux Technology Center
Quoted 22 lines · Hollis Blanchard
Quoted 7 lines · On Fri, 2008-10-10 at 12:59 +0200, [email protected] wrote:
From: Christian Ehrhardt <[email protected]>
In
kvmppc_deliver_interruptis just one case left in the switch and it is a rare one (less than 8%) when looking at the exit numbers. Therefore we can at least drop the switch/case and if an if. I inserted an unlikely too, but that's open for discussion.Quoted 12 lines
In
kvmppc_can_deliver_interruptall frequent cases are in the default case. I know compilers are smart but we can make it easier for them. By writing down all options and removing the default case combined with the fact that ithe values are constants 0..15 should allow the compiler to write an easy jump table.
Modifyingkvmppc_can_deliver_interruptpointed me to the fact that gcc seems to be unable to reduce priority_exception[x] to a build time constant. Therefore I changed the usage of the translation arrays in the interrupt delivery path completely. It is now using priority without translation to irq on the full irq delivery path.
To be able to do that ivpr regs are stored by their priority now.
Quoted 6 lines
I like this, but a few notes:
Why did you convert exception_priority[] to int? AFAICS it still only holds values 0-15, and using chars would shrink it from 2 32-byte cachelines (3 unaligned) to half of one.
Your right, I changed it while modifying the code to match the type used to call functions for a test and forgot to revert it.
Will be changed in v2.
Quoted 4 lines
It looks like you applied this on top of the pvmem patches. I guess the performance benefit is significant enough to apply those, but I'll have to find the patches again.
I can rebase them to bring them in pre pvmem, no need you do that work. This also fixed the dependencies to e.g. the exit timing patches.
Applying pv patches too would be nice, we can talk this week about that more in detail (if/when/how to do it).
Quoted 3 lines
I think the IVOR emulation has gotten wide enough that you can add some newlines.
I need to run checkpatch once more on the current version anyway - I just wanted to put that out for discussion on friday, thats why I missed those 80+ lines :-/
Quoted 3 lines
AFAICS the
*_PRIOconstants aren't used in assembly, so do they need to go intokvm_asm.h?
I wanted to place them near the non _PRIO irq constants, not needed for the code but nice to understand the code.
But your right, officially I think they should stay in asm/kvm_ppc.h - I can relocate them in v2 of the patches.
Signature · 3 lines
Grüsse / regards, Christian Ehrhardt IBM Linux Technology Center, Open Virtualization
PATCH 1/3 kvmppc: optimize irq delivery path
In reply to [email protected]From: Christian Ehrhardt <[email protected]>
In kvmppc_deliver_interrupt is just one case left in the switch and it is a rare one (less than 8%) when looking at the exit numbers. Therefore we can at least drop the switch/case and if an if. I inserted an unlikely too, but that's open for discussion.
In kvmppc_can_deliver_interrupt all frequent cases are in the default case. I know compilers are smart but we can make it easier for them. By writing down all options and removing the default case combined with the fact that ithe values are constants 0..15 should allow the compiler to write an easy jump table.
Modifying kvmppc_can_deliver_interrupt pointed me to the fact that gcc seems to be unable to reduce priority_exception[x] to a build time constant. Therefore I changed the usage of the translation arrays in the interrupt delivery path completely. It is now using priority without translation to irq on the full irq delivery path.
To be able to do that ivpr regs are stored by their priority now.
Additionally the decision made in kvmppc_can_deliver_interrupt is already sufficient to get the value of interrupt_msr_mask[x]. Therefore we can replace the 16x4byte array used here with a single 4byte variable (might still be one miss, but the chance to find this in cache should be better than the right entry of the whole array).
---
[diffstat]
arch/powerpc/kvm/booke_guest.c | 153 ++++++++++++++++------------------------- arch/powerpc/kvm/emulate.c | 128 +++++++++++++++++++++++++--------- arch/powerpc/kvm/powerpc.c | 5 - include/asm-powerpc/kvm_ppc.h | 25 +++++- 4 files changed, 180 insertions(+), 131 deletions(-)
[diff]
arch/powerpc/kvm/booke_guest.c +62 -93
@@ -53,63 +53,24 @@ { NULL } }; -static const u32 interrupt_msr_mask[16 ] = { - [BOOKE_INTERRUPT_CRITICAL ] =MSR_ME , - [BOOKE_INTERRUPT_MACHINE_CHECK ] =0 , - [BOOKE_INTERRUPT_DATA_STORAGE ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_INST_STORAGE ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_EXTERNAL ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_ALIGNMENT ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_PROGRAM ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_FP_UNAVAIL ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_SYSCALL ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_AP_UNAVAIL ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_DECREMENTER ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_FIT ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_WATCHDOG ] =MSR_ME , - [BOOKE_INTERRUPT_DTLB_MISS ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_ITLB_MISS ] =MSR_CE |MSR_ME |MSR_DE , - [BOOKE_INTERRUPT_DEBUG ] =MSR_ME , +const unsigned char exception_priority[] = { + [BOOKE_INTERRUPT_DATA_STORAGE ] =BOOKE_IRQPRIO_DATA_STORAGE , + [BOOKE_INTERRUPT_INST_STORAGE ] =BOOKE_IRQPRIO_INST_STORAGE , + [BOOKE_INTERRUPT_ALIGNMENT ] =BOOKE_IRQPRIO_ALIGNMENT , + [BOOKE_INTERRUPT_PROGRAM ] =BOOKE_IRQPRIO_PROGRAM , + [BOOKE_INTERRUPT_FP_UNAVAIL ] =BOOKE_IRQPRIO_FP_UNAVAIL , + [BOOKE_INTERRUPT_SYSCALL ] =BOOKE_IRQPRIO_SYSCALL , + [BOOKE_INTERRUPT_AP_UNAVAIL ] =BOOKE_IRQPRIO_AP_UNAVAIL , + [BOOKE_INTERRUPT_DTLB_MISS ] =BOOKE_IRQPRIO_DTLB_MISS , + [BOOKE_INTERRUPT_ITLB_MISS ] =BOOKE_IRQPRIO_ITLB_MISS , + [BOOKE_INTERRUPT_MACHINE_CHECK ] =BOOKE_IRQPRIO_MACHINE_CHECK , + [BOOKE_INTERRUPT_DEBUG ] =BOOKE_IRQPRIO_DEBUG , + [BOOKE_INTERRUPT_CRITICAL ] =BOOKE_IRQPRIO_CRITICAL , + [BOOKE_INTERRUPT_WATCHDOG ] =BOOKE_IRQPRIO_WATCHDOG , + [BOOKE_INTERRUPT_EXTERNAL ] =BOOKE_IRQPRIO_EXTERNAL , + [BOOKE_INTERRUPT_FIT ] =BOOKE_IRQPRIO_FIT , + [BOOKE_INTERRUPT_DECREMENTER ] =BOOKE_IRQPRIO_DECREMENTER , }; - -const unsigned char exception_priority[] = { - [BOOKE_INTERRUPT_DATA_STORAGE ] =0 , - [BOOKE_INTERRUPT_INST_STORAGE ] =1 , - [BOOKE_INTERRUPT_ALIGNMENT ] =2 , - [BOOKE_INTERRUPT_PROGRAM ] =3 , - [BOOKE_INTERRUPT_FP_UNAVAIL ] =4 , - [BOOKE_INTERRUPT_SYSCALL ] =5 , - [BOOKE_INTERRUPT_AP_UNAVAIL ] =6 , - [BOOKE_INTERRUPT_DTLB_MISS ] =7 , - [BOOKE_INTERRUPT_ITLB_MISS ] =8 , - [BOOKE_INTERRUPT_MACHINE_CHECK ] =9 , - [BOOKE_INTERRUPT_DEBUG ] =10 , - [BOOKE_INTERRUPT_CRITICAL ] =11 , - [BOOKE_INTERRUPT_WATCHDOG ] =12 , - [BOOKE_INTERRUPT_EXTERNAL ] =13 , - [BOOKE_INTERRUPT_FIT ] =14 , - [BOOKE_INTERRUPT_DECREMENTER ] =15 , -}; - -const unsigned char priority_exception[] = { -BOOKE_INTERRUPT_DATA_STORAGE , -BOOKE_INTERRUPT_INST_STORAGE , -BOOKE_INTERRUPT_ALIGNMENT , -BOOKE_INTERRUPT_PROGRAM , -BOOKE_INTERRUPT_FP_UNAVAIL , -BOOKE_INTERRUPT_SYSCALL , -BOOKE_INTERRUPT_AP_UNAVAIL , -BOOKE_INTERRUPT_DTLB_MISS , -BOOKE_INTERRUPT_ITLB_MISS , -BOOKE_INTERRUPT_MACHINE_CHECK , -BOOKE_INTERRUPT_DEBUG , -BOOKE_INTERRUPT_CRITICAL , -BOOKE_INTERRUPT_WATCHDOG , -BOOKE_INTERRUPT_EXTERNAL , -BOOKE_INTERRUPT_FIT , -BOOKE_INTERRUPT_DECREMENTER , -}; -void kvmppc_dump_tlbs (struct kvm_vcpu *vcpu) {
@@ -158,72 +119,80 @@ }/* Check if we are ready to deliver the interrupt */ -static int kvmppc_can_deliver_interrupt (struct kvm_vcpu *vcpu,int interrupt) +static inline int kvmppc_can_deliver_interrupt_by_prio (struct kvm_vcpu *vcpu, +unsigned int priority, +u32 *mask) { -int r; +int r =0 ; -switch (interrupt) { -case BOOKE_INTERRUPT_CRITICAL : +switch (priority) { +case BOOKE_IRQPRIO_PROGRAM : +case BOOKE_IRQPRIO_DTLB_MISS : +case BOOKE_IRQPRIO_ITLB_MISS : +case BOOKE_IRQPRIO_SYSCALL : +case BOOKE_IRQPRIO_DATA_STORAGE : +case BOOKE_IRQPRIO_INST_STORAGE : +case BOOKE_IRQPRIO_FP_UNAVAIL : +case BOOKE_IRQPRIO_AP_UNAVAIL : +case BOOKE_IRQPRIO_ALIGNMENT : + r =1 ; + *mask =MSR_CE |MSR_ME |MSR_DE ; +break ; +case BOOKE_IRQPRIO_CRITICAL : +case BOOKE_IRQPRIO_WATCHDOG : r = vcpu->arch.msr &MSR_CE ; + *mask =MSR_ME ;break ; -case BOOKE_INTERRUPT_MACHINE_CHECK : +case BOOKE_IRQPRIO_MACHINE_CHECK : r = vcpu->arch.msr &MSR_ME ; + *mask =0 ;break ; -case BOOKE_INTERRUPT_EXTERNAL : +case BOOKE_IRQPRIO_EXTERNAL : +case BOOKE_IRQPRIO_DECREMENTER : +case BOOKE_IRQPRIO_FIT : r = vcpu->arch.msr &MSR_EE ; + *mask =MSR_CE |MSR_ME |MSR_DE ;break ; -case BOOKE_INTERRUPT_DECREMENTER : - r = vcpu->arch.msr &MSR_EE ; +case BOOKE_IRQPRIO_DEBUG : + r = vcpu->arch.msr &MSR_DE ; + *mask =MSR_ME ;break ; -case BOOKE_INTERRUPT_FIT : - r = vcpu->arch.msr &MSR_EE ; -break ; -case BOOKE_INTERRUPT_WATCHDOG : - r = vcpu->arch.msr &MSR_CE ; -break ; -case BOOKE_INTERRUPT_DEBUG : - r = vcpu->arch.msr &MSR_DE ; -break ; -default : - r =1 ; }return r; } -static void kvmppc_deliver_interrupt (struct kvm_vcpu *vcpu,int interrupt) +static inline void kvmppc_deliver_interrupt_by_prio (struct kvm_vcpu *vcpu, +unsigned int priority, +u32 mask) { -switch (interrupt) { -case BOOKE_INTERRUPT_DECREMENTER : +if (unlikely (priority =BOOKE_IRQPRIO_DECREMENTER )) vcpu->arch.tsr |=TSR_DIS ; -break ; - } vcpu->arch.srr0 = vcpu->arch.pc; vcpu->arch.srr1 = vcpu->arch.msr; - vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[interrupt]; -kvmppc_set_msr (vcpu, vcpu->arch.msr & interrupt_msr_mask[interrupt]); + vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority]; +kvmppc_set_msr (vcpu, vcpu->arch.msr & mask); }/* Check pending exceptions and deliver one, if possible. */ void kvmppc_check_and_deliver_interrupts (struct kvm_vcpu *vcpu) {unsigned long *pending = &vcpu->arch.pending_exceptions; -unsigned int exception; -unsigned int priority; +unsigned int prio; +u32 mask; - priority =find_first_bit (pending,BITS_PER_BYTE *sizeof (*pending)); -while (priority <=BOOKE_MAX_INTERRUPT ) { - exception = priority_exception[priority]; -if (kvmppc_can_deliver_interrupt (vcpu, exception)) { -kvmppc_clear_exception (vcpu, exception); -kvmppc_deliver_interrupt (vcpu, exception); + prio =find_first_bit (pending,BITS_PER_BYTE *sizeof (*pending)); +while (prio <=BOOKE_MAX_INTERRUPT ) { +if (kvmppc_can_deliver_interrupt_by_prio (vcpu, prio, &mask)) { +kvmppc_clear_exception_by_prio (pending, prio); +kvmppc_deliver_interrupt_by_prio (vcpu, prio, mask);break ; } - priority =find_next_bit (pending, -BITS_PER_BYTE *sizeof (*pending), - priority +1 ); + prio =find_next_bit (pending, +BITS_PER_BYTE *sizeof (*pending), + prio +1 ); } }
arch/powerpc/kvm/emulate.c +64 -32
138 lines not on this page · raw message
arch/powerpc/kvm/powerpc.c +2 -3
@@ -206,9 +206,8 @@int kvm_cpu_has_pending_timer (struct kvm_vcpu *vcpu) { -unsigned int priority = exception_priority[BOOKE_INTERRUPT_DECREMENTER ]; - -return test_bit (priority, &vcpu->arch.pending_exceptions); +return test_bit (BOOKE_IRQPRIO_DECREMENTER , + &vcpu->arch.pending_exceptions); }static void kvmppc_decrementer_func (unsigned long data)
include/asm-powerpc/kvm_ppc.h +21 -4
@@ -29,6 +29,24 @@#include <linux/kvm_types.h> #include <linux/kvm_host.h> +/* interrupt priortity ordering */ +#define BOOKE_IRQPRIO_DATA_STORAGE 0 +#define BOOKE_IRQPRIO_INST_STORAGE 1 +#define BOOKE_IRQPRIO_ALIGNMENT 2 +#define BOOKE_IRQPRIO_PROGRAM 3 +#define BOOKE_IRQPRIO_FP_UNAVAIL 4 +#define BOOKE_IRQPRIO_SYSCALL 5 +#define BOOKE_IRQPRIO_AP_UNAVAIL 6 +#define BOOKE_IRQPRIO_DTLB_MISS 7 +#define BOOKE_IRQPRIO_ITLB_MISS 8 +#define BOOKE_IRQPRIO_MACHINE_CHECK 9 +#define BOOKE_IRQPRIO_DEBUG 10 +#define BOOKE_IRQPRIO_CRITICAL 11 +#define BOOKE_IRQPRIO_WATCHDOG 12 +#define BOOKE_IRQPRIO_EXTERNAL 13 +#define BOOKE_IRQPRIO_FIT 14 +#define BOOKE_IRQPRIO_DECREMENTER 15 +struct kvm_tlb {struct tlbe guest_tlb[PPC44x_TLB_SIZE];struct tlbe shadow_tlb[PPC44x_TLB_SIZE];
@@ -42,7 +60,6 @@ };extern const unsigned char exception_priority[]; -extern const unsigned char priority_exception[];extern int __kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu);extern char kvmppc_handlers_start[];
@@ -74,10 +91,10 @@set_bit (priority, &vcpu->arch.pending_exceptions); } -static inline void kvmppc_clear_exception (struct kvm_vcpu *vcpu,int exception) +static inline void kvmppc_clear_exception_by_prio (unsigned long *pending, +unsigned int priority) { -unsigned int priority = exception_priority[exception]; -clear_bit (priority, &vcpu->arch.pending_exceptions); +clear_bit (priority, pending); }/* Helper function for "full" MSR writes. No need to call this if only EE is