~kris/9p

9hist

2a898c74fd025a804879fbb782ea10adb0c08d69 — David du Colombier 36 years ago e4edfca
Plan 9 from Bell Labs 1990-07-28
M gnot/clock.c => gnot/clock.c +16 -8
@@ 87,13 87,15 @@ delay(int ms)
		;
}

#define NA 10
void
clock(Ureg *ur)
{
	int i;
	int i, n;
	Alarm *a;
	void (*f)(void*);
	Proc *p;
	Alarm *alist[NA];

	SYNCREG[1] = 0x5F;	/* clear interrupt */
	m->ticks++;


@@ 106,16 108,22 @@ clock(Ureg *ur)
		if(m->alarm){
			a = m->alarm;
			a->dt--;
			while(a && a->dt<=0){
				f = a->f;	/* avoid race with cancel */
				if(f)
					(*f)(a);
			for(n = 0; a && a->dt<=0 && n<NA; n++){
				alist[n] = a;
				delete(&m->alarm, 0, a);
				a->busy = 0;
				a = m->alarm;
			}
		}
		unlock(&m->alarmlock);
			unlock(&m->alarmlock);

			/*  execute alarm functions outside the lock */
			for(i = 0; i < n; i++){
				f = alist[i]->f;	/* avoid race with cancel */
				if(f)
					(*f)(alist[i]);
				alist[i]->busy = 0;
			}
		} else
			unlock(&m->alarmlock);
	}
	kbdclock();
	mouseclock();

M gnot/devdk.c => gnot/devdk.c +11 -5
@@ 456,6 456,7 @@ dkmuxconfig(Dk *dp, Block *bp)
	 */
	dp->restart = 1;
	n = getfields((char *)bp->rptr, fields, 4, ' ');
	strcpy(dp->name, "dk");
	switch(n){
	case 4:
		strncpy(dp->name, fields[3], sizeof(dp->name));


@@ 494,7 495,7 @@ dkmuxconfig(Dk *dp, Block *bp)
	/*
	 *  start a process to deal with it
	 */
	sprint(buf, "**csckproc%d**", dp->ncsc);
	sprint(buf, "csckproc%d", dp->ncsc);
	kproc(buf, dkcsckproc, dp);
	poperror();



@@ 503,7 504,7 @@ dkmuxconfig(Dk *dp, Block *bp)
	 */
	if(dktimeron == 0){
		dktimeron = 1;
		kproc("**dktimer**", dktimer, 0);
		kproc("dktimer", dktimer, 0);
	}
}



@@ 592,8 593,10 @@ dkattach(char *spec)
	Dk *dp;

	/*
	 *  find a multiplexor with the same name
	 *  find a multiplexor with the same name (default dk)
	 */
	if(*spec == 0)
		spec = "dk";
	for(dp = dk; dp < &dk[Ndk]; dp++){
		qlock(dp);
		if(dp->wq && strcmp(spec, dp->name)==0) {


@@ 859,8 862,10 @@ dkmesg(Dk *dp, int type, int srv, int p0, int p1)

	if(dp->csc == 0)
		return -1;
	if(waserror())
	if(waserror()){
		print("dkmesg: error\n");
		return -1;
	}
	d.type = type;
	d.srv = srv;
	d.param0l = p0;


@@ 1477,7 1482,8 @@ dktimer(void *a)
	Dk *dp;
	Line *lp;

	waserror();
	while(waserror())
		print("dktimer: error\n");

	for(;;){
		/*

M gnot/devmnt.c => gnot/devmnt.c +0 -1
@@ 291,7 291,6 @@ mntattach(char *spec)
	mh = mhalloc();
	if(waserror()){
		mhfree(mh);
		mqfree(q);
		close(c);
		nexterror();
	}

M gnot/errno.h => gnot/errno.h +1 -0
@@ 50,6 50,7 @@ enum{
	Enobitmap,	/* out of bitmap descriptors */
	Enobitstore,	/* out of bitmap storage */
	Ebadbitmap,	/* unallocated bitmap */
	Ebadfont,	/* unallocated font */
	Eshortmsg,	/* short message */
	Ebadmsg,	/* format error or mismatch in message */
	Ebadcnt,	/* read count greater than requested */

M gnot/page.c => gnot/page.c +8 -5
@@ 560,10 560,14 @@ growpte(Orig *o, ulong n)
	lock(&ptealloc);
	lock(o);
	if(o->pte){
		if(o->npte == n)
			panic("growpte pointless");
		if(o->npte == n){
			print("growpte pointless\n");
			goto Return;
		}
		p = (PTEA*)(o->pte - 1);
		if(o->npte > n){
			print("growpte shrink");
			goto Return;
			nfree = o->npte - n;
			p->n -= nfree;
			o->npte -= nfree;


@@ 589,9 593,7 @@ growpte(Orig *o, ulong n)
			p->n = n;
			o->npte = n-1;
		}
		unlock(o);
		unlock(&ptealloc);
		return;
		goto Return;
	}
	n++;
	compactpte(o, n);


@@ 602,6 604,7 @@ growpte(Orig *o, ulong n)
	p->o = o;
	o->pte = p+1;
	o->npte = n-1;
    Return:
	unlock(o);
	unlock(&ptealloc);
}

M gnot/proc.c => gnot/proc.c +8 -3
@@ 575,6 575,7 @@ kproc(char *name, void (*func)(void *), void *arg)
	int lastvar;	/* used to compute stack address */
	User *up;
	KMap *k;
	static Pgrp *kpgrp;

	/*
	 * Kernel stack


@@ 612,12 613,16 @@ kproc(char *name, void (*func)(void *), void *arg)
		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);
	if(kpgrp == 0){
		kpgrp = newpgrp();
		strcpy(kpgrp->user, "bootes");
	}
	p->pgrp = kpgrp;
	incref(kpgrp);
	sprint(p->text, "%s.%.6s", name, u->p->pgrp->user);
	p->nchild = 0;
	p->parent = 0;
	memset(p->time, 0, sizeof(p->time));

M gnot/sturp.c => gnot/sturp.c +53 -31
@@ 11,7 11,7 @@ enum {
	Nmask=		0x7,
};

#define DPRINT if(q->flag&QDEBUG)kprint
#define DPRINT /*if(q->flag&QDEBUG)kprint*/

typedef struct Urp	Urp;



@@ 116,6 116,7 @@ static void	sendrej(Urp*);
static void	initoutput(Urp*, int);
static void	initinput(Urp*, int);
static void	urpkproc(void *arg);
static void	urptimer(Alarm*);
static void	urpvomit(char*, Urp*);

Qinfo urpinfo = { urpciput, urpoput, urpopen, urpclose, "urp" };


@@ 125,6 126,7 @@ urpreset(void)
{
	newqinfo(&urpinfo);
	urp = (Urp *)ialloc(conf.nurp*sizeof(Urp), 0);
	alarm(500, urptimer, 0);
}

static void


@@ 160,17 162,22 @@ urpopen(Queue *q, Stream *s)
	/*
	 *  start the ack/(re)xmit process
	 */
	if(up->kstarted == 0){
		up->kstarted = 1;
		sprint(name, "**urp%d**", up - urp);
		kproc(name, urpkproc, up);
	}
	sprint(name, "urp%d", up - urp);
	kproc(name, urpkproc, up);
}

/*
 *  Shut down the connection and kill off the kernel process
 */
static int
isdead(void *a)
{
	Urp *up;

	up = (Urp *)a;
	return up->kstarted==0;
}
static int
isflushed(void *a)
{
	Urp *up;


@@ 199,7 206,7 @@ urpclose(Queue *q)
	tsleep(&up->r, isflushed, up, 2*60*1000);

	/*
	 *  kill off the kernel process
	 *  tell kernel process to die
	 */
	up->state |= HUNGUP;
	wakeup(&up->rq->r);


@@ 223,10 230,13 @@ urpclose(Queue *q)
		}
	qunlock(&up->xmit);

	if(up->kstarted == 0){
		DPRINT("urpclose %ux\n", up);
		up->state = 0;
	}
	/*
	 *  wait for kernel process to die
	 */
	while(up->kstarted)
		sleep(&up->r, isdead, up);

	up->state = 0;
}

/*


@@ 607,9 617,7 @@ output(Urp *up)
			sendctl(up, INIT1);
			up->timer = now + MSrexmit;
		}
		qunlock(&up->xmit);
		poperror();
		return;
		goto out;
	}

	/*


@@ 653,9 661,7 @@ output(Urp *up)
		up->timer = NOW + MSrexmit;
		up->state &= ~REJECTING;
		sendctl(up, ENQ);
		qunlock(&up->xmit);
		poperror();
		return;
		goto out;
	}

	/*


@@ 676,6 682,7 @@ output(Urp *up)
		up->next = NEXT(up->next);
		poperror();
	}
out:
	qunlock(&up->xmit);
	poperror();
}


@@ 941,40 948,55 @@ todo(void *arg)
static void
urpkproc(void *arg)
{
	Urp *up; Queue *q;
	Urp *up;

	up = (Urp *)arg;
	q = up->wq;
	up->kstarted = 1;

	if(waserror()){
		print("urpkproc error %ux\n", up);
		up->state = 0;
		up->kstarted = 0;
		wakeup(&up->r);
		return;
	}
	for(;;){
		if(up->state & (HUNGUP|CLOSING)){
			if(isflushed(up))
				wakeup(&up->r);
			if(up->state & HUNGUP)
				break;
		}
		if(up->state == 0){
			DPRINT("urpkproc: %ux->state == 0\n", up);
		if(up->state & HUNGUP)
			break;
		}
		if(!QFULL(up->rq->next))
			sendack(up);
		output(up);
		tsleep(&up->rq->r, todo, up, MSrexmit/2);
		sleep(&up->rq->r, todo, up);
	}
	up->state = 0;
	up->kstarted = 0;
	wakeup(&up->r);
	poperror();
	DPRINT("urpkproc %ux\n", up);
}

/*
 *  timer to wakeup urpkproc's for retransmissions
 */
static void
urptimer(Alarm *a)
{
	Urp *up;
	Urp *last;
	Queue *q;

	cancel(a);
	alarm(500, urptimer, 0);
	for(up = urp, last = &urp[conf.nurp]; up < last; up++){
		if(up->state==0)
			continue;
		if(up->unacked!=up->next && NOW>up->timer){
			q = up->rq;
			if(q)
				wakeup(&q->r);
		}
	}
}

/*
 *  urp got very confused, complain
 */
static void

M port/devbit.c => port/devbit.c +2 -2
@@ 61,7 61,7 @@ struct{

Cursor	arrow =
{
	{0, 0},
	{1, 1},
	{0xFF, 0xE0, 0xFF, 0xE0, 0xFF, 0xC0, 0xFF, 0x00,
	 0xFF, 0x00, 0xFF, 0x80, 0xFF, 0xC0, 0xFF, 0xE0,
	 0xE7, 0xF0, 0xE3, 0xF8, 0xC1, 0xFC, 0x00, 0xFE,


@@ 657,7 657,7 @@ bitwrite(Chan *c, void *va, long n)
			v = GSHORT(p+1);
			f = &bit.font[v];
			if(v<0 || v>=conf.nfont || f->bits==0)
				error(0, Ebadbitmap);
				error(0, Ebadfont);
			f->bits = 0;
			m -= 3;
			p += 3;

M port/page.c => port/page.c +9 -5
@@ 560,10 560,15 @@ growpte(Orig *o, ulong n)
	lock(&ptealloc);
	lock(o);
	if(o->pte){
		if(o->npte == n)
			panic("growpte pointless");
		if(o->npte == n){
if(u && u->p) print("%s: ", u->p->text);
			print("growpte pointless\n");
			goto Return;
		}
		p = (PTEA*)(o->pte - 1);
		if(o->npte > n){
			print("growpte shrink");
			goto Return;
			nfree = o->npte - n;
			p->n -= nfree;
			o->npte -= nfree;


@@ 589,9 594,7 @@ growpte(Orig *o, ulong n)
			p->n = n;
			o->npte = n-1;
		}
		unlock(o);
		unlock(&ptealloc);
		return;
		goto Return;
	}
	n++;
	compactpte(o, n);


@@ 602,6 605,7 @@ growpte(Orig *o, ulong n)
	p->o = o;
	o->pte = p+1;
	o->npte = n-1;
    Return:
	unlock(o);
	unlock(&ptealloc);
}

M port/proc.c => port/proc.c +0 -1
@@ 299,7 299,6 @@ void
twakeme(Alarm *a)
{
	wakeup((Rendez*)(a->arg));
	cancel(a);
}

int

M port/sturp.c => port/sturp.c +28 -58
@@ 68,12 68,6 @@ struct Urp {
#define NEXT(x) (((x)+1)&Nmask)

/*
 *  Alarm for urptiming
 */
Alarm	*urptiming;
Lock	urptlock;

/*
 *  Protocol control bytes
 */
#define	SEQ	0010		/* sequence number, ends trailers */


@@ 132,6 126,7 @@ urpreset(void)
{
	newqinfo(&urpinfo);
	urp = (Urp *)ialloc(conf.nurp*sizeof(Urp), 0);
	alarm(500, urptimer, 0);
}

static void


@@ 167,28 162,22 @@ urpopen(Queue *q, Stream *s)
	/*
	 *  start the ack/(re)xmit process
	 */
	if(up->kstarted == 0){
		up->kstarted = 1;
		sprint(name, "urp%d", up - urp);
		kproc(name, urpkproc, up);
	}

	/*
	 *  start the urptimer if it isn't already
	 */
	if(urptiming==0){
		if(canlock(&urptlock)){
			if(urptiming == 0)
				urptiming = alarm(500, urptimer, 0);
			unlock(&urptlock);
		}
	}
	sprint(name, "urp%d", up - urp);
	kproc(name, urpkproc, up);
}

/*
 *  Shut down the connection and kill off the kernel process
 */
static int
isdead(void *a)
{
	Urp *up;

	up = (Urp *)a;
	return up->kstarted==0;
}
static int
isflushed(void *a)
{
	Urp *up;


@@ 217,7 206,7 @@ urpclose(Queue *q)
	tsleep(&up->r, isflushed, up, 2*60*1000);

	/*
	 *  kill off the kernel process
	 *  tell kernel process to die
	 */
	up->state |= HUNGUP;
	wakeup(&up->rq->r);


@@ 241,10 230,13 @@ urpclose(Queue *q)
		}
	qunlock(&up->xmit);

	if(up->kstarted == 0){
		DPRINT("urpclose %ux\n", up);
		up->state = 0;
	}
	/*
	 *  wait for kernel process to die
	 */
	while(up->kstarted)
		sleep(&up->r, isdead, up);

	up->state = 0;
}

/*


@@ 607,17 599,6 @@ output(Urp *up)
	int n;
	int i;

	/*
	 *  start the urptimer if it isn't already
	 */
	if(urptiming==0){
		if(canlock(&urptlock)){
			if(urptiming == 0)
				urptiming = alarm(500, urptimer, 0);
			unlock(&urptlock);
		}
	}

	if(!canqlock(&up->xmit))
		return;



@@ 636,9 617,7 @@ output(Urp *up)
			sendctl(up, INIT1);
			up->timer = now + MSrexmit;
		}
		qunlock(&up->xmit);
		poperror();
		return;
		goto out;
	}

	/*


@@ 682,9 661,7 @@ output(Urp *up)
		up->timer = NOW + MSrexmit;
		up->state &= ~REJECTING;
		sendctl(up, ENQ);
		qunlock(&up->xmit);
		poperror();
		return;
		goto out;
	}

	/*


@@ 705,6 682,7 @@ output(Urp *up)
		up->next = NEXT(up->next);
		poperror();
	}
out:
	qunlock(&up->xmit);
	poperror();
}


@@ 970,36 948,28 @@ todo(void *arg)
static void
urpkproc(void *arg)
{
	Urp *up; Queue *q;
	Urp *up;

	up = (Urp *)arg;
	q = up->wq;
	up->kstarted = 1;

	if(waserror()){
		print("urpkproc error %ux\n", up);
		up->state = 0;
		up->kstarted = 0;
		wakeup(&up->r);
		return;
	}
	for(;;){
		if(up->state & (HUNGUP|CLOSING)){
			if(isflushed(up))
				wakeup(&up->r);
			if(up->state & HUNGUP)
				break;
		}
		if(up->state == 0){
			DPRINT("urpkproc: %ux->state == 0\n", up);
		if(up->state & HUNGUP)
			break;
		}
		if(!QFULL(up->rq->next))
			sendack(up);
		output(up);
		sleep(&up->rq->r, todo, up);
	}
	up->state = 0;
	up->kstarted = 0;
	wakeup(&up->r);
	poperror();
	DPRINT("urpkproc %ux\n", up);
}



@@ 1014,7 984,7 @@ urptimer(Alarm *a)
	Queue *q;

	cancel(a);
	urptiming = 0;
	alarm(500, urptimer, 0);
	for(up = urp, last = &urp[conf.nurp]; up < last; up++){
		if(up->state==0)
			continue;

M power/clock.c => power/clock.c +16 -8
@@ 135,13 135,15 @@ clockinit(void)
	m->ticks = 0;
}

#define NA 10
void
clock(ulong n)
{
	int i;
	int i, na;
	Alarm *a;
	void (*f)(void*);
	Proc *p;
	Alarm *alist[NA];

	if(n&INTR2){
		i = *CLRTIM0;


@@ 170,16 172,22 @@ clock(ulong n)
			if(m->alarm){
				a = m->alarm;
				a->dt--;
				while(a && a->dt<=0){
					f = a->f;	/* avoid race with cancel */
					if(f)
						(*f)(a);
				for(na = 0; a && a->dt<=0 && na<NA; na++){
					alist[na] = a;
					delete(&m->alarm, 0, a);
					a->busy = 0;
					a = m->alarm;
				}
			}
			unlock(&m->alarmlock);
				unlock(&m->alarmlock);
	
				/*  execute alarm functions outside the lock */
				for(i = 0; i < na; i++){
					f = alist[i]->f;	/* avoid race with cancel */
					if(f)
						(*f)(alist[i]);
					alist[i]->busy = 0;
				}
			} else
				unlock(&m->alarmlock);
		}
		return;
	}