From 690662798a0ea72bcba69698bf4edd1704e533f9 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 31 Mar 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-03-31 --- gnot/dat.h | 1 + gnot/devdk.c | 6 +++++- gnot/devincon.c | 14 +++----------- gnot/devpipe.c | 9 +++++++-- gnot/stream.c | 38 ++++++++++++++++++++++++++++++++++---- gnot/sturp.c | 3 ++- port/devkprof.c | 3 ++- port/stream.c | 36 +++++++++++++++++++++++++++++++++--- port/sturp.c | 3 ++- power/dat.h | 1 + 10 files changed, 90 insertions(+), 24 deletions(-) diff --git a/gnot/dat.h b/gnot/dat.h index 13c6b7fe9edaf1e6fdf626329fe84a0290a0a4c5..2433dd49d5927d4d4d198dcc745c9ec7da4e7132 100644 --- a/gnot/dat.h +++ b/gnot/dat.h @@ -408,6 +408,7 @@ struct Queue { struct Stream { Lock; /* structure lock */ int inuse; /* use count */ + int hread; /* number of reads after hangup */ int type; /* correclation with Chan */ int dev; /* ... */ int id; /* ... */ diff --git a/gnot/devdk.c b/gnot/devdk.c index 1596de189450dea05e4f4e24fae5c01c5ca15b3c..21d2438c162aff3b4835d70fc661023a220c809b 100644 --- a/gnot/devdk.c +++ b/gnot/devdk.c @@ -417,7 +417,11 @@ dkoput(Queue *q, Block *bp) bp->rptr[0] = line; bp->rptr[1] = line>>8; - PUTNEXT(dp->wq, bp); + if(dp->wq->len >= Streamhi){ + print("dkoput free\n"); + freeb(bp); + } else + PUTNEXT(dp->wq, bp); } /* diff --git a/gnot/devincon.c b/gnot/devincon.c index e7c7015a979339ca6f11b272726f6e02ea04bd2c..4b7a319720c68faa57521ca5e462028dae20595c 100644 --- a/gnot/devincon.c +++ b/gnot/devincon.c @@ -243,7 +243,7 @@ inconrestart(Incon *ip) break; case Selected: print("incon[%d] station %d\n", ip-incon, ip->station); - inconset(ip, 8, 9); + inconset(ip, 3, 15); break; default: print("incon[%d] bollixed\n", ip-incon); @@ -264,7 +264,7 @@ inconreset(void) incon[0].dev = INCON; incon[0].state = Selected; incon[0].ri = incon[0].wi = 0; -/* inconset(&incon[0], 8, 9); /**/ +/* inconset(&incon[0], 3, 15); /**/ for(i=1; iri != ip->wi){ bp = ip->inb[ip->ri]; n = BLEN(bp); - if(n <= 64){ - nbp = allocb(n); - memcpy(nbp->wptr, bp->rptr, n); - nbp->wptr += n; - freeb(bp); - PUTNEXT(ip->rq, nbp); - } else { - PUTNEXT(ip->rq, bp); - } + PUTNEXT(ip->rq, bp); bp = ip->inb[ip->ri] = allocb(Bsize); bp->wptr += 3; ip->ri = (ip->ri+1)%Nin; diff --git a/gnot/devpipe.c b/gnot/devpipe.c index 4e6b2cace5496d679cf69afd501d71f071fc28ff..0c027c00ccf05e6002a2537c26ba02f4cb9f6353 100644 --- a/gnot/devpipe.c +++ b/gnot/devpipe.c @@ -11,7 +11,7 @@ static void pipeiput(Queue*, Block*); static void pipeoput(Queue*, Block*); static void pipestclose(Queue *); -Qinfo pipeinfo = { pipeiput, pipeoput, 0, pipestclose, "process" }; +Qinfo pipeinfo = { pipeiput, pipeoput, 0, pipestclose, "pipe" }; void pipeinit(void) @@ -154,7 +154,8 @@ pipeerrstr(Error *e, char *buf) static void pipeiput(Queue *q, Block *bp) { - flowctl(q); + if(q->next->len >= Streamhi) + flowctl(q); PUTNEXT(q, bp); } @@ -168,6 +169,10 @@ pipeoput(Queue *q, Block *bp) lock(q); if(q->next) pipeiput(q->next, bp); + else{ + print("pipeoput losing block\n"); + freeb(bp); + } unlock(q); } diff --git a/gnot/stream.c b/gnot/stream.c index 349fcfa086fa6e2c468010e2a3f0f3d0b045c864..b92e43b9eb4f222ea743f3972f7b468dc31ff78b 100644 --- a/gnot/stream.c +++ b/gnot/stream.c @@ -58,9 +58,31 @@ Bclass bclass[Nclass]={ { 0 }, { 68 }, { 260 }, - { 4096 }, + { 1024 }, }; +/* + * Dump all block information of how many blocks are in which queues + */ +void +dumpqueues(void) +{ + Queue *q; + int count; + Block *bp; + + for(q = qlist; q < qlist + conf.nqueue; q++, q++){ + if(!(q->flag & QINUSE)) + continue; + for(count = 0, bp = q->first; bp; bp = bp->next) + count++; + print("%s %ux RD count %d len %d", q->info->name, q, count, q->len); + for(count = 0, bp = WR(q)->first; bp; bp = bp->next) + count++; + print(" WR count %d len %d\n", count, WR(q)->len); + } +} + /* * Allocate streams, queues, and blocks. Allocate n block classes with * 1/2(m+1) to class m < n-1 @@ -123,8 +145,11 @@ allocb(ulong size) lock(bcp); while(bcp->first == 0){ unlock(bcp); - if(loop++ > 10) + if(loop++ > 10){ + dumpqueues(); + dumpstack(); panic("waiting for blocks\n"); + } qlock(bcp); tsleep(&bcp->r, isblock, (void *)bcp, 250); qunlock(bcp); @@ -614,6 +639,7 @@ streamnew(Chan *c, Qinfo *qi) * hang a device and process q off the stream */ s->inuse = 1; + s->hread = 0; s->tag[0] = 0; q = allocq(&procinfo); s->procq = WR(q); @@ -825,8 +851,12 @@ streamread(Chan *c, void *vbuf, long n) while(left){ bp = getq(q); if(bp == 0){ - if(q->flag & QHUNGUP) - break; + if(q->flag & QHUNGUP){ + if(s->hread++ < 3) + break; + else + error(0, Ehungup); + } sleep(&q->r, &isinput, (void *)q); continue; } diff --git a/gnot/sturp.c b/gnot/sturp.c index 708e1717abd53e4a75dc4d7dc3e02ff05efcc7db..df558b40ef8db351dfa145226bb4e916416a39e0 100644 --- a/gnot/sturp.c +++ b/gnot/sturp.c @@ -63,7 +63,8 @@ struct Urp { int kstarted; }; -#define WINDOW(u) ((u->unechoed + u->maxout - u->next)%8) +#define WINDOW(u) ((u)->unechoed>(u)->next ? (u)->unechoed+(u)->maxout-(u)->next-8 :\ + (u)->unechoed+(u)->maxout-(u)->next) #define IN(x, f, n) (f<=n ? x>=f && x=f) #define NEXT(x) (((x)+1)&Nmask) diff --git a/port/devkprof.c b/port/devkprof.c index 282d84689d151c3b7d0e8782db75aad5b1c4af12..bf76eef63e35439700dc55daedf1104445641d84 100644 --- a/port/devkprof.c +++ b/port/devkprof.c @@ -162,5 +162,6 @@ kproftimer(ulong pc) pc -= KTZERO; pc >>= LRES; timerbuf[pc]++; - } + } else + timerbuf[1]++; } diff --git a/port/stream.c b/port/stream.c index 349fcfa086fa6e2c468010e2a3f0f3d0b045c864..2adeb5b1006b115080a69e0bf412dbd09f152ebe 100644 --- a/port/stream.c +++ b/port/stream.c @@ -61,6 +61,28 @@ Bclass bclass[Nclass]={ { 4096 }, }; +/* + * Dump all block information of how many blocks are in which queues + */ +void +dumpqueues(void) +{ + Queue *q; + int count; + Block *bp; + + for(q = qlist; q < qlist + conf.nqueue; q++, q++){ + if(!(q->flag & QINUSE)) + continue; + for(count = 0, bp = q->first; bp; bp = bp->next) + count++; + print("%s %ux RD count %d len %d", q->info->name, q, count, q->len); + for(count = 0, bp = WR(q)->first; bp; bp = bp->next) + count++; + print(" WR count %d len %d\n", count, WR(q)->len); + } +} + /* * Allocate streams, queues, and blocks. Allocate n block classes with * 1/2(m+1) to class m < n-1 @@ -123,8 +145,11 @@ allocb(ulong size) lock(bcp); while(bcp->first == 0){ unlock(bcp); - if(loop++ > 10) + if(loop++ > 10){ + dumpqueues(); + dumpstack(); panic("waiting for blocks\n"); + } qlock(bcp); tsleep(&bcp->r, isblock, (void *)bcp, 250); qunlock(bcp); @@ -614,6 +639,7 @@ streamnew(Chan *c, Qinfo *qi) * hang a device and process q off the stream */ s->inuse = 1; + s->hread = 0; s->tag[0] = 0; q = allocq(&procinfo); s->procq = WR(q); @@ -825,8 +851,12 @@ streamread(Chan *c, void *vbuf, long n) while(left){ bp = getq(q); if(bp == 0){ - if(q->flag & QHUNGUP) - break; + if(q->flag & QHUNGUP){ + if(s->hread++ < 3) + break; + else + error(0, Ehungup); + } sleep(&q->r, &isinput, (void *)q); continue; } diff --git a/port/sturp.c b/port/sturp.c index 708e1717abd53e4a75dc4d7dc3e02ff05efcc7db..df558b40ef8db351dfa145226bb4e916416a39e0 100644 --- a/port/sturp.c +++ b/port/sturp.c @@ -63,7 +63,8 @@ struct Urp { int kstarted; }; -#define WINDOW(u) ((u->unechoed + u->maxout - u->next)%8) +#define WINDOW(u) ((u)->unechoed>(u)->next ? (u)->unechoed+(u)->maxout-(u)->next-8 :\ + (u)->unechoed+(u)->maxout-(u)->next) #define IN(x, f, n) (f<=n ? x>=f && x=f) #define NEXT(x) (((x)+1)&Nmask) diff --git a/power/dat.h b/power/dat.h index f2e0896252969565f3ad8894d3fdbe303e1ae185..fc69ec4673dcc76013659c5cd042e0de53461268 100644 --- a/power/dat.h +++ b/power/dat.h @@ -425,6 +425,7 @@ struct Queue { struct Stream { Lock; /* structure lock */ int inuse; /* use count */ + int hread; /* number of reads after hangup */ int type; /* correclation with Chan */ int dev; /* ... */ int id; /* ... */