Use scratch registers on XLR/XLS/XLP
PATCH v3 3/4 MIPS: mm: Use scratch for PGD when !CONFIG_MIPS_PGD_C0_CONTEXT
In reply to Jayachandran CAllow usage of scratch register for current pgd even when MIPS_PGD_C0_CONTEXT is not configured. MIPS_PGD_C0_CONTEXT is set for 64r2 platforms to indicate availability of Xcontext for saving cpuid, and this was also tied to using scratch registers for PGD.
This commit will allow usage of scratch register to store the current pgd, if one can be allocated for the platform, even in other cases (i.e when MIPS_PGD_C0_CONTEXT is not set). The processor id will be kept in the CP0 Context register in this case.
The code to store the current pgd for the TLB miss handler is now generated in all cases, and if scratch register is available, the pgd is also stored in the scratch register.
--- arch/mips/include/asm/mmu_context.h | 6 +- arch/mips/mm/tlbex.c | 143 ++++++++++++++++++++++------------- 2 files changed, 92 insertions(+), 57 deletions(-)
arch/mips/include/asm/mmu_context.h +1 -5
@@ -24,8 +24,6 @@#endif /* SMTC */ #include <asm-generic/mm_hooks.h> -#ifdef CONFIG_MIPS_PGD_C0_CONTEXT -#define TLBMISS_HANDLER_SETUP_PGD (pgd) \ do { \ void (*tlbmiss_handler_setup_pgd)(unsigned long); \
@@ -36,6 +34,7 @@ do { \tlbmiss_handler_setup_pgd ((unsigned long )(pgd)); \ } while (0) +#ifdef CONFIG_MIPS_PGD_C0_CONTEXT #define TLBMISS_HANDLER_SETUP () \ do { \ TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir); \
@@ -51,9 +50,6 @@ do { \*/ extern unsigned long pgd_current[]; -#define TLBMISS_HANDLER_SETUP_PGD (pgd) \ - pgd_current[smp_processor_id()] = (unsigned long)(pgd) -#ifdef CONFIG_32BIT #define TLBMISS_HANDLER_SETUP () \ write_c0_context((unsigned long) smp_processor_id() << 25); \
arch/mips/mm/tlbex.c +91 -52
224 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v3 1/4 MIPS: Allow platform specific scratch registers
In reply to Jayachandran CXLR/XLP COP0 scratch is register 22, sel 0-7. Add a function kscratch_reg() which returns the scratch register for the platform, and use the return value while generating TLB handlers.
Setup kscratch_mask to 0xf for XLR/XLP since the config4 register does not exist. This allows the kernel to allocate scratch registers 0-3 if needed.
--- arch/mips/kernel/cpu-probe.c | 1 + arch/mips/mm/tlbex.c | 43 +++++++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 15 deletions(-)
arch/mips/kernel/cpu-probe.c +1 -0
@@ -959,6 +959,7 @@ static inline void cpu_probe_netlogic(struct cpuinfo_mips *c, int cpu)set_isa (c,MIPS_CPU_ISA_M64R1 ); c->tlbsize = ((read_c0_config1 () >>25 ) &0x3f ) +1 ; } + c->kscratch_mask =0xf ; }#ifdef CONFIG_64BIT
arch/mips/mm/tlbex.c +28 -15
129 lines not on this page · raw message
Signature · 1 line
1.7.9.5
v3 cover Use scratch registers on XLR/XLS/XLP
This set of patches enable the use of scratch registers on XLR/XLS and XLP (cop0 reg 22, sel 0-7) to optimize the generated TLB handlers.
The current code assumes scratch is 31, which is fixed by the first patch. The second patch fixes a minor issue in checking if scratch is allocated. The third patch enables use of a scratch register when it is available even on a 32-bit or non-r2 platform. The fourth patch is a cleanup to consolidate all the defines needed into one file, this patch does not have any change in logic.
In the earlier scheme, if MIPS_PGD_C0_CONTEXT was defined, the Context register or a scratch register would contain the current PGD, and the Xcontext would contain the smp_processor_id shifted to index pointers.
In the new scheme, the behavior when MIPS_PGD_C0_CONTEXT is defined remains the same. But when it is not defined, we still try to allocate a scratch register for the current pgd. and the smp processor id remains in Context.
There is also an additional change is to generate the tlbmiss_handler_setup_pgd() function even when MIPS_PGD_C0_CONTEXT is not defined. This function will save the PGD in pgd_current[] and also in the scratch register if one has been allocated.
Comments/testing welcome.
Thanks,
JC.
Changes in v3:
* Add patch 2 - fix up check for a valid scratch register
Changes in v2:
* Update macros in thread-info.h, remove __ASSEMBLY__ part
* add ASM_CPUID_MFC0 and UASM_i_CPUID_MFC0 which allows us to remove a lot of conditional compilation.
* make c0_kscratch a inline function and remove global variable
Jayachandran C (4):
MIPS: Allow platform specific scratch registers
MIPS: Fixup check for invalid scratch register
MIPS: mm: Use scratch for PGD when !CONFIG_MIPS_PGD_C0_CONTEXT
MIPS: Move definition of SMP processor id register to header file
arch/mips/include/asm/mmu_context.h | 22 ++-- arch/mips/include/asm/stackframe.h | 23 ++-- arch/mips/include/asm/thread_info.h | 33 +++++- arch/mips/kernel/cpu-probe.c | 1 + arch/mips/mm/tlbex.c | 200 ++++++++++++++++++----------------- 5 files changed, 149 insertions(+), 130 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v3 4/4 MIPS: Move definition of SMP processor id register to header file
The definition of the CP0 register used to save the smp processor id is repicated in many files, move them all to thread_info.h.
--- arch/mips/include/asm/mmu_context.h | 16 +++---- arch/mips/include/asm/stackframe.h | 23 ++++------- arch/mips/include/asm/thread_info.h | 33 ++++++++++++++- arch/mips/mm/tlbex.c | 78 +++++++---------------------------- 4 files changed, 60 insertions(+), 90 deletions(-)
arch/mips/include/asm/mmu_context.h +5 -11
@@ -38,10 +38,11 @@ do { \#define TLBMISS_HANDLER_SETUP () \ do { \ TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir); \ - write_c0_xcontext((unsigned long) smp_processor_id() << 51); \ + write_c0_xcontext((unsigned long) smp_processor_id() << \ + SMP_CPUID_REGSHIFT); \ } while (0) -#else /* CONFIG_MIPS_PGD_C0_CONTEXT: using pgd_current*/ +#else /* !CONFIG_MIPS_PGD_C0_CONTEXT: using pgd_current*/ /* * For the fast tlb miss handlers, we keep a per cpu array of pointers
@@ -50,18 +51,11 @@ do { \*/ extern unsigned long pgd_current[]; -#ifdef CONFIG_32BIT #define TLBMISS_HANDLER_SETUP () \ - write_c0_context((unsigned long) smp_processor_id() << 25); \ + write_c0_context((unsigned long) smp_processor_id() << \ + SMP_CPUID_REGSHIFT); \ back_to_back_c0_hazard(); \ TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir) -#endif -#ifdef CONFIG_64BIT -#define TLBMISS_HANDLER_SETUP () \ - write_c0_context((unsigned long) smp_processor_id() << 26); \ - back_to_back_c0_hazard(); \ - TLBMISS_HANDLER_SETUP_PGD(swapper_pg_dir) -#endif #endif /* CONFIG_MIPS_PGD_C0_CONTEXT*/ #if defined(CONFIG_CPU_R3000 ) || defined(CONFIG_CPU_TX39XX )
arch/mips/include/asm/stackframe.h +8 -15
@@ -17,6 +17,7 @@#include <asm/asmmacro.h> #include <asm/mipsregs.h> #include <asm/asm-offsets.h> +#include <asm/thread_info.h> /* * For SMTC kernel, global IE should be left set, and interrupts
@@ -86,20 +87,12 @@#ifdef CONFIG_SMP #ifdef CONFIG_MIPS_MT_SMTC -#define PTEBASE_SHIFT 19/* TCBIND */ -#define CPU_ID_REG CP0_TCBIND -#define CPU_ID_MFC0 mfc0 -#elif defined(CONFIG_MIPS_PGD_C0_CONTEXT ) -#define PTEBASE_SHIFT 48/* XCONTEXT */ -#define CPU_ID_REG CP0_XCONTEXT -#define CPU_ID_MFC0 MFC0 +#define SMP_CPUID_MFC0 mfc0#else -#define PTEBASE_SHIFT 23/* CONTEXT */ -#define CPU_ID_REG CP0_CONTEXT -#define CPU_ID_MFC0 MFC0 +#define SMP_CPUID_MFC0 MFC0#endif .macro get_saved_sp /* SMP variation */ - CPU_ID_MFC0 k0, CPU_ID_REG + SMP_CPUID_MFC0 k0, SMP_CPUID_REG#if defined(CONFIG_32BIT ) || defined(KBUILD_64BIT_SYM32 ) lui k1, %hi(kernelsp) #else
@@ -109,17 +102,17 @@ daddiu k1, %hi(kernelsp) dsll k1, 16 #endif - LONG_SRL k0, PTEBASE_SHIFT + LONG_SRL k0, SMP_CPUID_PTRSHIFT LONG_ADDU k1, k0 LONG_L k1, %lo(kernelsp)(k1) .endm .macro set_saved_sp stackp temp temp2 - CPU_ID_MFC0 \temp, CPU_ID_REG - LONG_SRL \temp, PTEBASE_SHIFT + SMP_CPUID_MFC0 \temp, SMP_CPUID_REG + LONG_SRL \temp, SMP_CPUID_PTRSHIFT LONG_S \stackp, kernelsp(\temp) .endm -#else +#else /* !CONFIG_SMP */ .macro get_saved_sp /* Uniprocessor variation */ #ifdef CONFIG_CPU_JUMP_WORKAROUNDS/*
arch/mips/include/asm/thread_info.h +32 -1
@@ -147,6 +147,37 @@ static inline struct thread_info *current_thread_info(void)#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \ _TIF_WORK_SYSCALL_EXIT) -#endif /* __KERNEL__ */ +/* +* We stash processor id into a COP0 register to retrieve it fast +* at kernel exception entry. The register and shift used for this. +*/ +#ifdef CONFIG_MIPS_MT_SMTC +#ifdef __ASSEMBLY__ +#define SMP_CPUID_REG $2, 2/* TCBIND */ +#else +#define SMP_CPUID_REG 2, 2 +#endif +#define SMP_CPUID_PTRSHIFT 19 +#elif defined(CONFIG_MIPS_PGD_C0_CONTEXT ) +#ifdef __ASSEMBLY__ +#define SMP_CPUID_REG $20, 0/* XCONTEXT */ +#else +#define SMP_CPUID_REG 20, 0 +#endif +#define SMP_CPUID_PTRSHIFT 48 +#else +#ifdef __ASSEMBLY__ +#define SMP_CPUID_REG $4, 0/* CONTEXT */ +#else +#define SMP_CPUID_REG 4, 0 +#endif +#define SMP_CPUID_PTRSHIFT 23 +#endif +#ifdef CONFIG_64BIT +#define SMP_CPUID_REGSHIFT (SMP_CPUID_PTRSHIFT + 3) +#else +#define SMP_CPUID_REGSHIFT (SMP_CPUID_PTRSHIFT + 2) +#endif +#endif /* __KERNEL__ */ #endif /* _ASM_THREAD_INFO_H */
arch/mips/mm/tlbex.c +15 -63
110 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v3 2/4 MIPS: Fixup check for invalid scratch register
In reply to Jayachandran CThe invalid value for scratch register is -1, so update the checks of the form (scratch_reg > 0) to be (scratch_reg >= 0). This will fix the case in Netlogic XLP where the scratch_reg can be 0.
--- arch/mips/mm/tlbex.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/mips/mm/tlbex.c +5 -5
@@ -350,7 +350,7 @@ static struct work_registers __cpuinit build_get_work_registers(u32 **p)int smp_processor_id_sel;int smp_processor_id_shift; -if (scratch_reg >0 ) { +if (scratch_reg >=0 ) {/* Save in CPU local C0_KScratch? */ UASM_i_MTC0 (p,1 , c0_kscratch, scratch_reg); r.r1 =K0 ;
@@ -400,7 +400,7 @@ static struct work_registers __cpuinit build_get_work_registers(u32 **p)static void __cpuinit build_restore_work_registers (u32 **p) { -if (scratch_reg >0 ) { +if (scratch_reg >=0 ) {UASM_i_MFC0 (p,1 , c0_kscratch, scratch_reg);return ; }
@@ -689,7 +689,7 @@ static __cpuinit void build_restore_pagemask(u32 **p,uasm_i_mtc0 (p,0 ,C0_PAGEMASK );uasm_il_b (p, r, lid); } -if (scratch_reg >0 ) +if (scratch_reg >=0 )UASM_i_MFC0 (p,1 , c0_kscratch, scratch_reg);else UASM_i_LW (p,1 ,scratchpad_offset (0 ),0 );
@@ -945,7 +945,7 @@ build_get_pgd_vmalloc64(u32 **p, struct uasm_label **l, struct uasm_reloc **r,uasm_i_jr (p, ptr);if (mode == refill_scratch) { -if (scratch_reg >0 ) +if (scratch_reg >=0 )UASM_i_MFC0 (p,1 , c0_kscratch, scratch_reg);else UASM_i_LW (p,1 ,scratchpad_offset (0 ),0 );
@@ -1302,7 +1302,7 @@ static void __cpuinit build_r4000_tlb_refill_handler(void)memset (relocs,0 ,sizeof (relocs));memset (final_handler,0 ,sizeof (final_handler)); -if ((scratch_reg >0 ||scratchpad_available ()) &&use_bbit_insns ()) { +if ((scratch_reg >=0 ||scratchpad_available ()) &&use_bbit_insns ()) { htlb_info =build_fast_tlb_refill_handler (&p, &l, &r,K0 ,K1 , scratch_reg); vmalloc_mode = refill_scratch;
Signature · 1 line
1.7.9.5
Quoted 2 lines · Jayachandran C
This set of patches enable the use of scratch registers on XLR/XLS and XLP (cop0 reg 22, sel 0-7) to optimize the generated TLB handlers.
Looks like I submitted an older version of this patchset - I will post the updated version.
I have marked the patches as superseded in patchwork.
JC.