shithub: riscv

Download patch

ref: 36af8405521be371605e4658ec8f4b133f3c7d6f
parent: 02e6003fc87ca7ace27beef200813426dd954852
parent: 13785bbbef60f5c13aa973c1e7d4277aa55f6a2d
author: Ori Bernstein <[email protected]>
date: Sun Dec 8 06:58:19 EST 2019

merge

--- a/sys/src/9/pc/mmu.c
+++ b/sys/src/9/pc/mmu.c
@@ -643,10 +643,7 @@
 void
 vunmap(void *v, int size)
 {
-	int i;
 	ulong va, o;
-	Mach *nm;
-	Proc *p;
 	
 	/*
 	 * might not be aligned
@@ -675,25 +672,8 @@
 		putcr3(PADDR(MACHP(0)->pdb));
 		return;
 	}
-	for(i=0; i<conf.nproc; i++){
-		p = proctab(i);
-		if(p->state == Dead)
-			continue;
-		if(p != up)
-			p->newtlb = 1;
-	}
-	for(i=0; i<conf.nmach; i++){
-		nm = MACHP(i);
-		if(nm != m)
-			nm->flushmmu = 1;
-	}
+	procflushothers();
 	flushmmu();
-	for(i=0; i<conf.nmach; i++){
-		nm = MACHP(i);
-		if(nm != m)
-			while(active.machs[nm->machno] && nm->flushmmu)
-				;
-	}
 }
 
 /*
--- a/sys/src/9/port/portclock.c
+++ b/sys/src/9/port/portclock.c
@@ -148,7 +148,7 @@
 		m->proc->pc = ur->pc;
 
 	if(m->flushmmu){
-		if(up)
+		if(up && up->newtlb)
 			flushmmu();
 		m->flushmmu = 0;
 	}
--- a/sys/src/9/port/portfns.h
+++ b/sys/src/9/port/portfns.h
@@ -229,6 +229,7 @@
 int		procfdprint(Chan*, int, char*, int);
 void		procflushseg(Segment*);
 void		procflushpseg(Physseg*);
+void		procflushothers(void);
 int		procindex(ulong);
 void		procinit0(void);
 ulong		procpagecount(Proc*);
--- a/sys/src/9/port/proc.c
+++ b/sys/src/9/port/proc.c
@@ -1331,6 +1331,7 @@
 static void
 procflushmmu(int (*match)(Proc*, void*), void *a)
 {
+	Proc *await[MAXMACH];
 	int i, nm, nwait;
 	Proc *p;
 
@@ -1337,30 +1338,42 @@
 	/*
 	 *  tell all matching processes to flush their mmu's
 	 */
+	memset(await, 0, conf.nmach*sizeof(await[0]));
 	nwait = 0;
-	for(i=0; i<conf.nproc; i++) {
+	for(i = 0; i < conf.nproc; i++){
 		p = &procalloc.arena[i];
 		if(p->state != Dead && (*match)(p, a)){
 			p->newtlb = 1;
 			for(nm = 0; nm < conf.nmach; nm++){
 				if(MACHP(nm)->proc == p){
+					coherence();
 					MACHP(nm)->flushmmu = 1;
-					nwait++;
+					if(await[nm] == nil)
+						nwait++;
+					await[nm] = p;
 				}
 			}
 		}
 	}
 
-	if(nwait == 0)
-		return;
-
 	/*
 	 *  wait for all other processors to take a clock interrupt
 	 *  and flush their mmu's
 	 */
-	for(nm = 0; nm < conf.nmach; nm++)
-		while(m->machno != nm && MACHP(nm)->flushmmu)
-			sched();
+	for(;;){
+		if(nwait == 0 || nwait == 1 && await[m->machno] != nil)
+			break;
+
+		sched();
+
+		for(nm = 0; nm < conf.nmach; nm++){
+			p = await[nm];
+			if(p != nil && (MACHP(nm)->proc != p || MACHP(nm)->flushmmu == 0)){
+				await[nm] = nil;
+				nwait--;
+			}
+		}
+	}
 }
 
 static int
@@ -1397,6 +1410,17 @@
 procflushpseg(Physseg *ps)
 {
 	procflushmmu(matchpseg, ps);
+}
+
+static int
+matchother(Proc *p, void *a)
+{
+	return p != a;
+}
+void
+procflushothers(void)
+{
+	procflushmmu(matchother, up);
 }
 
 void