+ int new, old = tpcb->tp_dt_ticks;
+ int delta, elapsed = tick - tpcb->tp_rttemit;
+
+ if (tpcb->tp_rtt != 0) {
+ /*
+ * rtt is the smoothed round trip time in machine clock ticks (hz).
+ * it is stored as a fixed point number, unscaled (unlike the tcp
+ * srtt. The rationale here is that it is only significant to the
+ * nearest unit of slowtimo, which is at least 8 machine clock ticks
+ * so there is no need to scale. The smoothing is done according
+ * to the same formula as TCP (rtt = rtt*7/8 + measured_rtt/8).
+ */
+ delta = elapsed - tpcb->tp_rtt;
+ if ((tpcb->tp_rtt += (delta >> TP_RTT_ALPHA)) <= 0)
+ tpcb->tp_rtt = 1;
+ /*
+ * rtv is a smoothed accumulated mean difference, unscaled
+ * for reasons expressed above.
+ * It is smoothed with an alpha of .75, and the round trip timer
+ * will be set to rtt + 4*rtv, also as TCP does.
+ */
+ if (delta < 0)
+ delta = -delta;
+ if ((tpcb->tp_rtv += ((delta - tpcb->tp_rtv) >> TP_RTV_ALPHA)) <= 0)
+ tpcb->tp_rtv = 1;
+ } else {
+ /*
+ * No rtt measurement yet - use the unsmoothed rtt.
+ * Set the variance to half the rtt (so our first
+ * retransmit happens at 3*rtt)
+ */
+ tpcb->tp_rtt = elapsed;
+ tpcb->tp_rtv = elapsed >> 1;
+ }
+ tpcb->tp_rttemit = 0;
+ tpcb->tp_rxtshift = 0;
+ /*
+ * Quoting TCP: "the retransmit should happen at rtt + 4 * rttvar.
+ * Because of the way we do the smoothing, srtt and rttvar
+ * will each average +1/2 tick of bias. When we compute
+ * the retransmit timer, we want 1/2 tick of rounding and
+ * 1 extra tick because of +-1/2 tick uncertainty in the
+ * firing of the timer. The bias will give us exactly the
+ * 1.5 tick we need. But, because the bias is
+ * statistical, we have to test that we don't drop below
+ * the minimum feasible timer (which is 2 ticks)."
+ */
+ new = (((tpcb->tp_rtt + (tpcb->tp_rtv << 2)) * PR_SLOWHZ) + hz) / hz;
+ new = MAX(new + 1, tpcb->tp_peer_acktime);
+ new = MAX(new, 2);
+ IFTRACE(D_RTT)
+ tptraceTPCB(TPPTmisc, "oldticks ,rtv, rtt, newticks",
+ old, rtv, rtt, new);
+ ENDTRACE
+ tpcb->tp_rxtcur = tpcb->tp_dt_ticks = new;