shithub: 9ferno

Download patch

ref: 63803922ee18701c20767be70f1b5d2d9aa82ecb
parent: 47300e194a5276a5c9b91080944c2cb0ff4dd979
author: 9ferno <gophone2015@gmail.com>
date: Sun Oct 24 00:04:18 EDT 2021

removed the duplicate unlock(&up->rlock)

--- a/os/port/proc.c	Sat Oct 23 20:08:14 2021
+++ b/os/port/proc.c	Sun Oct 24 00:04:18 2021
@@ -95,7 +95,6 @@
 				up->edf = nil;
 			}
 */
-
 			lock(&procalloc);
 			up->mach = nil;
 			up->qnext = procalloc.free;
@@ -148,7 +147,7 @@
 {
 	Proc *p;
 
-	if(m->ilockdepth)
+	if(m->ilockdepth != 0)
 		panic("cpu%d: ilockdepth %d, last lock %#p at %#p, sched called from %#p",
 			m->machno,
 			m->ilockdepth,
@@ -188,7 +187,8 @@
 		return;
 	}
 	/* if up == nil, it is the scheduler process after the
-	 * previous process state has been saved
+	 * previous process state has been saved and also the
+	 * first time entering schedinit()
 	 */
 	p = runproc();
 	up = p;
@@ -325,8 +325,9 @@
 	}
 
 found:
-	/* print("runproc\n");
-	procdump(); */
+/*	print("runproc\n");
+	procdump();
+*/
 	splhi();
 	/*
 	 * try to remove the process from a scheduling queue
@@ -407,7 +408,7 @@
 
 /*
  * TODO
- *	add p->wired and procwired()
+ *	add procwired() to set p->wired
  *  pid reuse
  */
 Proc*
@@ -425,26 +426,32 @@
 	p->qnext = nil;
 	unlock(&procalloc);
 
+	p->psstate = "New";
+	p->fpstate = FPinit;
+	p->procctl = 0;
+	p->dbgreg = nil;
+	p->nerrlab = 0;
 	p->type = Unknown;
 	p->state = Scheding;
 	p->priority = PriNormal;
-	p->psstate = "New";
 	p->mach = 0;
 	p->qnext = 0;
-	p->fpstate = FPinit;
 	p->kp = 0;
 	p->killed = 0;
 	p->swipend = 0;
-	p->mp = 0;
+	p->nlocks = 0;
 	p->delaysched = 0;
-	p->edf = nil;
 	memset(&p->defenv, 0, sizeof(p->defenv));
 	p->env = &p->defenv;
-	p->dbgreg = 0;
 	kstrdup(&p->env->user, "*nouser");
 	p->env->errstr = p->env->errbuf0;
 	p->env->syserrstr = p->env->errbuf1;
 
+	/* sched params */
+	p->mp = 0;
+	p->wired = 0;
+	p->edf = nil;
+
 	p->pid = incref(&pidalloc);
 	if(p->pid == 0)
 		panic("pidalloc");
@@ -502,8 +509,11 @@
 	s = splhi();
 
 	if(up->nlocks)
-		print("process %zud sleeps with %d locks held, last lock %#p locked at pc %#p, sleep called from %#p\n",
-			up->pid, up->nlocks, up->lastlock, up->lastlock->pc, getcallerpc(&r));
+		print("process %zd name %s sleeps with %d locks held,"
+				" last lock %#p locked at pc %#p, sleep called from %#p\n",
+			up->pid, up->text, up->nlocks,
+			up->lastlock, up->lastlock->pc, getcallerpc(&r));
+
 	lock(r);
 	lock(&up->rlock);
 	if(r->p != nil){
@@ -539,8 +549,6 @@
 		up->r = r;	/* for swiproc */
 		unlock(&up->rlock);
 		unlock(r);
-		up->swipend = 0;
-		unlock(&up->rlock);
 		procswitch();
 	}
 
@@ -714,7 +722,8 @@
 	else
 		*tmp = '\0';
 	print("%p:%3ud:%14s pc %.8zux %s/%s qpc %.8zux priority %d%s\n",
-		p, p->pid, p->text, p->pc, s, statename[p->state], p->qpc, p->priority, tmp);
+		p, p->pid, p->text, p->pc, s, statename[p->state], p->qpc,
+		p->priority, tmp);
 }
 
 void