ppc: Do some batching of TCG tlb flushes
On ppc64 especially, we flush the tlb on any slbie or tlbie instruction. However, those instructions often come in bursts of 3 or more (context switch will favor a series of slbie's for example to an slbia if the SLB has less than a certain number of entries in it, and tlbie's can happen in a series, with PAPR, H_BULK_REMOVE can remove up to 4 entries at a time. Doing a tlb_flush() each time is a waste of time. We end up doing a memset of the whole TLB, reloading it for the next instruction, memset'ing again, etc... Those instructions don't have to take effect immediately. For slbie, they can wait for the next context synchronizing event. For tlbie, the next tlbsync. This implements batching by keeping a flag that indicates that we have a TLB in need of flushing. We check it on interrupts, rfi's, isync's and tlbsync and flush the TLB if needed. This reduces the number of tlb_flush() on a boot to a ubuntu installer first dialog screen from roughly 360K down to 36K. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> [clg: added a 'CPUPPCState *' variable in h_remove() and h_bulk_remove() ] Signed-off-by: Cédric Le Goater <clg@kaod.org> [dwg: removed spurious whitespace change, use 0/1 not true/false consistently, since tlb_need_flush has int type] Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
9fb0449114
commit
cd0c6f4735
|
@ -186,6 +186,7 @@ static RemoveResult remove_hpte(PowerPCCPU *cpu, target_ulong ptex,
|
||||||
static target_ulong h_remove(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
static target_ulong h_remove(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
||||||
target_ulong opcode, target_ulong *args)
|
target_ulong opcode, target_ulong *args)
|
||||||
{
|
{
|
||||||
|
CPUPPCState *env = &cpu->env;
|
||||||
target_ulong flags = args[0];
|
target_ulong flags = args[0];
|
||||||
target_ulong pte_index = args[1];
|
target_ulong pte_index = args[1];
|
||||||
target_ulong avpn = args[2];
|
target_ulong avpn = args[2];
|
||||||
|
@ -196,6 +197,7 @@ static target_ulong h_remove(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case REMOVE_SUCCESS:
|
case REMOVE_SUCCESS:
|
||||||
|
check_tlb_flush(env);
|
||||||
return H_SUCCESS;
|
return H_SUCCESS;
|
||||||
|
|
||||||
case REMOVE_NOT_FOUND:
|
case REMOVE_NOT_FOUND:
|
||||||
|
@ -232,7 +234,9 @@ static target_ulong h_remove(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
||||||
static target_ulong h_bulk_remove(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
static target_ulong h_bulk_remove(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
||||||
target_ulong opcode, target_ulong *args)
|
target_ulong opcode, target_ulong *args)
|
||||||
{
|
{
|
||||||
|
CPUPPCState *env = &cpu->env;
|
||||||
int i;
|
int i;
|
||||||
|
target_ulong rc = H_SUCCESS;
|
||||||
|
|
||||||
for (i = 0; i < H_BULK_REMOVE_MAX_BATCH; i++) {
|
for (i = 0; i < H_BULK_REMOVE_MAX_BATCH; i++) {
|
||||||
target_ulong *tsh = &args[i*2];
|
target_ulong *tsh = &args[i*2];
|
||||||
|
@ -265,14 +269,18 @@ static target_ulong h_bulk_remove(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REMOVE_PARM:
|
case REMOVE_PARM:
|
||||||
return H_PARAMETER;
|
rc = H_PARAMETER;
|
||||||
|
goto exit;
|
||||||
|
|
||||||
case REMOVE_HW:
|
case REMOVE_HW:
|
||||||
return H_HARDWARE;
|
rc = H_HARDWARE;
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exit:
|
||||||
|
check_tlb_flush(env);
|
||||||
|
|
||||||
return H_SUCCESS;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static target_ulong h_protect(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
static target_ulong h_protect(PowerPCCPU *cpu, sPAPRMachineState *spapr,
|
||||||
|
|
|
@ -958,6 +958,8 @@ struct CPUPPCState {
|
||||||
/* PowerPC 64 SLB area */
|
/* PowerPC 64 SLB area */
|
||||||
ppc_slb_t slb[MAX_SLB_ENTRIES];
|
ppc_slb_t slb[MAX_SLB_ENTRIES];
|
||||||
int32_t slb_nr;
|
int32_t slb_nr;
|
||||||
|
/* tcg TLB needs flush (deferred slb inval instruction typically) */
|
||||||
|
uint32_t tlb_need_flush;
|
||||||
#endif
|
#endif
|
||||||
/* segment registers */
|
/* segment registers */
|
||||||
hwaddr htab_base;
|
hwaddr htab_base;
|
||||||
|
|
|
@ -718,6 +718,11 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)
|
||||||
/* Reset exception state */
|
/* Reset exception state */
|
||||||
cs->exception_index = POWERPC_EXCP_NONE;
|
cs->exception_index = POWERPC_EXCP_NONE;
|
||||||
env->error_code = 0;
|
env->error_code = 0;
|
||||||
|
|
||||||
|
/* Any interrupt is context synchronizing, check if TCG TLB
|
||||||
|
* needs a delayed flush on ppc64
|
||||||
|
*/
|
||||||
|
check_tlb_flush(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ppc_cpu_do_interrupt(CPUState *cs)
|
void ppc_cpu_do_interrupt(CPUState *cs)
|
||||||
|
@ -943,6 +948,9 @@ static inline void do_rfi(CPUPPCState *env, target_ulong nip, target_ulong msr,
|
||||||
* as rfi is always the last insn of a TB
|
* as rfi is always the last insn of a TB
|
||||||
*/
|
*/
|
||||||
cs->interrupt_request |= CPU_INTERRUPT_EXITTB;
|
cs->interrupt_request |= CPU_INTERRUPT_EXITTB;
|
||||||
|
|
||||||
|
/* Context synchronizing: check if TCG TLB needs flush */
|
||||||
|
check_tlb_flush(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void helper_rfi(CPUPPCState *env)
|
void helper_rfi(CPUPPCState *env)
|
||||||
|
|
|
@ -16,6 +16,7 @@ DEF_HELPER_1(rfmci, void, env)
|
||||||
DEF_HELPER_1(rfid, void, env)
|
DEF_HELPER_1(rfid, void, env)
|
||||||
DEF_HELPER_1(hrfid, void, env)
|
DEF_HELPER_1(hrfid, void, env)
|
||||||
#endif
|
#endif
|
||||||
|
DEF_HELPER_1(check_tlb_flush, void, env)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DEF_HELPER_3(lmw, void, env, tl, i32)
|
DEF_HELPER_3(lmw, void, env, tl, i32)
|
||||||
|
|
|
@ -151,4 +151,17 @@ static inline int hreg_store_msr(CPUPPCState *env, target_ulong value,
|
||||||
return excp;
|
return excp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
|
||||||
|
static inline void check_tlb_flush(CPUPPCState *env)
|
||||||
|
{
|
||||||
|
CPUState *cs = CPU(ppc_env_get_cpu(env));
|
||||||
|
if (env->tlb_need_flush) {
|
||||||
|
env->tlb_need_flush = 0;
|
||||||
|
tlb_flush(cs, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static inline void check_tlb_flush(CPUPPCState *env) { }
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* !defined(__HELPER_REGS_H__) */
|
#endif /* !defined(__HELPER_REGS_H__) */
|
||||||
|
|
|
@ -99,10 +99,8 @@ void dump_slb(FILE *f, fprintf_function cpu_fprintf, PowerPCCPU *cpu)
|
||||||
|
|
||||||
void helper_slbia(CPUPPCState *env)
|
void helper_slbia(CPUPPCState *env)
|
||||||
{
|
{
|
||||||
PowerPCCPU *cpu = ppc_env_get_cpu(env);
|
int n;
|
||||||
int n, do_invalidate;
|
|
||||||
|
|
||||||
do_invalidate = 0;
|
|
||||||
/* XXX: Warning: slbia never invalidates the first segment */
|
/* XXX: Warning: slbia never invalidates the first segment */
|
||||||
for (n = 1; n < env->slb_nr; n++) {
|
for (n = 1; n < env->slb_nr; n++) {
|
||||||
ppc_slb_t *slb = &env->slb[n];
|
ppc_slb_t *slb = &env->slb[n];
|
||||||
|
@ -113,12 +111,9 @@ void helper_slbia(CPUPPCState *env)
|
||||||
* and we still don't have a tlb_flush_mask(env, n, mask)
|
* and we still don't have a tlb_flush_mask(env, n, mask)
|
||||||
* in QEMU, we just invalidate all TLBs
|
* in QEMU, we just invalidate all TLBs
|
||||||
*/
|
*/
|
||||||
do_invalidate = 1;
|
env->tlb_need_flush = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (do_invalidate) {
|
|
||||||
tlb_flush(CPU(cpu), 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void helper_slbie(CPUPPCState *env, target_ulong addr)
|
void helper_slbie(CPUPPCState *env, target_ulong addr)
|
||||||
|
@ -138,7 +133,7 @@ void helper_slbie(CPUPPCState *env, target_ulong addr)
|
||||||
* and we still don't have a tlb_flush_mask(env, n, mask)
|
* and we still don't have a tlb_flush_mask(env, n, mask)
|
||||||
* in QEMU, we just invalidate all TLBs
|
* in QEMU, we just invalidate all TLBs
|
||||||
*/
|
*/
|
||||||
tlb_flush(CPU(cpu), 1);
|
env->tlb_need_flush = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "exec/exec-all.h"
|
#include "exec/exec-all.h"
|
||||||
#include "exec/cpu_ldst.h"
|
#include "exec/cpu_ldst.h"
|
||||||
#include "exec/log.h"
|
#include "exec/log.h"
|
||||||
|
#include "helper_regs.h"
|
||||||
|
|
||||||
//#define DEBUG_MMU
|
//#define DEBUG_MMU
|
||||||
//#define DEBUG_BATS
|
//#define DEBUG_BATS
|
||||||
|
@ -1924,6 +1925,7 @@ void ppc_tlb_invalidate_all(CPUPPCState *env)
|
||||||
case POWERPC_MMU_2_06a:
|
case POWERPC_MMU_2_06a:
|
||||||
case POWERPC_MMU_2_07:
|
case POWERPC_MMU_2_07:
|
||||||
case POWERPC_MMU_2_07a:
|
case POWERPC_MMU_2_07a:
|
||||||
|
env->tlb_need_flush = 0;
|
||||||
#endif /* defined(TARGET_PPC64) */
|
#endif /* defined(TARGET_PPC64) */
|
||||||
tlb_flush(CPU(cpu), 1);
|
tlb_flush(CPU(cpu), 1);
|
||||||
break;
|
break;
|
||||||
|
@ -1986,7 +1988,7 @@ void ppc_tlb_invalidate_one(CPUPPCState *env, target_ulong addr)
|
||||||
* and we still don't have a tlb_flush_mask(env, n, mask) in QEMU,
|
* and we still don't have a tlb_flush_mask(env, n, mask) in QEMU,
|
||||||
* we just invalidate all TLBs
|
* we just invalidate all TLBs
|
||||||
*/
|
*/
|
||||||
tlb_flush(CPU(cpu), 1);
|
env->tlb_need_flush = 1;
|
||||||
break;
|
break;
|
||||||
#endif /* defined(TARGET_PPC64) */
|
#endif /* defined(TARGET_PPC64) */
|
||||||
default:
|
default:
|
||||||
|
@ -2875,6 +2877,11 @@ void helper_booke206_tlbflush(CPUPPCState *env, target_ulong type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void helper_check_tlb_flush(CPUPPCState *env)
|
||||||
|
{
|
||||||
|
check_tlb_flush(env);
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
/* try to fill the TLB and return an exception if error. If retaddr is
|
/* try to fill the TLB and return an exception if error. If retaddr is
|
||||||
|
|
|
@ -3275,9 +3275,32 @@ static void gen_eieio(DisasContext *ctx)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(CONFIG_USER_ONLY) && defined(TARGET_PPC64)
|
||||||
|
static inline void gen_check_tlb_flush(DisasContext *ctx)
|
||||||
|
{
|
||||||
|
TCGv_i32 t = tcg_temp_new_i32();
|
||||||
|
TCGLabel *l = gen_new_label();
|
||||||
|
|
||||||
|
tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, tlb_need_flush));
|
||||||
|
tcg_gen_brcondi_i32(TCG_COND_EQ, t, 0, l);
|
||||||
|
gen_helper_check_tlb_flush(cpu_env);
|
||||||
|
gen_set_label(l);
|
||||||
|
tcg_temp_free_i32(t);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static inline void gen_check_tlb_flush(DisasContext *ctx) { }
|
||||||
|
#endif
|
||||||
|
|
||||||
/* isync */
|
/* isync */
|
||||||
static void gen_isync(DisasContext *ctx)
|
static void gen_isync(DisasContext *ctx)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* We need to check for a pending TLB flush. This can only happen in
|
||||||
|
* kernel mode however so check MSR_PR
|
||||||
|
*/
|
||||||
|
if (!ctx->pr) {
|
||||||
|
gen_check_tlb_flush(ctx);
|
||||||
|
}
|
||||||
gen_stop_exception(ctx);
|
gen_stop_exception(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3434,6 +3457,15 @@ STCX(stqcx_, 16);
|
||||||
/* sync */
|
/* sync */
|
||||||
static void gen_sync(DisasContext *ctx)
|
static void gen_sync(DisasContext *ctx)
|
||||||
{
|
{
|
||||||
|
uint32_t l = (ctx->opcode >> 21) & 3;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For l == 2, it's a ptesync, We need to check for a pending TLB flush.
|
||||||
|
* This can only happen in kernel mode however so check MSR_PR as well.
|
||||||
|
*/
|
||||||
|
if (l == 2 && !ctx->pr) {
|
||||||
|
gen_check_tlb_flush(ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wait */
|
/* wait */
|
||||||
|
@ -4851,10 +4883,11 @@ static void gen_tlbsync(DisasContext *ctx)
|
||||||
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
|
gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* This has no effect: it should ensure that all previous
|
/* tlbsync is a nop for server, ptesync handles delayed tlb flush,
|
||||||
* tlbie have completed
|
* embedded however needs to deal with tlbsync. We don't try to be
|
||||||
|
* fancy and swallow the overhead of checking for both.
|
||||||
*/
|
*/
|
||||||
gen_stop_exception(ctx);
|
gen_check_tlb_flush(ctx);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue