Subject: Re: evbppc reserved-tlb cleanup
To: Simon Burge <simonb@NetBSD.org>
From: Jachym Holecek <freza@dspfpga.com>
List: port-powerpc
Date: 10/31/2006 13:39:02
# Simon Burge 2006-10-27:
> [... too many wired TLB entries with larger RAM ...]
> 
> I've changed pmap_tlbmiss() to log kernel and non-kernel TLB misses
> separately, and booting to multiuser results in on 3.99.17:
> 
> 	evcnt type 2: cpu tlbmiss  =  433543
> 	evcnt type 2: cpu ktlbmiss =   17236
> 
> and with 4.99.3:
> 
> 	evcnt type 2: cpu tlbmiss  =  596968
> 
> No kernel TLB misses with 4.99.3 obviously, but around 150k or 33% more
> overall TLB misses were needed with needed with -current.  To show the
> effect of wiring too many TLBs, I rigged initppc() to wired enough TLBs
> for 512MB of RAM (32 wired TLBs), and see:
> 
> 	evcnt type 2: cpu tlbmiss  = 1275548
> 
> which results in nearly double the TLB misses as used by 16 wired TLBs.
> And here's with initppc() only wiring one TLB for RAM:
> 
> 	evcnt type 2: cpu tlbmiss  =  406119
> 	evcnt type 2: cpu ktlbmiss =   16270

Thanks for the analysis, sorry I didn't get around to measurements myself.

The patch below changes evbppc to map just 0 upto endkernel to make sure
the trap code has everything it could possibly need. Looks OK to commit?
(I've only compile-tested, I hope I can run it on the virtex later today)

Typically, this would mean one 16MB TLB entry is wired for kernel, but
we'll be safe even with huge ramdisk image embedded (or whatever).

	-- Jachym

Index: sys/arch/evbppc/explora/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/evbppc/explora/machdep.c,v
retrieving revision 1.15
diff -d -p -u -r1.15 machdep.c
--- sys/arch/evbppc/explora/machdep.c	23 Oct 2006 06:49:17 -0000	1.15
+++ sys/arch/evbppc/explora/machdep.c	31 Oct 2006 12:31:26 -0000
@@ -188,12 +188,11 @@ bootstrap(u_int startkernel, u_int endke
 
 	/*
 	 * Setup initial tlbs.
-	 * Physical memory and  console device are
+	 * Kernel memory and  console device are
 	 * mapped into the first (reserved) tlbs.
 	 */
 
-	t = 0;
-	for (maddr = 0; maddr < phys_mem[0].size; maddr += TLB_PG_SIZE)
+	for (maddr = 0; maddr < endkernel; maddr += TLB_PG_SIZE)
 		ppc4xx_tlb_reserve(maddr, maddr, TLB_PG_SIZE, TLB_EX);
 
 	/* Map PCKBC, PCKBC2, COM, LPT. */
Index: sys/arch/evbppc/obs405/obs200_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/evbppc/obs405/obs200_machdep.c,v
retrieving revision 1.4
diff -d -p -u -r1.4 obs200_machdep.c
--- sys/arch/evbppc/obs405/obs200_machdep.c	16 Oct 2006 18:14:35 -0000	1.4
+++ sys/arch/evbppc/obs405/obs200_machdep.c	31 Oct 2006 12:31:26 -0000
@@ -132,11 +132,11 @@ initppc(u_int startkernel, u_int endkern
 	bios_board_init(info_block, startkernel);
 	memsize = bios_board_memsize_get();
 
-	/* Linear map whole physmem. */
-	for (va = 0; va < memsize; va += TLB_PG_SIZE)
+	/* Linear map kernel memory. */
+	for (va = 0; va < endkernel; va += TLB_PG_SIZE)
 		ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
 
-	/* Map console right after RAM. */
+	/* Map console right after kernel. */
 	ppc4xx_tlb_reserve(OBS405_CONADDR, va, TLB_PG_SIZE, TLB_I | TLB_G);
 
 	/* Initialize IBM405GPr CPU */
Index: sys/arch/evbppc/obs405/obs266_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/evbppc/obs405/obs266_machdep.c,v
retrieving revision 1.5
diff -d -p -u -r1.5 obs266_machdep.c
--- sys/arch/evbppc/obs405/obs266_machdep.c	16 Oct 2006 18:14:35 -0000	1.5
+++ sys/arch/evbppc/obs405/obs266_machdep.c	31 Oct 2006 12:31:26 -0000
@@ -128,8 +128,8 @@ initppc(u_int startkernel, u_int endkern
 	openbios_board_init(info_block, startkernel);
 	memsize = openbios_board_memsize_get();
 
-	/* Linear map whole physmem */
-	for (va = 0; va < memsize; va += TLB_PG_SIZE)
+	/* Linear map kernel memory */
+	for (va = 0; va < endkernel; va += TLB_PG_SIZE)
 		ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
 
 	/* Map console just after RAM */
Index: sys/arch/evbppc/walnut/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/evbppc/walnut/machdep.c,v
retrieving revision 1.30
diff -d -p -u -r1.30 machdep.c
--- sys/arch/evbppc/walnut/machdep.c	16 Oct 2006 18:14:35 -0000	1.30
+++ sys/arch/evbppc/walnut/machdep.c	31 Oct 2006 12:31:26 -0000
@@ -195,11 +195,11 @@ initppc(u_int startkernel, u_int endkern
 	availmemr[0].start = startkernel; 
 	availmemr[0].size = board_data.mem_size - availmemr[0].start;
 
-	/* Linear map whole physmem */
-	for (va = 0; va < board_data.mem_size; va += TLB_PG_SIZE)
+	/* Linear map kernel memory */
+	for (va = 0; va < endkernel; va += TLB_PG_SIZE)
 		ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
 
-	/* Map console just after RAM */
+	/* Map console just after kernel */
 	ppc4xx_tlb_reserve(0xef000000, va, TLB_PG_SIZE, TLB_I | TLB_G);
 
 	/*