~kris/9p

9hist

7b7a681b78fc3c933cbdc554d26aec57637597ef — David du Colombier 27 years ago f4ff188
Plan 9 from Bell Labs 1999-07-11
M carrera/main.c => carrera/main.c +1 -1
@@ 474,7 474,7 @@ confinit(void)

	if(top > 16*MB/BY2PG){
		conf.upages = (conf.npage*60)/100;
		poolsetparam("Image", 0, 0, 4*1024*1024, nil);
		poolconfig(imagmem, 0, 4*1024*1024, 0, nil);
	}else
		conf.upages = (conf.npage*40)/100;
	conf.ialloc = ((conf.npage-conf.upages)/2)*BY2PG;

M ip/devip.c => ip/devip.c +6 -4
@@ 1035,10 1035,12 @@ Fsprotoclone(Proto *p, char *user)
			qlock(c);
			c->p = p;
			c->x = pp - p->conv;
			c->ptcl = malloc(p->ptclsize);
			if(c->ptcl == nil) {
				free(c);
				error(Enomem);
			if(p->ptclsize != 0){
				c->ptcl = malloc(p->ptclsize);
				if(c->ptcl == nil) {
					free(c);
					error(Enomem);
				}
			}
			*pp = c;
			p->ac++;

M pc/ether2114x.c => pc/ether2114x.c +11 -2
@@ 815,8 815,17 @@ typephylink(Ctlr* ctlr, uchar*)
	}
	else if((bmcr & 0x2100) == 0x2100)
		x = 0x4000;
	else if(bmcr & 0x2000)
		x = 0x2000;
	else if(bmcr & 0x2000){
		/*
		 * If FD capable, force it if necessary.
		 */
		if((bmsr & 0x4000) && ctlr->fd){
			miiw(ctlr, ctlr->curphyad, Bmcr, 0x2100);
			x = 0x4000;
		}
		else
			x = 0x2000;
	}
	else if(bmcr & 0x0100)
		x = 0x1000;
	else

M pc/main.c => pc/main.c +3 -3
@@ 434,7 434,7 @@ confinit(void)
		 * 4MB on the first Image chunk allocation.
		 */
		if(conf.npage*BY2PG < 16*MB)
			poolsetparam(imagmem, 0, 4*1024*1024, 0, nil);
			poolconfig(imagmem, 0, 4*1024*1024, 0, nil);
	}
	conf.upages = conf.npage - kpages;
	conf.ialloc = (kpages/2)*BY2PG;


@@ 450,14 450,14 @@ confinit(void)
		+ conf.nimage*sizeof(Image)
		+ conf.nswap
		+ conf.nswppo*sizeof(Page);
	poolsetparam(mainmem, kpages, 0, 0, nil);
	poolconfig(mainmem, kpages, 0, 0, nil);
	if(!cpuserver){
		/*
		 * give terminals lots of image memory, too; the dynamic
		 * allocation will balance the load properly, hopefully.
		 * be careful with 32-bit overflow.
		 */
		poolsetparam(imagmem, kpages, 0, 0, nil);
		poolconfig(imagmem, kpages, 0, 0, nil);
	}
}


M port/alloc.c => port/alloc.c +0 -6
@@ 54,9 54,6 @@ malloc(ulong size)
	ulong *l;
	void *v;

	if(size == 0)
		return nil;

	v = poolalloc(mainmem, size+8);
	if(v != nil) {
		l = v;


@@ 73,9 70,6 @@ mallocz(ulong size, int clr)
	void *v;
	ulong *l;

	if(size == 0)
		return nil;

	v = poolalloc(mainmem, size+8);
	if(v != nil) {
		l = v;

M port/devcons.c => port/devcons.c +195 -175
@@ 32,6 32,10 @@ vlong	fasthz;
static ulong	randomread(void*, ulong);
static void	randominit(void);
static void	seedrand(void);
static int	readtime(ulong, char*, int);
static int	readbintime(char*, int);
static int	writetime(char*, int);
static int	writebintime(char*, int);

void
printinit(void)


@@ 340,19 344,14 @@ enum{
	Qauth,
	Qauthcheck,
	Qauthent,
	Qtiming,
	Qclock,
	Qbintime,
	Qcons,
	Qconsctl,
	Qcputime,
	Qdrivers,
	Qfastclock,
	Qhz,
	Qkey,
	Qhostdomain,
	Qhostowner,
	Qmsec,
	Qnsec,
	Qnull,
	Qpgrpid,
	Qpid,


@@ 371,18 370,14 @@ static Dirtab consdir[]={
	"authenticate",	{Qauth},	0,		0666,
	"authcheck",	{Qauthcheck},	0,		0666,
	"authenticator", {Qauthent},	0,		0666,
	"clock",	{Qclock},	2*NUMSIZE,	0444,
	"bintime",	{Qbintime},	24,		0664,
	"cons",		{Qcons},	0,		0660,
	"consctl",	{Qconsctl},	0,		0220,
	"cputime",	{Qcputime},	6*NUMSIZE,	0444,
	"drivers",	{Qdrivers},	0,		0644,
	"fastclock",	{Qfastclock},	4*NUMSIZE,	0664,
	"hostdomain",	{Qhostdomain},	DOMLEN,		0664,
	"hostowner",	{Qhostowner},	NAMELEN,	0664,
	"hz",		{Qhz},		NUMSIZE,	0666,
	"key",		{Qkey},		DESKEYLEN,	0622,
	"msec",		{Qmsec},	NUMSIZE,	0444,
	"nsec",		{Qnsec},	NUMSIZE,	0664,
	"null",		{Qnull},	0,		0666,
	"pgrpid",	{Qpgrpid},	NUMSIZE,	0444,
	"pid",		{Qpid},		NUMSIZE,	0444,


@@ 392,56 387,11 @@ static Dirtab consdir[]={
	"swap",		{Qswap},	0,		0664,
	"sysname",	{Qsysname},	0,		0664,
	"sysstat",	{Qsysstat},	0,		0666,
	"time",		{Qtime},	NUMSIZE,	0664,
	"timing",	{Qtiming},	3*8,		0664,
	"time",		{Qtime},	7*NUMSIZE,	0664,
	"user",		{Quser},	NAMELEN,	0666,
	"zero",	{Qzero},	0,	0666,
	"zero",		{Qzero},	0,		0666,
};

uvlong billion = 1000000000ULL;
uvlong bilbil = 1000000000ULL*1000000000ULL;

//
//  this routine is a hack till we get 64 bit ops faster
//
int
readvlnum(ulong off, char *buf, ulong n, uvlong val, int size)
{
	char tmp[64];
	char num[64];
	ulong y;
	int i;

	i = 0;
	if(val > bilbil){
		y = val/bilbil;
		i += sprint(num+i, "%lud", y);
		val -= y*bilbil;
		y = val/billion;
		i += sprint(num+i, "%9.9lud", y);
		val -= y*billion;
		y = val;
		sprint(num+i,  "%9.9lud", y);
	} else if(val > billion){
		y = val/billion;
		i += sprint(num+i, "%lud", y);
		val -= y*billion;
		y = val;
		sprint(num+i, "%9.9lud", y);
	} else {
		y = val;
		sprint(num+i, "%lud", y);
	}
	snprint(tmp, sizeof(tmp), "%*s", size-1, num);
	tmp[size-1] = ' ';
	if(off >= size)
		return 0;
	if(off+n > size)
		n = size-off;
	memmove(buf, tmp+off, n);
	return n;
}

int
readnum(ulong off, char *buf, ulong n, ulong val, int size)
{


@@ 532,21 482,6 @@ consclose(Chan *c)
	}
}


uvlong order = 0x0001020304050607ULL;

void
vlong2le(char *t, vlong from)
{
	uchar *f, *o;
	int i;

	f = (uchar*)&from;
	o = (uchar*)&order;
	for(i = 0; i < 8; i++)
		t[i] = f[o[i]];
}

static long
consread(Chan *c, void *buf, long n, vlong off)
{


@@ 556,8 491,7 @@ consread(Chan *c, void *buf, long n, vlong off)
	char tmp[128];		/* must be >= 6*NUMSIZE */
	char *cbuf = buf;
	int ch, i, k, id, eol;
	vlong offset = off, x;
	vlong ticks, nsec;
	vlong offset = off;

	if(n <= 0)
		return n;


@@ 647,50 581,11 @@ consread(Chan *c, void *buf, long n, vlong off)
	case Qppid:
		return readnum((ulong)offset, buf, n, up->parentpid, NUMSIZE);

	case Qclock:
		k = offset;
		if(k >= 2*NUMSIZE)
			return 0;
		if(k+n > 2*NUMSIZE)
			n = 2*NUMSIZE - k;
		readnum(0, tmp, NUMSIZE, MACHP(0)->ticks, NUMSIZE);
		readnum(0, tmp+NUMSIZE, NUMSIZE, HZ, NUMSIZE);
		memmove(buf, tmp+k, n);
		return n;

	case Qfastclock:
		if(fasthz == 0L)
			ticks = fastticks((uvlong*)&fasthz);
		else
			ticks = fastticks(nil);

		k = offset;
		if(k >= 4*NUMSIZE)
			return 0;
		if(k+n > 4*NUMSIZE)
			n = 4*NUMSIZE - k;
		readvlnum(0, tmp, 2*NUMSIZE, ticks, 2*NUMSIZE);
		readvlnum(0, tmp+2*NUMSIZE, 2*NUMSIZE, fasthz, 2*NUMSIZE);
		memmove(buf, tmp+k, n);
		return n;
	case Qtime:
		return readtime((ulong)offset, buf, n);

	case Qtiming:
		k = 0;
		nsec = todget(&ticks);
		if(n >= 3*8){
			vlong2le(cbuf+16, fasthz);
			k += 8;
		}
		if(n >= 2*8){
			vlong2le(cbuf+8, ticks);
			k += 8;
		}
		if(n >= 8){
			vlong2le(cbuf, nsec);
			k += 8;
		}
		return k;
			
	case Qbintime:
		return readbintime(buf, n);

	case Qkey:
		return keyread(buf, n, offset);


@@ 716,25 611,6 @@ consread(Chan *c, void *buf, long n, vlong off)
	case Qnull:
		return 0;

	case Qnsec:
		x = todget(nil);
		return readvlnum((ulong)offset, buf, n, x, 2*NUMSIZE);

	case Qmsec:
		x = todget(nil);
		x /= 1000000LL;
		i = x;
		return readnum((ulong)offset, buf, n, i, NUMSIZE);

	case Qtime:
		x = todget(nil);
		x /= 1000000000LL;
		i = x;
		return readnum((ulong)offset, buf, n, i, NUMSIZE);

	case Qhz:
		return readnum((ulong)offset, buf, n, HZ, NUMSIZE);

	case Qsysstat:
		b = smalloc(conf.nmach*(NUMSIZE*8+1) + 1);	/* +1 for NUL */
		bp = b;


@@ 802,7 678,6 @@ consread(Chan *c, void *buf, long n, vlong off)
static long
conswrite(Chan *c, void *va, long n, vlong off)
{
	char cbuf[64];
	char buf[256];
	long l, bp;
	char *a = va;


@@ 810,7 685,6 @@ conswrite(Chan *c, void *va, long n, vlong off)
	int id, fd;
	Chan *swc;
	ulong offset = off;
	vlong f, nsec, delta;

	switch(c->qid.path){
	case Qcons:


@@ 857,43 731,14 @@ conswrite(Chan *c, void *va, long n, vlong off)
		break;

	case Qtime:
		if(n<=0 || !iseve())
			return 0;
		if(n >= sizeof cbuf)
			n = sizeof cbuf - 1;
		strncpy(cbuf, a, n);
		cbuf[n] = 0;
		nsec = strtol(cbuf, 0, 0);
		nsec *= 1000000000LL;
		todset(nsec, 0, 0);
		break;

	case Qfastclock:
		if(n<=0 || !iseve())
			return 0;
		if(n >= sizeof(cbuf))
			n = sizeof(cbuf)-1;
		strncpy(cbuf, a, n);
		cbuf[n] = 0;
		f = strtoll(cbuf, 0, 0);
		if(f <= 0L)
			error(Ebadarg);
		fasthz = f;
		todsetfreq(f);
		break;
		if(!iseve())
			error(Eperm);
		return writetime(a, n);

	case Qnsec:
		if(n<=0 || !iseve())
			return 0;
		if(n >= sizeof cbuf)
			n = sizeof cbuf - 1;
		strncpy(cbuf, a, n);
		cbuf[n] = 0;
		nsec = strtoll(cbuf, &a, 0);
		delta = strtoll(a, &a, 0);
		n = strtol(a, &a, 0);
		todset(nsec, delta, n);
		break;
	case Qbintime:
		if(!iseve())
			error(Eperm);
		return writebintime(a, n);

	case Qkey:
		return keywrite(a, n);


@@ 1165,3 1010,178 @@ randomread(void *xp, ulong n)

	return n;
}

static uvlong uvorder = 0x0001020304050607ULL;

static uchar*
le2vlong(vlong *to, uchar *f)
{
	uchar *t, *o;
	int i;

	t = (uchar*)to;
	o = (uchar*)&uvorder;
	for(i = 0; i < sizeof(vlong); i++)
		t[o[i]] = f[i];
	return f+sizeof(vlong);
}

static uchar*
vlong2le(uchar *t, vlong from)
{
	uchar *f, *o;
	int i;

	f = (uchar*)&from;
	o = (uchar*)&uvorder;
	for(i = 0; i < sizeof(vlong); i++)
		t[i] = f[o[i]];
	return t+sizeof(vlong);
}

static long order = 0x00010203;

static uchar*
le2long(long *to, uchar *f)
{
	uchar *t, *o;
	int i;

	t = (uchar*)to;
	o = (uchar*)&order;
	for(i = 0; i < sizeof(long); i++)
		t[o[i]] = f[i];
	return f+sizeof(long);
}

static uchar*
long2le(uchar *t, long from)
{
	uchar *f, *o;
	int i;

	f = (uchar*)&from;
	o = (uchar*)&order;
	for(i = 0; i < sizeof(long); i++)
		t[i] = f[o[i]];
	return t+sizeof(long);
}

char *Ebadtimectl = "bad time control";

/*
 *  like the old #c/time but with added info.  Return
 *
 *	secs	nanosecs	fastticks	fasthz
 */
static int
readtime(ulong off, char *buf, int n)
{
	vlong	nsec, ticks;
	long sec;
	char str[7*NUMSIZE+4];	// extra 4 bytes are null plus doprint
				// reserving space for a frigging UTF
				// char

	nsec = todget(&ticks);
	if(fasthz == 0LL)
		fastticks((uvlong*)&fasthz);
	sec = nsec/1000000000ULL;
	snprint(str, sizeof(str), "%*.0lud %*.0llud %*.0llud %*.0llud ",
		NUMSIZE-1, sec,
		2*NUMSIZE-1, nsec,
		2*NUMSIZE-1, ticks,
		2*NUMSIZE-1, fasthz);
	return readstr(off, buf, n, str);
}

/*
 *  set the time in seconds
 */
static int
writetime(char *buf, int n)
{
	char b[13];
	long i;
	vlong now;

	if(n >= sizeof(b))
		error(Ebadtimectl);
	strncpy(b, buf, n);
	b[n] = 0;
	i = strtol(b, 0, 0);
	if(i <= 0)
		error(Ebadtimectl);
	now = i*1000000000LL;
	todset(now, 0, 0);
	return n;
}

/*
 *  read binary time info.  all numbers are little endian.
 *  ticks and nsec are syncronized.
 */
static int
readbintime(char *buf, int n)
{
	int i;
	vlong nsec, ticks;
	uchar *b = (uchar*)buf;

	i = 0;
	if(fasthz == 0LL)
		fastticks((uvlong*)&fasthz);
	nsec = todget(&ticks);
	if(n >= 3*sizeof(uvlong)){
		vlong2le(b+2*sizeof(uvlong), fasthz);
		i += sizeof(uvlong);
	}
	if(n >= 2*sizeof(uvlong)){
		vlong2le(b+sizeof(uvlong), ticks);
		i += sizeof(uvlong);
	}
	if(n >= 8){
		vlong2le(b, nsec);
		i += sizeof(vlong);
	}
	return i;
}

/*
 *  set any of the following
 *	- time in nsec
 *	- nsec trim applied over some seconds
 *	- clock frequency
 */
static int
writebintime(char *buf, int n)
{
	uchar *p;
	vlong delta;
	long period;

	n--;
	p = (uchar*)buf + 1;
	switch(*buf){
	case 'n':
		if(n < sizeof(vlong))
			error(Ebadtimectl);
		le2vlong(&delta, p);
		todset(delta, 0, 0);
		break;
	case 'd':
		if(n < sizeof(vlong)+sizeof(long))
			error(Ebadtimectl);
		p = le2vlong(&delta, p);
		le2long(&period, p);
		todset(-1, delta, period);
		break;
	case 'f':
		if(n < sizeof(uvlong))
			error(Ebadtimectl);
		le2vlong(&fasthz, p);
		todsetfreq(fasthz);
		break;
	}
	return n;
}

M port/devintrts.c => port/devintrts.c +2 -2
@@ 31,10 31,10 @@ static	struct {
void
_saveintrts(void)
{
	lock(&tsalloc);
	ilock(&tsalloc);
	if(tsalloc.n < nelem(tsalloc.ts))
		tsalloc.ts[tsalloc.n++] = m->intrts;
	unlock(&tsalloc);
	iunlock(&tsalloc);
}

/* read interrupt timestamps */

M port/devns16552.c => port/devns16552.c +6 -16
@@ 632,16 632,14 @@ ns16552intr(int dev)
		case 4:	/* received data available */
		case 12:
			ch = uartrdreg(p, Data) & 0xff;
			ilock(&p->tlock);
			if(p->xonoff){
				if(ch == CTLS){
					p->blocked = 1;
				}else if (ch == CTLQ){
					p->blocked = 0;
					 /* clock gets output going again */
					p->ctsbackoff = 2; /* clock gets output going again */
				}
			}
			iunlock(&p->tlock);
			if(p->putc)
				p->putc(p->iq, ch);
			else {


@@ 660,31 658,23 @@ ns16552intr(int dev)
		case 0:	/* modem status */
			ch = uartrdreg(p, Mstat);
			if(ch & Ctsc){
				ilock(&p->tlock);
				l = p->cts;
				p->cts = ch & Cts;
				if(l == 0 && p->cts)
					p->ctsbackoff = 2; /* clock gets output going again */
				iunlock(&p->tlock);
			}
	 		if (ch & Dsrc) {
				l = ch & Dsr;
				if(p->hup_dsr && p->dsr && !l){
					ilock(&p->rlock);
					p->dohup = 1;
					iunlock(&p->rlock);
				}
				if(p->hup_dsr && p->dsr && !l)
					p->dohup = 1;	 /* clock peforms hangup */
				p->dsr = l;
			}
	 		if (ch & Dcdc) {
				l = ch & Dcd;
				if(l == 0 && p->dcd != 0 && p->dcdts && saveintrts != nil)
					(*saveintrts)();
				if(p->hup_dcd && p->dcd && !l){
					ilock(&p->rlock);
					p->dohup = 1;
					iunlock(&p->rlock);
				}
				if(p->hup_dcd && p->dcd && !l)
					p->dohup = 1;	 /* clock peforms hangup */
				p->dcd = l;
			}
			break;


@@ 744,7 734,7 @@ uartclock(void)
			iunlock(&p->rlock);
		}

		/* this adds hysteresis to hardware flow control */
		/* this adds hysteresis to hardware/software flow control */
		if(p->ctsbackoff){
			ilock(&p->tlock);
			if(p->ctsbackoff){

M port/devproc.c => port/devproc.c +1 -2
@@ 907,8 907,7 @@ procctlreq(Proc *p, char *va, int n)
		if(n < 6)
			error(Ebadctl);
		i = atoi(buf+6);
		if(i)
			procwired(p);
		procwired(p, i);
	}
	else
	if(strncmp(buf, "profile", 7) == 0) {

M port/portfns.h => port/portfns.h +1 -1
@@ 206,7 206,7 @@ void		procdump(void);
void		procinit0(void);
void		procflushseg(Segment*);
Proc*		proctab(int);
void		procwired(Proc*);
void		procwired(Proc*, int);
Pte*		ptealloc(void);
Pte*		ptecpy(Pte*);
int		pullblock(Block**, int);

M port/proc.c => port/proc.c +23 -13
@@ 220,7 220,7 @@ loop:
			if(xrq != nil){
				rq = xrq;
				p = rq->head;
				if(p != nil)
				if(p != nil && p->wired == nil)
					p->movetime = 0;
				goto found;
			}


@@ 351,22 351,32 @@ newproc(void)
 * wire this proc to a machine
 */
void
procwired(Proc *p)
procwired(Proc *p, int bm)
{
	Proc *pp;
	int i, bm;
	int i;
	char nwired[MAXMACH];
	Mach *wm;

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

	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);
	p->movetime = 0xffffffff;
	p->mp = p->wired;

M port/sysproc.c => port/sysproc.c +4 -2
@@ 26,6 26,7 @@ sysrfork(ulong *arg)
	Rgrp *org;
	Egrp *oeg;
	ulong pid, flag;
	Mach *wm;

	flag = arg[0];
	/* Check flags before we commit */


@@ 179,8 180,9 @@ sysrfork(ulong *arg)
	p->priority = up->priority;
	p->basepri = up->basepri;
	p->mp = up->mp;
	if(up->wired)
		procwired(p);
	wm = up->wired;
	if(wm)
		procwired(p, wm->machno);
	ready(p);
	sched();
	return pid;