~kris/9p

9hist

9f9c4529f0dd1f46f100c09b8f0e6e205f649508 — David du Colombier 31 years ago da643d4
Plan 9 from Bell Labs 1995-01-04
9 files changed, 87 insertions(+), 93 deletions(-)

M carrera/clock.c
M carrera/trap.c
M pc/clock.c
M port/devcons.c
M port/portfns.h
M port/proc.c
M port/qio.c
M port/qlock.c
M power/clock.c
M carrera/clock.c => carrera/clock.c +1 -22
@@ 47,34 47,13 @@ clockinit(void)
void
clock(Ureg *ur)
{
	Proc *p;
	int i, nrun;

	wrcompare(rdcount()+(m->speed*1000000)/HZ);

	m->ticks++;
	if(m->proc)
		m->proc->pc = ur->pc;

	nrun = 0;
	if(m->machno == 0) {
		p = m->proc;
		if(p) {
			nrun++;
			p->time[p->insyscall]++;
		}
		for(i=1; i<conf.nmach; i++) {
			if(active.machs & (1<<i)) {
				p = MACHP(i)->proc;
				if(p) {
					p->time[p->insyscall]++;
					nrun++;
				}
			}
		}
		nrun = (nrdy+nrun)*1000;
		m->load = (m->load*19+nrun)/20;
	}
	accounttime();

	ifjab();


M carrera/trap.c => carrera/trap.c +1 -1
@@ 600,8 600,8 @@ noted(Ureg **urp, ulong arg0)
			qunlock(&up->debug);
			pexit("Suicide", 0);
		}
		splhi();
		qunlock(&up->debug);
		splhi();
		rfnote(urp);
		break;


M pc/clock.c => pc/clock.c +1 -16
@@ 35,30 35,15 @@ static int cpuidax, cpuiddx;
static void
clock(Ureg *ur, void *arg)
{
	Proc *p;
	int nrun = 0;

	USED(arg);

	m->ticks++;

	accounttime();
	checkalarms();
	hardclock();
	uartclock();

	/*
	 *  process time accounting
	 */
	p = m->proc;
	if(p){
		nrun = 1;
		p->pc = ur->pc;
		if (p->state==Running)
			p->time[p->insyscall]++;
	}
	nrun = (nrdy+nrun)*1000;
	MACHP(0)->load = (MACHP(0)->load*19+nrun)/20;

	if(up && up->state == Running){
		if(anyready())
			sched();

M port/devcons.c => port/devcons.c +0 -19
@@ 11,7 11,6 @@ Queue	*mouseq;
Queue	*kbdq;		/* unprocessed console input */
Queue	*lineq;		/* processed console input */
Queue	*printq;	/* console output */
Queue	*klogq;

static struct
{


@@ 33,8 32,6 @@ char	sysname[NAMELEN];
void
printinit(void)
{
	klogq = qopen(32*1024, 0, 0, 0);
	qnoblock(klogq, 1);
	lineq = qopen(2*1024, 0, 0, 0);
	qnoblock(lineq, 1);
}


@@ 127,17 124,6 @@ fprint(int fd, char *fmt, ...)	/* needed so we can use user-level libg */
	return n;
}

int
kprint(char *fmt, ...)
{
	char buf[PRINTSIZE];
	int n;

	n = doprint(buf, buf+sizeof(buf), fmt, (&fmt+1)) - buf;
	qwrite(klogq, buf, n);
	return n;
}

void
panic(char *fmt, ...)
{


@@ 327,7 313,6 @@ enum{
	Qkey,
	Qhostdomain,
	Qhostowner,
	Qklog,
	Qlights,
	Qmsec,
	Qnoise,


@@ 354,7 339,6 @@ Dirtab consdir[]={
	"hostowner",	{Qhostowner},	NAMELEN,	0664,
	"hz",		{Qhz},		NUMSIZE,	0666,
	"key",		{Qkey},		DESKEYLEN,	0622,
	"klog",		{Qklog},	0,		0444,
	"lights",	{Qlights},	0,		0220,
	"msec",		{Qmsec},	NUMSIZE,	0444,
	"noise",	{Qnoise},	0,		0220,


@@ 604,9 588,6 @@ consread(Chan *c, void *buf, long n, ulong offset)
	case Qnull:
		return 0;

	case Qklog:
		return qread(klogq, buf, n);

	case Qmsec:
		return readnum(offset, buf, n, TK2MS(MACHP(0)->ticks), NUMSIZE);


M port/portfns.h => port/portfns.h +1 -0
@@ 1,3 1,4 @@
void		accounttime(void);
void		addrootfile(char*, uchar*, ulong);
void		alarmkproc(void*);
Block*		allocb(int);

M port/proc.c => port/proc.c +74 -15
@@ 31,6 31,7 @@ typedef struct

int	nrdy;
Schedq	runq;
int	priconst[NiceMax];

char *statename[] =
{			/* BUG: generate automatically */


@@ 60,7 61,6 @@ schedinit(void)		/* never returns */
			ready(up);
			break;
		case Moribund:
			up->pid = 0;
			up->state = Dead;
			/* 
			 * Holding locks from pexit:


@@ 70,9 70,6 @@ schedinit(void)		/* never returns */

			up->qnext = procalloc.free;
			procalloc.free = up;
		
			unlock(&palloc);
			qunlock(&up->debug);
			unlock(&procalloc);
			break;
		}


@@ 300,7 297,6 @@ procwired(Proc *p)
		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


@@ 316,6 312,14 @@ procinit0(void)		/* bad planning - clashes with devproc.c */
	for(i=0; i<conf.nproc-1; i++,p++)
		p->qnext = p+1;
	p->qnext = 0;

	/*
	 * 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);
}

void


@@ 468,7 472,8 @@ postnote(Proc *p, int dolock, char *n, int flag)
	if(dolock)
		qunlock(&p->debug);

	if(r = p->r) {
	r = p->r;
	if(r != 0) {
		for(;;) {
			s = splhi();
			if(canlock(r))


@@ 649,9 654,12 @@ pexit(char *exitstr, int freemem)
		addbroken(up);

	es = &up->seg[NSEG];
	for(s = up->seg; s < es; s++)
		if(*s)
	for(s = up->seg; s < es; s++) {
		if(*s) {
			putseg(*s);
			*s = 0;
		}
	}

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


@@ 662,18 670,16 @@ pexit(char *exitstr, int freemem)
		free(f);
	}

	/*
	 * sched() cannot wait on these locks
	 */
	qlock(&up->debug);
	/* release debuggers */
	qlock(&up->debug);
	if(up->pdbg) {
		wakeup(&up->pdbg->sleep);
		up->pdbg = 0;
	}
	qunlock(&up->debug);

	/* Sched must not loop for this lock */
	lock(&procalloc);
	lock(&palloc);

	up->state = Moribund;
	sched();


@@ 898,7 904,7 @@ killbig(void)
		l = 0;
		for(i=1; i<NSEG; i++) {
			s = p->seg[i];
			if(s)
			if(s != 0)
				l += s->top - s->base;
		}
		if(l > max) {


@@ 906,8 912,15 @@ killbig(void)
			max = l;
		}
	}
	print("%d: %s killed because no swap configured\n", kp->pid, kp->text);
	kp->procctl = Proc_exitme;
	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);
	postnote(kp, 1, "killed: proc too big", NExit);
}



@@ 925,3 938,49 @@ renameuser(char *old, char *new)
		if(strcmp(old, p->user) == 0)
			memmove(p->user, new, NAMELEN);
}

/*
 *  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;
			}
	}
}

M port/qio.c => port/qio.c +3 -0
@@ 520,6 520,9 @@ qwrite(Queue *q, void *vp, int len)

	dowakeup = 0;

	if((getstatus()&IE) == 0)
		print("qwrite hi %lux\n", getcallerpc(q));

	if(waserror()){
		qunlock(&q->wlock);
		nexterror();

M port/qlock.c => port/qlock.c +4 -0
@@ 10,6 10,8 @@ qlock(QLock *q)
{
	Proc *p, *mp;

	if((getstatus()&IE)==0)
		print("qlock hi %lux\n", getcallerpc(q));
	lock(&q->use);
	if(!q->locked) {
		q->locked = 1;


@@ 48,6 50,8 @@ qunlock(QLock *q)
{
	Proc *p;

	if((getstatus()&IE)==0)
		print("qunlock hi %lux\n", getcallerpc(q));
	lock(&q->use);
	p = q->head;
	if(p) {

M power/clock.c => power/clock.c +2 -20
@@ 71,8 71,7 @@ clockinit(void)
void
clock(Ureg *ur)
{
	Proc *p;
	int i, nrun;
	int i;

	if((ur->cause&INTR2) == 0) {
		if(ur->cause & INTR4) {


@@ 89,24 88,7 @@ clock(Ureg *ur)
	if(m->proc)
		m->proc->pc = ur->pc;

	if(m->machno == 0) {
		p = m->proc;
		if(p) {
			nrun++;
			p->time[p->insyscall]++;
		}
		for(i=1; i<conf.nmach; i++) {
			if(active.machs & (1<<i)) {
				p = MACHP(i)->proc;
				if(p) {
					p->time[p->insyscall]++;
					nrun++;
				}
			}
		}
		nrun = (nrdy+nrun)*1000;
		m->load = (m->load*19+nrun)/20;
	}
	accounttime();
	duartslave();
	if((active.machs&(1<<m->machno)) == 0)
		return;