From 7b7a681b78fc3c933cbdc554d26aec57637597ef Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 11 Jul 1999 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1999-07-11 --- carrera/main.c | 2 +- ip/devip.c | 10 +- pc/ether2114x.c | 13 +- pc/main.c | 6 +- port/alloc.c | 6 - port/devcons.c | 370 ++++++++++++++++++++++++---------------------- port/devintrts.c | 4 +- port/devns16552.c | 22 +-- port/devproc.c | 3 +- port/portfns.h | 2 +- port/proc.c | 36 +++-- port/sysproc.c | 6 +- 12 files changed, 253 insertions(+), 227 deletions(-) diff --git a/carrera/main.c b/carrera/main.c index f752601beae5ed53e39abb9ca08503891fa96b26..a1c8fe8b7482d5d17cf09bed65f227eb7c093167 100644 --- a/carrera/main.c +++ b/carrera/main.c @@ -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; diff --git a/ip/devip.c b/ip/devip.c index 8e9963828e6a368b76223e2529608a246554fbfd..54226e77c43f00b8b9f70dc993645ab95f3ebd9d 100644 --- a/ip/devip.c +++ b/ip/devip.c @@ -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++; diff --git a/pc/ether2114x.c b/pc/ether2114x.c index 8eff8b71dfa1efa6a568b8c80550cba255cd58d2..0ce4ad724dd4ef0e334e8569b32e12709faccfe3 100644 --- a/pc/ether2114x.c +++ b/pc/ether2114x.c @@ -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 diff --git a/pc/main.c b/pc/main.c index 6ca0cbfe60560bdfb3b5ee7d9bcde4e79186bd2b..b044b9c78be273466668706d247d0c136b642c8a 100644 --- a/pc/main.c +++ b/pc/main.c @@ -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); } } diff --git a/port/alloc.c b/port/alloc.c index 54183d99a6de9a455bb3fd482400f6f4d7bec9b5..9aa3582bdce7ca667148d76460d01b546451a865 100644 --- a/port/alloc.c +++ b/port/alloc.c @@ -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; diff --git a/port/devcons.c b/port/devcons.c index dd51a613461cfdd32d270ab622258d476bac70f6..ff7150f2d84fda706165666c65423ea9851e5560 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -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*)ℴ - 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*)ℴ + 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*)ℴ + 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; +} diff --git a/port/devintrts.c b/port/devintrts.c index 6ff3551825355827dfdb416e05cb9c1ed3499fff..4c64d08202fedbe761aa566d5cabd93fb024ee49 100644 --- a/port/devintrts.c +++ b/port/devintrts.c @@ -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 */ diff --git a/port/devns16552.c b/port/devns16552.c index d7a1cc32d28d3b5644c1a1c5003f367e9383bfdf..4251c8cfa553ca20ed6a3e36f8542542ebeb2515 100644 --- a/port/devns16552.c +++ b/port/devns16552.c @@ -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){ diff --git a/port/devproc.c b/port/devproc.c index d2513173f5519d38e692e7adcfaf1910716dbc43..9721564371e864f3220d90e4b79a1cc36213a0c5 100644 --- a/port/devproc.c +++ b/port/devproc.c @@ -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) { diff --git a/port/portfns.h b/port/portfns.h index 30dd926b2c86531f1794530e5f370c4e6f5b1143..e49555b6533087168bf84148a17219f31f86402c 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -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); diff --git a/port/proc.c b/port/proc.c index c7ee02c77919f6230ef8d88251b0fc947aabcd70..dc38de3ced5c730fc3ef9158977fe0edb0aa8a8f 100644 --- a/port/proc.c +++ b/port/proc.c @@ -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; iwired; + if(wm && pp->pid) + nwired[wm->machno]++; + } + bm = 0; + for(i=0; iwired = 0; - pp = proctab(0); - for(i=0; iwired && pp->pid) - nwired[pp->wired->machno]++; - bm = 0; - for(i=0; iwired = MACHP(bm); p->movetime = 0xffffffff; p->mp = p->wired; diff --git a/port/sysproc.c b/port/sysproc.c index 0ebdf50cc9249b53fe221229ad44eea39beedc49..4d5c60f52f0490c4e87ddcc8c2ee82e8dc22619c 100644 --- a/port/sysproc.c +++ b/port/sysproc.c @@ -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;