Skip to content

Commit 5b06d16

Browse files
npigginmpe
authored andcommitted
powerpc/pseries: Use doorbells even if XIVE is available
KVM supports msgsndp in guests by trapping and emulating the instruction, so it was decided to always use XIVE for IPIs if it is available. However on PowerVM systems, msgsndp can be used and gives better performance. On large systems, high XIVE interrupt rates can have sub-linear scaling, and using msgsndp can reduce the load on the interrupt controller. So switch to using core local doorbells even if XIVE is available. This reduces performance for KVM guests with an SMT topology by about 50% for ping-pong context switching between SMT vCPUs. An option vector (or dt-cpu-ftrs) could be defined to disable msgsndp to get KVM performance back. Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Tested-by: Cédric Le Goater <clg@kaod.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20200726035155.1424103-3-npiggin@gmail.com
1 parent 1f0ce49 commit 5b06d16

1 file changed

Lines changed: 36 additions & 18 deletions

File tree

  • arch/powerpc/platforms/pseries

‎arch/powerpc/platforms/pseries/smp.c‎

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,16 @@ static int pseries_smp_prepare_cpu(int cpu)
162162
return 0;
163163
}
164164

165-
static void smp_pseries_cause_ipi(int cpu)
165+
/* Cause IPI as setup by the interrupt controller (xics or xive) */
166+
static void (*ic_cause_ipi)(int cpu) __ro_after_init;
167+
168+
/* Use msgsndp doorbells target is a sibling, else use interrupt controller */
169+
static void dbell_or_ic_cause_ipi(int cpu)
166170
{
167-
/* POWER9 should not use this handler */
168171
if (doorbell_try_core_ipi(cpu))
169172
return;
170173

171-
icp_ops->cause_ipi(cpu);
174+
ic_cause_ipi(cpu);
172175
}
173176

174177
static int pseries_cause_nmi_ipi(int cpu)
@@ -192,26 +195,41 @@ static int pseries_cause_nmi_ipi(int cpu)
192195
return 0;
193196
}
194197

195-
static __init void pSeries_smp_probe_xics(void)
196-
{
197-
xics_smp_probe();
198-
199-
if (cpu_has_feature(CPU_FTR_DBELL) && !is_secure_guest())
200-
smp_ops->cause_ipi = smp_pseries_cause_ipi;
201-
else
202-
smp_ops->cause_ipi = icp_ops->cause_ipi;
203-
}
204-
205198
static __init void pSeries_smp_probe(void)
206199
{
207200
if (xive_enabled())
208-
/*
209-
* Don't use P9 doorbells when XIVE is enabled. IPIs
210-
* using MMIOs should be faster
211-
*/
212201
xive_smp_probe();
213202
else
214-
pSeries_smp_probe_xics();
203+
xics_smp_probe();
204+
205+
/* No doorbell facility, must use the interrupt controller for IPIs */
206+
if (!cpu_has_feature(CPU_FTR_DBELL))
207+
return;
208+
209+
/* Doorbells can only be used for IPIs between SMT siblings */
210+
if (!cpu_has_feature(CPU_FTR_SMT))
211+
return;
212+
213+
/*
214+
* KVM emulates doorbells by disabling FSCR[MSGP] so msgsndp faults
215+
* to the hypervisor which then reads the instruction from guest
216+
* memory. This can't be done if the guest is secure, so don't use
217+
* doorbells in secure guests.
218+
*
219+
* Under PowerVM, FSCR[MSGP] is enabled so doorbells could be used
220+
* by secure guests if we distinguished this from KVM.
221+
*/
222+
if (is_secure_guest())
223+
return;
224+
225+
/*
226+
* The guest can use doobells for SMT sibling IPIs, which stay in
227+
* the core rather than going to the interrupt controller. This
228+
* tends to be slower under KVM where doorbells are emulated, but
229+
* faster for PowerVM where they're enabled.
230+
*/
231+
ic_cause_ipi = smp_ops->cause_ipi;
232+
smp_ops->cause_ipi = dbell_or_ic_cause_ipi;
215233
}
216234

217235
static struct smp_ops_t pseries_smp_ops = {

0 commit comments

Comments
 (0)