powerpc/kvm: Speed up wakeups of CPUs on HV KVM
Subsystems (3)
PATCH 6/7 powerpc/kvm: Speed up wakeups of CPUs on HV KVM
Currently, we wake up a CPUs by sending a host IPI with smp_send_reschedule() to thread 0 of that core, which will take all threads out of the guest, and cause them to re-evalutate their interrupt status on the way back in.
This adds a mechanism to differenciate real host IPIs and IPIs sent by KVM for guest threads to poke each other, in order to target the guest threads precisely when possible and avoid that global switch of the core to host state.
Then use this new facility in the in-kernel XICS code
Signed-off-by Benjamin Herrenschmidt <[email protected]>
--- arch/powerpc/include/asm/kvm_book3s_asm.h | 8 ++- arch/powerpc/include/asm/kvm_ppc.h | 29 ++++++++ arch/powerpc/kernel/asm-offsets.c | 2 + arch/powerpc/kvm/book3s_hv.c | 26 ++++++- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 112 +++++++++++++++++++++++------ arch/powerpc/kvm/book3s_xics.c | 2 +- arch/powerpc/sysdev/xics/icp-native.c | 8 +++ 7 files changed, 163 insertions(+), 24 deletions(-)
arch/powerpc/include/asm/kvm_book3s_asm.h +7 -1
@@ -20,6 +20,11 @@#ifndef __ASM_KVM_BOOK3S_ASM_H__#define __ASM_KVM_BOOK3S_ASM_H__ +/* XICS ICP register offsets */ +#define XICS_XIRR 4 +#define XICS_MFRR 0xc +#define XICS_IPI 2/* interrupt source # for IPIs */ +#ifdef __ASSEMBLY__#ifdef CONFIG_KVM_BOOK3S_HANDLER
@@ -82,10 +87,11 @@ struct kvmppc_host_state {#ifdef CONFIG_KVM_BOOK3S_64_HV u8 hwthread_req;u8 hwthread_state; - +u8 host_ipi;struct kvm_vcpu *kvm_vcpu;struct kvmppc_vcore *kvm_vcore;unsigned long xics_phys; +u32 saved_xirr;u64 dabr;u64 host_mmcr[3 ];u32 host_pmc[8 ];
arch/powerpc/include/asm/kvm_ppc.h +29 -0
@@ -212,6 +212,21 @@ static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr) paca[cpu].kvm_hstate.xics_phys = addr; } +static inline u32 kvmppc_get_xics_latch (void ) +{ +u32 xirr =get_paca ()->kvm_hstate.saved_xirr; + +get_paca ()->kvm_hstate.saved_xirr =0 ; + +return xirr; +} + +static inline void kvmppc_set_host_ipi (int cpu,u8 host_ipi) +{ + paca[cpu].kvm_hstate.host_ipi = host_ipi; +} + +extern void kvmppc_fast_vcpu_kick (struct kvm_vcpu *vcpu);extern void kvm_linear_init (void );#else
@@ -221,6 +236,18 @@ static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)static inline void kvm_linear_init (void ) {} +static inline u32 kvmppc_get_xics_latch (void ) +{ +return 0 ; +} + +static inline void kvmppc_set_host_ipi (int cpu,u8 host_ipi) +{} + +static inline void kvmppc_fast_vcpu_kick (struct kvm_vcpu *vcpu) +{ +kvm_vcpu_kick (vcpu); +}#endif #ifdef CONFIG_PPC_BOOK3S_64
@@ -251,4 +278,6 @@ void kvmppc_claim_lpid(long lpid);void kvmppc_free_lpid (long lpid);void kvmppc_init_lpid (unsigned long nr_lpids); +extern void xics_wake_cpu (int cpu); +#endif /* __POWERPC_KVM_PPC_H__ */
arch/powerpc/kernel/asm-offsets.c +2 -0
@@ -544,6 +544,8 @@ int main(void)HSTATE_FIELD (HSTATE_KVM_VCPU , kvm_vcpu);HSTATE_FIELD (HSTATE_KVM_VCORE , kvm_vcore);HSTATE_FIELD (HSTATE_XICS_PHYS , xics_phys); +HSTATE_FIELD (HSTATE_SAVED_XIRR , saved_xirr); +HSTATE_FIELD (HSTATE_HOST_IPI , host_ipi);HSTATE_FIELD (HSTATE_MMCR , host_mmcr);HSTATE_FIELD (HSTATE_PMC , host_pmc);HSTATE_FIELD (HSTATE_PURR , host_purr);
arch/powerpc/kvm/book3s_hv.c +25 -1
@@ -58,6 +58,31 @@static void kvmppc_end_cede (struct kvm_vcpu *vcpu);static int kvmppc_hv_setup_htab_rma (struct kvm_vcpu *vcpu); +void kvmppc_fast_vcpu_kick (struct kvm_vcpu *vcpu) +{ +int me; +int cpu = vcpu->cpu; +wait_queue_head_t *wqp; + + wqp =kvm_arch_vcpu_wq (vcpu); +if (waitqueue_active (wqp)) { +wake_up_interruptible (wqp); + ++vcpu->stat.halt_wakeup; + } + + me =get_cpu (); + +/* CPU points to the first thread of the core */ +if (cpu != me && cpu >=0 && cpu < nr_cpu_ids) { +int real_cpu = cpu + vcpu->arch.ptid; +if (paca[real_cpu].kvm_hstate.xics_phys) +xics_wake_cpu (real_cpu); +else if (cpu_online (cpu)) +smp_send_reschedule (cpu); + } +put_cpu (); +} +void kvmppc_core_vcpu_load (struct kvm_vcpu *vcpu,int cpu) {struct kvmppc_vcore *vc = vcpu->arch.vcore;
@@ -775,7 +800,6 @@ static void kvmppc_end_cede(struct kvm_vcpu *vcpu) }extern int __kvmppc_vcore_entry (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu); -extern void xics_wake_cpu (int cpu);static void kvmppc_remove_runnable (struct kvmppc_vcore *vc,struct kvm_vcpu *vcpu)
arch/powerpc/kvm/book3s_hv_rmhandlers.S +91 -21
150 lines not on this page · raw message
arch/powerpc/kvm/book3s_xics.c +1 -1
@@ -318,7 +318,7 @@ static inline bool icp_try_update(struct kvmppc_icp *icp,kvmppc_book3s_queue_irqprio (icp->vcpu,BOOK3S_INTERRUPT_EXTERNAL_LEVEL );if (!change_self) -kvm_vcpu_kick (icp->vcpu); +kvmppc_fast_vcpu_kick (icp->vcpu); } bail:return success;
arch/powerpc/sysdev/xics/icp-native.c +8 -0
@@ -51,6 +51,12 @@ static struct icp_ipl __iomem *icp_native_regs[NR_CPUS];static inline unsigned int icp_native_get_xirr (void ) {int cpu =smp_processor_id (); +unsigned int xirr; + +/* Handled an interrupt latched by KVM */ + xirr =kvmppc_get_xics_latch (); +if (xirr) +return xirr;return in_be32 (&icp_native_regs[cpu]->xirr.word); }
@@ -138,6 +144,7 @@ static unsigned int icp_native_get_irq(void)static void icp_native_cause_ipi (int cpu,unsigned long data) { +kvmppc_set_host_ipi (cpu,1 );icp_native_set_qirr (cpu,IPI_PRIORITY ); }
@@ -151,6 +158,7 @@ static irqreturn_t icp_native_ipi_action(int irq, void *dev_id) {int cpu =smp_processor_id (); +kvmppc_set_host_ipi (cpu,0 );icp_native_set_qirr (cpu,0xff );return smp_ipi_demux ();