ext4: Retry block allocation if new blocks are allocated from system zone.
[linux-2.6/lfs.git] / net / sunrpc / timer.c
blob31becbf092632fcb4151b649c4507b6a794f46e8
1 /*
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)
28 void
29 rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo)
31 unsigned long init = 0;
32 unsigned i;
34 rt->timeo = timeo;
36 if (timeo > RPC_RTO_INIT)
37 init = (timeo - RPC_RTO_INIT) << 3;
38 for (i = 0; i < 5; i++) {
39 rt->srtt[i] = init;
40 rt->sdrtt[i] = RPC_RTO_INIT;
41 rt->ntimeouts[i] = 0;
44 EXPORT_SYMBOL_GPL(rpc_init_rtt);
47 * NB: When computing the smoothed RTT and standard deviation,
48 * be careful not to produce negative intermediate results.
50 void
51 rpc_update_rtt(struct rpc_rtt *rt, unsigned timer, long m)
53 long *srtt, *sdrtt;
55 if (timer-- == 0)
56 return;
58 /* jiffies wrapped; ignore this one */
59 if (m < 0)
60 return;
62 if (m == 0)
63 m = 1L;
65 srtt = (long *)&rt->srtt[timer];
66 m -= *srtt >> 3;
67 *srtt += m;
69 if (m < 0)
70 m = -m;
72 sdrtt = (long *)&rt->sdrtt[timer];
73 m -= *sdrtt >> 2;
74 *sdrtt += m;
76 /* Set lower bound on the variance */
77 if (*sdrtt < RPC_RTO_MIN)
78 *sdrtt = RPC_RTO_MIN;
80 EXPORT_SYMBOL_GPL(rpc_update_rtt);
83 * Estimate rto for an nfs rpc sent via. an unreliable datagram.
84 * Use the mean and mean deviation of rtt for the appropriate type of rpc
85 * for the frequent rpcs and a default for the others.
86 * The justification for doing "other" this way is that these rpcs
87 * happen so infrequently that timer est. would probably be stale.
88 * Also, since many of these rpcs are
89 * non-idempotent, a conservative timeout is desired.
90 * getattr, lookup,
91 * read, write, commit - A+4D
92 * other - timeo
95 unsigned long
96 rpc_calc_rto(struct rpc_rtt *rt, unsigned timer)
98 unsigned long res;
100 if (timer-- == 0)
101 return rt->timeo;
103 res = ((rt->srtt[timer] + 7) >> 3) + rt->sdrtt[timer];
104 if (res > RPC_RTO_MAX)
105 res = RPC_RTO_MAX;
107 return res;
109 EXPORT_SYMBOL_GPL(rpc_calc_rto);