From 7fb9b011ed8bcc683dd44e23cb48e1986c29dc71 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 2 Aug 1997 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1997-08-02 --- ip/il.c | 100 ++++++++++++++++++++----------------------------------- ip/tcp.c | 2 +- 2 files changed, 38 insertions(+), 64 deletions(-) diff --git a/ip/il.c b/ip/il.c index f1edc7539081940dd367453c0da1a8841ca5746e..6b624bb4b14dcc7379ef946fff0f83b29e69265a 100644 --- a/ip/il.c +++ b/ip/il.c @@ -74,11 +74,10 @@ struct Ilcb /* Control block */ int delay; /* Average of the fixed rtt delay */ int rate; /* Average byte rate */ int mdev; /* Mean deviation of rtt */ + int maxrtt; /* largest rtt seen */ ulong rttack; /* The ack we are waiting for */ int rttlen; /* Length of rttack packet */ ulong rttms; /* Time we issued rttack packet */ - int lrtt; /* Last rtt seen */ - int lrttlen; /* Length of the packet lrtt is for */ int window; /* Maximum receive window */ int rexmit; char buf[128]; @@ -125,8 +124,8 @@ enum Ackkeepalive = 6000*Iltickms, Acktime = 2*Iltickms, /* max time twixt message rcvd & ack sent */ - Slowtime = 90*Seconds, /* min time waiting for an ack before hangup */ - Fasttime = 4*Iltickms, /* min time between rexmit */ + Slowtime = 90*Seconds, /* max time waiting for an ack before hangup */ + Fasttime = 4*Seconds, /* max time between rexmit */ Querytime = 5*Seconds, /* time between subsequent queries */ Keepalivetime = 60*Seconds, /* time before first query */ Deathtime = 120*Seconds, /* time between first query and hangup */ @@ -136,7 +135,7 @@ enum AGain = 1<state == Ilclosed) isclose = 1; - sprint(ic->buf, "%s del %d Br %d md %d una %d rex %d", ilstates[ic->state], + sprint(ic->buf, "%s del %d Br %d md %d una %d rex %d max %d", ilstates[ic->state], ic->delay>>LogAGain, ic->rate>>LogAGain, ic->mdev>>LogDGain, - ic->unackedbytes, ic->rexmit); + ic->unackedbytes, ic->rexmit, ic->maxrtt); *msg = ic->buf; return isclose; } @@ -369,75 +368,45 @@ ilinitrtt(Ilcb *ic) ic->delay = Iltickms<mdev = Iltickms<rate = DefByteRate<lrtt = 0; - ic->lrttlen = 0; } static void ilrttcalc(Ilcb *ic) { - int dlen, dt, t, pt, x; + int rtt, tt, pt, delay, rate; - t = msec - ic->rttms; + /* add in clock resolution hack */ + rtt = (msec + TK2MS(1) - 1) - ic->rttms; + delay = ic->delay; + rate = ic->rate; /* Guard against the ulong zero wrap of MACHP(0)->ticks */ - if(t > 120000) + if(rtt > 120000) return; - - /* seed connection parameters with time of first ack */ - if(ic->lrttlen == 0){ - ic->lrttlen = ic->rttlen; - /* account pessimisticly for clock resolution */ - if(t == 0) - t = TK2MS(1); - ic->lrtt = t; - x = (ic->rttlen/t)<rate = x; - ic->delay = t<mdev = t<rttlen - ic->lrttlen; - dt = t - ic->lrtt; - - /* fixed delay */ - if(dlen == 0) - x = t - ic->rttlen/(ic->rate>>LogAGain); - else - x = (ic->lrtt*ic->rttlen - t*ic->lrttlen)/dlen; - if(x > 0){ - x += ic->delay - (ic->delay>>LogAGain); - if(x < AGain) - x = AGain; - ic->delay = x; + /* guess fixed delay as rtt of small packets */ + if(ic->rttlen < 128){ + delay += rtt - (delay>>LogAGain); + if(delay < AGain) + delay = AGain; + ic->delay = delay; } /* rate */ - if(dt == 0){ - if(dlen) - x = DefByteRate; - else - x = -1; - } else - x = dlen/dt; - if(x > 0){ - x += ic->rate - (ic->rate>>LogAGain); - if(x < AGain) - x = AGain; - ic->rate = x; + tt = rtt - (delay>>LogAGain); + if(tt > 0){ + rate += ic->rttlen/tt - (rate>>LogAGain); + if(rate < AGain) + rate = AGain; + ic->rate = rate; } /* mdev */ - pt = ic->rttlen/(ic->rate>>LogAGain) + (ic->delay>>LogAGain); - ic->mdev += abs(t-pt) - (ic->mdev>>LogDGain); + pt = ic->rttlen/(rate>>LogAGain) + (delay>>LogAGain); + ic->mdev += abs(rtt-pt) - (ic->mdev>>LogDGain); -out: - ic->lrtt = t; - ic->lrttlen = ic->rttlen; + if(rtt > ic->maxrtt) + ic->maxrtt = rtt; } void @@ -450,7 +419,7 @@ ilackto(Ilcb *ic, ulong ackto) if(ic->rttack == ackto) ilrttcalc(ic); - /* Cancel if we lost the packet we were interested in */ + /* Cancel if we've passed the packet we were interested in */ if(ic->rttack <= ackto) ic->rttack = 0; @@ -762,6 +731,7 @@ ilrexmit(Ilcb *ic) il.rexmit++; ic->rexmit++; + ic->rttack = 0; /* stop counting rtt */ ipoput(nb, 0, ic->conv->ttl); } @@ -1021,7 +991,7 @@ loop: void ilbackoff(Ilcb *ic) { - ic->fasttime = (ic->fasttime)*3/2; + ic->fasttime += ic->fasttime<<1; } char* @@ -1096,8 +1066,12 @@ iltimers(Ilcb *ic) ic->timeout = 0; pt = (ic->delay>>LogAGain) + ic->unackedbytes/(ic->rate>>LogAGain) + ic->mdev; - ic->fasttime = (Fasttime*pt)/Iltickms; - ic->slowtime = (Slowtime*pt)/Iltickms; + ic->fasttime = (Fasttime/Seconds)*pt; + if(ic->fasttime > Fasttime) + ic->fasttime = Fasttime; + ic->slowtime = (Slowtime/Seconds)*pt; + if(ic->slowtime > Slowtime) + ic->slowtime = Slowtime; } void diff --git a/ip/tcp.c b/ip/tcp.c index d88544ff9ca4588b092b469b96edd96c613afb93..efc0432bb1030efdd03ea5c6cd5cb9aed8b41427 100644 --- a/ip/tcp.c +++ b/ip/tcp.c @@ -900,7 +900,7 @@ seq_within(ulong x, ulong low, ulong high) return 1; } else { - if(low >= x && x >= high) + if(x >= low || x <= high) return 1; } return 0;