]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] RTO estimator cleanup patch
authorChuck Lever <cel@citi.umich.edu>
Fri, 8 Nov 2002 11:28:49 +0000 (03:28 -0800)
committerLinus Torvalds <torvalds@home.transmeta.com>
Fri, 8 Nov 2002 11:28:49 +0000 (03:28 -0800)
clean up RPC client's RTO estimator.

include/linux/sunrpc/timer.h
include/linux/sunrpc/xprt.h
net/sunrpc/timer.c
net/sunrpc/xprt.c

index 7ea36ae4037b50df678c221513ba78ef31a57543..ff6bc599eeec521f5da7319b258f6f4aa23beebe 100644 (file)
@@ -20,8 +20,8 @@ struct rpc_rtt {
 
 
 extern void rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo);
-extern void rpc_update_rtt(struct rpc_rtt *rt, int timer, long m);
-extern unsigned long rpc_calc_rto(struct rpc_rtt *rt, int timer);
+extern void rpc_update_rtt(struct rpc_rtt *rt, unsigned timer, long m);
+extern unsigned long rpc_calc_rto(struct rpc_rtt *rt, unsigned timer);
 
 static inline void rpc_inc_timeo(struct rpc_rtt *rt)
 {
index 3eebc1722ea2efb8c8ca45c0b4d6d0b458bbfcf4..034aa2ac05e9c4b5cfe9f921d6d0de1486d391fb 100644 (file)
@@ -71,7 +71,7 @@ struct rpc_timeout {
                                to_initval,             /* initial timeout */
                                to_maxval,              /* max timeout */
                                to_increment;           /* if !exponential */
-       short                   to_retries;             /* max # of retries */
+       unsigned int            to_retries;             /* max # of retries */
        unsigned char           to_exponential;
 };
 
index fda098fd3ac0d4d9dd578e36bb7d9afc6994fd16..6cd6f8a9a8db67907ee4c6f95d27ab72f299e3f4 100644 (file)
@@ -1,3 +1,20 @@
+/*
+ * linux/net/sunrpc/timer.c
+ *
+ * Estimate RPC request round trip time.
+ *
+ * Based on packet round-trip and variance estimator algorithms described
+ * in appendix A of "Congestion Avoidance and Control" by Van Jacobson
+ * and Michael J. Karels (ACM Computer Communication Review; Proceedings
+ * of the Sigcomm '88 Symposium in Stanford, CA, August, 1988).
+ *
+ * This RTT estimator is used only for RPC over datagram protocols.
+ *
+ * Copyright (C) 2002 Trond Myklebust <trond.myklebust@fys.uio.no>
+ */
+
+#include <asm/param.h>
+
 #include <linux/version.h>
 #include <linux/types.h>
 #include <linux/unistd.h>
@@ -15,18 +32,25 @@ rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo)
 {
        unsigned long init = 0;
        unsigned i;
+
        rt->timeo = timeo;
+
        if (timeo > RPC_RTO_INIT)
                init = (timeo - RPC_RTO_INIT) << 3;
        for (i = 0; i < 5; i++) {
                rt->srtt[i] = init;
                rt->sdrtt[i] = RPC_RTO_INIT;
        }
+
        atomic_set(&rt->ntimeouts, 0);
 }
 
+/*
+ * NB: When computing the smoothed RTT and standard deviation,
+ *     be careful not to produce negative intermediate results.
+ */
 void
-rpc_update_rtt(struct rpc_rtt *rt, int timer, long m)
+rpc_update_rtt(struct rpc_rtt *rt, unsigned timer, long m)
 {
        unsigned long *srtt, *sdrtt;
 
@@ -36,16 +60,21 @@ rpc_update_rtt(struct rpc_rtt *rt, int timer, long m)
        /* jiffies wrapped; ignore this one */
        if (m < 0)
                return;
+
        if (m == 0)
-               m = 1;
+               m = 1L;
+
        srtt = &rt->srtt[timer];
        m -= *srtt >> 3;
        *srtt += m;
+
        if (m < 0)
                m = -m;
+
        sdrtt = &rt->sdrtt[timer];
        m -= *sdrtt >> 2;
        *sdrtt += m;
+
        /* Set lower bound on the variance */
        if (*sdrtt < RPC_RTO_MIN)
                *sdrtt = RPC_RTO_MIN;
@@ -65,13 +94,16 @@ rpc_update_rtt(struct rpc_rtt *rt, int timer, long m)
  */
 
 unsigned long
-rpc_calc_rto(struct rpc_rtt *rt, int timer)
+rpc_calc_rto(struct rpc_rtt *rt, unsigned timer)
 {
        unsigned long res;
+
        if (timer-- == 0)
                return rt->timeo;
+
        res = (rt->srtt[timer] >> 3) + rt->sdrtt[timer];
        if (res > RPC_RTO_MAX)
                res = RPC_RTO_MAX;
+
        return res;
 }
index cb37554a9bcbb9e0bc48b4d82bf7b3532d79048c..480c7354eb9029f04ba25ae4021650d0bee0ba9e 100644 (file)
@@ -584,9 +584,11 @@ xprt_complete_rqst(struct rpc_xprt *xprt, struct rpc_rqst *req, int copied)
                xprt_adjust_cwnd(xprt, copied);
                __xprt_put_cong(xprt, req);
                if (!req->rq_nresend) {
-                       int timer = rpcproc_timer(clnt, task->tk_msg.rpc_proc);
+                       unsigned timer =
+                               rpcproc_timer(clnt, task->tk_msg.rpc_proc);
                        if (timer)
-                               rpc_update_rtt(&clnt->cl_rtt, timer, (long)jiffies - req->rq_xtime);
+                               rpc_update_rtt(&clnt->cl_rtt, timer,
+                                               (long)jiffies - req->rq_xtime);
                }
                rpc_clear_timeo(&clnt->cl_rtt);
        }