From 4ab17bda7b8be961e15296746a1f0bc3edda0ee5 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 20 Mar 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-03-20 --- gnot/dat.h | 2 +- gnot/devincon.c | 99 +++++++++++++++++++++++++++++-------------------- gnot/main.c | 11 +++--- gnot/screen.c | 2 +- gnot/sturp.c | 32 +++++++--------- 5 files changed, 80 insertions(+), 66 deletions(-) diff --git a/gnot/dat.h b/gnot/dat.h index ca74d0139ff1241c766bf88a8cc60c9662b61f59..0e448613d366161de393a479513917a8d0e4acf6 100644 --- a/gnot/dat.h +++ b/gnot/dat.h @@ -432,7 +432,7 @@ enum { Sdataqid = Shighqid, Sctlqid = Sdataqid-1, Slowqid = Sctlqid, - Streamhi= (32*1024), /* stream high water mark */ + Streamhi= (8*1024), /* stream high water mark */ }; #define PRINTSIZE 256 diff --git a/gnot/devincon.c b/gnot/devincon.c index afa5add509c90c5e0d2da47962b13987ecd9e70f..a07aa4c87a1e0820b2d45765293787d07238a9ce 100644 --- a/gnot/devincon.c +++ b/gnot/devincon.c @@ -7,6 +7,7 @@ #include "devtab.h" #include "io.h" +#include "ureg.h" typedef struct Incon Incon; typedef struct Device Device; @@ -22,7 +23,8 @@ enum { Minstation= 2, /* lowest station # to poll */ Maxstation= 15, /* highest station # to poll */ Nincon= 1, /* number of incons */ - Nin= 32, /* size of raw input buffer */ + Nin= 16, /* Blocks in the input ring */ + Bsize= 128, /* size of an input ring block */ }; /* @@ -522,9 +524,7 @@ inconoput(Queue *q, Block *bp) n = 16; size = n; dev->cdata = chan; - DPRINT("CH|%uo->\n", chan); while(n--){ - DPRINT("->%uo\n", *bp->rptr); *(uchar *)&dev->data_cntl = *bp->rptr++; } @@ -554,13 +554,13 @@ inconoput(Queue *q, Block *bp) if(ctl){ if(size >= 16){ dev->cdata = 0; - DPRINT("CH|%uo->\n", chan); + MICROSECOND; dev->cdata = chan; + MICROSECOND; } - DPRINT("CTL|%uo->\n", ctl); dev->cdata = ctl; - MICROSECOND; } + MICROSECOND; dev->cdata = 0; qunlock(&ip->xmit); @@ -596,7 +596,7 @@ inconkproc(void *arg) * create a number of blocks for input */ for(i = 0; i < Nin; i++){ - bp = ip->inb[i] = allocb(128); + bp = ip->inb[i] = allocb(Bsize); bp->wptr += 3; } @@ -622,7 +622,7 @@ inconkproc(void *arg) */ while(ip->ri != ip->wi){ PUTNEXT(ip->rq, ip->inb[ip->ri]); - bp = ip->inb[ip->ri] = allocb(128); + bp = ip->inb[ip->ri] = allocb(Bsize); bp->wptr += 3; ip->ri = (ip->ri+1)%Nin; } @@ -639,10 +639,13 @@ droppacket(Device *dev) int i; int c; - for(i = 0; i < 17; i++){ - c = dev->data_cntl; - if(c==0) - break; + screenputc('!'); + while(!(dev->status & RCV_EMPTY)){ + for(i = 0; i < 17; i++){ + c = dev->data_cntl; + if(c==0) + break; + } } } @@ -655,16 +658,19 @@ static Block * nextin(Incon *ip, unsigned int c) { Block *bp = ip->inb[ip->wi]; + int next; + next = (ip->wi+1)%Nin; + if(next == ip->ri){ + bp->wptr = bp->base+3; + droppacket(ip->dev); + return 0; + } bp->base[0] = ip->chan; bp->base[1] = ip->chan>>8; bp->base[2] = c; - ip->wi = (ip->wi + 1) % Nin; + ip->wi = next; - if(((ip->wi+1)%Nin) == ip->ri){ - droppacket(ip->dev); - return 0; - } return ip->inb[ip->wi]; } @@ -678,26 +684,28 @@ rdpackets(Incon *ip) Block *bp; unsigned int c; Device *dev; + uchar *p; + int first = ip->wi; dev = ip->dev; + bp = ip->inb[ip->wi]; + if(bp==0){ + droppacket(ip->dev); + goto done; + } + p = bp->wptr; while(!(dev->status & RCV_EMPTY)){ - bp = ip->inb[ip->wi]; - if(((ip->wi+1)%Nin) == ip->ri || bp==0){ - c = dev->data_cntl; - droppacket(dev); - continue; - } - /* * get channel number */ c = (dev->data_cntl)>>8; - DPRINT("<-CH|%uo\n", c); if(ip->chan != c){ - if(bp->wptr - bp->rptr > 3){ + if(p - bp->rptr > 3){ + bp->wptr = p; bp = nextin(ip, 0); if(bp == 0) - continue; + goto done; + p = bp->wptr; } ip->chan = c; } @@ -710,28 +718,39 @@ rdpackets(Incon *ip) /* * data byte, put in local buffer */ - c = *bp->wptr++ = c>>8; - DPRINT("<-%uo\n", c); - if(bp->wptr >= bp->lim){ - bp = nextin(ip, 0); - if(bp == 0) - continue; - } + *p++ = c>>8; } else if (c>>=8) { /* * control byte ends block */ - DPRINT("<-CTL|%uo\n", c); + bp->wptr = p; bp = nextin(ip, c); if(bp == 0) - continue; + goto done; + p = bp->wptr; } else { /* end of packet */ break; } } - } - wakeup(&ip->kr); + + /* + * pass a block on if it doesn't have room for one more + * packet. this way we don't have to check per byte. + */ + if(p + 16 > bp->lim){ + bp->wptr = p; + bp = nextin(ip, 0); + if(bp == 0) + goto done; + p = bp->wptr; + } + } + bp->wptr = p; + +done: + if(first != ip->wi)/**/ + wakeup(&ip->kr); } /* @@ -754,11 +773,11 @@ inconintr(Ureg *ur) /* check for exceptional conditions */ if(status&(OVERFLOW|CRC_ERROR)){ if(status&OVERFLOW){ - print("incon overflow\n"); + screenputc('^'); ip->overflow++; } if(status&CRC_ERROR){ - print("incon crc error\n"); + screenputc('+'); ip->crc++; } } diff --git a/gnot/main.c b/gnot/main.c index 6faf5925c7df169cfa2739e0bdd21f4015528a9f..62bf54e6035a1a7d4b5c58d3226a2b30ad93ed91 100644 --- a/gnot/main.c +++ b/gnot/main.c @@ -23,7 +23,6 @@ void unloadboot(void); void main(void) { - Lock l; unloadboot(); machinit(); mmuinit(); @@ -69,12 +68,12 @@ mmuinit(void) for(l=0; l<4*1024*1024; l+=BY2PG) putmmu(l, INVALIDPTE); /* - * Two meg of usable memory + * Four meg of usable memory, with top 256K for screen */ - for(i=1,l=KTZERO; i<2*1024*1024/BY2PG; l+=BY2PG,i++) + for(i=1,l=KTZERO; i<(4*1024*1024-256*1024)/BY2PG; l+=BY2PG,i++) putkmmu(l, PPN(l)|PTEVALID|PTEKERNEL); /* - * Screen at two meg + * Screen at top of memory */ for(i=0,d=DISPLAYRAM; i<256*1024/BY2PG; d+=BY2PG,l+=BY2PG,i++) putkmmu(l, PPN(d)|PTEVALID|PTEKERNEL); @@ -234,9 +233,9 @@ confinit(void) conf.nmach = 1; if(conf.nmach > MAXMACH) panic("confinit"); - conf.nproc = 15; + conf.nproc = 32; conf.npgrp = 15; - conf.npage = (2*1024*1024)/BY2PG; + conf.npage = (4*1024*1024-256*1024)/BY2PG; conf.npte = 500; conf.nmod = 50; conf.nalarm = 1000; diff --git a/gnot/screen.c b/gnot/screen.c index 1a078314d9893873cb2c6ebee35098c456fa65b2..b03284017f4743d3f5752b1c4b3f007a15be29c6 100644 --- a/gnot/screen.c +++ b/gnot/screen.c @@ -18,7 +18,7 @@ struct{ Bitmap screen = { - (ulong*)(2*1024*1024|KZERO), /* BUG */ + (ulong*)((4*1024*1024-256*1024)|KZERO), /* BUG */ 0, 64, 0, diff --git a/gnot/sturp.c b/gnot/sturp.c index 70382de704fd090fd8491fcc5cfa92535136af55..8064d1a53ca81a094c6d421135b81aaa91f53abd 100644 --- a/gnot/sturp.c +++ b/gnot/sturp.c @@ -123,8 +123,6 @@ urpopen(Queue *q, Stream *s) int i; char name[128]; - DPRINT("urpopen\n"); - /* * find a free urp structure */ @@ -200,13 +198,11 @@ urpclose(Queue *q) i = 7; rcvack(up, ECHO+i); qunlock(&up->xmit); - DPRINT("urpclose(%ux)\n", up); /* * kill off the kernel process */ wakeup(&up->rq->r); - DPRINT("urpclosed(%ux)\n", up); } /* @@ -381,7 +377,7 @@ urpiput(Queue *q, Block *bp) case 0: break; case ENQ: - print("rENQ %uo %uo\n", up->lastecho, ACK+up->iseq); + DPRINT("rENQ %uo %uo\n", up->lastecho, ACK+up->iseq); urpstat.enqsr++; sendctl(up, up->lastecho); sendctl(up, ACK+up->iseq); @@ -422,7 +418,7 @@ urpiput(Queue *q, Block *bp) case REJ+0: case REJ+1: case REJ+2: case REJ+3: case REJ+4: case REJ+5: case REJ+6: case REJ+7: - print("rREJ\n"); + DPRINT("rREJ\n"); rcvack(up, ctl); break; @@ -445,20 +441,24 @@ urpiput(Queue *q, Block *bp) if(up->trx != 3){ urpstat.rjtrs++; flushinput(up); - print("sREJ1 %d\n", up->iseq); - sendctl(up, up->lastecho = REJ+up->iseq); + DPRINT("sREJ1 %d\n", up->iseq); + if((up->lastecho&~7)==ECHO) + sendctl(up, up->lastecho = REJ+up->iseq);/**/ break; } else if(q->len != up->trbuf[1] + (up->trbuf[2]<<8)){ urpstat.rjpks++; + DPRINT("sREJ2 %d %d %d\n", up->iseq, q->len, + up->trbuf[1] + (up->trbuf[2]<<8)); flushinput(up); - print("sREJ2 %d\n", up->iseq); - sendctl(up, up->lastecho = REJ+up->iseq); + if((up->lastecho&~7)==ECHO) + sendctl(up, up->lastecho = REJ+up->iseq);/**/ break; } else if(i != ((up->iseq+1)&Nmask)) { urpstat.rjseq++; flushinput(up); - print("sREJ3 %d %d\n", i, up->iseq); - sendctl(up, up->lastecho = REJ+up->iseq); + DPRINT("sREJ3 %d %d\n", i, up->iseq); + if((up->lastecho&~7)==ECHO) + sendctl(up, up->lastecho = REJ+up->iseq);/**/ break; } @@ -481,8 +481,7 @@ urpiput(Queue *q, Block *bp) * acknowledge receipt */ if(q->next->len < Streamhi){ - sendctl(up, ECHO+i); - up->lastecho = ECHO+i; + sendctl(up, up->lastecho = ECHO+i); wakeup(&up->rq->r); } up->iseq = i; @@ -510,7 +509,6 @@ urpctloput(Urp *up, Queue *q, Block *bp) outwin = strtoul(fields[0], 0, 0); } /* initinput(up, inwin); */ - DPRINT("initoutput %d\n", outwin); initoutput(up, outwin); freeb(bp); return; @@ -596,7 +594,7 @@ output(Urp *up) * if a retransmit time has elapsed since a transmit, send an ENQ */ if(up->unechoed != up->next && NOW > up->timer){ - print("sENQ\n"); + DPRINT("sENQ\n"); up->timer = NOW + MSrexmit; up->state &= ~REJECTING; sendctl(up, ENQ); @@ -826,7 +824,6 @@ urpkproc(void *arg) Urp *up; up = (Urp *)arg; - DPRINT("urpkproc started\n"); for(;;){ if(up->state & (HUNGUP|CLOSING)){ @@ -840,7 +837,6 @@ urpkproc(void *arg) output(up); tsleep(&up->rq->r, todo, up, MSrexmit/2); } - DPRINT("urpkproc exiting %ux\n", up); up->kstarted = 0; up->state = 0; }