From: Alexander Graf <agraf@suse.de>
To: Paul Mackerras <paulus@samba.org>,
kvm-ppc@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH 20/23] KVM: PPC: Book3S HV: Use msgsnd for signalling threads on POWER8
Date: Fri, 20 Mar 2015 11:28:25 +0000 [thread overview]
Message-ID: <550C0459.5040204@suse.de> (raw)
In-Reply-To: <1426844400-12017-21-git-send-email-paulus@samba.org>
On 20.03.15 10:39, Paul Mackerras wrote:
> This uses msgsnd where possible for signalling other threads within
> the same core on POWER8 systems, rather than IPIs through the XICS
> interrupt controller. This includes waking secondary threads to run
> the guest, the interrupts generated by the virtual XICS, and the
> interrupts to bring the other threads out of the guest when exiting.
>
> Signed-off-by: Paul Mackerras <paulus@samba.org>
> ---
> arch/powerpc/kernel/asm-offsets.c | 4 +++
> arch/powerpc/kvm/book3s_hv.c | 48 ++++++++++++++++++++++-----------
> arch/powerpc/kvm/book3s_hv_rm_xics.c | 11 ++++++++
> arch/powerpc/kvm/book3s_hv_rmhandlers.S | 41 ++++++++++++++++++++++++----
> 4 files changed, 83 insertions(+), 21 deletions(-)
>
> diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
> index fa7b57d..0ce2aa6 100644
> --- a/arch/powerpc/kernel/asm-offsets.c
> +++ b/arch/powerpc/kernel/asm-offsets.c
> @@ -37,6 +37,7 @@
> #include <asm/thread_info.h>
> #include <asm/rtas.h>
> #include <asm/vdso_datapage.h>
> +#include <asm/dbell.h>
> #ifdef CONFIG_PPC64
> #include <asm/paca.h>
> #include <asm/lppaca.h>
> @@ -568,6 +569,7 @@ int main(void)
> DEFINE(VCORE_LPCR, offsetof(struct kvmppc_vcore, lpcr));
> DEFINE(VCORE_PCR, offsetof(struct kvmppc_vcore, pcr));
> DEFINE(VCORE_DPDES, offsetof(struct kvmppc_vcore, dpdes));
> + DEFINE(VCORE_PCPU, offsetof(struct kvmppc_vcore, pcpu));
> DEFINE(VCPU_SLB_E, offsetof(struct kvmppc_slb, orige));
> DEFINE(VCPU_SLB_V, offsetof(struct kvmppc_slb, origv));
> DEFINE(VCPU_SLB_SIZE, sizeof(struct kvmppc_slb));
> @@ -757,5 +759,7 @@ int main(void)
> offsetof(struct paca_struct, subcore_sibling_mask));
> #endif
>
> + DEFINE(PPC_DBELL_SERVER, PPC_DBELL_SERVER);
> +
> return 0;
> }
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 03a8bb4..2c34bae 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -51,6 +51,7 @@
> #include <asm/hvcall.h>
> #include <asm/switch_to.h>
> #include <asm/smp.h>
> +#include <asm/dbell.h>
> #include <linux/gfp.h>
> #include <linux/vmalloc.h>
> #include <linux/highmem.h>
> @@ -84,9 +85,34 @@ static DECLARE_BITMAP(default_enabled_hcalls, MAX_HCALL_OPCODE/4 + 1);
> static void kvmppc_end_cede(struct kvm_vcpu *vcpu);
> static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu);
>
> +static bool kvmppc_ipi_thread(int cpu)
> +{
> + /* On POWER8 for IPIs to threads in the same core, use msgsnd */
> + if (cpu_has_feature(CPU_FTR_ARCH_207S)) {
> + preempt_disable();
> + if ((cpu & ~7) = (smp_processor_id() & ~7)) {
> + unsigned long msg = PPC_DBELL_TYPE(PPC_DBELL_SERVER);
> + msg |= cpu & 7;
> + smp_mb();
> + __asm__ __volatile__ (PPC_MSGSND(%0) : : "r" (msg));
> + preempt_enable();
> + return true;
> + }
> + preempt_enable();
> + }
> +
> +#if defined(CONFIG_PPC_ICP_NATIVE) && defined(CONFIG_SMP)
> + if (cpu >= 0 && cpu < nr_cpu_ids && paca[cpu].kvm_hstate.xics_phys) {
> + xics_wake_cpu(cpu);
> + return true;
> + }
> +#endif
> +
> + return false;
> +}
> +
> static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu)
> {
> - int me;
> int cpu = vcpu->cpu;
> wait_queue_head_t *wqp;
>
> @@ -96,20 +122,12 @@ static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu)
> ++vcpu->stat.halt_wakeup;
> }
>
> - me = get_cpu();
> + if (kvmppc_ipi_thread(cpu + vcpu->arch.ptid))
> + return;
>
> /* CPU points to the first thread of the core */
> - if (cpu != me && cpu >= 0 && cpu < nr_cpu_ids) {
> -#ifdef CONFIG_PPC_ICP_NATIVE
> - int real_cpu = cpu + vcpu->arch.ptid;
> - if (paca[real_cpu].kvm_hstate.xics_phys)
> - xics_wake_cpu(real_cpu);
> - else
> -#endif
> - if (cpu_online(cpu))
> - smp_send_reschedule(cpu);
> - }
> - put_cpu();
> + if (cpu >= 0 && cpu < nr_cpu_ids && cpu_online(cpu))
> + smp_send_reschedule(cpu);
> }
>
> /*
> @@ -1754,10 +1772,8 @@ static void kvmppc_start_thread(struct kvm_vcpu *vcpu)
> /* Order stores to hstate.kvm_vcore etc. before store to kvm_vcpu */
> smp_wmb();
> tpaca->kvm_hstate.kvm_vcpu = vcpu;
> -#if defined(CONFIG_PPC_ICP_NATIVE) && defined(CONFIG_SMP)
> if (cpu != smp_processor_id())
> - xics_wake_cpu(cpu);
> -#endif
> + kvmppc_ipi_thread(cpu);
> }
>
> static void kvmppc_wait_for_nap(void)
> diff --git a/arch/powerpc/kvm/book3s_hv_rm_xics.c b/arch/powerpc/kvm/book3s_hv_rm_xics.c
> index 6dded8c..457a8b1 100644
> --- a/arch/powerpc/kvm/book3s_hv_rm_xics.c
> +++ b/arch/powerpc/kvm/book3s_hv_rm_xics.c
> @@ -18,6 +18,7 @@
> #include <asm/debug.h>
> #include <asm/synch.h>
> #include <asm/ppc-opcode.h>
> +#include <asm/dbell.h>
>
> #include "book3s_xics.h"
>
> @@ -83,6 +84,16 @@ static void icp_rm_set_vcpu_irq(struct kvm_vcpu *vcpu,
> /* In SMT cpu will always point to thread 0, we adjust it */
> cpu += vcpu->arch.ptid;
>
> + /* On POWER8 for IPIs to threads in the same core, use msgsnd */
> + if (cpu_has_feature(CPU_FTR_ARCH_207S) &&
> + (cpu & ~7) = (raw_smp_processor_id() & ~7)) {
Can we somehow encapsulate the secret knowledge that 8 threads mean one
core?
Alex
WARNING: multiple messages have this Message-ID (diff)
From: Alexander Graf <agraf@suse.de>
To: Paul Mackerras <paulus@samba.org>,
kvm-ppc@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH 20/23] KVM: PPC: Book3S HV: Use msgsnd for signalling threads on POWER8
Date: Fri, 20 Mar 2015 12:28:25 +0100 [thread overview]
Message-ID: <550C0459.5040204@suse.de> (raw)
In-Reply-To: <1426844400-12017-21-git-send-email-paulus@samba.org>
On 20.03.15 10:39, Paul Mackerras wrote:
> This uses msgsnd where possible for signalling other threads within
> the same core on POWER8 systems, rather than IPIs through the XICS
> interrupt controller. This includes waking secondary threads to run
> the guest, the interrupts generated by the virtual XICS, and the
> interrupts to bring the other threads out of the guest when exiting.
>
> Signed-off-by: Paul Mackerras <paulus@samba.org>
> ---
> arch/powerpc/kernel/asm-offsets.c | 4 +++
> arch/powerpc/kvm/book3s_hv.c | 48 ++++++++++++++++++++++-----------
> arch/powerpc/kvm/book3s_hv_rm_xics.c | 11 ++++++++
> arch/powerpc/kvm/book3s_hv_rmhandlers.S | 41 ++++++++++++++++++++++++----
> 4 files changed, 83 insertions(+), 21 deletions(-)
>
> diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
> index fa7b57d..0ce2aa6 100644
> --- a/arch/powerpc/kernel/asm-offsets.c
> +++ b/arch/powerpc/kernel/asm-offsets.c
> @@ -37,6 +37,7 @@
> #include <asm/thread_info.h>
> #include <asm/rtas.h>
> #include <asm/vdso_datapage.h>
> +#include <asm/dbell.h>
> #ifdef CONFIG_PPC64
> #include <asm/paca.h>
> #include <asm/lppaca.h>
> @@ -568,6 +569,7 @@ int main(void)
> DEFINE(VCORE_LPCR, offsetof(struct kvmppc_vcore, lpcr));
> DEFINE(VCORE_PCR, offsetof(struct kvmppc_vcore, pcr));
> DEFINE(VCORE_DPDES, offsetof(struct kvmppc_vcore, dpdes));
> + DEFINE(VCORE_PCPU, offsetof(struct kvmppc_vcore, pcpu));
> DEFINE(VCPU_SLB_E, offsetof(struct kvmppc_slb, orige));
> DEFINE(VCPU_SLB_V, offsetof(struct kvmppc_slb, origv));
> DEFINE(VCPU_SLB_SIZE, sizeof(struct kvmppc_slb));
> @@ -757,5 +759,7 @@ int main(void)
> offsetof(struct paca_struct, subcore_sibling_mask));
> #endif
>
> + DEFINE(PPC_DBELL_SERVER, PPC_DBELL_SERVER);
> +
> return 0;
> }
> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 03a8bb4..2c34bae 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -51,6 +51,7 @@
> #include <asm/hvcall.h>
> #include <asm/switch_to.h>
> #include <asm/smp.h>
> +#include <asm/dbell.h>
> #include <linux/gfp.h>
> #include <linux/vmalloc.h>
> #include <linux/highmem.h>
> @@ -84,9 +85,34 @@ static DECLARE_BITMAP(default_enabled_hcalls, MAX_HCALL_OPCODE/4 + 1);
> static void kvmppc_end_cede(struct kvm_vcpu *vcpu);
> static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu);
>
> +static bool kvmppc_ipi_thread(int cpu)
> +{
> + /* On POWER8 for IPIs to threads in the same core, use msgsnd */
> + if (cpu_has_feature(CPU_FTR_ARCH_207S)) {
> + preempt_disable();
> + if ((cpu & ~7) == (smp_processor_id() & ~7)) {
> + unsigned long msg = PPC_DBELL_TYPE(PPC_DBELL_SERVER);
> + msg |= cpu & 7;
> + smp_mb();
> + __asm__ __volatile__ (PPC_MSGSND(%0) : : "r" (msg));
> + preempt_enable();
> + return true;
> + }
> + preempt_enable();
> + }
> +
> +#if defined(CONFIG_PPC_ICP_NATIVE) && defined(CONFIG_SMP)
> + if (cpu >= 0 && cpu < nr_cpu_ids && paca[cpu].kvm_hstate.xics_phys) {
> + xics_wake_cpu(cpu);
> + return true;
> + }
> +#endif
> +
> + return false;
> +}
> +
> static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu)
> {
> - int me;
> int cpu = vcpu->cpu;
> wait_queue_head_t *wqp;
>
> @@ -96,20 +122,12 @@ static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu)
> ++vcpu->stat.halt_wakeup;
> }
>
> - me = get_cpu();
> + if (kvmppc_ipi_thread(cpu + vcpu->arch.ptid))
> + return;
>
> /* CPU points to the first thread of the core */
> - if (cpu != me && cpu >= 0 && cpu < nr_cpu_ids) {
> -#ifdef CONFIG_PPC_ICP_NATIVE
> - int real_cpu = cpu + vcpu->arch.ptid;
> - if (paca[real_cpu].kvm_hstate.xics_phys)
> - xics_wake_cpu(real_cpu);
> - else
> -#endif
> - if (cpu_online(cpu))
> - smp_send_reschedule(cpu);
> - }
> - put_cpu();
> + if (cpu >= 0 && cpu < nr_cpu_ids && cpu_online(cpu))
> + smp_send_reschedule(cpu);
> }
>
> /*
> @@ -1754,10 +1772,8 @@ static void kvmppc_start_thread(struct kvm_vcpu *vcpu)
> /* Order stores to hstate.kvm_vcore etc. before store to kvm_vcpu */
> smp_wmb();
> tpaca->kvm_hstate.kvm_vcpu = vcpu;
> -#if defined(CONFIG_PPC_ICP_NATIVE) && defined(CONFIG_SMP)
> if (cpu != smp_processor_id())
> - xics_wake_cpu(cpu);
> -#endif
> + kvmppc_ipi_thread(cpu);
> }
>
> static void kvmppc_wait_for_nap(void)
> diff --git a/arch/powerpc/kvm/book3s_hv_rm_xics.c b/arch/powerpc/kvm/book3s_hv_rm_xics.c
> index 6dded8c..457a8b1 100644
> --- a/arch/powerpc/kvm/book3s_hv_rm_xics.c
> +++ b/arch/powerpc/kvm/book3s_hv_rm_xics.c
> @@ -18,6 +18,7 @@
> #include <asm/debug.h>
> #include <asm/synch.h>
> #include <asm/ppc-opcode.h>
> +#include <asm/dbell.h>
>
> #include "book3s_xics.h"
>
> @@ -83,6 +84,16 @@ static void icp_rm_set_vcpu_irq(struct kvm_vcpu *vcpu,
> /* In SMT cpu will always point to thread 0, we adjust it */
> cpu += vcpu->arch.ptid;
>
> + /* On POWER8 for IPIs to threads in the same core, use msgsnd */
> + if (cpu_has_feature(CPU_FTR_ARCH_207S) &&
> + (cpu & ~7) == (raw_smp_processor_id() & ~7)) {
Can we somehow encapsulate the secret knowledge that 8 threads mean one
core?
Alex
next prev parent reply other threads:[~2015-03-20 11:28 UTC|newest]
Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-20 9:39 [PATCH 00/23] Bug fixes and improvements for HV KVM Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 01/23] KVM: PPC: Book3S HV: Fix spinlock/mutex ordering issue in kvmppc_set_lpcr() Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 02/23] KVM: PPC: Book3S HV: Endian fix for accessing VPA yield count Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 03/23] KVM: PPC: Book3S HV: Fix instruction emulation Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 04/23] KVM: PPC: Book3S HV: Add fast real-mode H_RANDOM implementation Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 05/23] KVM: PPC: Book3S HV: Remove RMA-related variables from code Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 06/23] KVM: PPC: Book3S HV: Add helpers for lock/unlock hpte Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 07/23] KVM: PPC: Book3S: Allow reuse of vCPU object Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 11:01 ` Alexander Graf
2015-03-20 11:01 ` Alexander Graf
2015-03-20 11:26 ` Paul Mackerras
2015-03-20 11:26 ` Paul Mackerras
2015-03-20 11:34 ` Alexander Graf
2015-03-20 11:34 ` Alexander Graf
2015-03-20 15:51 ` Bharata B Rao
2015-03-20 15:51 ` Bharata B Rao
2015-03-21 14:58 ` Alexander Graf
2015-03-21 14:58 ` Alexander Graf
2015-03-23 7:50 ` Bharata B Rao
2015-03-23 7:51 ` Bharata B Rao
2015-03-23 8:31 ` Alexander Graf
2015-03-23 8:31 ` Alexander Graf
2015-03-20 9:39 ` [PATCH 08/23] KVM: PPC: Book3S HV: Add guest->host real mode completion counters Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 09/23] KVM: PPC: Book3S HV: Convert ICS mutex lock to spin lock Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 10/23] KVM: PPC: Book3S HV: Move virtual mode ICP functions to real-mode Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 11/23] KVM: PPC: Book3S HV: Add ICP real mode counters Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 12/23] KVM: PPC: Book3S HV: Create debugfs file for each guest's HPT Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 11:20 ` Alexander Graf
2015-03-20 11:20 ` Alexander Graf
2015-03-20 9:39 ` [PATCH 13/23] KVM: PPC: Book3S HV: Accumulate timing information for real-mode code Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 11:15 ` Alexander Graf
2015-03-20 11:15 ` Alexander Graf
2015-03-20 11:25 ` Paul Mackerras
2015-03-20 11:25 ` Paul Mackerras
2015-03-20 11:35 ` Alexander Graf
2015-03-20 11:35 ` Alexander Graf
2015-03-22 22:57 ` Paul Mackerras
2015-03-22 22:57 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 14/23] KVM: PPC: Book3S HV: Simplify handling of VCPUs that need a VPA update Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 15/23] KVM: PPC: Book3S HV: Minor cleanups Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 16/23] KVM: PPC: Book3S HV: Move vcore preemption point up into kvmppc_run_vcpu Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 17/23] KVM: PPC: Book3S HV: Get rid of vcore nap_count and n_woken Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 18/23] KVM: PPC: Book3S HV: Don't wake thread with no vcpu on guest IPI Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 19/23] KVM: PPC: Book3S HV: Use decrementer to wake napping threads Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 20/23] KVM: PPC: Book3S HV: Use msgsnd for signalling threads on POWER8 Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 11:28 ` Alexander Graf [this message]
2015-03-20 11:28 ` Alexander Graf
2015-03-23 0:44 ` Paul Mackerras
2015-03-23 0:44 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 21/23] KVM: PPC: Book3S HV: Streamline guest entry and exit Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:39 ` [PATCH 22/23] KVM: PPC: Book3S HV: Use bitmap of active threads rather than count Paul Mackerras
2015-03-20 9:39 ` Paul Mackerras
2015-03-20 9:40 ` [PATCH 23/23] KVM: PPC: Book3S HV: Translate kvmhv_commence_exit to C Paul Mackerras
2015-03-20 9:40 ` Paul Mackerras
2015-03-20 10:45 ` [PATCH 00/23] Bug fixes and improvements for HV KVM Alexander Graf
2015-03-20 10:45 ` Alexander Graf
2015-03-20 11:36 ` Alexander Graf
2015-03-20 11:36 ` Alexander Graf
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=550C0459.5040204@suse.de \
--to=agraf@suse.de \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=paulus@samba.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.