Subject: small pmap.c change proposed
To: None <port-mips@netbsd.org>
From: Toru Nishimura <nisimura@itc.aist-nara.ac.jp>
List: port-mips
Date: 03/29/2000 11:51:04
Folks,

Will the following hack make any performance difference with yours?

Index: pmap.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/mips/mips/pmap.c,v
retrieving revision 1.87
diff -c -r1.87 pmap.c
*** pmap.c	2000/03/28 05:58:33	1.87
--- pmap.c	2000/03/29 02:44:56
***************
*** 308,321 ****
  	 */
  	simple_lock_init(&pmap_kernel()->pm_lock);
  	pmap_kernel()->pm_count = 1;
! 	pmap_kernel()->pm_asid = 1;
  	pmap_kernel()->pm_asidgen = 0;
  
  	pmap_max_asid = MIPS_TLB_NUM_PIDS;
! 	pmap_next_asid = 2;
  	pmap_asid_generation = 0;
  
! 	MachSetPID(1);
  
  #ifdef MIPS3
  	/*
--- 308,321 ----
  	 */
  	simple_lock_init(&pmap_kernel()->pm_lock);
  	pmap_kernel()->pm_count = 1;
! 	pmap_kernel()->pm_asid = 0;
  	pmap_kernel()->pm_asidgen = 0;
  
  	pmap_max_asid = MIPS_TLB_NUM_PIDS;
! 	pmap_next_asid = 1;
  	pmap_asid_generation = 0;
  
! 	MachSetPID(0);
  
  #ifdef MIPS3
  	/*
***************
*** 692,698 ****
  	vaddr_t nssva;
  	pt_entry_t *pte;
  	unsigned entry;
! 	unsigned asid, needflush;
  
  #ifdef DEBUG
  	if (pmapdebug & (PDB_FOLLOW|PDB_REMOVE|PDB_PROTECT))
--- 692,698 ----
  	vaddr_t nssva;
  	pt_entry_t *pte;
  	unsigned entry;
! 	unsigned needflush;
  
  #ifdef DEBUG
  	if (pmapdebug & (PDB_FOLLOW|PDB_REMOVE|PDB_PROTECT))
***************
*** 751,758 ****
  		}
  	}
  #endif
! 	asid = pmap->pm_asid << MIPS_TLB_PID_SHIFT;
! 	needflush = (pmap->pm_asidgen == pmap_asid_generation);
  	while (sva < eva) {
  		nssva = mips_trunc_seg(sva) + NBSEG;
  		if (nssva == 0 || nssva > eva)
--- 751,757 ----
  		}
  	}
  #endif
! 	needflush = 0;
  	while (sva < eva) {
  		nssva = mips_trunc_seg(sva) + NBSEG;
  		if (nssva == 0 || nssva > eva)
***************
*** 773,792 ****
  			entry = pte->pt_entry;
  			if (!mips_pg_v(entry))
  				continue;
  			if (mips_pg_wired(entry))
  				pmap->pm_stats.wired_count--;
  			pmap->pm_stats.resident_count--;
  			pmap_remove_pv(pmap, sva, pfn_to_vad(entry));
  			pte->pt_entry = mips_pg_nv_bit();
- 			/*
- 			 * Flush the TLB for the given address.
- 			 */
- 			if (needflush) {
- 				MachTLBFlushAddr(sva | asid);
  #ifdef DEBUG
! 				remove_stats.flushes++;
  #endif
! 			}
  		}
  	}
  }
--- 772,795 ----
  			entry = pte->pt_entry;
  			if (!mips_pg_v(entry))
  				continue;
+ 			needflush = 1;
  			if (mips_pg_wired(entry))
  				pmap->pm_stats.wired_count--;
  			pmap->pm_stats.resident_count--;
  			pmap_remove_pv(pmap, sva, pfn_to_vad(entry));
  			pte->pt_entry = mips_pg_nv_bit();
  #ifdef DEBUG
! 			remove_stats.flushes++;
  #endif
! 		}
! 	}
! 	if (needflush && (pmap->pm_asidgen == pmap_asid_generation)) {
! 		pmap->pm_asid = PMAP_ASID_RESERVED;
! 		if (curproc == NULL)
! 			panic("pmap_remove: curproc == 0");
! 		if (pmap == curproc->p_vmspace->vm_map.pmap) {
! 			pmap->pm_asid = pmap_alloc_asid(curproc);
! 			MachSetPID(pmap->pm_asid);
  		}
  	}
  }
***************
*** 869,875 ****
  	pt_entry_t *pte;
  	unsigned entry;
  	u_int p;
! 	unsigned asid, needupdate;
  
  #ifdef DEBUG
  	if (pmapdebug & (PDB_FOLLOW|PDB_PROTECT))
--- 872,878 ----
  	pt_entry_t *pte;
  	unsigned entry;
  	u_int p;
! 	unsigned needupdate;
  
  #ifdef DEBUG
  	if (pmapdebug & (PDB_FOLLOW|PDB_PROTECT))
***************
*** 929,936 ****
  		}
  	}
  #endif
! 	asid = pmap->pm_asid << MIPS_TLB_PID_SHIFT;
! 	needupdate = (pmap->pm_asidgen == pmap_asid_generation);
  	while (sva < eva) {
  		nssva = mips_trunc_seg(sva) + NBSEG;
  		if (nssva == 0 || nssva > eva)
--- 932,938 ----
  		}
  	}
  #endif
! 	needupdate = 0;
  	while (sva < eva) {
  		nssva = mips_trunc_seg(sva) + NBSEG;
  		if (nssva == 0 || nssva > eva)
***************
*** 951,964 ****
  			entry = pte->pt_entry;
  			if (!mips_pg_v(entry))
  				continue;
  			entry = (entry & ~(mips_pg_m_bit() |
  			    mips_pg_ro_bit())) | p;
  			pte->pt_entry = entry;
! 			/*
! 			 * Update the TLB if the given address is in the cache.
! 			 */
! 			if (needupdate)
! 				MachTLBUpdate(sva | asid, entry);
  		}
  	}
  }
--- 953,971 ----
  			entry = pte->pt_entry;
  			if (!mips_pg_v(entry))
  				continue;
+ 			needupdate = 1;
  			entry = (entry & ~(mips_pg_m_bit() |
  			    mips_pg_ro_bit())) | p;
  			pte->pt_entry = entry;
! 		}
! 	}
! 	if (needupdate && (pmap->pm_asidgen == pmap_asid_generation)) {
! 		pmap->pm_asid = PMAP_ASID_RESERVED;
! 		if (curproc == NULL)
! 			panic("pmap_protect: curproc == 0");
! 		if (pmap == curproc->p_vmspace->vm_map.pmap) {
! 			pmap->pm_asid = pmap_alloc_asid(curproc);
! 			MachSetPID(pmap->pm_asid);
  		}
  	}
  }