shithub: riscv

Download patch

ref: f37ee95fbcd5d837c4eff29e7feb5a999420dae2
parent: 413977c19bb65fb1b704d58ae9a59cdf64179c84
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Fri Nov 1 17:21:24 EDT 2013

rio: enforce flush reply ordering for all xfids

flushing isnt optional for concurrently handled requests.
we need to ensure that Rflush is replied *after* the
origianl request.

so we assign the flushtag for *every* xfid in xfidctl(),
and filsysrespond() checks if the xfid was flushed
*after* replying and wakes up the flushing xfid.

--- a/sys/src/cmd/rio/fsys.c
+++ b/sys/src/cmd/rio/fsys.c
@@ -270,6 +270,8 @@
 	free(x->buf);
 	x->buf = nil;
 	x->flushtag = -1;
+	if(x->flushing)
+		recv(x->flushc, nil);	/* wakeup flushing xfid */
 	return x;
 }
 
--- a/sys/src/cmd/rio/xfid.c
+++ b/sys/src/cmd/rio/xfid.c
@@ -80,6 +80,8 @@
 				fprint(2, "%p decref %ld\n", x, x->ref);
 				error("decref");
 			}
+			if(x->flushing)
+				error("flushing in free");
 			if(x->flushtag != -1)
 				error("flushtag in free");
 			x->free = xfidfree;
@@ -110,6 +112,7 @@
 	threadsetname(buf);
 	for(;;){
 		f = recvp(x->c);
+		x->flushtag = x->tag;
 		(*f)(x);
 		if(decref(x) == 0)
 			sendp(cxfidfree, x);
@@ -127,12 +130,13 @@
 			incref(xf);	/* to hold data structures up at tail of synchronization */
 			if(xf->ref == 1)
 				error("ref 1 in flush");
-			/* take over flushtag so follow up flushes wait for us */
-			x->flushtag = x->oldtag;
 			xf->flushtag = -1;
 			break;
 		}
 
+	/* take over flushtag so follow up flushes wait for us */
+	x->flushtag = x->oldtag;
+
 	/*
 	 * wakeup filsysflush() in the filsysproc so the next
 	 * flush can come in.
@@ -257,7 +261,7 @@
 		w->ctlopen = TRUE;
 		break;
 	case Qkbdin:
-		if(w !=  wkeyboard){
+		if(w != wkeyboard){
 			filsysrespond(x->fs, x, &t, Eperm);
 			return;
 		}
@@ -417,7 +421,6 @@
 			memmove(x->f->rpart, x->data+nb, cnt-nb);
 			x->f->nrpart = cnt-nb;
 		}
-		x->flushtag = x->tag;
 
 		alts[CWdata].c = w->conswrite;
 		alts[CWdata].v = &cwm;
@@ -658,8 +661,6 @@
 	cnt = x->count;
 	switch(qid){
 	case Qcons:
-		x->flushtag = x->tag;
-
 		alts[CRdata].c = w->consread;
 		alts[CRdata].v = &crm;
 		alts[CRdata].op = CHANRCV;
@@ -725,8 +726,6 @@
 		break;
 
 	case Qmouse:
-		x->flushtag = x->tag;
-
 		alts[MRdata].c = w->mouseread;
 		alts[MRdata].v = &mrm;
 		alts[MRdata].op = CHANRCV;
@@ -778,8 +777,6 @@
 		break;
 
 	case Qkbd:
-		x->flushtag = x->tag;
-
 		alts[MRdata].c = w->kbdread;
 		alts[MRdata].v = &krm;
 		alts[MRdata].op = CHANRCV;
@@ -919,7 +916,6 @@
 			filsysrespond(x->fs, x, &fc, Etooshort);
 			break;
 		}
-		x->flushtag = x->tag;
 
 		alts[WCRdata].c = w->wctlread;
 		alts[WCRdata].v = &cwrm;
--