From 15dbd11a73043027299fb69fa893f469665166c4 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 22 Oct 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-10-22 --- port/devcons.c | 3 +++ port/devenv.c | 41 ++++++++++++++++++++++++++++++++++++++++- port/stil.c | 36 +++++++++++++++++++++--------------- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/port/devcons.c b/port/devcons.c index bb20ddeeb1d32052a79c591b8b918a2344f53723..1bf4f8fe9f06119c317b44511f04182256b7a4ac 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -225,6 +225,9 @@ echo(int c) switch(c){ case 0x14: break; /* pass it on */ + case 'e': + envdump(); + return; case 'm': mntdump(); return; diff --git a/port/devenv.c b/port/devenv.c index b7dc325ead031a36d32201e3caa21c640734267d..9d215c8f14b72d1385f455b9a77fb5e23846d247 100644 --- a/port/devenv.c +++ b/port/devenv.c @@ -28,6 +28,7 @@ struct Envval *free[EVFREE+1]; char *block; /* the free page we are allocating from */ char *lim; /* end of block */ + int npage; /* total pages gotten from newpage() */ }envalloc; QLock evlock; @@ -366,9 +367,10 @@ evalloc(ulong n) b += ALIGN + sizeof *ev; } b = (char*)VA(kmap(newpage(0, 0, 0))); + envalloc.npage++; envalloc.lim = b + BY2PG; } - + ev = (Envval*)b; ev->val = b + sizeof *ev; ev->ref = 1; @@ -400,6 +402,43 @@ evfree(Envval *ev) envalloc.free[n] = ev; } +void +envdump(void) +{ + Envval *ev; + int i, j; + + qlock(&evlock); + print("pages allocated: %d\n", envalloc.npage); + print("bytes left in page: %d\n", envalloc.lim - envalloc.block); + for(i = 0; i < EVFREE + 1; i++){ + j = 0; + if(i == EVFREE) + print("big blocks:\n"); + else + print("%d byte blocks:\n", (i + 1) * ALIGN); + for(ev = envalloc.free[i]; ev; ev = ev->next){ + if(j++ == 1000){ + print("circular\n"); + break; + } + if(j < 10) + print("\tenv %d %lux n%lux p%lux r%d\n", + ev->len, ev, ev->next, ev->prev, ev->ref); + } + } + for(i = 0; i < EVHASH; i++){ + j = 0; + for(ev = evhash[i].next; ev; ev = ev->next){ + if(j++ == 1000){ + print("hash bucket %d circular\n", i); + break; + } + } + } + qunlock(&evlock); +} + /* * to let the kernel set environment variables */ diff --git a/port/stil.c b/port/stil.c index 8c0f732fc353aeabc9c8edf5737682dc216e4352..7962f033de43761b2277ac5550a8c9fdee2f3be1 100644 --- a/port/stil.c +++ b/port/stil.c @@ -19,7 +19,9 @@ char *ilstate[] = { "Closed", "Syncer", "Syncee", "Established", "Listening", "C void ilrcvmsg(Ipconv*, Block*); void ilackproc(void*); -void ilsendctl(Ipconv *, Ilhdr *, int); +void ilsendctl(Ipconv*, Ilhdr*, int, int); +void ilackq(Ilcb*, Block*); +void ilprocess(Ipconv*, Ilhdr*, Block*); void ilopen(Queue *q, Stream *s) @@ -127,7 +129,7 @@ iloput(Queue *q, Block *bp) } void -ilackq(Ilctl *ic, Block *bp) +ilackq(Ilcb *ic, Block *bp) { Block *np; @@ -148,7 +150,7 @@ ilackq(Ilctl *ic, Block *bp) } void -ilackto(Ilctl *ic, ulong ackto) +ilackto(Ilcb *ic, ulong ackto) { Ilhdr *h; Block *bp; @@ -157,7 +159,7 @@ ilackto(Ilctl *ic, ulong ackto) lock(ic); if(ic->unacked) { h = (Ilhdr *)ic->unacked->rptr; - if(ackto < hngetl(h->ilack)) { + if(ackto < nhgetl(h->ilack)) { unlock(ic); break; } @@ -184,7 +186,8 @@ ilrcvmsg(Ipconv *ipc, Block *bp) { Ilhdr *ih; int plen; - Ipconv *s; + Ipconv *s, *etab; + short sp, dp; ih = (Ilhdr *)bp; @@ -197,43 +200,46 @@ ilrcvmsg(Ipconv *ipc, Block *bp) goto drop; } + sp = nhgets(ih->ildst); + dp = nhgets(ih->ilsrc); etab = &ipc[conf.ip]; for(s = ipc; s < etab; s++) { - if(s->sport == ih->ildst && s->dport == ih->ilsrc) { + if(s->psrc == sp && s->pdst == dp) { ilprocess(s, ih, bp); return; } } for(s = ipc; s < etab; s++) { - if(s->state == Illistening && s->sport == 0) { + if(s->ilctl.state == Illistening && s->psrc == 0) { /* Do the listener stuff */ ilprocess(s, ih, bp); return; } } - ilsendctl(0, ih, Ilreset); + ilsendctl(0, ih, Ilreset, 0); +drop: freeb(bp); } void -ilprocess(Ipconv *s, Ihdr *h, Block *bp) +ilprocess(Ipconv *s, Ilhdr *h, Block *bp) { switch(s->ilctl.state) { case Ilclosed: case Ilclosing: - case Illistener: + case Illistening: error(Ehungup); } - switch(h->type) { + switch(h->iltype) { case Ilsync: if(s->ilctl.state == Ilsync) s->ilctl.state = Ilestablished; freeb(bp); break; case Ilack: - ilackto(&s->ilctl, hngetl(g->ilack)); + ilackto(&s->ilctl, nhgetl(h->ilack)); freeb(bp); break; case Ilquerey: @@ -242,12 +248,12 @@ ilprocess(Ipconv *s, Ihdr *h, Block *bp) break; case Ildataquery: case Ildata: - ilackto(&s->ilctl, hngetl(h->ilack)); + ilackto(&s->ilctl, nhgetl(h->ilack)); bp->rptr += IL_EHSIZE+IL_HDRSIZE; PUTNEXT(s->readq, bp); break; case Ilreset: - s->ilctl.state = Closed; + s->ilctl.state = Ilclosed; freeb(bp); } } @@ -324,7 +330,7 @@ ilstart(Ipconv *ipc, int type, int window) break; case IL_ACTIVE: ic->state = Ilsyncer; - ilsendctl(ipc, 0, Ilsync); + ilsendctl(ipc, 0, Ilsync, 1); break; }