From d477c0a1a355367a90d69c2f84bf4c00f3cdb612 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 1 Jan 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-01-01 --- gnot/fns.h | 1 + pc/devuart.c | 2 + pc/fns.h | 1 + port/chan.c | 12 ++++-- port/devip.c | 106 ++++++++++++++++++++++++++++++++++++++------------ port/stil.c | 10 +++-- port/stip.c | 49 ++++++++++++----------- port/stream.c | 2 +- power/fns.h | 1 + power/main.c | 4 +- ss/fns.h | 1 + ss/main.c | 10 ++--- ss/mmu.c | 19 ++++++--- 13 files changed, 148 insertions(+), 70 deletions(-) diff --git a/gnot/fns.h b/gnot/fns.h index 4668969b6dd93296e702b83a35f28a74963e75c0..d716717da3652788b8b76119c85f4efee3efdff8 100644 --- a/gnot/fns.h +++ b/gnot/fns.h @@ -60,3 +60,4 @@ int splduart(void); int tas(char*); void touser(void); #define waserror() (u->nerrlab++, setlabel(&u->errlab[u->nerrlab-1])) +#define kmapperm(x) kmap(x) diff --git a/pc/devuart.c b/pc/devuart.c index 9f7cc3a403c26ca22a56e3dc9ca5bee1e73fbb97..9c8836bd828d64a0379c1f616d8ee42818a4de7c 100644 --- a/pc/devuart.c +++ b/pc/devuart.c @@ -140,6 +140,8 @@ uartrts(Uart *up, int n) void uartbreak(Uart *up, int ms) { + if(ms == 0) + ms = 200; uartwrreg(up, Format, Break); tsleep(&u->p->sleep, return0, 0, ms); uartwrreg(up, Format, 0); diff --git a/pc/fns.h b/pc/fns.h index c80b7e93c360af94293cff5e36833aeabca23061..8d04c80a43d54ce727afaf8018eaa1ed176f38e6 100644 --- a/pc/fns.h +++ b/pc/fns.h @@ -62,3 +62,4 @@ void uartclock(void); void uartintr0(Ureg*); void vgainit(void); #define waserror() (u->nerrlab++, setlabel(&u->errlab[u->nerrlab-1])) +#define kmapperm(x) kmap(x) diff --git a/port/chan.c b/port/chan.c index 66ab35aeee0f372c19a4e4180d7654cd9fd807c9..e441d6a270acd7fe212e9fe1209ebca675e685a4 100644 --- a/port/chan.c +++ b/port/chan.c @@ -634,7 +634,7 @@ skipslash(char *name) return name; } -char isfrog[]={ +char isfrog[256]={ /*NUL*/ 1, 1, 1, 1, 1, 1, 1, 1, /*BKS*/ 1, 1, 1, 1, 1, 1, 1, 1, /*DLE*/ 1, 1, 1, 1, 1, 1, 1, 1, @@ -642,6 +642,10 @@ char isfrog[]={ [' '] 1, ['/'] 1, [0x7f] 1, +/*0x80+ NUL*/ 1, 1, 1, 1, 1, 1, 1, 1, + /*BKS*/ 1, 1, 1, 1, 1, 1, 1, 1, + /*DLE*/ 1, 1, 1, 1, 1, 1, 1, 1, + /*CAN*/ 1, 1, 1, 1, 1, 1, 1, 1, }; void @@ -651,7 +655,7 @@ nameok(char *elem) eelem = elem+NAMELEN; while(*elem) { - if((*elem&0x80) || isfrog[*elem]) + if(isfrog[*(uchar*)elem]) error(Ebadchar); elem++; if(elem >= eelem) @@ -681,8 +685,8 @@ nextelem(char *name, char *elem) end = e; } while(name < end){ - c = *name++; - if((c&0x80) || isfrog[c]) + c = *(uchar*)name++; + if(isfrog[c]) error(Ebadchar); *elem++ = c; } diff --git a/port/devip.c b/port/devip.c index d9f17437d690f07e26640606a437a6034c8aec52..2681e2f95f5373ddae8631e15878e5dfea0be397 100644 --- a/port/devip.c +++ b/port/devip.c @@ -683,14 +683,76 @@ tcpstclose(Queue *q) } -/* - * ptcl_csum - protcol checksum routine - */ +static short endian = 1; +static char* aendian = (char*)&endian; +#define LITTLE *aendian + +ushort +ptcl_bsum(uchar *addr, int len) +{ + ulong losum, hisum, mdsum, x; + ulong t1, t2; + + losum = 0; + hisum = 0; + mdsum = 0; + + x = 0; + if((ulong)addr & 1) { + if(len) { + hisum += addr[0]; + len--; + addr++; + } + x = 1; + } + while(len >= 16) { + t1 = *(ushort*)(addr+0); + t2 = *(ushort*)(addr+2); mdsum += t1; + t1 = *(ushort*)(addr+4); mdsum += t2; + t2 = *(ushort*)(addr+6); mdsum += t1; + t1 = *(ushort*)(addr+8); mdsum += t2; + t2 = *(ushort*)(addr+10); mdsum += t1; + t1 = *(ushort*)(addr+12); mdsum += t2; + t2 = *(ushort*)(addr+14); mdsum += t1; + mdsum += t2; + len -= 16; + addr += 16; + } + while(len >= 2) { + mdsum += *(ushort*)addr; + len -= 2; + addr += 2; + } + if(x) { + if(len) + losum += addr[0]; + if(LITTLE) + losum += mdsum; + else + hisum += mdsum; + } else { + if(len) + hisum += addr[0]; + if(LITTLE) + hisum += mdsum; + else + losum += mdsum; + } + + losum += hisum >> 8; + losum += (hisum & 0xff) << 8; + while(hisum = losum>>16) + losum = hisum + (losum & 0xffff); + + return losum & 0xffff; +} + ushort ptcl_csum(Block *bp, int offset, int len) { uchar *addr; - ulong losum = 0, hisum = 0; + ulong losum, hisum; ushort csum; int odd, blen, x; @@ -704,26 +766,24 @@ ptcl_csum(Block *bp, int offset, int len) addr = bp->rptr + offset; blen = BLEN(bp) - offset; + + if(bp->next == 0) + return ~ptcl_bsum(addr, MIN(len, blen)) & 0xffff; + + losum = 0; + hisum = 0; + odd = 0; while(len) { - if(odd) { - losum += *addr++; - blen--; - len--; - odd = 0; - } - for(x = MIN(len, blen); x > 1; x -= 2) { - hisum += addr[0]; - losum += addr[1]; - len -= 2; - blen -= 2; - addr += 2; - } - if(blen && x) { - odd = 1; - hisum += addr[0]; - len--; - } + x = MIN(len, blen); + csum = ptcl_bsum(addr, x); + if(odd) + hisum += csum; + else + losum += csum; + odd = (odd+x) & 1; + len -= x; + bp = bp->next; if(bp == 0) break; @@ -736,8 +796,6 @@ ptcl_csum(Block *bp, int offset, int len) while((csum = losum>>16) != 0) losum = csum + (losum & 0xffff); - losum &= 0xffff; - return ~losum & 0xffff; } diff --git a/port/stil.c b/port/stil.c index f4ef04279719790ad870cb078b5bfaf646595185..36f8bc5ca3f97ffff72a3f164771af06793a6948 100644 --- a/port/stil.c +++ b/port/stil.c @@ -465,13 +465,15 @@ ilrexmit(Ilcb *ic) Block *nb; Ilhdr *h; - if(ic->unacked == 0) - return; - + nb = 0; qlock(&ic->ackq); - nb = copyb(ic->unacked, blen(ic->unacked)); + if(ic->unacked) + nb = copyb(ic->unacked, blen(ic->unacked)); qunlock(&ic->ackq); + if(nb == 0) + return; + h = (Ilhdr*)nb->rptr; DBG("rxmit %d.", nhgetl(h->ilid)); diff --git a/port/stip.c b/port/stip.c index 8fa87975d657e2bb4e02a9336e199114dcc91f88..ec381a3ce6b6b524782605c1120289cc80dfc602 100644 --- a/port/stip.c +++ b/port/stip.c @@ -389,19 +389,23 @@ ip_reassemble(int offset, Block *bp, Etherhdr *ip) Ipaddr src, dst; ushort id; Block *bl, **l, *last, *prev; - int ovlap, len, fragsize; + int ovlap, len, fragsize, pktposn; src = nhgetl(ip->src); dst = nhgetl(ip->dst); id = nhgets(ip->id); + qlock(&fraglock); for(f = flisthead; f; f = f->next) { - if(f->src == src && f->dst == dst && f->id == id) + if(f->src == src) + if(f->dst == dst) + if(f->id == id) break; } + qunlock(&fraglock); if(!ip->tos && (offset & ~(IP_MF|IP_DF)) == 0) { - if(f) { + if(f != 0) { qlock(f); ipfragfree(f); } @@ -415,10 +419,6 @@ ip_reassemble(int offset, Block *bp, Etherhdr *ip) /* First fragment allocates a reassembly queue */ if(f == 0) { f = ipfragallo(); - if(f == 0) { - freeb(bp); - return 0; - } qlock(f); f->id = id; f->src = src; @@ -475,17 +475,18 @@ ip_reassemble(int offset, Block *bp, Etherhdr *ip) } } - /* Now look for a completed queue */ + pktposn = 0; for(bl = f->blist; bl; bl = bl->next) { + if(BLKFRAG(bl)->foff != pktposn) + break; if((BLKIP(bl)->frag[0]&(IP_MF>>8)) == 0) goto complete; - if(bl->next == 0 || - BLKFRAG(bl)->foff+BLKFRAG(bl)->flen != BLKFRAG(bl->next)->foff) - break; + + pktposn += BLKFRAG(bl)->flen; } qunlock(f); return 0; - + complete: bl = f->blist; last = bl; @@ -519,16 +520,13 @@ complete: void ipfragfree(Fragq *frag) { - Block *f, *next; Fragq *fl, **l; - for(f = frag->blist; f; f = next) { - next = f->next; - freeb(f); - } + freeb(frag->blist); frag->src = 0; frag->id = 0; + frag->blist = 0; qunlock(frag); qlock(&fraglock); @@ -546,8 +544,6 @@ ipfragfree(Fragq *frag) fragfree = frag; qunlock(&fraglock); - - } /* @@ -559,20 +555,23 @@ ipfragallo(void) Fragq *f; qlock(&fraglock); - if(!fragfree) { - qunlock(&fraglock); - print("ipfragallo: no queue\n"); - return 0; + while(fragfree == 0) { + for(f = flisthead; f; f = f->next) + if(canqlock(f)) { + qunlock(&fraglock); + ipfragfree(f); + break; + } + qlock(&fraglock); } f = fragfree; fragfree = f->next; f->next = flisthead; flisthead = f; - f->age = TK2MS(MACHP(0)->ticks)/1000 + 600; + f->age = TK2MS(MACHP(0)->ticks) + 30000; qunlock(&fraglock); return f; - } /* diff --git a/port/stream.c b/port/stream.c index 6d211e6f5a9d580fbed3c6b0f84815caae2178ca..77acf7489a27d4fe35623fef8d8e6f7607e5c110 100644 --- a/port/stream.c +++ b/port/stream.c @@ -116,7 +116,7 @@ newblock(Bclass *bcp) uchar *cp; page = newpage(1, 0, 0); - page->va = VA(kmap(page)); + page->va = VA(kmapperm(page)); if(bcp == bclass){ /* * create some level zero blocks and return diff --git a/power/fns.h b/power/fns.h index 6d9749bc80ad53ec1061839ea2be0fe4ef483d11..3d71f263983cca0beefe293c8c56361d5d73f5fb 100644 --- a/power/fns.h +++ b/power/fns.h @@ -69,3 +69,4 @@ void vector80(void); void vmereset(void); void wbflush(void); #define waserror() setlabel(&u->errlab[u->nerrlab++]) +#define kmapperm(x) kmap(x) diff --git a/power/main.c b/power/main.c index 6acba6103c0aab7e9d5e87832aaf827bab07582d..d22b5dd1e4e8b02bdbd72394dcd93d4c884d54b9 100644 --- a/power/main.c +++ b/power/main.c @@ -561,7 +561,7 @@ confinit(void) * set minimal default values */ conf.nmach = 1; - conf.nproc = 32; + conf.nproc = 100; conf.npgrp = conf.nproc / 4; conf.npgenv = 4 * conf.npgrp; conf.nenv = 4 * conf.nproc; @@ -578,7 +578,7 @@ confinit(void) conf.nstream = 2 * conf.nproc; conf.nalarm = 500; conf.nmount = 500; - conf.nsrv = 3; + conf.nsrv = 20; conf.nnoifc = 1; conf.nnoconv = 32; conf.nurp = 25; diff --git a/ss/fns.h b/ss/fns.h index 6682682b8d687c02b85459853819d9f1370f2fe5..b8708f2bf0206177b70635bb0b67abd2f5356b6f 100644 --- a/ss/fns.h +++ b/ss/fns.h @@ -25,6 +25,7 @@ void kbdrepeat(int); KMap* kmap(Page*); void kmapinit(void); KMap* kmappa(ulong, ulong); +KMap* kmapperm(Page*); int kprint(char*, ...); void kproftimer(ulong); void kunmap(KMap*); diff --git a/ss/main.c b/ss/main.c index e17f1972df90238cd0b401352b5b48354f6ce273..ffd172585b2df0a0df6d8ad5583d50fa00769718 100644 --- a/ss/main.c +++ b/ss/main.c @@ -51,7 +51,7 @@ intrinit(void) { KMap *k; - k = kmappa(INTRREG, PTEIO); + k = kmappa(INTRREG, PTEIO|PTENOCACHE); intrreg = (uchar*)k->va; } @@ -259,10 +259,10 @@ lancesetup(Lance *lp) ulong pa, pte, va; int i, j; - k = kmappa(ETHER, PTEIO); + k = kmappa(ETHER, PTEIO|PTENOCACHE); lp->rdp = (void*)(k->va+0); lp->rap = (void*)(k->va+2); - k = kmappa(EEPROM, PTEIO); + k = kmappa(EEPROM, PTEIO|PTENOCACHE); cp = (uchar*)(k->va+0x7da); for(i=0; i<6; i++) lp->ea[i] = *cp++; @@ -280,7 +280,7 @@ lancesetup(Lance *lp) */ pa = (ulong)ialloc(BY2PG, 1)&~KZERO; /* one whole page */ /* map at LANCESEGM */ - k = kmappa(pa, PTEMAINMEM); + k = kmappa(pa, PTEMAINMEM|PTENOCACHE); lp->lanceram = (ushort*)k->va; lp->lm = (Lancemem*)k->va; @@ -294,7 +294,7 @@ lancesetup(Lance *lp) pa = (ulong)ialloc(i*BY2PG, 1)&~KZERO; va = 0; for(j=i-1; j>=0; j--){ - k = kmappa(pa+j*BY2PG, PTEMAINMEM); + k = kmappa(pa+j*BY2PG, PTEMAINMEM|PTENOCACHE); if(va){ if(va != k->va+BY2PG) panic("lancesetup va unordered"); diff --git a/ss/mmu.c b/ss/mmu.c index dd325eece6ca01a2bd8d0029cd1035cd11bd1d30..c4561804eda67332f6207fd0e6b0a2abeb808ae3 100644 --- a/ss/mmu.c +++ b/ss/mmu.c @@ -341,20 +341,29 @@ kmappa(ulong pa, ulong flag) kmapalloc.free = k->next; unlock(&kmapalloc); k->pa = pa; + s = splhi(); + putpmeg(k->va, PPN(pa)|PTEVALID|PTEKERNEL|PTEWRITE|flag); + splx(s); + return k; +} + +KMap* +kmap(Page *pg) +{ /* * Cache is virtual and a pain to deal with. * Must avoid having the same entry in the cache twice, so * must use NOCACHE or else extreme cleverness elsewhere. */ - s = splhi(); - putpmeg(k->va, PPN(pa)|PTEVALID|PTEKERNEL|PTEWRITE|PTENOCACHE|flag); - splx(s); - return k; + return kmappa(pg->pa, PTEMAINMEM|PTENOCACHE); } KMap* -kmap(Page *pg) +kmapperm(Page *pg) { + /* + * Here we know it's a permanent entry and can be cached. + */ return kmappa(pg->pa, PTEMAINMEM); }