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>
20 #include <linux/module.h>
22 #include <linux/sunrpc/clnt.h>
24 #define RPC_RTO_MAX (60*HZ)
25 #define RPC_RTO_INIT (HZ/5)
26 #define RPC_RTO_MIN (HZ/10)
29 * rpc_init_rtt - Initialize an RPC RTT estimator context
30 * @rt: context to initialize
31 * @timeo: initial timeout value, in jiffies
34 void rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo)
36 unsigned long init = 0;
41 if (timeo > RPC_RTO_INIT)
42 init = (timeo - RPC_RTO_INIT) << 3;
43 for (i = 0; i < 5; i++) {
45 rt->sdrtt[i] = RPC_RTO_INIT;
49 EXPORT_SYMBOL_GPL(rpc_init_rtt);
52 * rpc_update_rtt - Update an RPC RTT estimator context
53 * @rt: context to update
54 * @timer: timer array index (request type)
55 * @m: recent actual RTT, in jiffies
57 * NB: When computing the smoothed RTT and standard deviation,
58 * be careful not to produce negative intermediate results.
60 void rpc_update_rtt(struct rpc_rtt *rt, unsigned timer, long m)
67 /* jiffies wrapped; ignore this one */
74 srtt = (long *)&rt->srtt[timer];
81 sdrtt = (long *)&rt->sdrtt[timer];
85 /* Set lower bound on the variance */
86 if (*sdrtt < RPC_RTO_MIN)
89 EXPORT_SYMBOL_GPL(rpc_update_rtt);
92 * rpc_calc_rto - Provide an estimated timeout value
93 * @rt: context to use for calculation
94 * @timer: timer array index (request type)
96 * Estimate RTO for an NFS RPC sent via an unreliable datagram. Use
97 * the mean and mean deviation of RTT for the appropriate type of RPC
98 * for frequently issued RPCs, and a fixed default for the others.
100 * The justification for doing "other" this way is that these RPCs
101 * happen so infrequently that timer estimation would probably be
102 * stale. Also, since many of these RPCs are non-idempotent, a
103 * conservative timeout is desired.
106 * read, write, commit - A+4D
109 unsigned long rpc_calc_rto(struct rpc_rtt *rt, unsigned timer)
116 res = ((rt->srtt[timer] + 7) >> 3) + rt->sdrtt[timer];
117 if (res > RPC_RTO_MAX)
122 EXPORT_SYMBOL_GPL(rpc_calc_rto);