shithub: gefs

Download patch

ref: 0170f073563a6fc46d36f4edeff0f9faa0dde7b1
parent: 9244c8930f982302093f84016987a91fa7f007b3
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Dec 15 22:54:49 EST 2021

cons: quiesce in console reading.

syncing the tree can require quiescence

--- a/blk.c
+++ b/blk.c
@@ -453,10 +453,12 @@
 		return -1;
 	return 0;
 }
+
 /*
  * Allocate from an arena, with lock
- * held. May be called recursively, to
- * alloc space for the alloc log.
+ * held. May be called multiple times
+ * per operation, to alloc space for
+ * the alloc log.
  */
 static vlong
 blkalloc_lk(Arena *a)
--- a/cons.c
+++ b/cons.c
@@ -96,7 +96,7 @@
 };
 
 void
-runcons(int, void *pfd)
+runcons(int tid, void *pfd)
 {
 	char buf[256], *f[4], **ap;
 	int i, n, nf, na, fd;
@@ -106,6 +106,7 @@
 	while(1){
 		if((n = read(fd, buf, sizeof(buf)-1)) == -1)
 			break;
+		quiesce(tid);
 		buf[n] = 0;
 		nf = tokenize(buf, f, nelem(f));
 		if(nf == 0 || strlen(f[0]) == 0)
@@ -119,7 +120,8 @@
 			if(c->sub != nil){
 				if(strcmp(c->sub, *ap) != 0)
 					continue;
-				ap++; na--;
+				ap++;
+				na--;
 			}
 			if(na < c->minarg || na > c->maxarg)
 				continue;
@@ -132,5 +134,6 @@
 				fprint(fd, " %s", f[i]);
 			fprint(fd, "'\n");
 		}
+		quiesce(tid);
 	}
 }
--- a/fns.h
+++ b/fns.h
@@ -120,4 +120,4 @@
 
 /* it's in libc... */
 extern int cas(long*, long, long);
-extern int cas64(u64int*, u64int, u64int);
\ No newline at end of file
+extern int cas64(u64int*, u64int, u64int);
--- a/fs.c
+++ b/fs.c
@@ -1333,48 +1333,3 @@
 		quiesce(wid);
 	}
 }
-
-void
-quiesce(int tid)
-{
-	int i, allquiesced;
-	Bfree *p, *n;
-
-	lock(&fs->activelk);
-	allquiesced = 1;
-	fs->active[tid]++;
-	for(i = 0; i < fs->nproc; i++){
-		/*
-		 * Odd parity on quiescence implies
-		 * that we're between the exit from
-		 * and waiting for the next message
-		 * that enters us into the critical
-		 * section.
-		 */
-		if((fs->active[i] & 1) == 0)
-			continue;
-		if(fs->active[i] == fs->lastactive[i])
-			allquiesced = 0;
-	}
-	if(allquiesced)
-		for(i = 0; i < fs->nproc; i++)
-			fs->lastactive[i] = fs->active[i];
-	unlock(&fs->activelk);
-	if(!allquiesced)
-		return;
-
-	lock(&fs->freelk);
-	p = nil;
-	if(fs->freep != nil){
-		p = fs->freep->next;
-		fs->freep->next = nil;
-	}
-	unlock(&fs->freelk);
-
-	while(p != nil){
-		n = p->next;
-		reclaimblk(p->bp);
-		p = n;
-	}
-	fs->freep = fs->freehd;
-}
--- a/sync.c
+++ b/sync.c
@@ -152,3 +152,48 @@
 	qunlock(&fs->snaplk);
 	return r;
 }
+
+void
+quiesce(int tid)
+{
+	int i, allquiesced;
+	Bfree *p, *n;
+
+	lock(&fs->activelk);
+	allquiesced = 1;
+	fs->active[tid]++;
+	for(i = 0; i < fs->nproc; i++){
+		/*
+		 * Odd parity on quiescence implies
+		 * that we're between the exit from
+		 * and waiting for the next message
+		 * that enters us into the critical
+		 * section.
+		 */
+		if((fs->active[i] & 1) == 0)
+			continue;
+		if(fs->active[i] == fs->lastactive[i])
+			allquiesced = 0;
+	}
+	if(allquiesced)
+		for(i = 0; i < fs->nproc; i++)
+			fs->lastactive[i] = fs->active[i];
+	unlock(&fs->activelk);
+	if(!allquiesced)
+		return;
+
+	lock(&fs->freelk);
+	p = nil;
+	if(fs->freep != nil){
+		p = fs->freep->next;
+		fs->freep->next = nil;
+	}
+	unlock(&fs->freelk);
+
+	while(p != nil){
+		n = p->next;
+		reclaimblk(p->bp);
+		p = n;
+	}
+	fs->freep = fs->freehd;
+}