2 * linux/net/sunrpc/timer.c
4 * Estimate RPC request round trip time.
6 * Based on packet round-trip and variance estimator algorithms described
7 * in appendix A of "Congestion Avoidance and Control" by Van Jacobson
8 * and Michael J. Karels (ACM Computer Communication Review; Proceedings
9 * of the Sigcomm '88 Symposium in Stanford, CA, August, 1988).
11 * This RTT estimator is used only for RPC over datagram protocols.
13 * Copyright (C) 2002 Trond Myklebust <trond.myklebust@fys.uio.no>
16 #include <asm/param.h>
18 #include <linux/types.h>
19 #include <linux/unistd.h>
21 #include <linux/sunrpc/clnt.h>
22 #include <linux/sunrpc/xprt.h>
23 #include <linux/sunrpc/timer.h>
25 #define RPC_RTO_MAX (60*HZ)
26 #define RPC_RTO_INIT (HZ/5)
27 #define RPC_RTO_MIN (HZ/10)
30 rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo)
32 unsigned long init = 0;
37 if (timeo > RPC_RTO_INIT)
38 init = (timeo - RPC_RTO_INIT) << 3;
39 for (i = 0; i < 5; i++) {
41 rt->sdrtt[i] = RPC_RTO_INIT;
47 * NB: When computing the smoothed RTT and standard deviation,
48 * be careful not to produce negative intermediate results.
51 rpc_update_rtt(struct rpc_rtt *rt, unsigned timer, long m)
58 /* jiffies wrapped; ignore this one */
65 srtt = (long *)&rt->srtt[timer];
72 sdrtt = (long *)&rt->sdrtt[timer];
76 /* Set lower bound on the variance */
77 if (*sdrtt < RPC_RTO_MIN)
82 * Estimate rto for an nfs rpc sent via. an unreliable datagram.
83 * Use the mean and mean deviation of rtt for the appropriate type of rpc
84 * for the frequent rpcs and a default for the others.
85 * The justification for doing "other" this way is that these rpcs
86 * happen so infrequently that timer est. would probably be stale.
87 * Also, since many of these rpcs are
88 * non-idempotent, a conservative timeout is desired.
90 * read, write, commit - A+4D
95 rpc_calc_rto(struct rpc_rtt *rt, unsigned timer)
102 res = ((rt->srtt[timer] + 7) >> 3) + rt->sdrtt[timer];
103 if (res > RPC_RTO_MAX)