From 1d1f694ac63f5033ae6da6cd84e99d4ee491ef6d Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 6 Feb 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-02-06 --- port/devnonet.c | 84 +++++++++++++++++++++++------------------------- port/stnoether.c | 7 ++-- power/dat.h | 3 +- ss/dat.h | 1 - 4 files changed, 47 insertions(+), 48 deletions(-) diff --git a/port/devnonet.c b/port/devnonet.c index 39377a79cf914791401ce8f9c8bc685ab58e837c..0e2556c6b98047bf5039c0ce359b5f3ada83dc2e 100644 --- a/port/devnonet.c +++ b/port/devnonet.c @@ -8,6 +8,7 @@ #define DPRINT if(pnonet)print #define NOW (MACHP(0)->ticks*MS2HZ) +#define MSUCC(x) (((x)+1)%Nnomsg) static Noifc *noifc; int pnonet; @@ -501,9 +502,15 @@ noclose(Queue *q) } qlock(cp); + /* + * we give up, ack any unacked messages + */ + for(i = cp->first; i != cp->next; i = MSUCC(i)) + norack(cp, cp->out[i].mid); cp->rcvcircuit = -1; cp->state = Cclosed; qunlock(cp); + poperror(); } @@ -533,15 +540,7 @@ windowopen(void *a) Noconv *cp; cp = (Noconv *)a; - return cp->out[cp->next].inuse == 0; -} -static int -acked(void *a) -{ - Nomsg *mp; - - mp = (Nomsg *)a; - return mp->inuse; + return MSUCC(cp->next) != cp->first; } static void nooput(Queue *q, Block *bp) @@ -570,35 +569,26 @@ nooput(Queue *q, Block *bp) return; } - mp = 0; + /* + * block till we get an output buffer + */ if(waserror()){ - if(mp){ - q->len = 0; - q->first = q->last = 0; - if(mp->first){ - freeb(mp->first); - mp->first = 0; - } - mp->inuse = 0; - mp->acked = 0; - if(((cp->first+1)%Nnomsg) == cp->next) - cp->first = cp->next; - } + /* throw out the message */ + while(bp = getb(q)) + freeb(bp); qunlock(&cp->mlock); nexterror(); } - - /* - * block till we get a buffer - */ - while(cp->out[cp->next].inuse) + while(!windowopen(cp)) sleep(&cp->r, windowopen, cp); mp = &cp->out[cp->next]; - mp->inuse = 1; - cp->next = (cp->next+1)%Nnomsg; + cp->next = MSUCC(cp->next); + qlock(cp); + qunlock(&cp->mlock); + poperror(); /* - * stick the message in a Nomsg structure + * point the output buffer to the message */ mp->time = NOW + MSrexmit; mp->first = q->first; @@ -608,17 +598,27 @@ nooput(Queue *q, Block *bp) mp->acked = 0; /* - * init the queue for new messages + * take the message out of the queue */ - q->len = 0; + q->len = q->nb = 0; q->first = q->last = 0; cp->sent++; /* * send the message, the kproc will retry */ + if(waserror()){ + /* throw out the message */ + freeb(mp->first); + mp->first = 0; + mp->acked = 0; + if(MSUCC(cp->first) == cp->next) + cp->first = cp->next; + qunlock(cp); + nexterror(); + } nosend(cp, mp); - qunlock(&cp->mlock); + qunlock(cp); poperror(); } @@ -661,7 +661,6 @@ nostartconv(Noconv *cp, int circuit, char *raddr, int state) cp->out[i].mid = i | Nnomsg; cp->out[i].acked = 1; cp->out[i].rem = 0; - cp->out[i].inuse = 0; } cp->in[0].mid = Nnomsg; cp->in[0].acked = 0; @@ -927,11 +926,10 @@ norack(Noconv *cp, int mid) * free it */ cp->rexmit = 0; - mp->acked = 1; cp->lastacked = mid; + mp->acked = 1; freeb(mp->first); mp->first = 0; - mp->inuse = 0; /* * advance first if this is the first @@ -940,8 +938,9 @@ norack(Noconv *cp, int mid) while(cp->first != cp->next){ if(cp->out[cp->first].acked == 0) break; - cp->first = (cp->first+1) % Nnomsg; + cp->first = MSUCC(cp->first); } + wakeup(&cp->r); } } @@ -1403,19 +1402,18 @@ loop: * resend the first message */ if(cp->first!=cp->next && NOW>=cp->out[cp->first].time){ + mp = &(cp->out[cp->first]); if(cp->rexmit++ > 60){ - print("hanging up\n"); + norack(cp, mp->mid); nohangup(cp); - } else { - mp = &(cp->out[cp->first]); + } else nosend(cp, mp); - } } /* - * resend an acknowledge + * get the acknowledges out */ - if(cp->afirst != cp->anext){ + while(cp->afirst != cp->anext){ DPRINT("sending ack %d\n", cp->ack[cp->afirst]); nosendctl(cp, 0, 0); } diff --git a/port/stnoether.c b/port/stnoether.c index 00cbab2bc3268c72a7c7aa29f5832e3c8bd6704b..f1c99fb8f97cebaa8af8cb7e110bf9d6b116ed41 100644 --- a/port/stnoether.c +++ b/port/stnoether.c @@ -125,7 +125,9 @@ noetherbad(Noifc *ifc, Block *bp) * crack the packet header */ eh = (Etherhdr *)bp->rptr; - print("bad c %d m %d f %d\n", eh->circuit[0], eh->mid, eh->flag); + print("bad %.2ux%.2ux%.2ux%.2ux%.2ux%.2ux c %d m %d f %d\n", + eh->s[0], eh->s[1], eh->s[2], eh->s[3], eh->s[4], + eh->s[5], eh->circuit[0], eh->mid, eh->flag); if(eh->flag & NO_RESET) goto out; @@ -192,7 +194,8 @@ noetheriput(Queue *q, Block *bp) */ ep = &ifc->conv[conf.nnoconv]; for(cp = &ifc->conv[0]; cp < ep; cp++){ - if(circuit==cp->rcvcircuit && canqlock(cp)){ + if(circuit==cp->rcvcircuit){ + qlock(cp); ph = (Etherhdr *)(cp->media->rptr); if(circuit == cp->rcvcircuit && memcmp(ph->d, h->s, sizeof(h->s)) == 0){ diff --git a/power/dat.h b/power/dat.h index 775fb8a450fdc8585d97878eaaeb48dc8c6d0373..24892d78f0ad06c8de6962cc71480607f81a0e6e 100644 --- a/power/dat.h +++ b/power/dat.h @@ -533,7 +533,6 @@ struct Nohdr { */ struct Nomsg { Blist; - Rendez r; int mid; /* sequence number */ int rem; /* remaining */ ulong time; @@ -561,7 +560,7 @@ struct Noconv { QLock xlock; /* one trasmitter at a time */ Rendez r; /* process waiting for an output mid */ - QLock mlock; /* lock for out */ + QLock mlock; /* lock for allocating out messages */ Nomsg out[Nnomsg]; /* messages being sent */ int first; /* first unacknowledged message */ int next; /* next message buffer to use */ diff --git a/ss/dat.h b/ss/dat.h index 688565875d4df72f79cb730dab7e47682f868d28..4abf930cb17d24c8775e37904774e447dd4a27f8 100644 --- a/ss/dat.h +++ b/ss/dat.h @@ -547,7 +547,6 @@ struct Nohdr { */ struct Nomsg { Blist; - Rendez r; int mid; /* sequence number */ int rem; /* remaining */ ulong time;