Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/port/proc.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname port/proc.c 1990/0227
## diff -e /dev/null /n/bootesdump/1990/0227/sys/src/9/mips/proc.c
0a
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"errno.h"

struct
{
	Lock;
	ulong	pid;
}pidalloc;

struct
{
	Lock;
	Proc	*arena;
	Proc	*free;
}procalloc;

struct
{
	Lock;
	Proc	*head;
	Proc	*tail;
}runq;

char *statename[]={	/* BUG: generate automatically */
	"Dead",
	"Moribund",
	"Zombie",
	"Ready",
	"Scheding",
	"Running",
	"Queueing",
	"MMUing",
	"Exiting",
	"Inwait",
	"Wakeme",
	"Broken",
};

/*
 * Always splhi()'ed.
 */
void
schedinit(void)		/* never returns */
{
	Proc *p;

	setlabel(&m->sched);
	if(u){
		m->proc = 0;
		p = u->p;
		puttlbx(0, KZERO | PTEPID(0), 0);	/* safety first */
		u = 0;
		if(p->state == Running)
			ready(p);
		else if(p->state == Moribund){
			p->pid = 0;
			unlock(&p->debug);
			p->upage->ref--;
			/* procalloc already locked */
			p->qnext = procalloc.free;
			procalloc.free = p;
			p->upage = 0;
			unlock(&procalloc);
			p->state = Dead;
		}
		p->mach = 0;
	}
	sched();
}

void
sched(void)
{
	Proc *p;
	ulong tlbvirt, tlbphys;
	void (*f)(ulong);

	if(u){
		splhi();
		if(setlabel(&u->p->sched)){	/* woke up */
			p = u->p;
			p->state = Running;
			p->mach = m;
			m->proc = p;
			spllo();
			return;
		}
		gotolabel(&m->sched);
	}
	if(f = m->intr){			/* assign = */
		m->intr = 0;
		(*f)(m->cause);
	}
	spllo();
	p = runproc();
	splhi();
	mapstack(p);
	gotolabel(&p->sched);
}

void
ready(Proc *p)
{
	int s;

	s = splhi();
	lock(&runq);
	p->rnext = 0;
	if(runq.tail)
		runq.tail->rnext = p;
	else
		runq.head = p;
	runq.tail = p;
	p->state = Ready;
	unlock(&runq);
	splx(s);
}

/*
 * Always called spllo
 */
Proc*
runproc(void)
{
	Proc *p;
	int i;

loop:
	while(runq.head == 0)
		for(i=0; i<10; i++)
			;
	splhi();
	lock(&runq);
	p = runq.head;
	if(p==0 || p->mach){	/* p->mach==0 only when process state is saved */
		unlock(&runq);
		spllo();
		goto loop;
	}
	if(p->rnext == 0)
		runq.tail = 0;
	runq.head = p->rnext;
	if(p->state != Ready)
		print("runproc %s %d %s\n", p->text, p->pid, statename[p->state]);
	unlock(&runq);
	p->state = Scheding;
	spllo();
	return p;
}

Proc*
newproc(void)
{
	Proc *p;

loop:
	lock(&procalloc);
	if(p = procalloc.free){		/* assign = */
		procalloc.free = p->qnext;
		p->state = Zombie;
		unlock(&procalloc);
		p->mach = 0;
		p->qnext = 0;
		p->nchild = 0;
		p->child = 0;
		p->exiting = 0;
		memset(p->pidonmach, 0, sizeof p->pidonmach);
		memset(p->seg, 0, sizeof p->seg);
		lock(&pidalloc);
		p->pid = ++pidalloc.pid;
		unlock(&pidalloc);
		if(p->pid == 0)
			panic("pidalloc");
		return p;
	}
	unlock(&procalloc);
	print("no procs\n");
	if(u == 0)
		panic("newproc");
	alarm(1000, wakeme, u->p);
	sched();
	goto loop;
}

void
procinit0(void)		/* bad planning - clashes with devproc.c */
{
	Proc *p;
	int i;

	print("procinit\n");

	procalloc.free = ialloc(conf.nproc*sizeof(Proc), 0);
	procalloc.arena = procalloc.free;

	p = procalloc.free;
	for(i=0; i<conf.nproc-1; i++,p++)
		p->qnext = p+1;
	p->qnext = 0;
}

void
sleep1(Rendez *r, int (*f)(void*), void *arg)
{
	Proc *p;
	int s;

	/*
	 * spl is to allow lock to be called
	 * at interrupt time. lock is mutual exclusion
	 */
	s = splhi();
	lock(r);

	/*
	 * if condition happened, never mind
	 */
	if((*f)(arg)){	
		unlock(r);
		splx(s);
		return;
	}

	/*
	 * now we are committed to
	 * change state and call scheduler
	 */
	p = u->p;
	if(r->p)
		print("double sleep %d\n", r->p->pid);
	p->r = r;
	p->wokeup = 0;
	p->state = Wakeme;
	r->p = p;
	unlock(r);
}

void
sleep(Rendez *r, int (*f)(void*), void *arg)
{
	sleep1(r, f, arg);
	sched();
	if(u->p->wokeup){
		u->p->wokeup = 0;
		error(0, Eintr);
	}
}

void
tsleep(Rendez *r, int (*f)(void*), void *arg, int ms)
{
	Alarm *a;

	sleep1(r, f, arg);
	a = alarm(ms, twakeme, r);
	sched();
	cancel(a);
	if(u->p->wokeup){
		u->p->wokeup = 0;
		error(0, Eintr);
	}
}

void
wakeup(Rendez *r)
{
	Proc *p;
	int s;

	s = splhi();
	lock(r);
	p = r->p;
	if(p){
		r->p = 0;
		if(p->state != Wakeme)
			panic("wakeup: not Wakeme");
		p->r = 0;
		ready(p);
	}
	unlock(r);
	splx(s);
}

int
postnote(Proc *p, int dolock, char *n, int flag)
{
	User *up;
	int s;
	Rendez *r;

	if(dolock)
		lock(&p->debug);
	up = (User*)(p->upage->pa|KZERO);
	if(flag!=NUser && (up->notify==0 || up->notified))
		up->nnote = 0;	/* force user's hand */
	else if(up->nnote == NNOTE-1)
		return 0;
	strcpy(up->note[up->nnote].msg, n);
	up->note[up->nnote++].flag = flag;
	if(dolock)
		unlock(&p->debug);
	if(r = p->r){	/* assign = */
		/* wake up */
		s = splhi();
		lock(r);
		if(p->r==r && r->p==p){
			r->p = 0;
			if(p->state != Wakeme)
				panic("postnote wakeup: not Wakeme");
			p->wokeup = 1;
			p->r = 0;
			ready(p);
		}
		unlock(r);
		splx(s);
	}
	return 1;
}

void
wakeme(Alarm *a)
{
	ready((Proc*)(a->arg));
	cancel(a);
}

void
twakeme(Alarm *a)
{
	wakeup((Rendez*)(a->arg));
}

void
pexit(char *s, int freemem)
{
	char status[64];
	ulong mypid;
	Proc *p;
	Waitmsg w;
	int n;
	Chan *c;
	ulong *up, *ucp, *wp;

	mypid = u->p->pid;
	if(s)
		strcpy(status, s);
	else
		status[0] = 0;
	if(freemem){
		freesegs(-1);
		closepgrp(u->p->pgrp);
		close(u->dot);
	}
	for(n=0; n<=u->maxfd; n++)
		if(c = u->fd[n])	/* assign = */
			close(c);
	/*
	 * Any of my children exiting?
	 */
	while(u->p->nchild){
		lock(&u->p->wait.queue);
		if(canlock(&u->p->wait.use)){	/* no child is exiting */
			u->p->exiting = 1;
			unlock(&u->p->wait.use);
			unlock(&u->p->wait.queue);
			break;
		}else{				/* must wait for child */
			unlock(&u->p->wait.queue);
			pwait(0);
		}
	}

	u->p->time[TReal] = MACHP(0)->ticks - u->p->time[TReal];
	/*
	 * Tell my parent
	 */
	p = u->p->parent;
	if(p == 0)
		goto out;
	qlock(&p->wait);
	lock(&p->wait.queue);
	if(p->pid==u->p->parentpid && !p->exiting){
		w.pid = mypid;
		strcpy(w.msg, status);
		wp = &w.time[TUser];
		up = &u->p->time[TUser];
		ucp = &u->p->time[TCUser];
		*wp++ = (*up++ + *ucp++)*MS2HZ;
		*wp++ = (*up++ + *ucp  )*MS2HZ;
		*wp   = (*up           )*MS2HZ;
		p->child = u->p;
		/*
		 * Pass info through back door, to avoid huge Proc's
		 */
		p->waitmsg = (Waitmsg*)(u->p->upage->pa|(((ulong)&w)&(BY2PG-1))|KZERO);
		u->p->state = Exiting;
		if(p->state == Inwait)
			ready(p);
		unlock(&p->wait.queue);
		sched();
	}else{
		unlock(&p->wait.queue);
		qunlock(&p->wait);
	}
   out:
	if(!freemem){
		u->p->state = Broken;
		sched();		/* until someone lets us go */
		freesegs(-1);
		closepgrp(u->p->pgrp);
		close(u->dot);
	}
	lock(&procalloc);	/* sched() can't do this */
	lock(&u->p->debug);	/* sched() can't do this */
	u->p->state = Moribund;
	sched();	/* never returns */
}

ulong
pwait(Waitmsg *w)
{
	Proc *c, *p;
	ulong cpid;

	p = u->p;
again:
	while(canlock(&p->wait.use)){
		if(p->nchild == 0){
			qunlock(&p->wait);
			error(0, Enochild);
		}
		p->state = Inwait;
		qunlock(&p->wait);
		sched();
	}
	lock(&p->wait.queue);	/* wait until child is finished */
	c = p->child;
	if(c == 0){
		print("pwait %d\n", p->pid);
		p->state = Inwait;
		unlock(&p->wait.queue);
		sched();
		goto again;
	}
	p->child = 0;
	if(w)
		*w = *p->waitmsg;
	cpid = p->waitmsg->pid;
	p->time[TCUser] += c->time[TUser] + c->time[TCUser];
	p->time[TCSys] += c->time[TSys] + c->time[TCSys];
	p->time[TCReal] += c->time[TReal];
	p->nchild--;
	unlock(&p->wait.queue);
	qunlock(&p->wait);
	ready(c);
	return cpid;
}


Proc*
proctab(int i)
{
	return &procalloc.arena[i];
}

#include <ureg.h>
DEBUG()
{
	int i;
	Proc *p;

	print("DEBUG\n");
	for(i=0; i<conf.nproc; i++){
		p = procalloc.arena+i;
		if(p->state != Dead)
			print("%d:%s upc %lux %s ut %ld st %ld\n",
				p->pid, p->text, p->pc, statename[p->state],
				p->time[0], p->time[1]);
	}
}

void
kproc(char *name, void (*func)(void *), void *arg)
{
	Proc *p;
	int n;
	ulong upa;
	int lastvar;	/* used to compute stack address */
	User *up;

	/*
	 * Kernel stack
	 */
	p = newproc();
	p->upage = newpage(1, 0, USERADDR|(p->pid&0xFFFF));
	upa = p->upage->pa|KZERO;
	up = (User *)upa;

	/*
	 * Save time: only copy u-> data and useful stack
	 */
	memcpy((void*)upa, u, sizeof(User));
	n = USERADDR+BY2PG - (ulong)&lastvar;
	n = (n+32) & ~(BY2WD-1);	/* be safe & word align */
	memcpy((void*)(upa+BY2PG-n), (void*)((u->p->upage->pa|KZERO)+BY2PG-n), n);
	((User *)upa)->p = p;

	/*
	 * Refs
	 */
	incref(up->dot);
	for(n=0; n<=up->maxfd; n++)
		up->fd[n] = 0;
	up->maxfd = 0;

	/*
	 * Sched
	 */
	if(setlabel(&p->sched)){
		u->p = p;
		p->state = Running;
		p->mach = m;
		m->proc = p;
		spllo();
		strncpy(p->text, name, sizeof p->text);
		(*func)(arg);
		pexit(0, 1);
	}
	p->pgrp = u->p->pgrp;
	incref(p->pgrp);
	p->nchild = 0;
	p->parent = 0;
	memset(p->time, 0, sizeof(p->time));
	p->time[TReal] = MACHP(0)->ticks;
	ready(p);
	flushmmu();
}
.
## diffname port/proc.c 1990/03013
## diff -e /n/bootesdump/1990/0227/sys/src/9/mips/proc.c /n/bootesdump/1990/03013/sys/src/9/mips/proc.c
234c
		print("double sleep %d %d\n", r->p->pid, p->pid);
.
## diffname port/proc.c 1990/03081
## diff -e /n/bootesdump/1990/03013/sys/src/9/mips/proc.c /n/bootesdump/1990/03081/sys/src/9/mips/proc.c
418,419c
	lock(&c->debug);	/* sched() can't do this */
	c->state = Moribund;
.
416a

	/*
	 * Rearrange inheritance hierarchy
	 * 1. my children's pop is now my pop
	 */
	lock(&c->kidlock);
	p = c->pop;
	if(k = c->kid)		/* assign = */
		do{
			k->pop = p;
			k = k->sib;
		}while(k != c->kid);

	/*
	 * 2. cut me from pop's tree
	 */
	if(p == 0)	/* init process only; fix pops */
		goto done;
	lock(&p->kidlock);
	k = p->kid;
	while(k->sib != c)
		k = k->sib;
	if(k == c)
		p->kid = 0;
	else{
		if(p->kid == c)
			p->kid = c->sib;
		k->sib = c->sib;
	}

	/*
	 * 3. pass my children (pop's grandchildren) to pop
	 */
	if(k = c->kid){		/* assign = */
		if(p->kid == 0)
			p->kid = k;
		else{
			l = k->sib;
			k->sib = p->kid->sib;
			p->kid->sib = l;
		}
	}
	unlock(&p->kidlock);
    done:
	unlock(&c->kidlock);

.
414c
		closepgrp(c->pgrp);
.
411c
		c->state = Broken;
.
399,400c
		p->waitmsg = (Waitmsg*)(c->upage->pa|(((ulong)&w)&(BY2PG-1))|KZERO);
		c->state = Exiting;
.
395c
		p->child = c;
.
390,391c
		up = &c->time[TUser];
		ucp = &c->time[TCUser];
.
386c
	if(p->pid==c->parentpid && !p->exiting){
.
381c
	p = c->parent;
.
377c
	c->time[TReal] = MACHP(0)->ticks - c->time[TReal];
.
372c
			unlock(&c->wait.queue);
.
364,369c
	while(c->nchild){
		lock(&c->wait.queue);
		if(canlock(&c->wait.use)){	/* no child is exiting */
			c->exiting = 1;
			unlock(&c->wait.use);
			unlock(&c->wait.queue);
.
359,360c
		if(ch = u->fd[n])	/* assign = */
			close(ch);
.
355c
		closepgrp(c->pgrp);
.
348c
	c = u->p;
	mypid = c->pid;
.
345c
	Chan *ch;
.
342c
	Proc *p, *c, *k, *l;
.
167a
		p->kid = 0;
		p->sib = 0;
.
## diffname port/proc.c 1990/0309
## diff -e /n/bootesdump/1990/03081/sys/src/9/mips/proc.c /n/bootesdump/1990/0309/sys/src/9/mips/proc.c
169a
		p->pop = 0;
.
## diffname port/proc.c 1990/03091
## diff -e /n/bootesdump/1990/0309/sys/src/9/mips/proc.c /n/bootesdump/1990/03091/sys/src/9/mips/proc.c
325,337d
290a
void
wakeme(Alarm *a)
{
	ready((Proc*)(a->arg));
	cancel(a);
}

void
twakeme(Alarm *a)
{
	wakeup((Rendez*)(a->arg));
}

.
205a
	}
.
204c
	for(i=0; i<conf.nproc-1; i++,p++){
		lock(p);	/* allocate now, not during wakeup */
		unlock(p);
.
198,199d
## diffname port/proc.c 1990/0310
## diff -e /n/bootesdump/1990/03091/sys/src/9/mips/proc.c /n/bootesdump/1990/0310/sys/src/9/mips/proc.c
206d
202,204c
	for(i=0; i<conf.nproc-1; i++,p++)
.
## diffname port/proc.c 1990/0312
## diff -e /n/bootesdump/1990/0310/sys/src/9/mips/proc.c /n/bootesdump/1990/0312/sys/src/9/mips/proc.c
530a
			for(j=0; j<NSEG; j++){
				o = p->seg[j].o;
				if(o)
					print("	s%d %d %d\n", j, o->nmod, o->npte);
			}
		}
.
527c
		if(p->state != Dead){
.
522a
	Orig *o;
.
521c
	int i, j;
.
## diffname port/proc.c 1990/0322
## diff -e /n/bootesdump/1990/0312/sys/src/9/mips/proc.c /n/bootesdump/1990/0322/sys/src/9/mips/proc.c
505c
	unlock(&p->wait);
.
493c
		unlock(&p->wait);
.
488c
	lock(&p->wait);	/* wait until child is finished */
.
484a
		unlock(&p->wait);
.
480a
			unlock(&p->wait);
.
479c
	while(canlock(&p->wait)){
		if(p->wait.locked){	/* child is exiting; wait for him */
			unlock(&p->wait);
			break;
		}
.
408c
		unlock(&p->wait);
.
405c
		unlock(&p->wait);
.
387c
	lock(&p->wait);
.
374c
			unlock(&c->wait);
.
370,371c
			unlock(&c->wait);
.
367,368c
		lock(&c->wait);
		if(c->wait.locked == 0){	/* no child is exiting */
.
## diffname port/proc.c 1990/0324
## diff -e /n/bootesdump/1990/0322/sys/src/9/mips/proc.c /n/bootesdump/1990/0324/sys/src/9/mips/proc.c
510c
	unlock(&p->wait.queue);
.
498c
		unlock(&p->wait.queue);
.
493c
	lock(&p->wait.queue);	/* wait until child is finished */
.
489d
484d
478,482c
	while(canlock(&p->wait.use)){
.
407c
		unlock(&p->wait.queue);
.
404c
		unlock(&p->wait.queue);
.
386c
	lock(&p->wait.queue);
.
373c
			unlock(&c->wait.queue);
.
370c
			unlock(&c->wait.use);
			unlock(&c->wait.queue);
.
367,368c
		lock(&c->wait.queue);
		if(canlock(&c->wait.use)){	/* no child is exiting */
.
## diffname port/proc.c 1990/0330
## diff -e /n/bootesdump/1990/0324/sys/src/9/mips/proc.c /n/bootesdump/1990/0330/sys/src/9/mips/proc.c
532,536d
521c
	int i;
.
## diffname port/proc.c 1990/0424
## diff -e /n/bootesdump/1990/0330/sys/src/9/mips/proc.c /n/bootesdump/1990/0424/sys/src/9/mips/proc.c
543a
	int lastvar;	/* used to compute stack address */
.
542d
## diffname port/proc.c 1990/0509
## diff -e /n/bootesdump/1990/0424/sys/src/9/mips/proc.c /n/bootesdump/1990/0509/sys/src/9/mips/proc.c
414a
		lock(&broken);
		for(b=0; b<NBROKEN; b++)
			if(broken.p[b] == c){
				broken.n--;
				memcpy(&broken.p[b], &broken.p[b+1], sizeof(Proc*)*(NBROKEN-(b+1)));
				break;
			}
		unlock(&broken);
.
412a
		/*
		 * weird thing: keep at most NBROKEN around
		 */
		#define	NBROKEN 4
		static struct{
			Lock;
			int	n;
			Proc	*p[NBROKEN];
		}broken;
		int b;

		lock(&broken);
		if(broken.n == NBROKEN){
			ready(broken.p[0]);
			memcpy(&broken.p[0], &broken.p[1], sizeof(Proc*)*(NBROKEN-1));
			--broken.n;
		}
		broken.p[broken.n++] = c;
		unlock(&broken);
.
## diffname port/proc.c 1990/0614
## diff -e /n/bootesdump/1990/0509/sys/src/9/mips/proc.c /n/bootesdump/1990/0614/sys/src/9/mips/proc.c
394,396c
		*wp++ = TK2MS(*up++ + *ucp++);
		*wp++ = TK2MS(*up++ + *ucp  );
		*wp   = TK2MS(*up           );
.
## diffname port/proc.c 1990/0617
## diff -e /n/bootesdump/1990/0614/sys/src/9/mips/proc.c /n/bootesdump/1990/0617/sys/src/9/mips/proc.c
595a
	kunmap(k);
.
586,587c
	memcpy((void*)(upa+BY2PG-n), (void*)(USERADDR+BY2PG-n), n);
.
583c
	memcpy(up, u, sizeof(User));
.
577,578c
	k = kmap(p->upage);
	upa = VA(k);
	up = (User*)upa;
	up->p = p;
.
570a
	User *up;
	KMap *k;
.
569d
526,527c
		*w = *(Waitmsg*)(p->waitmsg|VA(k));
	cpid = ((Waitmsg*)(p->waitmsg|VA(k)))->pid;
	kunmap(k);
.
524a
	k = kmap(c->upage);
.
518d
501a
	KMap *k;
.
401c
		p->waitmsg = (((ulong)&w)&(BY2PG-1));
.
317a
	kunmap(k);
.
315a
	}
.
314c
	else if(up->nnote == NNOTE-1){
		kunmap(k);
.
311c
	k = kmap(p->upage);
	up = (User*)VA(k);
.
305a
	KMap *k;
.
## diffname port/proc.c 1990/0619
## diff -e /n/bootesdump/1990/0617/sys/src/9/mips/proc.c /n/bootesdump/1990/0619/sys/src/9/mips/proc.c
186a
	u->p->state = Wakeme;
.
## diffname port/proc.c 1990/0629
## diff -e /n/bootesdump/1990/0619/sys/src/9/mips/proc.c /n/bootesdump/1990/0629/sys/src/9/mips/proc.c
566c
				p->time[0], p->time[1], p->r);
.
564c
			print("%d:%s upc %lux %s ut %ld st %ld r %lux\n",
.
## diffname port/proc.c 1990/0704
## diff -e /n/bootesdump/1990/0629/sys/src/9/mips/proc.c /n/bootesdump/1990/0704/sys/src/9/mips/proc.c
564,565c
			print("%d:%s %s upc %lux %s ut %ld st %ld r %lux\n",
				p->pid, p->text, p->pgrp->user, p->pc, statename[p->state],
.
## diffname port/proc.c 1990/0722
## diff -e /n/bootesdump/1990/0704/sys/src/9/mips/proc.c /n/bootesdump/1990/0722/sys/src/9/mips/proc.c
621,622c
	if(kpgrp == 0){
		kpgrp = newpgrp();
		strcpy(kpgrp->user, "bootes");
	}
	p->pgrp = kpgrp;
	incref(kpgrp);
	sprint(p->text, "%s.%.6s", name, u->p->pgrp->user);
.
617d
579a
	static Pgrp *kpgrp;
.
173a
		p->fpstate = FPinit;
.
## diffname port/proc.c 1990/0726
## diff -e /n/bootesdump/1990/0722/sys/src/9/mips/proc.c /n/bootesdump/1990/0726/sys/src/9/mips/proc.c
301a
	cancel(a);
.
## diffname port/proc.c 1990/0728
## diff -e /n/bootesdump/1990/0726/sys/src/9/mips/proc.c /n/bootesdump/1990/0728/sys/src/9/mips/proc.c
302d
## diffname port/proc.c 1990/0731
## diff -e /n/bootesdump/1990/0728/sys/src/9/mips/proc.c /n/bootesdump/1990/0731/sys/src/9/mips/proc.c
96c
		(*f)(m->cause, m->pc);
.
80c
	void (*f)(ulong, ulong);
.
## diffname port/proc.c 1990/0801
## diff -e /n/bootesdump/1990/0731/sys/src/9/mips/proc.c /n/bootesdump/1990/0801/sys/src/9/mips/proc.c
61a
			unusepage(p->upage, 1);
.
## diffname port/proc.c 1990/1101
## diff -e /n/bootesdump/1990/0801/sys/src/9/mips/proc.c /n/bootesdump/1990/1101/sys/src/9/mips/proc.c
421,449c
		addbroken(c);
.
346a
addbroken(Proc *c)
{
	int b;

	lock(&broken);
	if(broken.n == NBROKEN){
		ready(broken.p[0]);
		memcpy(&broken.p[0], &broken.p[1], sizeof(Proc*)*(NBROKEN-1));
		--broken.n;
	}
	broken.p[broken.n++] = c;
	unlock(&broken);
	c->state = Broken;
	sched();		/* until someone lets us go */
	lock(&broken);
	for(b=0; b<NBROKEN; b++)
		if(broken.p[b] == c){
			broken.n--;
			memcpy(&broken.p[b], &broken.p[b+1], sizeof(Proc*)*(NBROKEN-(b+1)));
			break;
		}
	unlock(&broken);
}

int
freebroken(void)
{
	int n;


	lock(&broken);
	n = broken.n;
	while(broken.n > 0){
		ready(broken.p[0]);
		memcpy(&broken.p[0], &broken.p[1], sizeof(Proc*)*(NBROKEN-1));
		--broken.n;
	}
	unlock(&broken);
	return n;
}

void
.
345a

/*
 * weird thing: keep at most NBROKEN around
 */
#define	NBROKEN 4
struct{
	Lock;
	int	n;
	Proc	*p[NBROKEN];
}broken;

.
## diffname port/proc.c 1990/11211
## diff -e /n/bootesdump/1990/1101/sys/src/9/mips/proc.c /n/bootesdump/1990/11211/sys/src/9/mips/proc.c
543c
			error(Enochild);
.
268c
		error(Eintr);
.
253c
		error(Eintr);
.
## diffname port/proc.c 1990/1124
## diff -e /n/bootesdump/1990/11211/sys/src/9/mips/proc.c /n/bootesdump/1990/1124/sys/src/9/mips/proc.c
523d
480,521d
169,171d
## diffname port/proc.c 1990/1211
## diff -e /n/bootesdump/1990/1211/sys/src/9/mips/proc.c /n/bootesdump/1990/1211/sys/src/9/port/proc.c
575a
	clearmmucache();
.
135c
		for(i=0; i<10; i++)	/* keep out of shared memory for a while */
.
89a
			restore(p, procstate);
.
84a
		save(procstate, sizeof(procstate));
.
78a
	uchar procstate[64];		/* sleeze for portability */
.
55c
		invalidateu();	/* safety first */
.
## diffname port/proc.c 1990/1212
## diff -e /n/bootesdump/1990/1211/sys/src/9/port/proc.c /n/bootesdump/1990/1212/sys/src/9/port/proc.c
569a
	p->kp = 1;
.
483a
	unusepage(c->upage, 1);	/* sched() can't do this (it locks) */
.
92c
			procrestore(p, procstate);
.
86c
		procsave(procstate, sizeof(procstate));
.
62d
## diffname port/proc.c 1990/1220
## diff -e /n/bootesdump/1990/1212/sys/src/9/port/proc.c /n/bootesdump/1990/1220/sys/src/9/port/proc.c
538c
void
DEBUG(void)
.
## diffname port/proc.c 1990/1227
## diff -e /n/bootesdump/1990/1220/sys/src/9/port/proc.c /n/bootesdump/1990/1227/sys/src/9/port/proc.c
107a
int
anyready(void)
{
	return runq.head != 0;
}

.
## diffname port/proc.c 1991/0109
## diff -e /n/bootesdump/1990/1227/sys/src/9/port/proc.c /n/bootesdump/1991/0109/sys/src/9/port/proc.c
523,525c
		*w = p->waitmsg;
	cpid = p->waitmsg.pid;
.
521d
498d
464,467d
455,457c
		if(s)
			strcpy(p->waitmsg.msg, s);
		else
			p->waitmsg.msg[0] = 0;
		p->waitmsg.pid = mypid;
		wp = &p->waitmsg.time[TUser];
.
417,420d
410d
407d
395,399c
	for(i=0; i<n; i++)
		ready(broken.p[i]);
	broken.n = 0;
.
392d
390c
	int i, n;
.
330c
	if(up != u)
		kunmap(k);
.
325c
		if(up != u)
			kunmap(k);
.
320,321c
	if(p != u->p){
		k = kmap(p->upage);
		up = (User*)VA(k);
	}else{
		SET(k);
		up = u;
	}
.
## diffname port/proc.c 1991/0110
## diff -e /n/bootesdump/1991/0109/sys/src/9/port/proc.c /n/bootesdump/1991/0110/sys/src/9/port/proc.c
453,456c
		memcpy(p->waitmsg.msg, msg, ERRLEN);
.
416a
	if(s)	/* squirrel away; we'll lose our address space */
		strcpy(msg, s);
	else
		msg[0] = 0;
.
414a
	char msg[ERRLEN];
.
## diffname port/proc.c 1991/0209
## diff -e /n/bootesdump/1991/0110/sys/src/9/port/proc.c /n/bootesdump/1991/0209/sys/src/9/port/proc.c
326d
323,324c
	}else
.
97,100d
## diffname port/proc.c 1991/0317
## diff -e /n/bootesdump/1991/0209/sys/src/9/port/proc.c /n/bootesdump/1991/0317/sys/src/9/port/proc.c
175a
		p->pgrp = 0;
.
## diffname port/proc.c 1991/0318
## diff -e /n/bootesdump/1991/0317/sys/src/9/port/proc.c /n/bootesdump/1991/0318/sys/src/9/port/proc.c
582c
	memmove((void*)(upa+BY2PG-n), (void*)(USERADDR+BY2PG-n), n);
.
579c
	memmove(up, u, sizeof(User));
.
453c
		memmove(p->waitmsg.msg, msg, ERRLEN);
.
383c
			memmove(&broken.p[b], &broken.p[b+1], sizeof(Proc*)*(NBROKEN-(b+1)));
.
372c
		memmove(&broken.p[0], &broken.p[1], sizeof(Proc*)*(NBROKEN-1));
.
## diffname port/proc.c 1991/0420
## diff -e /n/bootesdump/1991/0318/sys/src/9/port/proc.c /n/bootesdump/1991/0420/sys/src/9/port/proc.c
154c
	unlock(&runhiq);
.
150,151c
		rq->tail = 0;
	rq->head = p->rnext;
.
145c
		unlock(&runhiq);
.
142,143c
	lock(&runhiq);
	if(runhiq.head)
		rq = &runhiq;
	else
		rq = &runloq;

	p = rq->head;
.
138c
	while(runhiq.head==0 && runloq.head==0)
.
133a
	Schedq *rq;
.
124c
	unlock(&runhiq);
.
121,122c
		rq->head = p;
	rq->tail = p;

.
118,119c
	if(rq->tail)
		rq->tail->rnext = p;
.
116c
	if(p->state == Running)
		rq = &runloq;
	else
		rq = &runhiq;

	lock(&runhiq);
.
112a
	Schedq *rq;
.
107c
	return runloq.head != 0 || runhiq.head != 0;
.
78c
	uchar procstate[64];		/* sleaze for portability */
.
27a
Schedq runhiq, runloq;

.
26c
}Schedq;
.
21c
typedef struct
.
## diffname port/proc.c 1991/0425
## diff -e /n/bootesdump/1991/0420/sys/src/9/port/proc.c /n/bootesdump/1991/0425/sys/src/9/port/proc.c
336a

.
335c
	}else 
.
331a

.
329a
	SET(k);
	USED(k);

.
192a
		p->kp = 0;
.
86a
		m->cs++;
.
## diffname port/proc.c 1991/0430
## diff -e /n/bootesdump/1991/0425/sys/src/9/port/proc.c /n/bootesdump/1991/0430/sys/src/9/port/proc.c
336a

	if(p->upage == 0)
		errors("noted process disappeared");
.
68a
			unlock(&p->debug);
.
67a
			p->upage->ref--;
.
63,64c
			memset(p->pidonmach, 0, sizeof p->pidonmach);
.
## diffname port/proc.c 1991/0501
## diff -e /n/bootesdump/1991/0430/sys/src/9/port/proc.c /n/bootesdump/1991/0501/sys/src/9/port/proc.c
120a

.
## diffname port/proc.c 1991/0507
## diff -e /n/bootesdump/1991/0501/sys/src/9/port/proc.c /n/bootesdump/1991/0507/sys/src/9/port/proc.c
197d
63c
			mmurelease(p);
.
## diffname port/proc.c 1991/0513
## diff -e /n/bootesdump/1991/0507/sys/src/9/port/proc.c /n/bootesdump/1991/0513/sys/src/9/port/proc.c
443a
	c->alarm = 0;
.
## diffname port/proc.c 1991/0517
## diff -e /n/bootesdump/1991/0513/sys/src/9/port/proc.c /n/bootesdump/1991/0517/sys/src/9/port/proc.c
451,453d
445a

	for(n=0; n<=u->maxfd; n++)
		if(ch = u->fd[n])	/* assign = */
			close(ch);


.
## diffname port/proc.c 1991/0523
## diff -e /n/bootesdump/1991/0517/sys/src/9/port/proc.c /n/bootesdump/1991/0523/sys/src/9/port/proc.c
346a

.
342c
	if(u == 0 || p != u->p){
.
## diffname port/proc.c 1991/0529
## diff -e /n/bootesdump/1991/0523/sys/src/9/port/proc.c /n/bootesdump/1991/0529/sys/src/9/port/proc.c
647a
	/*
	 *  since the bss/data segments are now shareable,
	 *  any mmu info about this process is now stale
	 *  and has to be discarded.
	 */
.
609c
	clearmmucache();	/* so child doesn't inherit any of your mappings */
.
## diffname port/proc.c 1991/0608
## diff -e /n/bootesdump/1991/0529/sys/src/9/port/proc.c /n/bootesdump/1991/0608/sys/src/9/port/proc.c
567c
procdump(void)
.
## diffname port/proc.c 1991/0705
## diff -e /n/bootesdump/1991/0608/sys/src/9/port/proc.c /n/bootesdump/1991/0705/sys/src/9/port/proc.c
653a
}

void
procctl(Proc *p)
{
	switch(p->procctl) {
	case Proc_exitme:
		pexit("Killed", 1);
	case Proc_stopme:
		p->procctl = 0;
		p->state = Stopped;
		sched();
		return;
	}
.
642c

	if(u->p->pgrp->user[0] != '\0')
		user = u->p->pgrp->user;
	sprint(p->text, "%s.%.6s", name, user);

.
638c
		strcpy(kpgrp->user, user);
.
635a

	user = "bootes";
.
619,621c
	p->fgrp = newfgrp();
.
593a
	char *user;
.
578,579c
				p->pid, p->text, p->pgrp->user, p->pc, 
				statename[p->state], p->time[0], p->time[1], p->r);
.
573c
	print("process table:\n");
.
571d
516c
	sched();
	panic("pexit");
.
512,514c
	/*
	 * sched() cannot wait on these locks
	 */
	lock(&procalloc);
	lock(&c->debug);
	lock(&palloc);

.
506a
		closeegrp(c->egrp);
.
505c
		flushvirt();
		for(i = 0; i < NSEG; i++)
			if(c->seg[i])
				putseg(c->seg[i]);
.
455a
		closeegrp(c->egrp);
.
454c
		flushvirt();
		for(i = 0; i < NSEG; i++)
			if(c->seg[i])
				putseg(c->seg[i]);
.
452d
448,450c
	closefgrp(c->fgrp);
.
443a
	
.
440c
	if(s) 	/* squirrel away; we'll lose our address space */
.
435c
	int n, i;
.
362c

	if(r = p->r) {		/* assign = */
.
303,304c
		if(p->state != Wakeme) 
			panic("wakeup: state");
.
196a
		p->procctl = 0;
.
194a
		p->egrp = 0;
		p->fgrp = 0;
.
177a
int
canpage(Proc *p)
{
	int ok = 0;

	splhi();
	lock(&runhiq);
	if(p->state != Running) {
		p->newtlb = 1;
		ok = 1;
	}
	unlock(&runhiq);
	spllo();

	return ok;
}

.
81c
	uchar procstate[64];
.
70a

.
67,68c
		
			unlock(&palloc);
.
64c
			/* 
			 * Holding locks:
			 * 	procalloc, debug, palloc
			 */
			pg = p->upage;
			pg->ref = 0;
			p->upage = 0;
			palloc.freecount++;
			if(palloc.head) {
				pg->next = palloc.head;
				palloc.head->prev = pg;
				pg->prev = 0;
				palloc.head = pg;
			}
			else {
				palloc.head = palloc.tail = pg;
				pg->prev = pg->next = 0;
			}

.
61c
		else if(p->state == Moribund) {
			/*
			 * The Grim Reaper lays waste the bodies of the dead
			 */
.
51a
	Page *pg;
.
42a
	"Stopped",
.
## diffname port/proc.c 1991/0710
## diff -e /n/bootesdump/1991/0705/sys/src/9/port/proc.c /n/bootesdump/1991/0710/sys/src/9/port/proc.c
728a

#include "errstr.h"

void
error(int code)
{
	strncpy(u->error, errstrtab[code], ERRLEN);
	nexterror();
}

void
errors(char *err)
{
	strncpy(u->error, err, ERRLEN);
	nexterror();
}

void
nexterror(void)
{
	gotolabel(&u->errlab[--u->nerrlab]);
}

.
## diffname port/proc.c 1991/0712
## diff -e /n/bootesdump/1991/0710/sys/src/9/port/proc.c /n/bootesdump/1991/0712/sys/src/9/port/proc.c
675d
502c
		if(c->egrp)
			closeegrp(c->egrp);
.
494c
	if(c->fgrp)
		closefgrp(c->fgrp);
.
## diffname port/proc.c 1991/0717
## diff -e /n/bootesdump/1991/0712/sys/src/9/port/proc.c /n/bootesdump/1991/0717/sys/src/9/port/proc.c
555,557c
		es = &c->seg[NSEG];
		for(s = c->seg; s < es; s++)
			if(os = *s) {
				*s = 0;
				putseg(os);
			}
.
499,501c
		es = &c->seg[NSEG];
		for(s = c->seg; s < es; s++)
			if(os = *s) {
				*s = 0;
				putseg(os);
			}
.
485,486c
	if(exitstr) 			/* squirrel away before we lose our address space */
		strcpy(msg, exitstr);
.
483a
	Segment **s, **es, *os;
.
476c
pexit(char *exitstr, int freemem)
.
70c
			 * Holding locks from pexit:
.
## diffname port/proc.c 1991/0720
## diff -e /n/bootesdump/1991/0717/sys/src/9/port/proc.c /n/bootesdump/1991/0720/sys/src/9/port/proc.c
645a
	print("procdump: ret\n");
.
642c
				p->pid, p->text, p->pgrp ? p->pgrp->user : "pgrp=0", p->pc, 
.
637c
	print("process table %d:\n", conf.nproc);
.
## diffname port/proc.c 1991/0721
## diff -e /n/bootesdump/1991/0720/sys/src/9/port/proc.c /n/bootesdump/1991/0721/sys/src/9/port/proc.c
646d
637d
## diffname port/proc.c 1991/0727
## diff -e /n/bootesdump/1991/0721/sys/src/9/port/proc.c /n/bootesdump/1991/0727/sys/src/9/port/proc.c
415d
411c
		if(p->r==r && r->p==p){	/* check we won the race */
.
407,408c
	if(r = p->r){		/* assign = */
		/* wake up; can't call wakeup itself because we're racing with it */
.
399a
	p->notepending = 1;
.
327,331c
	if(p->notepending == 0){
		a = alarm(ms, twakeme, r);
		sched();	/* notepending may go true while asleep */
		cancel(a);
	}
	if(p->notepending){
		p->notepending = 0;
.
325a
	p = u->p;
.
324a
	Proc *p;
.
314,316c
	if(p->notepending == 0)
		sched();	/* notepending may go true while asleep */
	if(p->notepending){
		p->notepending = 0;
.
312a
	Proc *p;

	p = u->p;
.
303,304d
300d
290c
	if((*f)(arg)){
		p->r = 0;
.
284a
	p = u->p;
	p->r = r;	/* early so postnote knows */
.
240a
		p->notepending = 0;
.
## diffname port/proc.c 1991/0805
## diff -e /n/bootesdump/1991/0727/sys/src/9/port/proc.c /n/bootesdump/1991/0805/sys/src/9/port/proc.c
422,426c
			if(p->state == Wakeme){
				r->p = 0;
				p->r = 0;
				ready(p);
			}
.
340a
		lock(r);
		if(r->p == p)
			r->p = 0;
		unlock(r);
.
321a
		lock(r);
		if(r->p == p)
			r->p = 0;
		unlock(r);
.
## diffname port/proc.c 1991/0806
## diff -e /n/bootesdump/1991/0805/sys/src/9/port/proc.c /n/bootesdump/1991/0806/sys/src/9/port/proc.c
438a
	if(p->state == Rendezvous) {
		lock(p->pgrp);
		if(p->state == Rendezvous) {
			p->rendval = 0;
			l = &REND(p->pgrp, p->rendtag);
			for(d = *l; d; d = d->rendhash) {
				if(d == p) {
					*l = p->rendhash;
					break;
				}
				l = &d->rendhash;
			}
			ready(p);
		}
		unlock(p->pgrp);
	}

.
392a
	Proc *d, **l;
.
43a
	"Rendez",
.
## diffname port/proc.c 1991/0807
## diff -e /n/bootesdump/1991/0806/sys/src/9/port/proc.c /n/bootesdump/1991/0807/sys/src/9/port/proc.c
677c
				p->pid, p->text, 
				p->pgrp ? p->pgrp->user : "pgrp=0", p->pc, 
.
444c
			p->rendval = ~0;
.
440a

.
306a
		dumpstack();
	}
.
305c
	if(r->p){
.
## diffname port/proc.c 1991/0810
## diff -e /n/bootesdump/1991/0807/sys/src/9/port/proc.c /n/bootesdump/1991/0810/sys/src/9/port/proc.c
418a
		if(dolock)
			unlock(&p->debug);
.
405a
	}
.
404c
	if(p->upage == 0){
		if(dolock)
			unlock(&p->debug);
.
## diffname port/proc.c 1991/0820
## diff -e /n/bootesdump/1991/0810/sys/src/9/port/proc.c /n/bootesdump/1991/0820/sys/src/9/port/proc.c
734d
722a
	up->p = p;
.
713d
## diffname port/proc.c 1991/0830
## diff -e /n/bootesdump/1991/0820/sys/src/9/port/proc.c /n/bootesdump/1991/0830/sys/src/9/port/proc.c
687c
				statename[p->state], p->time[0], p->time[1], p->r, p->qlockpc);
.
684c
			print("%d:%s %s upc %lux %s ut %ld st %ld r %lux qpc %lux\n",
.
## diffname port/proc.c 1991/0906
## diff -e /n/bootesdump/1991/0830/sys/src/9/port/proc.c /n/bootesdump/1991/0906/sys/src/9/port/proc.c
210c
	/* Only reliable way to see if we are Running */
	if(p->mach == 0) {
.
## diffname port/proc.c 1991/0919
## diff -e /n/bootesdump/1991/0906/sys/src/9/port/proc.c /n/bootesdump/1991/0919/sys/src/9/port/proc.c
765a
	clearmmucache();
	ready(p);
.
759d
734a
		/*
		 *  use u->p instead of p, because we
		 *  don't trust the compiler, after a
		 *  gotolabel, to find the correct contents
		 *  of a local variable.  Passed parameters
		 *  (func & arg) are a bit safer since we
		 *  don't play with them anywhere else.
		 */
		p = u->p;
.
## diffname port/proc.c 1991/0926
## diff -e /n/bootesdump/1991/0919/sys/src/9/port/proc.c /n/bootesdump/1991/0926/sys/src/9/port/proc.c
813a
Waitq *
newwaitq(void)
{
	Waitq *wq, *e, *f;

	for(;;) {
		lock(&waitqalloc);
		if(wq = waitqalloc.free) {
			waitqalloc.free = wq->next;
			unlock(&waitqalloc);
			return wq;
		}
		unlock(&waitqalloc);

		wq = (Waitq*)VA(kmap(newpage(0, 0, 0)));
		e = &wq[(BY2PG/sizeof(Waitq))-1];
		for(f = wq; f < e; f++)
			f->next = f+1;

		lock(&waitqalloc);
		e->next = waitqalloc.free;
		waitqalloc.free = wq;
		unlock(&waitqalloc);
	}
}

void
freewaitq(Waitq *wq)
{
	lock(&waitqalloc);
	wq->next = waitqalloc.free;
	waitqalloc.free = wq;
	unlock(&waitqalloc);
}
.
774,775d
767a
	ready(p);
.
735,743d
708a
	p->psstate = 0;
.
668d
656,664c
		memmove(w, &wq->w, sizeof(Waitmsg));
	cpid = wq->w.pid;
	freewaitq(wq);
.
646,654c
	unlock(&p->exl);

	sleep(&p->waitr, haswaitq, u->p);

	lock(&p->exl);
	wq = p->waitq;
	p->waitq = wq->next;
	p->nwait--;
	unlock(&p->exl);

.
636,644c

	lock(&p->exl);
	if(p->nchild == 0 && p->waitq == 0) {
		unlock(&p->exl);
		error(Enochild);
.
633a
	Waitq *wq;
.
632c
	Proc *p;
.
628a
int
haswaitq(void *x)
{
	Proc *p;

	p = (Proc *)x;
	return p->waitq != 0;
}

.
616a
	flushvirt();
	es = &c->seg[NSEG];
	for(s = c->seg; s < es; s++)
		if(os = *s) {
			*s = 0;
			putseg(os);
		}
	closepgrp(c->pgrp);
	closeegrp(c->egrp);
	close(u->dot);

	lock(&c->exl);		/* Prevent my children from leaving waits */
	c->pid = 0;
	unlock(&c->exl);

	for(f = c->waitq; f; f = next) {
		next = f->next;
		freewaitq(f);
	}

.
615c
	if(!freemem)
		addbroken(c);
.
600,612c
	else {
		unlock(&p->exl);
		freewaitq(wq);
.
577,598c

	lock(&p->exl);
	/* My parent still alive */
	if(p->pid == c->parentpid && p->state != Broken && p->nwait < 128) {	
		p->nchild--;
		p->time[TCUser] += c->time[TUser] + c->time[TCUser];
		p->time[TCSys] += c->time[TSys] + c->time[TCSys];

		wq->next = p->waitq;
		p->waitq = wq;
		p->nwait++;
		unlock(&p->exl);

		wakeup(&p->waitr);
.
572,575c
	/* Find my parent */
.
543,570c
	wq = newwaitq();
	wq->w.pid = c->pid;
	wq->w.time[TUser] = TK2MS(c->time[TUser]);
	wq->w.time[TCUser] = TK2MS(c->time[TCUser]);
	wq->w.time[TSys] = TK2MS(c->time[TSys]);
	wq->w.time[TCSys] = TK2MS(c->time[TCSys]);
	wq->w.time[TReal] = TK2MS(MACHP(0)->ticks - c->time[TReal]);
	if(exitstr)
		strncpy(wq->w.msg, exitstr, ERRLEN);
	else
		wq->w.msg[0] = '\0';
.
538d
531,535d
529a
	Waitq *wq, *f, *next;
.
523,528c
	Proc *p, *c;
.
494a
	c->psstate = 0;
.
235,236c
		p->nwait = 0;
		p->waitq = 0;
.
230c
		p->state = Scheding;
		p->psstate = "New";
.
38,40d
33d
20a
struct
{
	Lock;
	Waitq	*free;
}waitqalloc;

.
## diffname port/proc.c 1991/1003
## diff -e /n/bootesdump/1991/0926/sys/src/9/port/proc.c /n/bootesdump/1991/1003/sys/src/9/port/proc.c
79,89d
76,77c
			mmurelease(p);
			simpleputpage(p->upage);
.
71d
## diffname port/proc.c 1991/1005
## diff -e /n/bootesdump/1991/1003/sys/src/9/port/proc.c /n/bootesdump/1991/1005/sys/src/9/port/proc.c
537,556c
	if(c->kp == 0) {
		/* Find my parent */
		p = c->parent;
		lock(&p->exl);
		/* My parent still alive */
		if(p->pid == c->parentpid && p->state != Broken && p->nwait < 128) {	
			p->nchild--;
			p->time[TCUser] += c->time[TUser] + c->time[TCUser];
			p->time[TCSys] += c->time[TSys] + c->time[TCSys];
	
			wq->next = p->waitq;
			p->waitq = wq;
			p->nwait++;
			unlock(&p->exl);
	
			wakeup(&p->waitr);
		}
		else {
			unlock(&p->exl);
			freewaitq(wq);
		}
.
## diffname port/proc.c 1991/1006
## diff -e /n/bootesdump/1991/1005/sys/src/9/port/proc.c /n/bootesdump/1991/1006/sys/src/9/port/proc.c
571c
	if(c->egrp)
		closeegrp(c->egrp);
.
537a
		wq = newwaitq();
		wq->w.pid = c->pid;
		wq->w.time[TUser] = TK2MS(c->time[TUser]);
		wq->w.time[TCUser] = TK2MS(c->time[TCUser]);
		wq->w.time[TSys] = TK2MS(c->time[TSys]);
		wq->w.time[TCSys] = TK2MS(c->time[TCSys]);
		wq->w.time[TReal] = TK2MS(MACHP(0)->ticks - c->time[TReal]);
		if(exitstr)
			strncpy(wq->w.msg, exitstr, ERRLEN);
		else
			wq->w.msg[0] = '\0';

.
525,536d
## diffname port/proc.c 1991/1007
## diff -e /n/bootesdump/1991/1006/sys/src/9/port/proc.c /n/bootesdump/1991/1007/sys/src/9/port/proc.c
563d
## diffname port/proc.c 1991/1024
## diff -e /n/bootesdump/1991/1007/sys/src/9/port/proc.c /n/bootesdump/1991/1024/sys/src/9/port/proc.c
569,572d
523a
	closepgrp(c->pgrp);
	close(u->dot);
	if(c->egrp)
		closeegrp(c->egrp);
.
## diffname port/proc.c 1991/1105
## diff -e /n/bootesdump/1991/1024/sys/src/9/port/proc.c /n/bootesdump/1991/1105/sys/src/9/port/proc.c
718,719c
	if(u->p->user[0] != '\0')
		user = u->p->user;
.
713d
710a
	strcpy(p->user, user);
.
652,653c
				p->pid, p->text, p->user, p->pc, 
.
## diffname port/proc.c 1991/1108
## diff -e /n/bootesdump/1991/1105/sys/src/9/port/proc.c /n/bootesdump/1991/1108/sys/src/9/port/proc.c
743a
		p->psstate = state;
.
741a
		state = p->psstate;
		p->psstate = "Stopped";

.
736a
	char *state;

.
## diffname port/proc.c 1991/1109
## diff -e /n/bootesdump/1991/1108/sys/src/9/port/proc.c /n/bootesdump/1991/1109/sys/src/9/port/proc.c
709c
	user = eve;
.
230a
		p->procmode = 0644;
.
## diffname port/proc.c 1991/1110
## diff -e /n/bootesdump/1991/1109/sys/src/9/port/proc.c /n/bootesdump/1991/1110/sys/src/9/port/proc.c
747c
		/* free a waiting debugger */
		lock(&p->debug);
		if(p->pdbg) {
			wakeup(&p->pdbg->sleep);
			p->pdbg = 0;
		}
		unlock(&p->debug);
.
742a
	case Proc_traceme:
		if(u->nnote == 0)
			return;
		/* No break */
.
588a
	/* release debuggers */
	if(c->pdbg) {
		wakeup(&c->pdbg->sleep);
		c->pdbg = 0;
	}

	lock(&procalloc);
.
587d
244,251d
223,242c
		resrcwait("no procs");
.
216,221c
	for(;;) {
		lock(&procalloc);
		if(p = procalloc.free){		/* assign = */
			procalloc.free = p->qnext;
			p->state = Scheding;
			p->psstate = "New";
			unlock(&procalloc);
			p->mach = 0;
			p->qnext = 0;
			p->nchild = 0;
			p->nwait = 0;
			p->waitq = 0;
			p->pgrp = 0;
			p->egrp = 0;
			p->fgrp = 0;
			p->pdbg = 0;
			p->fpstate = FPinit;
			p->kp = 0;
			p->procctl = 0;
			p->notepending = 0;
			memset(p->seg, 0, sizeof p->seg);
			lock(&pidalloc);
			p->pid = ++pidalloc.pid;
			unlock(&pidalloc);
			if(p->pid == 0)
				panic("pidalloc");
			return p;
		}
.
## diffname port/proc.c 1991/1112
## diff -e /n/bootesdump/1991/1110/sys/src/9/port/proc.c /n/bootesdump/1991/1112/sys/src/9/port/proc.c
676a
	p->procmode = 0644;
.
184a
	nrdy--;
.
149a
	nrdy++;
.
98,99d
34c
Schedq	runhiq, runloq;
int	nrdy;
.
## diffname port/proc.c 1991/1115
## diff -e /n/bootesdump/1991/1112/sys/src/9/port/proc.c /n/bootesdump/1991/1115/sys/src/9/port/proc.c
402c
	}else
.
398a
	SET(k);
.
387,389d
## diffname port/proc.c 1991/1120
## diff -e /n/bootesdump/1991/1115/sys/src/9/port/proc.c /n/bootesdump/1991/1120/sys/src/9/port/proc.c
453c
	return ret;
.
414,415d
406,411c

	ret = 0;
	if(up->nnote < NNOTE){
		strcpy(up->note[up->nnote].msg, n);
		up->note[up->nnote++].flag = flag;
		ret = 1;
.
383c
	int s, ret;
.
## diffname port/proc.c 1991/1127
## diff -e /n/bootesdump/1991/1120/sys/src/9/port/proc.c /n/bootesdump/1991/1127/sys/src/9/port/proc.c
401a
	USED(k);
.
## diffname port/proc.c 1991/1215
## diff -e /n/bootesdump/1991/1127/sys/src/9/port/proc.c /n/bootesdump/1991/1215/sys/src/9/port/proc.c
529d
527d
## diffname port/proc.c 1991/1216
## diff -e /n/bootesdump/1991/1215/sys/src/9/port/proc.c /n/bootesdump/1991/1216/sys/src/9/port/proc.c
755c
		qunlock(&p->debug);
.
750c
		qlock(&p->debug);
.
578c
	qlock(&c->debug);
.
418c
		qunlock(&p->debug);
.
392c
			qunlock(&p->debug);
.
388c
		qlock(&p->debug);
.
84c
			qunlock(&p->debug);
.
## diffname port/proc.c 1991/1218
## diff -e /n/bootesdump/1991/1216/sys/src/9/port/proc.c /n/bootesdump/1991/1218/sys/src/9/port/proc.c
529,531c
		if(exitstr && exitstr[0]){
			n = sprint(wq->w.msg, "%s %d:", c->text, c->pid);
			strncpy(wq->w.msg+n, exitstr, ERRLEN-n);
		}else
.
508a
	int n;
.
## diffname port/proc.c 1992/0103
## diff -e /n/bootesdump/1991/1218/sys/src/9/port/proc.c /n/bootesdump/1992/0103/sys/src/9/port/proc.c
685d
## diffname port/proc.c 1992/0111
## diff -e /n/bootesdump/1992/0103/sys/src/9/port/proc.c /n/bootesdump/1992/0111/sys/src/9/port/proc.c
769c
	strncpy(u->error, err, ERRLEN);
.
767c
error(char err[])
.
6c
#include	"../port/error.h"
.
## diffname port/proc.c 1992/0114
## diff -e /n/bootesdump/1992/0111/sys/src/9/port/proc.c /n/bootesdump/1992/0114/sys/src/9/port/proc.c
783c
	char buf[ERRLEN];

	sprint(buf, "no free %s", resource);
	error(buf);
.
781c
exhausted(char *resource)
.
776,777c
	gotolabel(&u->errlab[--u->nerrlab]);
.
774c
nexterror(void)
.
393c
		error(Eprocdied);
.
## diffname port/proc.c 1992/0115
## diff -e /n/bootesdump/1992/0114/sys/src/9/port/proc.c /n/bootesdump/1992/0115/sys/src/9/port/proc.c
536,537d
524c
	/*
	 * if not a kernel process and have a parent,
	 * do some housekeeping.
	 */
	if(c->kp == 0 && (p = c->parent)) {
.
## diffname port/proc.c 1992/0120
## diff -e /n/bootesdump/1992/0115/sys/src/9/port/proc.c /n/bootesdump/1992/0120/sys/src/9/port/proc.c
643d
## diffname port/proc.c 1992/0122
## diff -e /n/bootesdump/1992/0120/sys/src/9/port/proc.c /n/bootesdump/1992/0122/sys/src/9/port/proc.c
109c
			procrestore(p);
.
103c
		procsave(u->p);
.
97d
## diffname port/proc.c 1992/0205
## diff -e /n/bootesdump/1992/0122/sys/src/9/port/proc.c /n/bootesdump/1992/0205/sys/src/9/port/proc.c
543,544c
			p->time[TCUser] += utime;
			p->time[TCSys] += stime;
.
530,531c
		utime = c->time[TUser] + c->time[TCUser];
		stime = c->time[TSys] + c->time[TCSys];
		wq->w.time[TUser] = TK2MS(utime);
		wq->w.time[TSys] = TK2MS(stime);
.
508a
	long utime, stime;
.
## diffname port/proc.c 1992/0301
## diff -e /n/bootesdump/1992/0205/sys/src/9/port/proc.c /n/bootesdump/1992/0301/sys/src/9/port/proc.c
68,70d
## diffname port/proc.c 1992/0303
## diff -e /n/bootesdump/1992/0301/sys/src/9/port/proc.c /n/bootesdump/1992/0303/sys/src/9/port/proc.c
525c
	if(c->kp == 0) {
		if((p = c->parent) == 0)
			panic("boot process died");
			
.
## diffname port/proc.c 1992/0309
## diff -e /n/bootesdump/1992/0303/sys/src/9/port/proc.c /n/bootesdump/1992/0309/sys/src/9/port/proc.c
634c
	cpid = atoi(wq->w.pid);
.
543c
		/* My parent still alive, processes are limited to 128 Zombies to
		 * prevent badly written daemon consuming all the wait records */
.
533,535c
		readnum(0, &wq->w.time[TUser*12], NUMSIZE,
			TK2MS(utime), NUMSIZE);
		readnum(0, &wq->w.time[TSys*12], NUMSIZE,
			TK2MS(stime), NUMSIZE);
		readnum(0, &wq->w.time[TReal*12], NUMSIZE,
			TK2MS(MACHP(0)->ticks - c->time[TReal]), NUMSIZE);
.
530c
		readnum(0, wq->w.pid, NUMSIZE, c->pid, NUMSIZE);
.
451d
234,236c
			p->pid = incref(&pidalloc);
.
37c
char *statename[] =
{			/* BUG: generate automatically */
.
8,12c
Ref	pidalloc;
.
## diffname port/proc.c 1992/0319
## diff -e /n/bootesdump/1992/0309/sys/src/9/port/proc.c /n/bootesdump/1992/0319/sys/src/9/port/proc.c
349a
if((p->sched.pc&KZERO) != KZERO){
	spllo();
	panic("wakeup");
}
.
## diffname port/proc.c 1992/0321
## diff -e /n/bootesdump/1992/0319/sys/src/9/port/proc.c /n/bootesdump/1992/0321/sys/src/9/port/proc.c
2c
#include	"../port/lib.h"
.
## diffname port/proc.c 1992/0328
## diff -e /n/bootesdump/1992/0321/sys/src/9/port/proc.c /n/bootesdump/1992/0328/sys/src/9/port/proc.c
643a
if((i < 0) || (i >= conf.nproc))
    panic("proctab(%d)\n", i);
.
## diffname port/proc.c 1992/0428
## diff -e /n/bootesdump/1992/0328/sys/src/9/port/proc.c /n/bootesdump/1992/0428/sys/src/9/port/proc.c
232c
			p->noteid = incref(&noteidalloc);
			if(p->pid==0 || p->noteid==0)
.
8a
Ref	noteidalloc;
.
## diffname port/proc.c 1992/0519
## diff -e /n/bootesdump/1992/0428/sys/src/9/port/proc.c /n/bootesdump/1992/0519/sys/src/9/port/proc.c
333a
		splx(s);
.
329a
		s = splhi();
.
319a
	int s;
.
310a
		splx(s);
.
306a
		s = splhi();
.
299a
	int s;
.
## diffname port/proc.c 1992/0520
## diff -e /n/bootesdump/1992/0519/sys/src/9/port/proc.c /n/bootesdump/1992/0520/sys/src/9/port/proc.c
826a
	return 0;		/* not reached */
.
240a
	return 0;		/* not reached */
.
## diffname port/proc.c 1992/0527
## diff -e /n/bootesdump/1992/0520/sys/src/9/port/proc.c /n/bootesdump/1992/0527/sys/src/9/port/proc.c
397c
		return 0;
.
## diffname port/proc.c 1992/0602
## diff -e /n/bootesdump/1992/0527/sys/src/9/port/proc.c /n/bootesdump/1992/0602/sys/src/9/port/proc.c
367,379d
359,362d
333,342c
	p->trend = r;
	p->twhen = when;
	p->tlink = *i;
	*i = p;
	unlock(&talarm);

	sleep(r, fn, arg);
	p->twhen = 0;
.
327,331c
	when = MS2TK(ms)+MACHP(0)->ticks;
	i = &talarm.list;

	lock(&talarm);
	l = &talarm.list;
	for(f = talarm.list; f; f = f->tlink) {
		if(f == p)
			*l = p->tlink;
		if(f->twhen && f->twhen < when)
			i = &f->tlink;
		l = &f->tlink;
.
322,324c
	ulong when;
	Proc *p, *f, **l, **i;
.
320c
tsleep(Rendez *r, int (*fn)(void*), void *arg, int ms)
.
## diffname port/proc.c 1992/0603
## diff -e /n/bootesdump/1992/0602/sys/src/9/port/proc.c /n/bootesdump/1992/0603/sys/src/9/port/proc.c
184d
173d
159a
	spllo();
.
150c
 * Always called splhi
.
111d
109d
## diffname port/proc.c 1992/0604
## diff -e /n/bootesdump/1992/0603/sys/src/9/port/proc.c /n/bootesdump/1992/0604/sys/src/9/port/proc.c
766c
error(char *err)
.
## diffname port/proc.c 1992/0609
## diff -e /n/bootesdump/1992/0604/sys/src/9/port/proc.c /n/bootesdump/1992/0609/sys/src/9/port/proc.c
757c
		sched();		/* sched returns spllo() */
		splhi();
.
739a
		spllo();	/* pexit has locks in it */
.
732a
/*
 *  called splhi() by notify().  See comment in notify for the
 *  reasoning.
 */
.
## diffname port/proc.c 1992/0617
## diff -e /n/bootesdump/1992/0609/sys/src/9/port/proc.c /n/bootesdump/1992/0617/sys/src/9/port/proc.c
341c
	sleep(r, tfn, arg);
.
337a
	p->tfn = fn;
.
315a
int
tfn(void *arg)
{
	Proc *p;

	p = u->p;
	return MACHP(0)->ticks >= p->twhen || (*p->tfn)(arg);
}

.
## diffname port/proc.c 1992/0619
## diff -e /n/bootesdump/1992/0617/sys/src/9/port/proc.c /n/bootesdump/1992/0619/sys/src/9/port/proc.c
247c
	procalloc.free = xalloc(conf.nproc*sizeof(Proc));
.
65c
		else
		if(p->state == Moribund) {
.
## diffname port/proc.c 1992/0620
## diff -e /n/bootesdump/1992/0619/sys/src/9/port/proc.c /n/bootesdump/1992/0620/sys/src/9/port/proc.c
802,837d
760a

.
756a

.
663c
				statename[p->state], p->time[0],
				p->time[1], p->r, p->qlockpc);
.
647,648d
640c
	free(wq);
.
583c
		free(f);
.
563c
			free(wq);
.
548c
		 * prevent a badly written daemon lots of wait records
		 */
.
530c
		wq = smalloc(sizeof(Waitq));
.
402d
82,83d
67a
			p->state = Dead;
.
## diffname port/proc.c 1992/0622
## diff -e /n/bootesdump/1992/0620/sys/src/9/port/proc.c /n/bootesdump/1992/0622/sys/src/9/port/proc.c
162a

.
160,161c
		;
.
## diffname port/proc.c 1992/0701
## diff -e /n/bootesdump/1992/0622/sys/src/9/port/proc.c /n/bootesdump/1992/0701/sys/src/9/port/proc.c
348c
	p->tlink = *l;
	*l = p;
.
346d
337,341c
	for(f = *l; f; f = f->tlink) {
		if(f->twhen >= when)
			break;
.
335a
	/* take out of list if checkalarm didn't */
	if(p->trend) {
		l = &talarm.list;
		for(f = *l; f; f = f->tlink) {
			if(f == p) {
				*l = p->tlink;
				break;
			}
			l = &f->tlink;
		}
	}
	/* insert in increasing time order */
.
333d
329c
	Proc *p, *f, **l;
.
## diffname port/proc.c 1992/0703
## diff -e /n/bootesdump/1992/0701/sys/src/9/port/proc.c /n/bootesdump/1992/0703/sys/src/9/port/proc.c
736c
	strcpy(p->text, name);
.
685a
	int lastvar;	/* used to compute stack address */
.
681d
## diffname port/proc.c 1992/0711
## diff -e /n/bootesdump/1992/0703/sys/src/9/port/proc.c /n/bootesdump/1992/0711/sys/src/9/port/proc.c
734,735d
155d
55d
## diffname port/proc.c 1992/0805
## diff -e /n/bootesdump/1992/0711/sys/src/9/port/proc.c /n/bootesdump/1992/0805/sys/src/9/port/proc.c
667,668c
				s, statename[p->state], p->time[0],
				p->time[1], p->r, p->qlockpc, bss);
.
665c
			bss = 0;
			if(p->seg[BSEG])
				bss = p->seg[BSEG]->top;

			s = p->psstate;
			if(s == 0)
				s = "kproc";
			print("%3d:%10s %10s pc %8lux %8s (%s) ut %ld st %ld r %lux qpc %lux bss %lux\n",
.
660a
	ulong bss;
.
659a
	char *s;
.
535a
		poperror();

.
534c

		while(waserror())
			;	
.
## diffname port/proc.c 1992/0902
## diff -e /n/bootesdump/1992/0805/sys/src/9/port/proc.c /n/bootesdump/1992/0902/sys/src/9/port/proc.c
532,533c
		if((p = c->parent) == 0) {
			if(exitstr == 0)
				exitstr = "unknown";
			panic("boot process died: %s", exitstr);
		}
.
## diffname port/proc.c 1992/0909
## diff -e /n/bootesdump/1992/0902/sys/src/9/port/proc.c /n/bootesdump/1992/0909/sys/src/9/port/proc.c
425,432c
		for(;;) {
			s = splhi();
			if(canlock(r))
				break;
			splx(s);
		}
		if(p->r==r && r->p==p && p->state==Wakeme){	/* check we won the race */
			r->p = 0;
			p->r = 0;
			ready(p);
.
361a
/*
 * Expects that only one process can call wakeup for any given Rendez
 */
.
## diffname port/proc.c 1992/1206
## diff -e /n/bootesdump/1992/0909/sys/src/9/port/proc.c /n/bootesdump/1992/1206/sys/src/9/port/proc.c
590,593c
		if(*s)
			putseg(*s);
.
560c
		}
		else
.
537c
		p = c->parent;
		if(p == 0) {
.
519c
	Segment **s, **es;
.
509c
	qunlock(&broken);
.
507a
		broken.p[i] = 0;
	}
.
506c
	for(i=0; i<n; i++) {
.
504c
	qlock(&broken);
.
498a
void
unbreak(Proc *p)
{
	int b;

	qlock(&broken);
	for(b=0; b < NBROKEN; b++) {
		if(broken.p[b] != p)
			continue;

		broken.n--;
		memmove(&broken.p[b], &broken.p[b+1], sizeof(Proc*)*(NBROKEN-(b+1)));
		ready(p);
	}
	qunlock(&broken);
}

.
484,496c
	broken.p[broken.n++] = p;
	qunlock(&broken);

	p->state = Broken;
	p->psstate = 0;
	sched();
.
476,479c
	qlock(&broken);
	if(broken.n == NBROKEN) {
.
474c
addbroken(Proc *p)
.
467,468c
struct
{
	QLock;
.
459c
	unlock(p->pgrp);
.
457c
		ready(p);
.
455c
			l = &d->rendhash;
.
444,453c
		p->rendval = ~0;
		l = &REND(p->pgrp, p->rendtag);
		for(d = *l; d; d = d->rendhash) {
			if(d == p) {
				*l = p->rendhash;
				break;
.
442a
	if(p->state != Rendezvous)
		return ret;

	/* Try and pull out of a rendezvous */
	lock(p->pgrp);
.
## diffname port/proc.c 1992/1208
## diff -e /n/bootesdump/1992/1206/sys/src/9/port/proc.c /n/bootesdump/1992/1208/sys/src/9/port/proc.c
498,505c
	for(b=0; b < broken.n; b++)
		if(broken.p[b] != p) {
			broken.n--;
			memmove(&broken.p[b], &broken.p[b+1],
					sizeof(Proc*)*(NBROKEN-(b+1)));
			ready(p);
			break;
		}
.
## diffname port/proc.c 1992/1225
## diff -e /n/bootesdump/1992/1208/sys/src/9/port/proc.c /n/bootesdump/1992/1225/sys/src/9/port/proc.c
499c
		if(broken.p[b] == p) {
.
## diffname port/proc.c 1993/0112
## diff -e /n/bootesdump/1992/1225/sys/src/9/port/proc.c /n/bootesdump/1993/0112/sys/src/9/port/proc.c
396a
	if(p->kp)
		print("sending %s to kproc %d %s\n", n, p->pid, p->text);

.
## diffname port/proc.c 1993/0216
## diff -e /n/bootesdump/1993/0112/sys/src/9/port/proc.c /n/bootesdump/1993/0216/sys/src/9/port/proc.c
461d
456a
				ready(p);
.
## diffname port/proc.c 1993/0309
## diff -e /n/bootesdump/1993/0216/sys/src/9/port/proc.c /n/bootesdump/1993/0309/sys/src/9/port/proc.c
668a

	qunlock(&p->qwaitr);
	poperror();
.
654a
	if(!canqlock(&p->qwaitr))
		error(Einuse);

	if(waserror()) {
		qunlock(&p->qwaitr);
		nexterror();
	}

.
593c

.
## diffname port/proc.c 1993/0501
## diff -e /n/bootesdump/1993/0309/sys/src/9/port/proc.c /n/fornaxdump/1993/0501/sys/src/brazil/port/proc.c
844c
	gotolabel(&up->errlab[--up->nerrlab]);
.
837c
	strncpy(up->error, err, ERRLEN);
.
809c
		if(p->nnote == 0)
.
805c
		spllo();		/* pexit has locks in it */
.
775d
771,773c
	strcpy(p->user, eve);
	if(kpgrp == 0)
.
759,769c
	kprocchild(p, func, arg);
.
753,757c
	memmove(p->note, up->note, sizeof(p->note));
	p->nnote = up->nnote;
	p->notified = 0;
	p->lastnote = up->lastnote;
	p->notify = up->notify;
	p->ureg = 0;
	p->dbgreg = 0;
.
744,751c
	p->fpsave = up->fpsave;
	p->scallnr = up->scallnr;
	p->s = up->s;
	p->nerrlab = 0;
	p->slash = up->slash;
	p->dot = up->dot;
	incref(p->dot);
.
739,742d
732,734d
729,730d
724,727d
709,716c
		s = p->psstate;
		if(s == 0)
			s = "kproc";
		print("%3d:%10s pc %8lux %8s (%s) ut %ld st %ld bss %lux\n",
			p->pid, p->text, p->pc,  s, statename[p->state],
			p->time[0], p->time[1], bss);
.
702,707c
	for(i=0; i<conf.nproc; i++) {
		p = &procalloc.arena[i];
		if(p->state == Dead)
			continue;
		bss = 0;
		if(p->seg[BSEG])
			bss = p->seg[BSEG]->top;
.
678c
	qunlock(&up->qwaitr);
.
672,676c
	lock(&up->exl);
	wq = up->waitq;
	up->waitq = wq->next;
	up->nwait--;
	unlock(&up->exl);
.
670c
	sleep(&up->waitr, haswaitq, up);
.
668c
	unlock(&up->exl);
.
663,665c
	lock(&up->exl);
	if(up->nchild == 0 && up->waitq == 0) {
		unlock(&up->exl);
.
659c
		qunlock(&up->qwaitr);
.
653,655c
	if(!canqlock(&up->qwaitr))
.
649d
632c
	up->state = Moribund;
.
624,626c
	if(up->pdbg) {
		wakeup(&up->pdbg->sleep);
		up->pdbg = 0;
.
622c
	qlock(&up->debug);
.
614c
	for(f = up->waitq; f; f = next) {
.
610,612c
	lock(&up->exl);		/* Prevent my children from leaving waits */
	up->pid = 0;
	unlock(&up->exl);
.
605,606c
	es = &up->seg[NSEG];
	for(s = up->seg; s < es; s++)
.
603c
		addbroken(up);
.
593c
	
.
584c
		if(p->pid == up->parentpid && p->state != Broken && p->nwait < 128) {	
.
581,582c
		/* My parent still alive, processes are limited to 128
		 * Zombies to prevent a badly written daemon lots of wait
		 * records
.
574c
			n = sprint(wq->w.msg, "%s %d:", up->text, up->pid);
.
572c
			TK2MS(MACHP(0)->ticks - up->time[TReal]), NUMSIZE);
.
564,566c
		readnum(0, wq->w.pid, NUMSIZE, up->pid, NUMSIZE);
		utime = up->time[TUser] + up->time[TCUser];
		stime = up->time[TSys] + up->time[TCSys];
.
560c
			;
	
.
551,552c
	if(up->kp == 0) {
		p = up->parent;
.
546a
	close(up->dot);
	closepgrp(up->pgrp);

.
540,545c
	if(up->fgrp)
		closefgrp(up->fgrp);
	if(up->egrp)
		closeegrp(up->egrp);
.
537,538c
	up->alarm = 0;
.
534a
	long utime, stime;
.
532,533c
	Proc *p;
.
461a
		ready(p);
.
457d
437c
		/* check we won the race */
		if(p->r == r && r->p == p && p->state==Wakeme) {
.
429,430c
	if(r = p->r) {
.
424,425d
418,420c
	if(p->nnote < NNOTE) {
		strcpy(p->note[up->nnote].msg, n);
		p->note[p->nnote++].flag = flag;
.
406,416d
400,404c
	if(flag != NUser && (p->notify == 0 || p->notified))
		p->nnote = 0;
.
388,389d
359c
	up->twhen = 0;
.
351,355c
	up->trend = r;
	up->twhen = when;
	up->tfn = fn;
	up->tlink = *l;
	*l = up;
.
337,338c
			if(f == up) {
				*l = up->tlink;
.
334c
	if(up->trend) {
.
329d
327c
	Proc *f, **l;
.
317,320c
	return MACHP(0)->ticks >= up->twhen || (*up->tfn)(arg);
.
306c
		if(r->p == up)
.
302,303c

	if(up->notepending) {
		up->notepending = 0;
.
300c
	if(up->notepending == 0)
.
298d
295d
287,288c
	up->state = Wakeme;
	r->p = up;
.
284c
		print("double sleep %d %d\n", r->p->pid, up->pid);
.
273c
		up->r = 0;
.
265,266c
	up->r = r;	/* early so postnote knows */
.
257d
236c
	procalloc.free = p->qnext;
	unlock(&procalloc);

	procalloc.free = p->qnext;
	p->state = Scheding;
	p->psstate = "New";
	p->mach = 0;
	p->qnext = 0;
	p->nchild = 0;
	p->nwait = 0;
	p->waitq = 0;
	p->pgrp = 0;
	p->egrp = 0;
	p->fgrp = 0;
	p->pdbg = 0;
	p->fpstate = FPinit;
	p->kp = 0;
	p->procctl = 0;
	p->notepending = 0;
	memset(p->seg, 0, sizeof p->seg);
	p->pid = incref(&pidalloc);
	p->noteid = incref(&noteidalloc);
	if(p->pid==0 || p->noteid==0)
		panic("pidalloc");
	if(p->kstack == 0)
		p->kstack = smalloc(KSTACK);

	return p;
.
234a
		lock(&procalloc);
.
207,232c
		if(p = procalloc.free)
			break;

.
205a
	lock(&procalloc);
.
168c
	/* p->mach==0 only when process state is saved */
	if(p == 0 || p->mach){	
.
157c
	while(runhiq.head == 0 && runloq.head == 0)
.
129,130d
126a
	rq = &runhiq;
.
123a
	Schedq *rq;
.
122d
108,110c
	up = runproc();
	up->state = Running;
	up->mach = m;
	m->proc = up;
	mmuswitch(up);
	gotolabel(&up->sched);
.
96,102c
		procsave(up);
		if(setlabel(&up->sched)) {
			procrestore(up);
.
91,93c
	if(up) {
.
83c
		up->mach = 0;
		up = 0;
.
81a
			break;
.
80c
			qunlock(&up->debug);
.
76,77c
			up->qnext = procalloc.free;
			procalloc.free = up;
.
72,74c
			mmurelease(up);
.
59,67c
		switch(up->state) {
		case Running:
			ready(up);
			break;
		case Moribund:
			up->pid = 0;
			up->state = Dead;
.
57c
	if(up) {
.
54,55d
## diffname port/proc.c 1993/0528
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/port/proc.c /n/fornaxdump/1993/0528/sys/src/brazil/port/proc.c
162a
		if(conf.nmach > 1)
			delay(7);	/* keep off the bus (tuned for everest) */
.
## diffname port/proc.c 1993/0729
## diff -e /n/fornaxdump/1993/0528/sys/src/brazil/port/proc.c /n/fornaxdump/1993/0729/sys/src/brazil/port/proc.c
86a
	kmapinval();
.
## diffname port/proc.c 1993/0731
## diff -e /n/fornaxdump/1993/0729/sys/src/brazil/port/proc.c /n/fornaxdump/1993/0731/sys/src/brazil/port/proc.c
87d
## diffname port/proc.c 1993/0801
## diff -e /n/fornaxdump/1993/0731/sys/src/brazil/port/proc.c /n/fornaxdump/1993/0801/sys/src/brazil/port/proc.c
138,140d
86a
	kmapinval();
.
## diffname port/proc.c 1993/0804
## diff -e /n/fornaxdump/1993/0801/sys/src/brazil/port/proc.c /n/fornaxdump/1993/0804/sys/src/brazil/port/proc.c
87d
## diffname port/proc.c 1993/0829
## diff -e /n/fornaxdump/1993/0804/sys/src/brazil/port/proc.c /n/fornaxdump/1993/0829/sys/src/brazil/port/proc.c
161c
			delay(7);
.
159a
		/* keep off the bus (tuned for everest) */
.
## diffname port/proc.c 1993/0830
## diff -e /n/fornaxdump/1993/0829/sys/src/brazil/port/proc.c /n/fornaxdump/1993/0830/sys/src/brazil/port/proc.c
160,162d
## diffname port/proc.c 1993/0904
## diff -e /n/fornaxdump/1993/0830/sys/src/brazil/port/proc.c /n/fornaxdump/1993/0904/sys/src/brazil/port/proc.c
147a

.
## diffname port/proc.c 1993/1123
## diff -e /n/fornaxdump/1993/0904/sys/src/brazil/port/proc.c /n/fornaxdump/1993/1123/sys/src/brazil/port/proc.c
800a

void
killbig(void)
{
	int i;
	Segment *s;
	ulong l, max;
	Proc *p, *ep, *kp;

	max = 0;
	kp = 0;
	ep = procalloc.arena+conf.nproc;
	for(p = procalloc.arena; p < ep; p++) {
		if(p->state == Dead || p->kp)
			continue;
		l = 0;
		for(i=1; i<NSEG; i++){
			s = p->seg[i];
			if(s)
				l += s->top - s->base;
		}
		if(l > max) {
			kp = p;
			max = l;
		}
	}
	print("%d: %s killed because no swap configured", kp->pid, kp->text);
	kp->procctl = Proc_exitme;
	postnote(kp, 1, "killed: proc too big", NExit);
}
.
## diffname port/proc.c 1993/1201
## diff -e /n/fornaxdump/1993/1123/sys/src/brazil/port/proc.c /n/fornaxdump/1993/1201/sys/src/brazil/port/proc.c
231a
	memset(p->counter, 0, sizeof(p->counter));
	memset(p->syscall, 0, sizeof(p->syscall));
.
89a
		up->counter[CSCNTR]++;
up->counter[TLBCNTR] += m->tlbfault - m->otlbfault;
m->otlbfault = m->tlbfault;
.
## diffname port/proc.c 1993/1204
## diff -e /n/fornaxdump/1993/1201/sys/src/brazil/port/proc.c /n/fornaxdump/1993/1204/sys/src/brazil/port/proc.c
227a
	p->mp = 0;
.
154a

	if(m->runq.head)
		rq = &m->runq;
	else
.
149c
	while(runhiq.head == 0 && runloq.head == 0 && m->runq.head == 0)
.
123a
	if(p->mp)
		rq = &p->mp->runq;
	else
.
112c
	return runloq.head != 0 || runhiq.head != 0 || m->runq.head != 0;
.
24,30d
## diffname port/proc.c 1993/1212
## diff -e /n/fornaxdump/1993/1204/sys/src/brazil/port/proc.c /n/fornaxdump/1993/1212/sys/src/brazil/port/proc.c
172a

.
159a
	lock(&runhiq);
.
150,154d
147d
145c
	while(runhiq.head == 0 && runloq.head == 0)
.
121a
	else
		rq = &runhiq;
.
116,119d
105c
	return runhiq.head != 0 || runloq.head != 0;
.
84,85c
		up->counter[TLBCNTR] += m->tlbfault - m->otlbfault;
		m->otlbfault = m->tlbfault;

.
81a

		/* statistics */
.
## diffname port/proc.c 1993/1214
## diff -e /n/fornaxdump/1993/1212/sys/src/brazil/port/proc.c /n/fornaxdump/1993/1214/sys/src/brazil/port/proc.c
153c
		rq = &m->loq;
.
150,151c
	if(m->hiq.head)
		rq = &m->hiq;
.
146c
	while(m->hiq.head == 0 && m->loq.head == 0)
.
122c
		rq = &affinity(p)->hiq;
.
120c
		rq = &m->loq;
.
108c
	return m->hiq.head != 0 || m->loq.head != 0;
.
86,87d
## diffname port/proc.c 1993/1215
## diff -e /n/fornaxdump/1993/1214/sys/src/brazil/port/proc.c /n/fornaxdump/1993/1215/sys/src/brazil/port/proc.c
162a
	rq->n--;
.
129c
	rq->n++;
.
25a
Schedq	runhiq;
.
24d
## diffname port/proc.c 1994/0311
## diff -e /n/fornaxdump/1993/1215/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0311/sys/src/brazil/port/proc.c
100a
}

void
newcallback(void (*func)(void))
{
	*m->cbin = func;
	if(++m->cbin >= m->cbend)
		m->cbin = m->calls;
}

void
callbacks(void)
{
	void (*func)(void);

	while(m->cbin != m->cbout) {
		func = *m->cbout;
		if(++m->cbout >= m->cbend)
			m->cbout = m->calls;
		func();
	}
.
89a
			callbacks();
.
46a
	m->cbin = m->calls;
	m->cbout = m->calls;
	m->cbend = &m->calls[NCALLBACK];

.
## diffname port/proc.c 1994/0320
## diff -e /n/fornaxdump/1994/0311/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0320/sys/src/brazil/port/proc.c
127,132d
115a
int
anyready(void)
{
	return m->hiq.head != 0 || m->loq.head != 0;
}

.
## diffname port/proc.c 1994/0321
## diff -e /n/fornaxdump/1994/0320/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0321/sys/src/brazil/port/proc.c
114,119d
107a
int
anyready(void)
{
	return m->hiq.head != 0 || m->loq.head != 0;
}

.
## diffname port/proc.c 1994/0322
## diff -e /n/fornaxdump/1994/0321/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0322/sys/src/brazil/port/proc.c
47,50d
## diffname port/proc.c 1994/0324
## diff -e /n/fornaxdump/1994/0322/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0324/sys/src/brazil/port/proc.c
115a

	if(m->hiq.head == 0 && m->loq.head == 0)
		return 1;

	return 0;
.
110c
int
.
## diffname port/proc.c 1994/0325
## diff -e /n/fornaxdump/1994/0324/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0325/sys/src/brazil/port/proc.c
856c
	print("%d: %s killed because no swap configured\n", kp->pid, kp->text);
.
846c
		for(i=1; i<NSEG; i++) {
.
715c
			p->qpc, p->time[0], p->time[1], bss);
.
713c
		print("%3d:%10s pc %8lux %8s (%s) q %lux ut %ld st %ld bss %lux\n",
.
132c

		c->func(c->arg);
.
129c
		c = m->cbout;
.
126c
	Callbk *c;
.
117,120c
	c->func = func;
	c->arg = a;
.
113c
	Callbk *c;

	c = m->cbin;
.
110,111c
void
newcallback(void (*func)(void*), void *a)
.
## diffname port/proc.c 1994/0406
## diff -e /n/fornaxdump/1994/0325/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0406/sys/src/brazil/port/proc.c
716c
			p->time[0], p->time[1], bss);
.
714c
		print("%3d:%10s pc %8lux %8s (%s) ut %ld st %ld bss %lux\n",
.
## diffname port/proc.c 1994/0407
## diff -e /n/fornaxdump/1994/0406/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0407/sys/src/brazil/port/proc.c
277a
		p->syscall = xalloc(nsyscall * sizeof(ulong));
	}
.
276c
	for(i=0; i<conf.nproc-1; i++,p++){
.
## diffname port/proc.c 1994/0508
## diff -e /n/fornaxdump/1994/0407/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0508/sys/src/brazil/port/proc.c
108,134d
90d
## diffname port/proc.c 1994/0612
## diff -e /n/fornaxdump/1994/0508/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0612/sys/src/brazil/port/proc.c
250,251d
248c
	for(i=0; i<conf.nproc-1; i++,p++)
.
232,233d
85d
## diffname port/proc.c 1994/0725
## diff -e /n/fornaxdump/1994/0612/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0725/sys/src/brazil/port/proc.c
117c
		rq = &balance(p)->loq;
.
## diffname port/proc.c 1994/0727
## diff -e /n/fornaxdump/1994/0725/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0727/sys/src/brazil/port/proc.c
152d
147c
	lock(&runhiq);
	if(runhiq.head)
		rq = &runhiq;
	else if(m->hiq.head)
.
143c
	while(runhiq.head == 0 && m->hiq.head == 0 && m->loq.head == 0)
.
116c
	if(p->priority)
		rq = &runhiq;
	else if(p->state == Running)
.
25c
Schedq	runhiq;		/* for hi priority process, don't bother with affinity */
.
## diffname port/proc.c 1994/0728
## diff -e /n/fornaxdump/1994/0727/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0728/sys/src/brazil/port/proc.c
689a
	}
	for(rq = runq; rq < &runq[Nrq]; rq++){
		print("rq%d:", rq-runq);
		for(p = rq->head; p; p = p->rnext)
			print(" %d", p->pid);
		print("\n");
.
674a
	Schedq *rq;
.
188c
	unlock(&runq[0]);
.
182c
	lock(&runq[0]);
.
172a
	p->mp = m;
.
170c
	unlock(runq);
.
164,165c
		rq->tail = l;
	if(l)
		l->rnext = p->rnext;
	else
		rq->head = p->rnext;
.
160c
		unlock(&runq[0]);
.
157,158c
	/*
	 *  affinity: look for a process last run on this processor,
	 *	otherwise, take first in list.
	 */
	l = 0;
	for(p = rq->head; p; p = p->rnext){
		if(p->mp == m)
			break;
		l = p;
	}
	if(p == 0){
		l = 0;
		p = rq->head;
	}

	/*
	 *  p->mach==0 only when process state is saved
	 */
.
149,155c
	lock(runq);
.
145,146c
	for(rq = runq; rq < &runq[Nrq]; rq++)
		if(rq->head)
			break;
	if(rq == &runq[Nrq])
		goto loop;
.
143a

	/*
	 *  find highest priority queue with runnable process
	 */
.
141c
	Proc *p, *l;
.
133c
	unlock(runq);
.
123c
	lock(runq);
.
116,121c
	if(p->priority != 0){
		if(p->state == Running){
			if(p->priority < Nrq-1)
				p->priority++;
		} else
			p->priority = 1;
	}
if(p->priority < 0 || p->priority >= Nrq) panic("ready");
	rq = &runq[p->priority];
.
105c
	Schedq *rq;

	for(rq = runq; rq < &runq[Nrq]; rq++)
		if(rq->head)
			return 1;

	return 0;
.
25c
Schedq	runq[Nrq];
.
23a

enum
{
	Nrq = 5,	/* number of run queues */
};

.
## diffname port/proc.c 1994/0729
## diff -e /n/fornaxdump/1994/0728/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0729/sys/src/brazil/port/proc.c
263a
	p->movetime = 0;
.
207a
	if(p->mp != m)
		p->movetime = m->ticks;
.
183,186d
179c
		if(rq == runq || p->mp == m || m->ticks - p->movetime > HZ/2)
.
173,176d
170a

found:
	splhi();
.
164,169c
	for(;;){
		for(rq = runq; rq < &runq[Nrq]; rq++){
			if(rq->head == 0)
				continue;
			for(p = rq->head; p; p = p->rnext){
				if(rq == runq || p->mp == m || 
				   m->ticks - p->movetime > HZ/2)
					goto found;
			}
		}
	}
.
161c
	 *  find a process at level 0 (programs from '/' file system),
	 *  one that last ran on this processor (affinity),
	 *  or one that hasn't moved in a while (load balancing).
.
135d
111,117c
	return nrdy;
.
## diffname port/proc.c 1994/0805
## diff -e /n/fornaxdump/1994/0729/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0805/sys/src/brazil/port/proc.c
368a
if(i++ > 20) {
	print("tlarm loop: %lux\n", talarm.list);
	for(i = 20, f = talarm.list; f && i--; f = f->tlink)
		print("%lux ", f);
		for(;;);
}
.
361a
i = 0;
.
354c
	ulong when, i;
.
## diffname port/proc.c 1994/0808
## diff -e /n/fornaxdump/1994/0805/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0808/sys/src/brazil/port/proc.c
122,128c
	if(p->state == Running){
		if(p->priority < Nrq-1)
			p->priority++;
	} else
		p->priority = p->basepri;
.
## diffname port/proc.c 1994/0809
## diff -e /n/fornaxdump/1994/0808/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0809/sys/src/brazil/port/proc.c
736a
	print("nrdy %d\n", nrdy);
.
113a
int
anyready0(void)
{
	return runq->head != 0;
}

.
## diffname port/proc.c 1994/0810
## diff -e /n/fornaxdump/1994/0809/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0810/sys/src/brazil/port/proc.c
740c
			print(" %d(%d)", p->pid, m->ticks - p->readyticks);
.
143a
	p->readyticks = m->ticks;
.
## diffname port/proc.c 1994/0812
## diff -e /n/fornaxdump/1994/0810/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0812/sys/src/brazil/port/proc.c
563a
	if(up->rgrp)
		closergrp(up->rgrp);
.
484c
	unlock(p->rgrp);
.
474c
		l = &REND(p->rgrp, p->rendtag);
.
471c
	lock(p->rgrp);
.
375,380d
367d
359c
	ulong when;
.
259a
	p->rgrp = 0;
.
## diffname port/proc.c 1994/0816
## diff -e /n/fornaxdump/1994/0812/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0816/sys/src/brazil/port/proc.c
25,29d
## diffname port/proc.c 1994/0817
## diff -e /n/fornaxdump/1994/0816/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0817/sys/src/brazil/port/proc.c
140a
	if(lastreadied > p->priority)
		lastreadied = p->priority;
.
112c
	int x;

	x = lastreadied;
	lastreadied = Nrq;
	return nrdy && x <= up->priority;
.
110c
anyhigher(void)
.
25a
int	lastreadied;
.
## diffname port/proc.c 1994/0830
## diff -e /n/fornaxdump/1994/0817/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0830/sys/src/brazil/port/proc.c
736a
		if(rq->head == 0)
			continue;
.
## diffname port/proc.c 1994/0914
## diff -e /n/fornaxdump/1994/0830/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0914/sys/src/brazil/port/proc.c
23a
typedef struct
{
	Lock;
	Proc	*head;
	Proc	*tail;
	int	n;
} Schedq;
.
## diffname port/proc.c 1994/0915
## diff -e /n/fornaxdump/1994/0914/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0915/sys/src/brazil/port/proc.c
743c
	for(rq = &runq[Nrq-1]; rq >= runq; rq--){
.
235c
	unlock(runq);
.
229c
	lock(runq);
.
201c
		unlock(runq);
.
192c
		if(p->mp == m || m->ticks - p->movetime > HZ/2)
.
178,179c
				if(p->mp == m || m->ticks - p->movetime > HZ/2)
.
174c
		for(rq = &runq[Nrq-1]; rq >= runq; rq--){
.
168,169c
	 *  find a process that last ran on this processor (affinity),
.
153c
	if(p->priority > lastreadied)
.
136,137c
		if(p->priority > 0)
			p->priority--;
.
123,124c
	lastreadied = 0;
	return nrdy && x >= up->priority;
.
## diffname port/proc.c 1994/0917
## diff -e /n/fornaxdump/1994/0915/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0917/sys/src/brazil/port/proc.c
332a
	up->art = (up->art + up->rt)>>1;
	up->rt = 0;
.
135,139c
	if(p->state == Running)
		p->rt++;
	pri = p->basepri - (((p->art + p->rt)>>1)/Squantum);
	if(pri < 0)
		pri = 0;
.
130c
	int s, pri;
.
126a
enum
{
	Squantum = (HZ+Nrq-1)/Nrq,
};

.
## diffname port/proc.c 1994/0918
## diff -e /n/fornaxdump/1994/0917/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0918/sys/src/brazil/port/proc.c
753c
			print(" %d(%d)", p->pid, m->ticks - p->readytime);
.
177a
		/*
		 *  Once a second we look for a long waiting process
		 *  in the lowest priority queue to make sure nothing
		 *  gets starved out by a malfunctioning high priority
		 *  process.
		 */
		if(m->machno == 0 && m->ticks - lastfair > HZ){
			lastfair = m->ticks;
			for(rq = runq; rq < &runq[Nrq]; rq++){
				p = rq->head;
				if(p){
					i = m->ticks - p->readytime;
					if(i > HZ){
						p->art = 0;
						p->movetime = 0;
						goto found;
					}
					break;
				}
			}
		}

		/*
		 *  get highest priority process that this
		 *  processor can run given affinity constraints
		 */
.
168a
	static ulong lastfair;
.
166a
	int i;
.
156c
	p->readytime = m->ticks;
.
144a
	p->priority = pri;
.
## diffname port/proc.c 1994/0920
## diff -e /n/fornaxdump/1994/0918/sys/src/brazil/port/proc.c /n/fornaxdump/1994/0920/sys/src/brazil/port/proc.c
813a

	p->basepri = PriKproc;
	p->priority = p->basepri;
.
367,368d
144a

	/* the only intersection between the classes is at PriNormal */
	if(pri < PriNormal && p->basepri > PriNormal)
		pri = PriNormal;
.
142c
		pri = ((p->art + (p->rt<<1))>>2)/Squantum;
	} else {
		p->art = (p->art + (p->rt<<1))>>2;
		p->rt = 0;
		pri = p->art/Squantum;
	}
	pri = p->basepri - pri;
.
140c
	/* history counts */
	if(p->state == Running){
.
## diffname port/proc.c 1994/1027
## diff -e /n/fornaxdump/1994/0920/sys/src/brazil/port/proc.c /n/fornaxdump/1994/1027/sys/src/brazil/port/proc.c
940a

/*
 *  change ownership to 'new' of all processes owned by 'old'.  Used when
 *  eve changes.
 */
void
renameuser(char *old, char *new)
{
	Proc *p, *ep;

	ep = procalloc.arena+conf.nproc;
	for(p = procalloc.arena; p < ep; p++)
		if(strcmp(old, p->user) == 0)
			memmove(p->user, new, NAMELEN);
}
.
## diffname port/proc.c 1995/0101
## diff -e /n/fornaxdump/1994/1027/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0101/sys/src/brazil/port/proc.c
221c
			for(; p; p = p->rnext){
.
219c
			p = rq->head;
			if(p == 0)
.
## diffname port/proc.c 1995/0102
## diff -e /n/fornaxdump/1995/0101/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0102/sys/src/brazil/port/proc.c
825,826c
	p->nice = NiceKproc;
	p->pri = 0;
.
787,792c
	if(runq.head != 0) {
		print("rq:");
		for(p = runq.head; p; p = p->rnext)
			print(" %d(%d)", p->pid, p->pri);
.
770d
332a
procwired(Proc *p)
{
	Proc *pp;
	int i, bm;
	char nwired[MAXMACH];

	memset(nwired, 0, sizeof(nwired));
	p->wired = 0;
	pp = proctab(0);
	for(i=0; i<conf.nproc; i++, pp++)
		if(pp->wired && pp->pid)
			nwired[pp->wired->machno]++;
	bm = 0;
	for(i=0; i<conf.nmach; i++)
		if(nwired[i] < nwired[bm])
			bm = i;
	p->wired = MACHP(bm);
print("pid %d wired to machine %d\n", p->pid, p->wired->machno);
}

void
.
331a
/*
 * wire this proc to a machine
 */
.
319,320c
	p->nice = NiceNormal;
	p->pri = 0;
	p->wired = 0;
.
279c
	unlock(&runq);
.
273c
	lock(&runq);
.
260,264c
	if(bp->state != Ready)
		print("runproc %s %d %s\n", bp->text, bp->pid, statename[bp->state]);
	unlock(&runq);

	bp->state = Scheding;
	return bp;
.
256,258d
253,254c
		op->rnext = bp->rnext;
	if(bp == runq.tail)
		runq.tail = op;

	/* clear next so that unlocked runq will not loop */
	bp->rnext = 0;

	runq.n--;
.
248,251c

found:
	/* unlink found proc from runq */
	op = 0;
	for(p=runq.head; p; p=p->rnext) {
		if(p == bp)
			break;
		op = p;
	}
	if(op == 0)
		runq.head = bp->rnext;
.
240,245c
	if(bp == 0) {
		unlock(&runq);
.
234,238c
	/* find best proc while locked */
	bp = 0;
	for(p=runq.head; p; p=p->rnext) {
		if(p->mach)
			continue;
		if(p->wired && p->wired != m)
			continue;
		if(bp == 0 || p->pri < bp->pri)
			bp = p;
.
232c
	lock(&runq);
.
229,230d
227a
	if(p == 0)
		goto loop;
.
218,226c
		if(p->wired && p->wired != m)
			continue;
		break;
.
215,216c
		 *  wired to another machine
.
198,213c
		if(p->mach)
			continue;
.
193,196c
		 *  state is not saved
.
191c

	/* look for potential proc while not locked */
	for(p=runq.head; p; p=p->rnext) {
.
185,189d
179,182c
	Proc *p, *bp, *op;
.
170,172c
	unlock(&runq);
.
168d
164,166c
		runq.head = p;
	runq.tail = p;
	runq.n++;
.
161,162c
	if(runq.tail)
		runq.tail->rnext = p;
.
140,159c
	lock(&runq);
.
135,136c
	int s;
.
127,131d
122,124c
	return nrdy;
.
120d
33,34c
Schedq	runq;
.
## diffname port/proc.c 1995/0104
## diff -e /n/fornaxdump/1995/0102/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0104/sys/src/brazil/port/proc.c
926a
}

/*
 *  time accounting called by clock() splhi'd
 */
void
accounttime(void)
{
	Proc *p;
	int i, pri;
	static int nrun, m0ticks;

	p = m->proc;
	if(p) {
		nrun++;
		p->time[p->insyscall]++;
		p->pri += priconst[p->nice];
	}

	/* only one processor gets to compute system load averages */
	if(m->machno != 0)
		return;

	/* calculate decaying load average */
	pri = nrun;
	nrun = 0;

	pri = (nrdy+pri)*1000;
	m->load = (m->load*19+pri)/20;

	/*
	 * decay per-process cpu usage
	 *	pri = (7/8)*pri twice per second
	 *	tc = (7/8)^2/(1-(7/8)^2) = 3.27 sec
	 */
	m0ticks--;
	if(m0ticks <= 0) {
		m0ticks = HZ/2;
		p = proctab(0);
		for(i=conf.nproc-1; i!=0; i--,p++)
			if(p->state != Dead) {
				pri = p->pri;
				pri -= pri >> 3;
				p->pri = pri;
			}
	}
.
910a
	for(i = 0; i < NSEG; i++) {
		s = kp->seg[i];
		if(s != 0 && canqlock(&s->lk)) {
			mfreeseg(s, s->base, (s->top - s->base)/BY2PG);
			qunlock(&s->lk);
		}
	}
	print("%d: %s killed because no swap configured\n", kp->pid, kp->text);
.
909d
901c
			if(s != 0)
.
676d
674a
	/* Sched must not loop for this lock */
.
673a
	qunlock(&up->debug);
.
669a
	qlock(&up->debug);
.
665,668d
654a
			*s = 0;
		}
	}
.
652,653c
	for(s = up->seg; s < es; s++) {
		if(*s) {
.
471c
	r = p->r;
	if(r != 0) {
.
318a

	/*
	 * set up priority increments
	 * normal priority sb about 1000/HZ
	 * highest pri (lowest number) sb about 0
	 */
	for(i=0; i<NiceMax; i++)
		priconst[i] = (i*1000)/(NiceNormal*HZ);
.
303d
73,75d
63d
33a
int	priconst[NiceMax];
.
## diffname port/proc.c 1995/0105
## diff -e /n/fornaxdump/1995/0104/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0105/sys/src/brazil/port/proc.c
967c
	pri = (runq.n+pri)*1000;
.
860d
857a
		splhi();
.
851a
		spllo();
.
772c
	print("nrdy %d\n", runq.n);
.
203d
135d
117c
	pri = up->pri;
	for(p=runq.head; p; p=p->rnext)
		if(p->pri < pri)
			if(p->wired == 0 || p->wired == m)
				return runq.n;
	return 0;
.
115a
	Proc *p;
	int pri;
.
110c
	return runq.n;
.
32d
## diffname port/proc.c 1995/0106
## diff -e /n/fornaxdump/1995/0105/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0106/sys/src/brazil/port/proc.c
372a
	}
.
371c
	if(up->notepending == 0) {
		up->yield = 1;
.
182a
		} else
		if(p->yield == 0 && p->pri < bp->pri)
			bp = p;
.
179,181c
		if(bp == 0) {
			p->yield = 0;
.
176,177c
	for(p = runq.head; p; p=p->rnext) {
		if(p->mach || (p->wired && p->wired != m))
.
159,166c
		if(!(p->mach || (p->wired && p->wired != m)))
			break;
.
157c
		 *  state is not saved or wired to another machine
.
155c
	for(p = runq.head; p; p=p->rnext) {
.
122c
				return 1;
.
## diffname port/proc.c 1995/0107
## diff -e /n/fornaxdump/1995/0106/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0107/sys/src/brazil/port/proc.c
120c
		if(p->pri <= pri)
.
117a
	return runq.n;
.
## diffname port/proc.c 1995/0108
## diff -e /n/fornaxdump/1995/0107/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0108/sys/src/brazil/port/proc.c
175c
			if(p->yield)
				p->yield = 0;
.
## diffname port/proc.c 1995/0109
## diff -e /n/fornaxdump/1995/0108/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0109/sys/src/brazil/port/proc.c
987c
				pri -= pri >> 2;
.
977,978c
	 *	pri = (3/4)*pri twice per second
	 *	tc = (3/4)^2/(1-(3/4)^2) = 1.286 sec
.
963a
	if(up) {
		i = up->inlock-1;
		if(i < 0)
			i = 0;
		up->inlock = i;
	}

.
118d
## diffname port/proc.c 1995/0110
## diff -e /n/fornaxdump/1995/0109/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0110/sys/src/brazil/port/proc.c
978,996c
	n = (nrdy+n)*1000;
	m->load = (m->load*19+n)/20;
.
975c
	n = nrun;
.
963,969d
960d
953,954c
	int n;
	static int nrun;
.
874a
	if((getstatus()&IE) == 0)
		print("error hi %lux\n", getcallerpc(err));
	spllo();
.
805,806c
	p->basepri = PriKproc;
	p->priority = p->basepri;
.
775c
	print("nrdy %d\n", nrdy);
.
769,772c
	for(rq = &runq[Nrq-1]; rq >= runq; rq--){
		if(rq->head == 0)
			continue;
		print("rq%d:", rq-runq);
		for(p = rq->head; p; p = p->rnext)
			print(" %d(%d)", p->pid, m->ticks - p->readytime);
.
752a
	Schedq *rq;
.
396a
	if((getstatus()&IE) == 0)
		print("tsleep hi %lux\n", getcallerpc(r));

.
371d
368,369c
	if(up->notepending == 0)
.
366a
	if((getstatus()&IE) == 0)
		print("sleep hi %lux\n", getcallerpc(r));

.
316,323d
300a
	p->movetime = 0xffffffff;
	p->mp = p->wired;
.
266,267c
	p->mp = 0;
	p->movetime = 0;
.
226c
	unlock(runq);
.
220c
	lock(runq);
.
201,211c
	p->state = Scheding;
	if(p->mp != m)
		p->movetime = m->ticks + HZ/2;
	p->mp = m;
	return p;
.
197,199c
		rq->head = p->rnext;
	rq->n--;
	nrdy--;
	if(p->state != Ready)
		print("runproc %s %d %s\n", p->text, p->pid, statename[p->state]);
	unlock(runq);
.
185,195c
	if(p->rnext == 0)
		rq->tail = l;
	if(l)
		l->rnext = p->rnext;
.
181,182c

	/*
	 *  p->mach==0 only when process state is saved
	 */
	if(p == 0 || p->mach){	
		unlock(runq);
.
168,179c
	l = 0;
	for(p = rq->head; p; p = p->rnext){
		if(p->mp == m || p->movetime < m->ticks)
			break;
		l = p;
.
166c
	lock(runq);
.
164a

found:
.
162,163d
159,160c
		for(rq = &runq[Nrq-1]; rq >= runq; rq--){
			p = rq->head;
			if(p == 0)
				continue;
			for(; p; p = p->rnext){
				if(p->mp == m || p->movetime < m->ticks)
					goto found;
			}
		}
.
157c
		 *  get highest priority process that this
		 *  processor can run given affinity constraints
.
154,155c
				i = m->ticks - p->readytime;
				if(i < HZ)
					break;

				p->art = 0;
				goto found;
			}
		}

.
152a
	for(;;){
		/*
		 *  Once a second we look for a long waiting process
		 *  in the lowest priority queue to make sure nothing
		 *  gets starved out by a malfunctioning high priority
		 *  process.
		 */
		if((m->ticks % HZ) == 0){
			for(rq = runq; rq < &runq[Nrq]; rq++){
				p = rq->head;
				if(p == 0 || p->mp != m)
					continue;
.
151a

	/*
	 *  find a process that last ran on this processor (affinity),
	 *  or one that hasn't moved in a while (load balancing).
	 */
.
149c
	int i;
	Schedq *rq;
	Proc *p, *l;
.
142c
	if(p->priority > lastreadied)
		lastreadied = p->priority;
	unlock(runq);
.
138,140c
		rq->head = p;
	rq->tail = p;
	rq->n++;
	nrdy++;
	p->readytime = m->ticks;
.
135,136c
	if(rq->tail)
		rq->tail->rnext = p;
.
133c
	/* history counts */
	if(p->state == Running){
		p->rt++;
		pri = ((p->art + (p->rt<<1))>>2)/Squantum;
	} else {
		p->art = (p->art + (p->rt<<1))>>2;
		p->rt = 0;
		pri = p->art/Squantum;
	}
	pri = p->basepri - pri;
	if(pri < 0)
		pri = 0;

	/* the only intersection between the classes is at PriNormal */
	if(pri < PriNormal && p->basepri > PriNormal)
		pri = PriNormal;
	p->priority = pri;
	rq = &runq[p->priority];

	lock(runq);
.
129c
	int s, pri;
	Schedq *rq;
.
125a
enum
{
	Squantum = (HZ+Nrq-1)/Nrq,
};

.
118,123c
	x = lastreadied;
	lastreadied = 0;
	return nrdy && x >= up->priority;
.
115,116c
	int x;
.
109c
	return nrdy;
.
32,33c
int	nrdy;
int	lastreadied;
Schedq	runq[Nrq];
.
## diffname port/proc.c 1995/0112
## diff -e /n/fornaxdump/1995/0110/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0112/sys/src/brazil/port/proc.c
913a
		splx(s);
.
912c
		sched();
.
903c
		s = spllo();
.
886a
	ulong s;
.
67c
			 * 	procalloc
.
## diffname port/proc.c 1995/0115
## diff -e /n/fornaxdump/1995/0112/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0115/sys/src/brazil/port/proc.c
315a
	p->ureg = 0;
.
## diffname port/proc.c 1995/0126
## diff -e /n/fornaxdump/1995/0115/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0126/sys/src/brazil/port/proc.c
926,927d
440,442d
409,411d
## diffname port/proc.c 1995/0215
## diff -e /n/fornaxdump/1995/0126/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0215/sys/src/brazil/port/proc.c
974d
965c
	kp->procctl = Proc_exitbig;
.
884a
	case Proc_exitbig:
		spllo();
		pexit("Killed: Insufficient physical memory", 1);

.
## diffname port/proc.c 1995/0329
## diff -e /n/fornaxdump/1995/0215/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0329/sys/src/brazil/port/proc.c
668a
			wq->w.msg[ERRLEN-1] = 0;
.
## diffname port/proc.c 1995/0811
## diff -e /n/fornaxdump/1995/0329/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0811/sys/src/brazil/port/proc.c
257c
	p->mp = MACHP(m->machno);
.
255c
	if(p->mp != MACHP(m->machno))
.
230c
		if(p->mp == MACHP(m->machno) || p->movetime < m->ticks)
.
217c
				if(p->mp == MACHP(m->machno) || p->movetime < m->ticks)
.
196c
				if(p == 0 || p->mp != MACHP(m->machno))
.
101c
	up->mach = MACHP(m->machno);
.
## diffname port/proc.c 1995/0910
## diff -e /n/fornaxdump/1995/0811/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0910/sys/src/brazil/port/proc.c
186c
	for(randomcount++;;randomcount++){
.
49a
ulong randomcount;

.
## diffname port/proc.c 1995/0912
## diff -e /n/fornaxdump/1995/0910/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0912/sys/src/brazil/port/proc.c
188c
	for(;;){
		if(m->machno == 0)
			randomcount++;

.
## diffname port/proc.c 1995/0913
## diff -e /n/fornaxdump/1995/0912/sys/src/brazil/port/proc.c /n/fornaxdump/1995/0913/sys/src/brazil/port/proc.c
189,191d
50,51d
## diffname port/proc.c 1995/1009
## diff -e /n/fornaxdump/1995/0913/sys/src/brazil/port/proc.c /n/fornaxdump/1995/1009/sys/src/brazil/port/proc.c
816c
			print(" %d(%d, %d)", p->pid, m->ticks - p->readytime,
				m->ticks - p->movetime);
.
795a
	if(up)
		print("up %d\n", up->pid);
	else
		print("no current process\n");
.
## diffname port/proc.c 1995/1024
## diff -e /n/fornaxdump/1995/1009/sys/src/brazil/port/proc.c /n/fornaxdump/1995/1024/sys/src/brazil/port/proc.c
811,812c
		print("%3d:%10s pc %8lux dbgpc %8lux  %8s (%s) ut %ld st %ld bss %lux\n",
			p->pid, p->text, p->pc, dbgpc(p),  s, statename[p->state],
.
## diffname port/proc.c 1995/1030
## diff -e /n/fornaxdump/1995/1024/sys/src/brazil/port/proc.c /n/fornaxdump/1995/1030/sys/src/brazil/port/proc.c
822a
		delay(150);
.
814a
}

void
scheddump(void)
{
	Proc *p;
	Schedq *rq;

.
808,813c
		dumpaproc(p);
		delay(150);
.
804,806d
793,794d
791d
787a
dumpaproc(Proc *p)
{
	ulong bss;
	char *s;

	if(p == 0)
		return;

	bss = 0;
	if(p->seg[BSEG])
		bss = p->seg[BSEG]->top;

	s = p->psstate;
	if(s == 0)
		s = "kproc";
	print("%3d:%10s pc %8lux dbgpc %8lux  %8s (%s) ut %ld st %ld bss %lux\n",
		p->pid, p->text, p->pc, dbgpc(p),  s, statename[p->state],
		p->time[0], p->time[1], bss, p->priority);
}

void
.
## diffname port/proc.c 1995/1111
## diff -e /n/fornaxdump/1995/1030/sys/src/brazil/port/proc.c /n/fornaxdump/1995/1111/sys/src/brazil/port/proc.c
296d
## diffname port/proc.c 1995/1230
## diff -e /n/fornaxdump/1995/1111/sys/src/brazil/port/proc.c /n/fornaxdump/1995/1230/sys/src/brazil/port/proc.c
725a
	lock(&palloc);
.
72a

			unlock(&palloc);
.
## diffname port/proc.c 1996/0121
## diff -e /n/fornaxdump/1995/1230/sys/src/brazil/port/proc.c /n/fornaxdump/1996/0121/sys/src/brazil/port/proc.c
710a
	wakeup(&up->waitr);
.
## diffname port/proc.c 1996/0315
## diff -e /n/fornaxdump/1996/0121/sys/src/brazil/port/proc.c /n/fornaxdump/1996/0315/sys/src/brazil/port/proc.c
224d
219c
				if(p->mp == MACHP(m->machno)
				|| p->movetime < m->ticks)
.
200,206c
				for(; p; p = p->rnext){
					if(p->mp != MACHP(m->machno))
					if(p->movetime >= m->ticks)
						continue;
					i = m->ticks - p->readytime;
					if(i >= 2*nrdy*p->art)
						goto found;
				}
.
198c
				if(p == 0)
.
195c
		if((m->ticks & 3) == 0){
.
190,193c
		 *  get lowest priority process that this
		 *  processor can run given affinity constraints
		 *  and that hasn't run in a while
.
## diffname port/proc.c 1996/0426
## diff -e /n/fornaxdump/1996/0315/sys/src/brazil/port/proc.c /n/fornaxdump/1996/0426/sys/src/brazil/port/proc.c
317a
	p->error[0] = '\0';
.
## diffname port/proc.c 1996/0511
## diff -e /n/fornaxdump/1996/0426/sys/src/brazil/port/proc.c /n/fornaxdump/1996/0511/sys/src/brazil/port/proc.c
140,141c
		if(up->priority == PriLock){
			pri = 0;
		} else {
			p->rt++;
			pri = ((p->art + (p->rt<<1))>>2)/Squantum;
		}
.
## diffname port/proc.c 1996/0516
## diff -e /n/fornaxdump/1996/0511/sys/src/brazil/port/proc.c /n/fornaxdump/1996/0516/sys/src/brazil/port/proc.c
158a

.
156c
	if(pri < PriNormal && base > PriNormal)
.
151c
	pri = base - pri;
.
140,145c
		p->rt++;
		pri = ((p->art + (p->rt<<1))>>2)/Squantum;
.
137a
	/*
	 *  This interacts with code in taslock().  The intent is to keep the
	 *  priority of a process trying for a lock lower than the process holding
	 *  the lock.
	 */
	if(p->lockpri)
		base = p->lockpri;
	else
		base = p->basepri;

.
133c
	int s, pri, base;
.
## diffname port/proc.c 1996/0522
## diff -e /n/fornaxdump/1996/0516/sys/src/brazil/port/proc.c /n/fornaxdump/1996/0522/sys/src/brazil/port/proc.c
329a
	p->lockpri = 0;
.
## diffname port/proc.c 1996/0523
## diff -e /n/fornaxdump/1996/0522/sys/src/brazil/port/proc.c /n/fornaxdump/1996/0523/sys/src/brazil/port/proc.c
165a
	/* hack for livelocks due to priority */
	if(p->lockpri)
		pri = 0;

	p->priority = pri;
.
164d
162c
	if(pri < PriNormal && p->basepri > PriNormal)
.
157c
	pri = p->basepri - pri;
.
138,147d
133c
	int s, pri;
.
## diffname port/proc.c 1996/0626
## diff -e /n/fornaxdump/1996/0523/sys/src/brazil/port/proc.c /n/fornaxdump/1996/0626/sys/src/brazil/port/proc.c
518c
		strcpy(p->note[p->nnote].msg, n);
.
## diffname port/proc.c 1996/1016
## diff -e /n/fornaxdump/1996/0626/sys/src/brazil/port/proc.c /n/fornaxdump/1996/1016/sys/src/brazil/port/proc.c
697a
			unlock(&p->exl);
.
695d
683,685c
		/*
		 *  If my parent is no longer alive, or if there would be more
		 *  than 128 zombie child processes for my parent, then don't
		 *  leave a wait record behind.  This helps prevent badly
		 *  written daemon processes from accumulating lots of wait
		 *  records.
.
539a

		unlock(&p->rlock);
.
533a

		/*  the canlock deals with a different lock ordering
		 *  twixt r and p->rlock than everywhere else.  If we
		 *  locked in the normal order we wouldn't be sure
		 *  r was valid when we did the lock.
		 */
		if(!canlock(r)){
			unlock(&p->rlock);
			splx(s);
			continue;
		}

.
532a
			break;
.
526,531c
	for(;;){
		s = splhi();
		lock(&p->rlock);
		r = p->r;
		if(r == 0){
			unlock(&p->rlock);
.
493a
		unlock(&p->rlock);
.
489a
		lock(&p->rlock);
.
426a
		unlock(&up->rlock);
.
424a
		lock(&up->rlock);
.
408a
	up->r = r;
	unlock(&up->rlock);
.
393a
		unlock(&up->rlock);
.
387a
	lock(&up->rlock);
.
386d
## diffname port/proc.c 1996/1017
## diff -e /n/fornaxdump/1996/1016/sys/src/brazil/port/proc.c /n/fornaxdump/1996/1017/sys/src/brazil/port/proc.c
564a
	unlock(&p->rlock);
	splx(s);
.
533,563c
	s = splhi();
	lock(&p->rlock);
	r = p->r;
	if(r){
		if(r->p != p || p->r != r || p->state != Wakeme)
			panic("postnote: state");
		r->p = 0;
		p->r = 0;
		ready(p);
.
503c

	unlock(&p->rlock);
.
500d
494,495c
	if(p == 0)
		return;

	s = splhi();
	lock(&p->rlock);

	if(r->p == p && p->r == r){
.
491,492d
432d
427d
412d
409d
404,407d
395d
393c
		r->p = 0;
.
387a
	if(r->p){
		print("double sleep %d %d\n", r->p->pid, up->pid);
		dumpstack();
	}
	r->p = up;
.
386d
## diffname port/proc.c 1997/0220
## diff -e /n/fornaxdump/1996/1017/sys/src/brazil/port/proc.c /n/emeliedump/1997/0220/sys/src/brazil/port/proc.c
502a

	return rv;
.
498a
		rv = 1;
.
488c
		return rv;
.
485a
	coherence();	/* force memory state to reflect processor state */

	rv = 0;
.
484c
	int s, rv;
.
480c
int
.
392a
	coherence();	/* force memory state to reflect processor state */

.
## diffname port/proc.c 1997/0327
## diff -e /n/emeliedump/1997/0220/sys/src/brazil/port/proc.c /n/emeliedump/1997/0327/sys/src/brazil/port/proc.c
987a
	iprint("%s\n", buf);
.
652c
	cclose(up->dot);
.
438c
	return MACHP(0)->ticks >= up->twhen || up->tfn(arg);
.
367a
	if(procalloc.free == nil)
		panic("cannot allocate %d procs\n", conf.nproc);
.
27,28c
	Proc*	head;
	Proc*	tail;
.
21c
	Waitq*	free;
.
14,15c
	Proc*	arena;
	Proc*	free;
.
## diffname port/proc.c 1997/0821
## diff -e /n/emeliedump/1997/0327/sys/src/brazil/port/proc.c /n/emeliedump/1997/0821/sys/src/brazil/port/proc.c
233c
	if(!canlock(runq))
		goto loop;
.
## diffname port/proc.c 1997/1104
## diff -e /n/emeliedump/1997/0821/sys/src/brazil/port/proc.c /n/emeliedump/1997/1104/sys/src/brazil/port/proc.c
648,649c
	if(up->fgrp){
		fgrp = up->fgrp;
		up->fgrp = nil;
		closefgrp(fgrp);
	}
.
644a
	Fgrp *fgrp;
.
## diffname port/proc.c 1998/0325
## diff -e /n/emeliedump/1997/1104/sys/src/brazil/port/proc.c /n/emeliedump/1998/0325/sys/src/brazil/port/proc.c
43a
	"QueueingW",
.
## diffname port/proc.c 1998/0425
## diff -e /n/emeliedump/1998/0325/sys/src/brazil/port/proc.c /n/emeliedump/1998/0425/sys/src/brazil/port/proc.c
653a
		qunlock(&up->debug);
.
650a
		qlock(&up->debug);
.
## diffname port/proc.c 1998/0508
## diff -e /n/emeliedump/1998/0425/sys/src/brazil/port/proc.c /n/emeliedump/1998/0508/sys/src/brazil/port/proc.c
432a
			up->state = Running;
		}
.
431c
		if(r->p == up){
			/* undo the sleep1() */
			up->r = 0;
.
## diffname port/proc.c 1998/0510
## diff -e /n/emeliedump/1998/0508/sys/src/brazil/port/proc.c /n/emeliedump/1998/0510/sys/src/brazil/port/proc.c
415a
	splx(s);
.
## diffname port/proc.c 1998/0511
## diff -e /n/emeliedump/1998/0510/sys/src/brazil/port/proc.c /n/emeliedump/1998/0511/sys/src/brazil/port/proc.c
436c
			if(up->state == Wakeme)
				up->state = Running;
.
## diffname port/proc.c 1998/0512
## diff -e /n/emeliedump/1998/0511/sys/src/brazil/port/proc.c /n/emeliedump/1998/0512/sys/src/brazil/port/proc.c
722c

.
718c

.
714c
		if(p->pid == up->parentpid && p->state != Broken && p->nwait < 128) {
.
685c

.
554c
			panic("postnote: state %d %d %d", r->p != p, p->r != r, p->state);
.
510c
		if(p->state != Wakeme)
.
247c
	if(p == 0 || p->mach){
.
66c
			/*
.
## diffname port/proc.c 1998/0513
## diff -e /n/emeliedump/1998/0512/sys/src/brazil/port/proc.c /n/emeliedump/1998/0513/sys/src/brazil/port/proc.c
442a

	splx(s);
.
430,439d
409,427d
405,406c
	} else {
		/*
		 *  now we are committed to
		 *  change state and call scheduler
		 */
		up->state = Wakeme;
		up->r = r;

		/* statistics */
		m->cs++;
	
		procsave(up);
		if(setlabel(&up->sched)) {
			/*
			 *  here when the process is awakened
			 */
			procrestore(up);
			spllo();
		} else {
			/*
			 *  here to go to sleep (i.e. stop Running)
			 */
			unlock(&up->rlock);
			gotolabel(&m->sched);
		}
.
402,403c
	r->p = up;
	coherence();

	if((*f)(arg) || up->notepending){
		/*
		 *  if condition happened or a note is pending
		 *  never mind
		 */
		r->p = nil;
.
400c
	 * Wakeup only knows there may be something to do by testing
	 * r->p in order to get something to lock on.
	 * Flush that information out to memory in case the sleep is
	 * committed.
.
397,398d
395d
389a

.
385,388d
381c
sleep(Rendez *r, int (*f)(void*), void *arg)
.
## diffname port/proc.c 1998/0514
## diff -e /n/emeliedump/1998/0513/sys/src/brazil/port/proc.c /n/emeliedump/1998/0514/sys/src/brazil/port/proc.c
498c
	/*
	 *  this makes sure that the condition sleep checks
	 *  with its (*f)(void) is visible to it
	 */
	coherence();
.
394,397c
	 *  Wakeup only knows there may be something to do by testing
	 *  r->p in order to get something to lock on.
	 *  Flush that information out to memory in case the sleep is
	 *  committed.
.
379a

/*
 *  Sleep, postnote, and wakeup are complicated by the
 *  fact that they at least one of them must indirect
 *  through an unlocked structure to find the synchronizing
 *  lock structure.  This is because sleep()
 *  and wakeup() share direct knowledge only of r while
 *  sleep() and postnote() share knowledge only of p.  We've
 *  chosen to put the synchronization lock in p, i.e.,
 *  p->rlock.  Therefore the interaction between sleep()
 *  and postnote() is completely synchronized by keeping
 *  p->rlock locked in sleep until the process has
 *  saved all the information it needs to become dormant.
 *
 *  However, wakeup() can only find what process is sleeping
 *  by looking at r->p.  A wakeup looks like:
 *
 *	1) set condition that sleep checks with (*f)()
 *	2) is p = r->p non zero
 *	3) lock(p->rlock)
 *	4) check r->p == p
 *	5) ...
 *
 *  A sleep looks like
 *
 *	a) lock(p->rlock)
 *	b) r->p = up
 *	c) check condition
 *	d) ...
 *
 *  On a multiprocessor, two processors
 *  may not see writes occur in the same order.  The coherence()
 *  instruction ensures that a processor has flushed all its
 *  writes to memory so that those writes will be seen by other
 *  processors and that the processor will see all writes flushed
 *  by other processors.
 *
 *  To make the above sequence work on a multiprocessor, we need
 *  to put a coherence() call between (1) and (2) and between
 *  (b) and (c).  That way we're guaranteed that if (1) and
 *  (2) occur after (c), the wakeup process will know
 *  which process is about to sleep and will enter its
 *  critical section.  If it doesn't, the sleep could proceed
 *  while the waker returns without doing anything.
 *  Similarly, if (b) and (c) occur after (2),
 *  the sleeper needs coherence to see that the condition was
 *  set.  Otherwise it could sleep even though the wakeup
 *  had already decided there was nothing to do.
 *
 *	jmk & presotto
 */
.
84a
/*
 *  If changing this routine, look also at sleep().  It
 *  contains a copy of the guts of sched().
 */
.
## diffname port/proc.c 1998/0603
## diff -e /n/emeliedump/1998/0514/sys/src/brazil/port/proc.c /n/emeliedump/1998/0603/sys/src/brazil/port/proc.c
269c
		p->movetime = m->ticks + HZ/10;
.
## diffname port/proc.c 1998/0604
## diff -e /n/emeliedump/1998/0603/sys/src/brazil/port/proc.c /n/emeliedump/1998/0604/sys/src/brazil/port/proc.c
330d
160,163d
## diffname port/proc.c 1998/0605
## diff -e /n/emeliedump/1998/0604/sys/src/brazil/port/proc.c /n/emeliedump/1998/0605/sys/src/brazil/port/proc.c
815c
	/* Sched must not loop for these locks */
.
332a
	p->nlocks = 0;
.
68a
			 *	palloc
.
## diffname port/proc.c 1998/0606
## diff -e /n/emeliedump/1998/0605/sys/src/brazil/port/proc.c /n/emeliedump/1998/0606/sys/src/brazil/port/proc.c
896c
	print("%3d:%10s pc %8lux dbgpc %8lux  %8s (%s) ut %ld st %ld bss %lux pri %d\n",
.
334d
201c
		if((m->fairness++ & 3) == 0){
.
160a
	/* stick at low priority any process waiting for a lock */
	if(p->lockwait)
		pri = PriLock;

.
## diffname port/proc.c 1998/0724
## diff -e /n/emeliedump/1998/0606/sys/src/brazil/port/proc.c /n/emeliedump/1998/0724/sys/src/brazil/port/proc.c
387c
 *  fact that at least one of them must indirect
.
## diffname port/proc.c 1998/0725
## diff -e /n/emeliedump/1998/0724/sys/src/brazil/port/proc.c /n/emeliedump/1998/0725/sys/src/brazil/port/proc.c
923a
/*
 *  wait till all processes have flushed their mmu
 *  state about segement s
 */
void
procflushseg(Segment *s)
{
	int i, ns, nm, nwait;
	Proc *p;

	/*
	 *  tell all processes with this
	 *  segment to flush their mmu's
	 */
	nwait = 0;
	for(i=0; i<conf.nproc; i++) {
		p = &procalloc.arena[i];
		if(p->state == Dead)
			continue;
		for(ns = 0; ns < NSEG; ns++)
			if(p->seg[ns] == s){
				p->newtlb = 1;
				for(nm = 0; nm < conf.nmach; nm++){
					if(MACHP(nm)->proc == p){
						MACHP(nm)->flushmmu = 1;
						nwait++;
					}
				}
				break;
			}
	}

	if(nwait == 0)
		return;

	/*
	 *  wait for all processors to take a clock interrupt
	 *  and flush their mmu's
	 */
	for(nm = 0; nm < conf.nmach; nm++)
		if(MACHP(nm) != m)
			while(MACHP(nm)->flushmmu)
				sched();
}

.
## diffname port/proc.c 1998/0806
## diff -e /n/emeliedump/1998/0725/sys/src/brazil/port/proc.c /n/emeliedump/1998/0806/sys/src/brazil/port/proc.c
43a
	"QueueingR",
.
## diffname port/proc.c 1998/0825
## diff -e /n/emeliedump/1998/0806/sys/src/brazil/port/proc.c /n/emeliedump/1998/0825/sys/src/brazil/port/proc.c
1146c
	print("%lud: %s killed because no swap configured\n", kp->pid, kp->text);
.
981c
			print(" %lud(%lud, %lud)", p->pid, m->ticks - p->readytime,
.
979c
		print("rq%ld:", rq-runq);
.
912c
		print("up %lud\n", up->pid);
.
900c
	print("%3lud:%10s pc %8lux dbgpc %8lux  %8s (%s) ut %ld st %ld bss %lux pri %lud\n",
.
759c
			n = sprint(wq->w.msg, "%s %lud:", up->text, up->pid);
.
594c
		print("sending %s to kproc %lud %s\n", n, p->pid, p->text);
.
445c
		print("double sleep %lud %lud\n", r->p->pid, up->pid);
.
266c
		print("runproc %s %lud %s\n", p->text, p->pid, statename[p->state]);
.
## diffname port/proc.c 1998/0901
## diff -e /n/emeliedump/1998/0825/sys/src/brazil/port/proc.c /n/emeliedump/1998/0901/sys/src/brazil/port/proc.c
219,233d
212,216c
					if(p->mp == MACHP(m->machno)
					|| p->movetime < m->ticks)
.
210a
				if(p->readytime < rt){
					xrq = rq;
					rt = p->readytime;
				}
			}
			if(xrq != nil){
				rq = xrq;
				p = rq->head;
				if(p != nil)
					p->movetime = 0;
			}
		} else {
			/*
			 *  get highest priority process that this
			 *  processor can run given affinity constraints
			 */
			for(rq = &runq[Nrq-1]; rq >= runq; rq--){
				p = rq->head;
				if(p == 0)
					continue;
.
201,206c
		if((++(m->fairness) & 3) == 0){
			/*
			 *  once in a while, run process that's been waiting longest
			 *  regardless of movetime
			 */
			rt = 0xffffffff;
			xrq = nil;
.
191a
	ulong rt;
.
189,190c
	Schedq *rq, *xrq;
.
## diffname port/proc.c 1998/0923
## diff -e /n/emeliedump/1998/0901/sys/src/brazil/port/proc.c /n/emeliedump/1998/0923/sys/src/brazil/port/proc.c
221a
				goto found;
.
## diffname port/proc.c 1999/0108
## diff -e /n/emeliedump/1998/0923/sys/src/brazil/port/proc.c /n/emeliedump/1999/0108/sys/src/brazil/port/proc.c
805a
	qunlock(&up->seglock);
.
798a
	qlock(&up->seglock);
.
## diffname port/proc.c 1999/0110
## diff -e /n/emeliedump/1999/0108/sys/src/brazil/port/proc.c /n/emeliedump/1999/0110/sys/src/brazil/port/proc.c
908c
		p->time[0], p->time[1], bss, p->qpc);
.
906c
	print("%3lud:%10s pc %8lux dbgpc %8lux  %8s (%s) ut %ld st %ld bss %lux qpc %lux\n",
.
## diffname port/proc.c 1999/0326
## diff -e /n/emeliedump/1999/0110/sys/src/brazil/port/proc.c /n/emeliedump/1999/0326/sys/src/brazil/port/proc.c
180,181d
127,129c
	if(nrdy == 0)
		return 0;

	for(rq = &runq[Nrq-1]; rq > &runq[up->priority]; rq--)
		if(rq->head != nil)
			return 1;
	
	return 0;
.
125c
	Schedq *rq;
.
33d
## diffname port/proc.c 1999/0327
## diff -e /n/emeliedump/1999/0326/sys/src/brazil/port/proc.c /n/emeliedump/1999/0327/sys/src/brazil/port/proc.c
202a
		idlehands();
.
## diffname port/proc.c 1999/0711
## diff -e /n/emeliedump/1999/0327/sys/src/brazil/port/proc.c /n/emeliedump/1999/0711/sys/src/brazil/port/proc.c
360,369c
	if(bm < 0){
		/* pick a machine to wire to */
		memset(nwired, 0, sizeof(nwired));
		p->wired = 0;
		pp = proctab(0);
		for(i=0; i<conf.nproc; i++, pp++){
			wm = pp->wired;
			if(wm && pp->pid)
				nwired[wm->machno]++;
		}
		bm = 0;
		for(i=0; i<conf.nmach; i++)
			if(nwired[i] < nwired[bm])
				bm = i;
	} else {
		/* use the virtual machine requested */
		bm = bm % conf.nmach;
	}

.
358a
	Mach *wm;
.
357c
	int i;
.
354c
procwired(Proc *p, int bm)
.
223c
				if(p != nil && p->wired == nil)
.
## diffname port/proc.c 1999/0811
## diff -e /n/emeliedump/1999/0711/sys/src/brazil/port/proc.c /n/emeliedump/1999/0811/sys/src/brazil/port/proc.c
1001c
				MACHP(0)->ticks - p->movetime);
.
278c
		p->movetime = MACHP(0)->ticks + HZ/10;
.
252c
		if(p->mp == MACHP(m->machno) || p->movetime < MACHP(0)->ticks)
.
238c
					|| p->movetime < MACHP(0)->ticks)
.
204c
		if((++(m->fairness) & 0x3) == 0){
.
## diffname port/proc.c 2000/0115
## diff -e /n/emeliedump/1999/0811/sys/src/brazil/port/proc.c /n/emeliedump/2000/0115/sys/src/9/port/proc.c
530c
	// avoid overflows at the cost of precision
	if(ms >= 1000000)
		when = ms/(1000/HZ);
	else
		when = MS2TK(ms);
	when += MACHP(0)->ticks;
.
## diffname port/proc.c 2000/0116
## diff -e /n/emeliedump/2000/0115/sys/src/9/port/proc.c /n/emeliedump/2000/0116/sys/src/9/port/proc.c
530c
	/* avoid overflows at the cost of precision */
.
## diffname port/proc.c 2000/0129
## diff -e /n/emeliedump/2000/0116/sys/src/9/port/proc.c /n/emeliedump/2000/0129/sys/src/9/port/proc.c
564a
	poperror();
.
562a
	if(waserror()){
		up->twhen = 0;
		nexterror();
	}
.
## diffname port/proc.c 2000/0325
## diff -e /n/emeliedump/2000/0129/sys/src/9/port/proc.c /n/emeliedump/2000/0325/sys/src/9/port/proc.c
756a
	up->pgrp = nil;
.
755a
	up->dot = nil;
.
753a
		up->rgrp = nil;
	}
.
752c
		up->egrp = nil;
	}
	if(up->rgrp){
.
750c
	if(up->egrp){
.
## diffname port/proc.c 2000/0331
## diff -e /n/emeliedump/2000/0325/sys/src/9/port/proc.c /n/emeliedump/2000/0331/sys/src/9/port/proc.c
761,762c
	qunlock(&up->debug);

	if(fgrp)
		closefgrp(fgrp);
	if(egrp)
		closeegrp(egrp);
	if(rgrp)
		closergrp(rgrp);
	if(dot)
		cclose(dot);
	if(pgrp)
		closepgrp(pgrp);
.
743,759c
	/* nil out all the resources under lock (free later) */
	qlock(&up->debug);
	fgrp = up->fgrp;
	up->fgrp = nil;
	egrp = up->egrp;
	up->egrp = nil;
	rgrp = up->rgrp;
	up->rgrp = nil;
	pgrp = up->pgrp;
	up->pgrp = nil;
	dot = up->dot;
.
739a
	Egrp *egrp;
	Rgrp *rgrp;
	Pgrp *pgrp;
	Chan *dot;
.
## diffname port/proc.c 2000/0519
## diff -e /n/emeliedump/2000/0331/sys/src/9/port/proc.c /n/emeliedump/2000/0519/sys/src/9/port/proc.c
620,621c
//	if(p->kp)
//		print("sending %s to kproc %lud %s\n", n, p->pid, p->text);
.
## diffname port/proc.c 2000/0714
## diff -e /n/emeliedump/2000/0519/sys/src/9/port/proc.c /n/emeliedump/2000/0714/sys/src/9/port/proc.c
11c
struct Procalloc
.
## diffname port/proc.c 2000/0919
## diff -e /n/emeliedump/2000/0714/sys/src/9/port/proc.c /n/emeliedump/2000/0919/sys/src/9/port/proc.c
636,644c
	/* this loop is to avoid lock ordering problems. */
	for(;;){
		s = splhi();
		lock(&p->rlock);
		r = p->r;

		/* waiting for a wakeup? */
		if(r == nil)
			break;	/* no */

		/* try for the second lock */
		if(canlock(r)){
			if(p->state != Wakeme || r->p != p)
				panic("postnote: state %d %d %d", r->p != p, p->r != r, p->state);
			p->r = nil;
			r->p = nil;
			ready(p);
			unlock(r);
			break;
		}

		/* give other process time to get out of critical section and try again */
		unlock(&p->rlock);
		splx(s);
		sched();
.
620,622d
609a
/*
 *  if waking a sleeping process, this routine must hold both
 *  p->rlock and r->lock.  However, it can't know them in
 *  the same order as wakeup causing a possible lock ordering
 *  deadlock.  We break the deadlock by giving up the p->rlock
 *  lock if we can't get the r->lock and retrying.
 */
.
604c
	unlock(r);

.
601a
		unlock(&p->rlock);
.
599c
		r->p = nil;
		p->r = nil;
.
595,597c
	lock(r);
	p = r->p;

	if(p != nil){
		lock(&p->rlock);
		if(p->state != Wakeme || p->r != r)
.
593d
588,591d
581,586d
573c
 *  Expects that only one process can call wakeup for any given Rendez.
 *  We hold both locks to ensure that r->p and p->r remain consistent.
 *  Richard Miller has a better solution that doesn't require both to
 *  be held simultaneously, but I'm a paranoid - presotto.
.
504a
			unlock(r);
.
481a
		unlock(r);
.
473d
459a
	lock(r);
.
416,451c
 *  we lock both the process and the rendezvous to keep r->p
 *  and p->r synchronized.
.
404,414c
 *  sleep if a condition is not true.  Another process will
 *  awaken us after it sets the condition.  When we awaken
 *  the condition may no longer be true.
.
402d
## diffname port/proc.c 2000/1018
## diff -e /n/emeliedump/2000/0919/sys/src/9/port/proc.c /n/emeliedump/2000/1018/sys/src/9/port/proc.c
1058a
	p->newtlb = 1;
.
## diffname port/proc.c 2000/1026
## diff -e /n/emeliedump/2000/1018/sys/src/9/port/proc.c /n/emeliedump/2000/1026/sys/src/9/port/proc.c
330c
	p->fpstate = FPINIT;
.
## diffname port/proc.c 2000/1027
## diff -e /n/emeliedump/2000/1026/sys/src/9/port/proc.c /n/emeliedump/2000/1027/sys/src/9/port/proc.c
330c
	p->fpstate = FPinit;
.
## diffname port/proc.c 2000/1106
## diff -e /n/emeliedump/2000/1027/sys/src/9/port/proc.c /n/emeliedump/2000/1106/sys/src/9/port/proc.c
941c
		prflush();
.
## diffname port/proc.c 2000/1130
## diff -e /n/emeliedump/2000/1106/sys/src/9/port/proc.c /n/emeliedump/2000/1130/sys/src/9/port/proc.c
242a
		idlehands();
.
203d
## diffname port/proc.c 2001/0207
## diff -e /n/emeliedump/2000/1130/sys/src/9/port/proc.c /n/emeliedump/2001/0207/sys/src/9/port/proc.c
556c
		rv = p;
.
540,541c
	Proc *p, *rv;
	int s;
.
537c
Proc*
.
## diffname port/proc.c 2001/0217
## diff -e /n/emeliedump/2001/0207/sys/src/9/port/proc.c /n/emeliedump/2001/0217/sys/src/9/port/proc.c
1016c
	p->psstate = "kproc";
.
919c
		s = statename[p->state];
.
## diffname port/proc.c 2001/0315
## diff -e /n/emeliedump/2001/0217/sys/src/9/port/proc.c /n/emeliedump/2001/0315/sys/src/9/port/proc.c
162,168c
		/* stick at low priority any process waiting for a lock */
		if(p->lockwait)
			pri = PriLock;
	}
.
154,160c
		/* history counts */
		if(p->state == Running){
			p->rt++;
			pri = ((p->art + (p->rt<<1))>>2)/Squantum;
		} else {
			p->art = (p->art + (p->rt<<1))>>2;
			p->rt = 0;
			pri = p->art/Squantum;
		}
		pri = p->basepri - pri;
		if(pri < 0)
			pri = 0;
	
		/* the only intersection between the classes is at PriNormal */
		if(pri < PriNormal && p->basepri > PriNormal)
			pri = PriNormal;
.
149,152c
	if(p->fixedpri){
		pri = p->basepri;
.
## diffname port/proc.c 2001/0510
## diff -e /n/emeliedump/2001/0315/sys/src/9/port/proc.c /n/emeliedump/2001/0510/sys/src/9/port/proc.c
1214a
}

static void
pidhash(Proc *p)
{
	int h;

	h = p->pid % nelem(procalloc.ht);
	lock(&procalloc);
	p->pidhash = procalloc.ht[h];
	procalloc.ht[h] = p;
	unlock(&procalloc);
}

static void
pidunhash(Proc *p)
{
	int h;
	Proc **l;

	h = p->pid % nelem(procalloc.ht);
	lock(&procalloc);
	for(l = &procalloc.ht[h]; *l != nil; l = &(*l)->pidhash)
		if(*l == p){
			*l = p->pidhash;
			break;
		}
	unlock(&procalloc);
}

int
procindex(int pid)
{
	Proc *p;
	int h;
	int s;

	s = -1;
	h = pid % nelem(procalloc.ht);
	lock(&procalloc);
	for(p = procalloc.ht[h]; p != nil; p = p->pidhash)
		if(p->pid == pid){
			s = p - procalloc.arena;
			break;
		}
	unlock(&procalloc);
	return s;
.
827a
	pidunhash(up);
.
344a
	pidhash(p);
.
50a
static void pidhash(Proc*);
static void pidunhash(Proc*);

.
13a
	Proc*	ht[128];
.
## diffname port/proc.c 2001/0527
## diff -e /n/emeliedump/2001/0510/sys/src/9/port/proc.c /n/emeliedump/2001/0527/sys/src/9/port/proc.c
1252c
procindex(ulong pid)
.
1191,1192c
		if(p->user!=nil && strcmp(old, p->user)==0)
			kstrdup(&p->user, new);
.
1137c
	char buf[ERRMAX];
.
1124c
	strncpy(up->error, err, ERRMAX);
.
1057,1058d
1051c
	kstrdup(&p->user, eve);
	kstrdup(&p->text, name);
.
1026,1027c
	p->psstate = 0;
	p->procmode = 0640;
.
951d
787,788c
			strncpy(wq->w.msg+n, exitstr, sizeof wq->w.msg-n);
			wq->w.msg[sizeof wq->w.msg-1] = 0;
.
346a
	kstrdup(&p->user, "*nouser");
	kstrdup(&p->text, "*notext");
	kstrdup(&p->args, "");
	p->nargs = 0;
.
33,35d
31a
static Schedq	runq[Nrq];
.
19,24d
17c
} procalloc;
.
11c
static Ref	pidalloc;

static struct Procalloc
.
8c
int	nrdy;
.
## diffname port/proc.c 2001/0529
## diff -e /n/emeliedump/2001/0527/sys/src/9/port/proc.c /n/emeliedump/2001/0529/sys/src/9/port/proc.c
571c
	return p;
.
563d
550d
547c
	Proc *p;
.
## diffname port/proc.c 2001/0717
## diff -e /n/emeliedump/2001/0529/sys/src/9/port/proc.c /n/emeliedump/2001/0717/sys/src/9/port/proc.c
478c
		if(up->kp)
			print("attempt to interrupt %ld %s\n", up->pid, up->text);
		else
			error(Eintr);
.
## diffname port/proc.c 2001/0802
## diff -e /n/emeliedump/2001/0717/sys/src/9/port/proc.c /n/emeliedump/2001/0802/sys/src/9/port/proc.c
1056,1057d
326a
	p->parent = 0;
.
## diffname port/proc.c 2001/0819
## diff -e /n/emeliedump/2001/0802/sys/src/9/port/proc.c /n/emeliedump/2001/0819/sys/src/9/port/proc.c
903c
	cpid = wq->w.pid;
.
776,789c
		wq->w.pid = up->pid;
		wq->w.time[TUser] = utime = up->time[TUser] + up->time[TCUser];
		wq->w.time[TSys] = stime = up->time[TSys] + up->time[TCSys];
		wq->w.time[TReal] = TK2MS(MACHP(0)->ticks - up->time[TReal]);
		if(exitstr && exitstr[0])
			snprint(wq->w.msg, sizeof(wq->w.msg), "%s %lud: %s", up->text, up->pid, exitstr);
.
720d
## diffname port/proc.c 2001/0822
## diff -e /n/emeliedump/2001/0819/sys/src/9/port/proc.c /n/emeliedump/2001/0822/sys/src/9/port/proc.c
1111c
	kstrcpy(up->error, err, sizeof up->error);
.
341a
	p->syserror[0] = '\0';
.
## diffname port/proc.c 2001/0924
## diff -e /n/emeliedump/2001/0822/sys/src/9/port/proc.c /n/emeliedump/2001/0924/sys/src/9/port/proc.c
1112c
	kstrcpy(up->errstr, err, ERRMAX);
.
341,342c
	p->errstr = p->errbuf0;
	p->syserrstr = p->errbuf1;
	p->errbuf0[0] = '\0';
	p->errbuf1[0] = '\0';
.
## diffname port/proc.c 2001/1117
## diff -e /n/emeliedump/2001/0924/sys/src/9/port/proc.c /n/emeliedump/2001/1117/sys/src/9/port/proc.c
340a
	p->privatemem = 0;
.
## diffname port/proc.c 2001/1218
## diff -e /n/emeliedump/2001/1117/sys/src/9/port/proc.c /n/emeliedump/2001/1218/sys/src/9/port/proc.c
483,486c
		error(Eintr);
.
## diffname port/proc.c 2002/0114
## diff -e /n/emeliedump/2001/1218/sys/src/9/port/proc.c /n/emeliedump/2002/0114/sys/src/9/port/proc.c
405c
		panic("cannot allocate %lud procs\n", conf.nproc);
.
## diffname port/proc.c 2002/0228
## diff -e /n/emeliedump/2002/0114/sys/src/9/port/proc.c /n/emeliedump/2002/0228/sys/src/9/port/proc.c
159c
		pri = p->basepri - (pri/Squantum);
.
157d
155c
			p->art = (p->art + p->rt + 2)/2;
			pri = (p->art + p->rt)/2;
.
153c
			pri = (p->art + p->rt)/2;
.
136c
	Squantum = 1,
.
## diffname port/proc.c 2002/0315
## diff -e /n/emeliedump/2002/0228/sys/src/9/port/proc.c /n/emeliedump/2002/0315/sys/src/9/port/proc.c
1098a
		if (isedf(up))
			edf_block(up);
.
846a
	if (isedf(up))
		edf_bury(up);
.
679a
	if (isedf(up))
		edf_bury(up);
.
569d
475a

			// Behind unlock, we may call wakeup on ourselves.
			if (isedf(up))
				edf_block(up);

.
462c

.
358a
	p->task = nil;

.
281a

.
196a
	if ((p = edf_runproc()) != nil)
		return p;

.
162c

.
146a
	if(isedf(p)){
		edf_ready(p);
		splx(s);
		return;
	}
.
130c

.
116c
	return nrdy || edf_anyready();
.
79c
		up = nil;
.
63a

			if (isedf(up))
				edf_bury(up);

.
43a
	"Released",
.
31c
{	/* BUG: generate automatically */
.
21,27d
6a
#include	"../port/edf.h"
.
## diffname port/proc.c 2002/0326
## diff -e /n/emeliedump/2002/0315/sys/src/9/port/proc.c /n/emeliedump/2002/0326/sys/src/9/port/proc.c
516,521c
	when = ms2tk(ms) + MACHP(0)->ticks;
.
509a
ulong
ms2tk(ulong ms)
{
	/* avoid overflows at the cost of precision */
	if(ms >= 1000000000/HZ)
		return (ms/1000)*HZ;
	return (ms+500)*HZ/1000;
}

.
## diffname port/proc.c 2002/0328
## diff -e /n/emeliedump/2002/0326/sys/src/9/port/proc.c /n/emeliedump/2002/0328/sys/src/9/port/proc.c
349a
	p->lockwait = nil;
.
## diffname port/proc.c 2002/0329
## diff -e /n/emeliedump/2002/0328/sys/src/9/port/proc.c /n/emeliedump/2002/0329/sys/src/9/port/proc.c
517c
	return (ms*HZ+500)/1000;
.
## diffname port/proc.c 2002/0402
## diff -e /n/emeliedump/2002/0329/sys/src/9/port/proc.c /n/emeliedump/2002/0402/sys/src/9/port/proc.c
1122,1123d
868,869d
699,700d
489,490d
201,203d
146,150d
115c
	return nrdy;
.
60,62d
7d
## diffname port/proc.c 2002/0403
## diff -e /n/emeliedump/2002/0402/sys/src/9/port/proc.c /n/emeliedump/2002/0403/sys/src/9/port/proc.c
93c
		if(setlabel(&up->sched)){
.
86c
	if(up){
		if(up->state == Running && up->nlocks){
			up->delaysched++;
			delayedscheds++;
			return;
		}

.
10a
long	delayedscheds;	/* statistics */

.
## diffname port/proc.c 2002/0404
## diff -e /n/emeliedump/2002/0403/sys/src/9/port/proc.c /n/emeliedump/2002/0404/sys/src/9/port/proc.c
1111a
		if (isedf(up))
			edf_block(up);
.
937c
		p->time[0], p->time[1], bss, p->qpc, p->nlocks, p->delaysched, p->lastlock ? p->lastlock->pc : 0);
.
935c
	print("%3lud:%10s pc %8lux dbgpc %8lux  %8s (%s) ut %ld st %ld bss %lux qpc %lux nl %lud nd %lud lpc %lux\n",
.
859a
	if (isedf(up))
		edf_bury(up);
.
692a
	if (isedf(up))
		edf_bury(up);
.
485a
			if (isedf(up))
				edf_block(up);

.
483d
435a
	if (up->nlocks)
		print("process %lud sleeps with %lud locks held, last lock 0x%p locked at pc 0x%lux\n",
			up->pid, up->nlocks, up->lastlock, up->lastlock->pc);
.
350a
	p->nlocks = 0;
	p->delaysched = 0;
.
199a
	if ((p = edf_runproc()) != nil)
		return p;

.
149a
	if(isedf(p)){
		edf_ready(p);
		splx(s);
		return;
	}
.
148a
#ifdef RSC
le('r',p);
#endif
.
119c
	return nrdy || edf_anyready();
.
108a
#ifdef RSC
le('u',up);
#endif
.
75a
#ifdef RSC
le('e', up);
#endif
.
59a
			if (isedf(up))
				edf_bury(up);
.
44a
/*DEBUGGING: scheduling event log */
#ifdef RSC
static ulong *lg;
enum {Nlg = 1024*1024};
static ulong wp, rp;
static void
le(int c, Proc *p)
{
	if(lg==nil)
		lg = malloc(Nlg*sizeof(lg[0]));
	lg[wp++&(Nlg-1)] = MACHP(0)->ticks;
	lg[wp++&(Nlg-1)] = c;
	lg[wp++&(Nlg-1)] = (ulong)p;
}
void
dumpschedlog(void)
{
	int i;

	i=0;
	iprint("%lux=>%lux\n", rp, wp);
	while((rp&(Nlg-1))!=(wp&(Nlg-1))){
		iprint("%lux ", lg[rp++&(Nlg-1)]);
		if(++i%8==0)
			iprint("\n");
	}
	if(i%8)
		iprint("\n");	
}
#endif

.
6a
#include	"../port/edf.h"
.
## diffname port/proc.c 2002/0406
## diff -e /n/emeliedump/2002/0404/sys/src/9/port/proc.c /n/emeliedump/2002/0406/sys/src/9/port/proc.c
146,148d
110,112d
## diffname port/proc.c 2002/0410
## diff -e /n/emeliedump/2002/0406/sys/src/9/port/proc.c /n/emeliedump/2002/0410/sys/src/9/port/proc.c
1169c
			edfblock(up);
.
915c
		edfbury(up);
.
746c
		edfbury(up);
.
536c
				edfblock(up);
.
242c
	if ((p = edfrunproc()) != nil)
.
188c
		edfready(p);
.
183,185d
153c
	return nrdy || edfanyready();
.
93c
				edfbury(up);
.
46,76d
7d
## diffname port/proc.c 2002/0413
## diff -e /n/emeliedump/2002/0410/sys/src/9/port/proc.c /n/emeliedump/2002/0413/sys/src/9/port/proc.c
1148a
	setlabel(&up->errlab[NERR-1]);
.
## diffname port/proc.c 2002/0414
## diff -e /n/emeliedump/2002/0413/sys/src/9/port/proc.c /n/emeliedump/2002/0414/sys/src/9/port/proc.c
92d
## diffname port/proc.c 2002/0415
## diff -e /n/emeliedump/2002/0414/sys/src/9/port/proc.c /n/emeliedump/2002/0415/sys/src/9/port/proc.c
361a
	p->movetime = 0;
.
266c
		if(p->mp == MACHP(m->machno) || p->movetime <= MACHP(0)->ticks)
.
## diffname port/proc.c 2002/0416
## diff -e /n/emeliedump/2002/0415/sys/src/9/port/proc.c /n/emeliedump/2002/0416/sys/src/9/port/proc.c
91a
			up->delaysched = 1;
.
## diffname port/proc.c 2002/0420
## diff -e /n/emeliedump/2002/0416/sys/src/9/port/proc.c /n/emeliedump/2002/0420/sys/src/9/port/proc.c
91,93c
		if(up->nlocks && up->state != Moribund){
 			delayedscheds++;
.
89a
	if(m->ilockdepth)
		panic("ilockdepth %d", m->ilockdepth);

.
## diffname port/proc.c 2002/0501
## diff -e /n/emeliedump/2002/0420/sys/src/9/port/proc.c /n/emeliedump/2002/0501/sys/src/9/port/proc.c
812,813c
		utime = up->time[TUser] + up->time[TCUser];
		stime = up->time[TSys] + up->time[TCSys];
		wq->w.time[TUser] = TK2MS(utime);
		wq->w.time[TSys] = TK2MS(stime);
.
## diffname port/proc.c 2002/0502
## diff -e /n/emeliedump/2002/0501/sys/src/9/port/proc.c /n/emeliedump/2002/0502/sys/src/9/port/proc.c
1058a
	p->noswap = 1;
.
357a
	p->noswap = 0;
.
## diffname port/proc.c 2002/0506
## diff -e /n/emeliedump/2002/0502/sys/src/9/port/proc.c /n/emeliedump/2002/0506/sys/src/9/port/proc.c
1196c
		if(l > max && strcmp(p->text, "kfs") != 0){
.
## diffname port/proc.c 2002/0626
## diff -e /n/emeliedump/2002/0506/sys/src/9/port/proc.c /n/emeliedump/2002/0626/sys/src/9/port/proc.c
91c
		panic("ilockdepth %d, last lock 0x%p at 0x%lux",
			m->ilockdepth, up?up->lastilock:nil,
			(up && up->lastilock)?up->lastilock->pc:0);
.
## diffname port/proc.c 2002/0704
## diff -e /n/emeliedump/2002/0626/sys/src/9/port/proc.c /n/emeliedump/2002/0704/sys/src/9/port/proc.c
1142,1143c
		if (edf->isedf(up))
			edf->edfblock(up);
.
887,888c
	if (edf->isedf(up))
		edf->edfbury(up);
.
716,717c
	if (edf->isedf(up))
		edf->edfbury(up);
.
506,507c
			if (edf->isedf(up))
				edf->edfblock(up);
.
211c
	if ((p = edf->edfrunproc()) != nil)
.
156,157c
	if(edf->isedf(p)){
		edf->edfready(p);
.
125c
	return nrdy || edf->edfanyready();
.
60,61c
			if (edf->isedf(up))
				edf->edfbury(up);
.
24a
extern Edfinterface	nulledf;

Edfinterface *edf = &nulledf;

.
## diffname port/proc.c 2002/0710
## diff -e /n/emeliedump/2002/0704/sys/src/9/port/proc.c /n/emeliedump/2002/0710/sys/src/9/port/proc.c
821,823c
		wq->w.time[TUser] = tk2ms(utime);
		wq->w.time[TSys] = tk2ms(stime);
		wq->w.time[TReal] = tk2ms(MACHP(0)->ticks - up->time[TReal]);
.
532,540d
## diffname port/proc.c 2002/0821
## diff -e /n/emeliedump/2002/0710/sys/src/9/port/proc.c /n/emeliedump/2002/0821/sys/src/9/port/proc.c
1249a

	/* calculate decaying duty cycle average */
	m->avginidle = (m->avginidle*(HZ-1)+m->inidle)/HZ;
	m->inidle = 0;
.
1247d
1231,1232c
	ulong n;
	static ulong nrun;
.
303a
	if(start)
		m->inidle += fastticks(nil)-start;
.
264a
		if(start == 0)
			start = fastticks(nil);
.
214a
	start = 0;

.
213a
	uvlong start;
.
## diffname port/proc.c 2002/0822
## diff -e /n/emeliedump/2002/0821/sys/src/9/port/proc.c /n/emeliedump/2002/0822/sys/src/9/port/proc.c
1256,1259d
1246a
	/* calculate decaying duty cycles */
	n = perfticks();
	per = n - m->perf.last;
	m->perf.last = n;
	if(per == 0)
		per = 1;
	m->perf.period = (m->perf.period*(HZ-1)+per)/HZ;

	m->perf.avg_inidle = (m->perf.avg_inidle*(HZ-1)+m->perf.inidle)/HZ;
	m->perf.inidle = 0;

	m->perf.avg_inintr = (m->perf.avg_inintr*(HZ-1)+m->perf.inintr)/HZ;
	m->perf.inintr = 0;

.
1238c
	ulong n, per;
.
309,310d
270a
		now = perfticks();
		m->perf.inidle += now-start;
		start = now;
.
268,269c

		/* remember how much time we're here */
.
216c
	start = perfticks();
.
214c
	ulong start, now;
.
## diffname port/proc.c 2002/0925
## diff -e /n/emeliedump/2002/0822/sys/src/9/port/proc.c /n/emeliedump/2002/0925/sys/src/9/port/proc.c
97c
			(up && up->lastilock)?up->lastilock->pc:0, getcallerpc(x+3));
.
95c
		panic("ilockdepth %d, last lock 0x%p at 0x%lux, sched called from 0x%lux",
.
93a
	int x[1];

.
## diffname port/proc.c 2002/1010
## diff -e /n/emeliedump/2002/0925/sys/src/9/port/proc.c /n/emeliedump/2002/1010/sys/src/9/port/proc.c
1254,1256c
	per = (m->perf.period*(HZ-1) + per)/HZ;
	if(per != 0)
		m->perf.period = per;
.
## diffname port/proc.c 2002/1104
## diff -e /n/emeliedump/2002/1010/sys/src/9/port/proc.c /n/emeliedump/2002/1104/sys/src/9/port/proc.c
386a
	p->setargs = 0;
.
## diffname port/proc.c 2003/0214
## diff -e /n/emeliedump/2002/1104/sys/src/9/port/proc.c /n/emeliedump/2003/0214/sys/src/9/port/proc.c
231c
		if(!unfair && (++(m->fairness) & 0x3) == 0){
.
11a
int unfair;			/* unfair scheduling */
.
## diffname port/proc.c 2003/0226
## diff -e /n/emeliedump/2003/0214/sys/src/9/port/proc.c /n/emeliedump/2003/0226/sys/src/9/port/proc.c
232c
		if((++(m->fairness) & 0x3) == 0){
.
12d
## diffname port/proc.c 2003/0228
## diff -e /n/emeliedump/2003/0226/sys/src/9/port/proc.c /n/emeliedump/2003/0228/sys/src/9/port/proc.c
1086,1087c
	procpriority(p, PriKproc, 0);
.
1050,1051c
			print(" %lud(%lud)", p->pid, m->ticks - p->readytime);
.
972c
		p->time[0], p->time[1], bss, p->qpc, p->nlocks, p->delaysched, p->lastlock ? p->lastlock->pc : 0, p->priority);
.
970c
	print("%3lud:%10s pc %8lux dbgpc %8lux  %8s (%s) ut %ld st %ld bss %lux qpc %lux nl %lud nd %lud lpc %lux pri %lud\n",
.
437a
procpriority(Proc *p, int pri, int fixed)
{
	if(pri >= Nrq)
		pri = Nrq - 1;
	else if(pri < 0)
		pri = 0;
	p->basepri = pri;
	p->priority = pri;
	if(fixed){
		p->quanta = 0xfffff;
		p->fixedpri = 1;
	} else {
		p->quanta = quanta[pri];
		p->fixedpri = 0;
	}
}

void
.
433d
396a
	/* sched params */
	p->mp = 0;
	p->wired = 0;
	procpriority(p, PriNormal, 0);

.
382d
375d
369,371d
310,311d
302a
	if(rq->head == nil)
		runvec &= ~(1<<(rq-runq));
.
285c
		if(p->mp == MACHP(m->machno) || (!p->wired && i > 0))
.
272a

		/* remember how much time we're here */
.
271d
247,268d
230,245c
	for(i = 0;; i++){
		/*
		 *  get highest priority process that this
		 *  processor can run given affinity constraints
		 */
		for(rq = &runq[Nrq-1]; rq >= runq; rq--){
			p = rq->head;
			if(p == 0)
				continue;
			for(; p; p = p->rnext){
				if(p->mp == MACHP(m->machno) || (!p->wired && i > 0))
					goto found;
.
227c
	 *  or one that hasn't moved in a while (load balancing).  Every
	 *  time around the loop affinity goes down.
.
224d
216a
	int i;
.
215d
213c
	Schedq *rq;
.
203a
	runvec |= 1<<pri;
.
193,194d
191a
	rq = &runq[pri];
.
179,189c
		p->quanta = quanta[pri];
.
170,177c
		if(p->quanta > quanta[pri]/2){
			/* blocked before using half its quanta, go up */
			if(++pri > p->basepri)
				pri = p->basepri;
.
168a
		p->quanta = HZ;
	} else if(p->state == Running){
		if(p->quanta <= 0){
			/* degrade priority of anyone that used their whole quanta */

			/* processes > PriNormal and those below don't mix */
			if(p->basepri > PriNormal){
				if(pri > PriNormal)
					pri--;
			} else {
				if(pri > 0)
					pri--;
			}
			p->quanta = quanta[pri];
		}
.
166a

	pri = p->priority;

.
151,152c
	if(up && up->state == Running)
	if(up->preempted == 0)
	if(anyhigher())
	if(!active.exiting){
		up->preempted = 1;
		sched();
		splhi();
		up->preempted = 0;
		return 1;
	}
	return 0;
}
.
149c
/*
 *  here at the end of non-clock interrupts to see if we should preempt the
 *  current process.  Returns 1 if preempted, 0 otherwise.
 */
int
preempted(void)
.
146c
	/* don't bother unless someone is elegible */
	if(anyhigher() || (!up->fixedpri && anyready())){
		sched();
		splhi();
	}
.
142,144c
	/* edf scheduler always gets first chance */
	if(edf->isedf(up))
		return;
.
139,140c
/*
 *  here once per clock tick to see if we should resched
 */
void
hzsched(void)
{
	/* another cycle, another quantum */
	up->quanta--;
.
137c
	return runvec & ~((1<<(up->priority+1))-1);
}
.
131c
	return runvec || edf->edfanyready();
.
23a
static ulong	runvec;
static int	quanta[Nrq] =
{
	Q+19*DQ, Q+18*DQ, Q+17*DQ, Q+16*DQ,
	Q+15*DQ, Q+14*DQ, Q+13*DQ, Q+12*DQ,
	Q+11*DQ, Q+10*DQ, Q+ 9*DQ, Q+ 8*DQ,
	Q+ 7*DQ, Q+ 6*DQ, Q+ 5*DQ, Q+ 4*DQ,
	Q+ 3*DQ, Q+ 2*DQ, Q+ 1*DQ, Q+ 0*DQ,
};
.
22a
enum
{
	Q=(HZ/20)*4,
	DQ=((HZ-Q)/40)*2,
};

.
## diffname port/proc.c 2003/0301
## diff -e /n/emeliedump/2003/0228/sys/src/9/port/proc.c /n/emeliedump/2003/0301/sys/src/9/port/proc.c
305c
		if(p == tp)
.
302a
	/*
	 *  the queue may have changed before we locked runq,
	 *  refind the target process.
	 */
.
289a
		/* waste time or halt the CPU */
.
284,285c
			for(; tp; tp = tp->rnext){
				if(tp->mp == nil || tp->mp == MACHP(m->machno)
				|| (!tp->wired && i > 0))
.
281,282c
			tp = rq->head;
			if(tp == 0)
.
277c
		 *  find the highest priority target process that this
.
259c
	Proc *p, *l, *tp;
.
217,225c
			if(pri > 0)
				pri--;
.
194a
/*
 *  ready(p) picks a new priority for a process and sticks it in the
 *  runq for that priority.
 *
 *  - fixed priority processes never move
 *  - a process that uses all its quanta before blocking goes down a
 *    priority level
 *  - a process that uses less than half its quanta before blocking
 *    goes up a priority level
 *  - a process that blocks after using up half or more of it's quanta
 *    stays at the same level
 *
 *  new quanta are assigned each time a process blocks or changes level
 */
.
## diffname port/proc.c 2003/0314
## diff -e /n/emeliedump/2003/0301/sys/src/9/port/proc.c /n/emeliedump/2003/0314/sys/src/9/port/proc.c
288,291c
			for(tp = rq->head; tp; tp = tp->rnext){
				if(tp->yield){
					tp->yield = 0;
					continue;
				}	
.
285c
		 *  processor can run given affinity constraints.
		 *
.
261a
/*
 *  yield the processor to any other runnable process
 */
void
yield(void)
{
	if(anyready()){
		up->yield = 1;
		sched();
	}
}

/*
 *  pick a process to run
 */
.
## diffname port/proc.c 2003/0316
## diff -e /n/emeliedump/2003/0314/sys/src/9/port/proc.c /n/emeliedump/2003/0316/sys/src/9/port/proc.c
328,359d
326c
	p = dequeueproc(rq, p);
	if(p == nil)
.
304,310c
			for(p = rq->head; p; p = p->rnext){
				if(p->mp == nil || p->mp == MACHP(m->machno)
				|| (!p->wired && i > 0))
.
289a
	if(m->fairness++ == 10){
		m->fairness = 0;
		rebalance();
	}

.
281c
	Proc *p;
.
274a
 *  move up any process waiting more than its quanta
 */
static void
rebalance(void)
{
	Schedq *rq;
	Proc *p;

	for(rq = runq; rq < &runq[Nrq]; rq++){
		p = rq->head;
		if(p == nil)
			continue;
		if(p->mp != MACHP(m->machno))
			continue;
		if(p->priority == p->basepri)
			continue;
		if(m->ticks - p->readytime < quanta[p->priority]/4)
			continue;
		splhi();
		p = dequeueproc(rq, p);
		spllo();
		if(p == nil)
			continue;
		p->quanta = quanta[p->priority];	/* act like we used none */
		ready(p);
	}
}

/*
.
269c
		up->quanta = 0;	/* act like you used them all up */
.
264a
static Proc*
dequeueproc(Schedq *rq, Proc *tp)
{
	Proc *l, *p;

	if(!canlock(runq))
		return nil;

	/*
	 *  the queue may have changed before we locked runq,
	 *  refind the target process.
	 */
	l = 0;
	for(p = rq->head; p; p = p->rnext){
		if(p == tp)
			break;
		l = p;
	}

	/*
	 *  p->mach==0 only when process state is saved
	 */
	if(p == 0 || p->mach){
		unlock(runq);
		return nil;
	}
	if(p->rnext == 0)
		rq->tail = l;
	if(l)
		l->rnext = p->rnext;
	else
		rq->head = p->rnext;
	if(rq->head == nil)
		runvec &= ~(1<<(rq-runq));
	rq->n--;
	nrdy--;
	if(p->state != Ready)
		print("dequeueproc %s %lud %s\n", p->text, p->pid, statename[p->state]);

	unlock(runq);
	return p;
}

/*
 *  yield the processor and drop our priority
 */
.
263c
 *  remove a process from a scheduling queue (called splhi)
.
## diffname port/proc.c 2003/0319
## diff -e /n/emeliedump/2003/0316/sys/src/9/port/proc.c /n/emeliedump/2003/0319/sys/src/9/port/proc.c
364a
	/* 10 is completely arbitrary - it interacts with the comparison in rebalance */
	/* presotto */
.
336a

		/* this comparison is too arbitrary - need a better one */
		/* presotto */
.
## diffname port/proc.c 2003/0406
## diff -e /n/emeliedump/2003/0319/sys/src/9/port/proc.c /n/emeliedump/2003/0406/sys/src/9/port/proc.c
1263c
		if(edf->isedf(up))
.
1010c
	if(edf->isedf(up))
.
839c
	if(edf->isedf(up))
.
638c
			if(edf->isedf(up))
.
636d
586c
	if(up->nlocks)
.
365c
	if((p = edf->edfrunproc()) != nil)
.
79c
			if(edf->isedf(up))
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].