Skip to contentSkip to conversation

PPC64 Improve SLB reload

PATCH New Paul Mackerras 1 participant 1 message Aug 2, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PPC64 Improve SLB reload

Rewrite/cleanup of the SLB management code. This removes nearly all the SLB related code from arch/ppc64/kernel/stab.c and puts a rewritten version in arch/ppc64/mm, where it better belongs. The main SLB miss path is in assembler and the other routines have been cleaned up and streamlined.

Notable changes:
- Ugly bitfields no longer used for generating SLB entries.

- slb_allocate() (the main SLB miss routine) is now in
assembler, and all the data it uses is stored in the PACA.

- The mm context is now copied into the PACA at context switch
time, to avoid looking up the thread struct on SLB miss.

- An SLB miss will now never (directly) result in a call to
do_page_fault. If we get a miss on a totally bogus address the handler will now put in an SLB referencing VSID 0. This will never have any pages, so we'll get the (fatal) page fault shortly afterwards. This simplifies the SLB entry and exit paths.

- The round-robin pointer in the PACA now references the
last-used instead of next-to-use SLB slot, which simplifies the asm for updating it slightly.

- Unify do_slb_bolted with the general SLB miss path. There
is now one SLB miss handler, in assembler, and called with only the low-level exception prolog (EXCEPTION_PROLOG_[PI]SERIES rather than EXCEPTION_PROLOG_COMMON) and minimal extra save/restore logic.

- Streamlines the exception entry/exit path of the SLB miss
handler to shave a few cycles off. The most significant change is that the RI bit is left off throughout the whole handler, which avoids an extra mtmsrd to turn it back off on the exit path.

arch/ppc64/kernel/asm-offsets.c +8 -1
diff -urN linux-2.5/arch/ppc64/kernel/asm-offsets.c g5-ppc64/arch/ppc64/kernel/asm-offsets.c
@@ -86,10 +86,17 @@
         DEFINE(PACASAVEDMSR, offsetof(struct paca_struct, saved_msr));
         DEFINE(PACASTABREAL, offsetof(struct paca_struct, stab_real));
         DEFINE(PACASTABVIRT, offsetof(struct paca_struct, stab_addr));
-	DEFINE(PACASTABRR, offsetof(struct paca_struct, stab_next_rr));
+	DEFINE(PACASTABRR, offsetof(struct paca_struct, stab_rr));
         DEFINE(PACAR1, offsetof(struct paca_struct, saved_r1));
 	DEFINE(PACATOC, offsetof(struct paca_struct, kernel_toc));
 	DEFINE(PACAPROCENABLED, offsetof(struct paca_struct, proc_enabled));
+	DEFINE(PACASLBCACHE, offsetof(struct paca_struct, slb_cache));
+	DEFINE(PACASLBCACHEPTR, offsetof(struct paca_struct, slb_cache_ptr));
+	DEFINE(PACACONTEXTID, offsetof(struct paca_struct, context.id));
+	DEFINE(PACASLBR3, offsetof(struct paca_struct, slb_r3));
+#ifdef CONFIG_HUGETLB_PAGE
+	DEFINE(PACAHTLBSEGS, offsetof(struct paca_struct, context.htlb_segs));
+#endif /* CONFIG_HUGETLB_PAGE */
 	DEFINE(PACADEFAULTDECR, offsetof(struct paca_struct, default_decr));
 	DEFINE(PACAPROFENABLED, offsetof(struct paca_struct, prof_enabled));
 	DEFINE(PACAPROFLEN, offsetof(struct paca_struct, prof_len));
arch/ppc64/kernel/head.S +77 -172

311 lines not on this page · raw message

arch/ppc64/kernel/pacaData.c +0 -1
diff -urN linux-2.5/arch/ppc64/kernel/pacaData.c g5-ppc64/arch/ppc64/kernel/pacaData.c
@@ -57,7 +57,6 @@
 	.stab_addr = (asrv),		/* Virt pointer to segment table */ \
 	.emergency_sp = &emergency_stack[((number)+1) * PAGE_SIZE],	    \
 	.cpu_start = (start),		/* Processor start */		    \
-	.stab_next_rr = 1,						    \
 	.lppaca = {							    \
 		.xDesc = 0xd397d781,	/* "LpPa" */			    \
 		.xSize = sizeof(struct ItLpPaca),			    \
arch/ppc64/kernel/smp.c +0 -2
diff -urN linux-2.5/arch/ppc64/kernel/smp.c g5-ppc64/arch/ppc64/kernel/smp.c
@@ -389,8 +389,6 @@
 
 	/* Fixup atomic count: it exited inside IRQ handler. */
 	paca[lcpu].__current->thread_info->preempt_count	= 0;
-	/* Fixup SLB round-robin so next segment (kernel) goes in segment 0 */
-	paca[lcpu].stab_next_rr = 0;
 
 	/* At boot this is done in prom.c. */
 	paca[lcpu].hw_cpu_id = pcpu;
arch/ppc64/kernel/stab.c +8 -269

309 lines not on this page · raw message

arch/ppc64/mm/Makefile +1 -1
diff -urN linux-2.5/arch/ppc64/mm/Makefile g5-ppc64/arch/ppc64/mm/Makefile
@@ -4,6 +4,6 @@
 
 EXTRA_CFLAGS += -mno-minimal-toc
 
-obj-y := fault.o init.o imalloc.o hash_utils.o hash_low.o tlb.o
+obj-y := fault.o init.o imalloc.o hash_utils.o hash_low.o tlb.o slb_low.o slb.o
 obj-$(CONFIG_DISCONTIGMEM) += numa.o
 obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
arch/ppc64/mm/fault.c +4 -2
diff -urN linux-2.5/arch/ppc64/mm/fault.c g5-ppc64/arch/ppc64/mm/fault.c
@@ -93,13 +93,15 @@
 	unsigned long is_write = error_code & 0x02000000;
 	unsigned long trap = TRAP(regs);
 
-	if (trap == 0x300 || trap == 0x380) {
+	BUG_ON((trap == 0x380) || (trap == 0x480));
+
+	if (trap == 0x300) {
 		if (debugger_fault_handler(regs))
 			return 0;
 	}
 
 	/* On a kernel SLB miss we can only check for a valid exception entry */
-	if (!user_mode(regs) && (trap == 0x380 || address >= TASK_SIZE))
+	if (!user_mode(regs) && (address >= TASK_SIZE))
 		return SIGSEGV;
 
 	if (error_code & 0x00400000) {
arch/ppc64/mm/slb.c new file +136 -0

136 lines not on this page · raw message

arch/ppc64/mm/slb_low.S new file +168 -0

168 lines not on this page · raw message

include/asm-ppc64/mmu.h +24 -35

77 lines not on this page · raw message

include/asm-ppc64/mmu_context.h +2 -6
diff -urN linux-2.5/include/asm-ppc64/mmu_context.h g5-ppc64/include/asm-ppc64/mmu_context.h
@@ -136,7 +136,7 @@
 }
 
 extern void flush_stab(struct task_struct *tsk, struct mm_struct *mm);
-extern void flush_slb(struct task_struct *tsk, struct mm_struct *mm);
+extern void switch_slb(struct task_struct *tsk, struct mm_struct *mm);
 
 /*
  * switch_mm is the entry point called from the architecture independent
@@ -161,7 +161,7 @@
 		return;
 
 	if (cur_cpu_spec->cpu_features & CPU_FTR_SLB)
-		flush_slb(tsk, next);
+		switch_slb(tsk, next);
 	else
 		flush_stab(tsk, next);
 }
@@ -181,10 +181,6 @@
 	local_irq_restore(flags);
 }
 
-#define VSID_RANDOMIZER 42470972311UL
-#define VSID_MASK	0xfffffffffUL
-
-
 /* This is only valid for kernel (including vmalloc, imalloc and bolted) EA's
  */
 static inline unsigned long
include/asm-ppc64/paca.h +8 -2
diff -urN linux-2.5/include/asm-ppc64/paca.h g5-ppc64/include/asm-ppc64/paca.h
@@ -78,20 +78,26 @@
 	u64 exmc[8];		/* used for machine checks */
 	u64 exslb[8];		/* used for SLB/segment table misses
 				 * on the linear mapping */
-	u64 exdsi[8];		/* used for linear mapping hash table misses */
+	u64 slb_r3;		/* spot to save R3 on SLB miss */
+	mm_context_t context;
+	u16 slb_cache[SLB_CACHE_ENTRIES];
+	u16 slb_cache_ptr;
 
 	/*
 	 * then miscellaneous read-write fields
 	 */
 	struct task_struct *__current;	/* Pointer to current */
 	u64 kstack;			/* Saved Kernel stack addr */
-	u64 stab_next_rr;		/* stab/slb round-robin counter */
+	u64 stab_rr;			/* stab/slb round-robin counter */
 	u64 next_jiffy_update_tb;	/* TB value for next jiffy update */
 	u64 saved_r1;			/* r1 save for RTAS calls */
 	u64 saved_msr;			/* MSR saved here by enter_rtas */
 	u32 lpevent_count;		/* lpevents processed  */
 	u8 proc_enabled;		/* irq soft-enable flag */
 
+	/* not yet used */
+	u64 exdsi[8];		/* used for linear mapping hash table misses */
+
 	/*
 	 * iSeries structues which the hypervisor knows about - Not
 	 * sure if these particularly need to be cacheline aligned.
include/asm-ppc64/page.h +3 -2
diff -urN linux-2.5/include/asm-ppc64/page.h g5-ppc64/include/asm-ppc64/page.h
@@ -27,6 +27,7 @@
 
 #define SID_SHIFT       28
 #define SID_MASK        0xfffffffffUL
+#define ESID_MASK	0xfffffffff0000000UL
 #define GET_ESID(x)     (((x) >> SID_SHIFT) & SID_MASK)
 
 #ifdef CONFIG_HUGETLB_PAGE
@@ -37,8 +38,8 @@
 #define HUGETLB_PAGE_ORDER	(HPAGE_SHIFT - PAGE_SHIFT)
 
 /* For 64-bit processes the hugepage range is 1T-1.5T */
-#define TASK_HPAGE_BASE 	(0x0000010000000000UL)
-#define TASK_HPAGE_END 	(0x0000018000000000UL)
+#define TASK_HPAGE_BASE ASM_CONST(0x0000010000000000)
+#define TASK_HPAGE_END 	ASM_CONST(0x0000018000000000)
 
 #define LOW_ESID_MASK(addr, len)	(((1U << (GET_ESID(addr+len-1)+1)) \
 	   	                	- (1U << GET_ESID(addr))) & 0xffff)