Commit 2752e009 authored by Chuck Lever's avatar Chuck Lever Committed by Linus Torvalds

[PATCH] RTO estimator cleanup patch

clean up RPC client's RTO estimator.
parent a7ec0168
...@@ -20,8 +20,8 @@ struct rpc_rtt { ...@@ -20,8 +20,8 @@ struct rpc_rtt {
extern void rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo); 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 void rpc_update_rtt(struct rpc_rtt *rt, unsigned timer, long m);
extern unsigned long rpc_calc_rto(struct rpc_rtt *rt, int timer); extern unsigned long rpc_calc_rto(struct rpc_rtt *rt, unsigned timer);
static inline void rpc_inc_timeo(struct rpc_rtt *rt) static inline void rpc_inc_timeo(struct rpc_rtt *rt)
{ {
......
...@@ -71,7 +71,7 @@ struct rpc_timeout { ...@@ -71,7 +71,7 @@ struct rpc_timeout {
to_initval, /* initial timeout */ to_initval, /* initial timeout */
to_maxval, /* max timeout */ to_maxval, /* max timeout */
to_increment; /* if !exponential */ to_increment; /* if !exponential */
short to_retries; /* max # of retries */ unsigned int to_retries; /* max # of retries */
unsigned char to_exponential; unsigned char to_exponential;
}; };
......
/*
* 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/version.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/unistd.h> #include <linux/unistd.h>
...@@ -15,18 +32,25 @@ rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo) ...@@ -15,18 +32,25 @@ rpc_init_rtt(struct rpc_rtt *rt, unsigned long timeo)
{ {
unsigned long init = 0; unsigned long init = 0;
unsigned i; unsigned i;
rt->timeo = timeo; rt->timeo = timeo;
if (timeo > RPC_RTO_INIT) if (timeo > RPC_RTO_INIT)
init = (timeo - RPC_RTO_INIT) << 3; init = (timeo - RPC_RTO_INIT) << 3;
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
rt->srtt[i] = init; rt->srtt[i] = init;
rt->sdrtt[i] = RPC_RTO_INIT; rt->sdrtt[i] = RPC_RTO_INIT;
} }
atomic_set(&rt->ntimeouts, 0); atomic_set(&rt->ntimeouts, 0);
} }
/*
* NB: When computing the smoothed RTT and standard deviation,
* be careful not to produce negative intermediate results.
*/
void 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; unsigned long *srtt, *sdrtt;
...@@ -36,16 +60,21 @@ rpc_update_rtt(struct rpc_rtt *rt, int timer, long m) ...@@ -36,16 +60,21 @@ rpc_update_rtt(struct rpc_rtt *rt, int timer, long m)
/* jiffies wrapped; ignore this one */ /* jiffies wrapped; ignore this one */
if (m < 0) if (m < 0)
return; return;
if (m == 0) if (m == 0)
m = 1; m = 1L;
srtt = &rt->srtt[timer]; srtt = &rt->srtt[timer];
m -= *srtt >> 3; m -= *srtt >> 3;
*srtt += m; *srtt += m;
if (m < 0) if (m < 0)
m = -m; m = -m;
sdrtt = &rt->sdrtt[timer]; sdrtt = &rt->sdrtt[timer];
m -= *sdrtt >> 2; m -= *sdrtt >> 2;
*sdrtt += m; *sdrtt += m;
/* Set lower bound on the variance */ /* Set lower bound on the variance */
if (*sdrtt < RPC_RTO_MIN) if (*sdrtt < RPC_RTO_MIN)
*sdrtt = RPC_RTO_MIN; *sdrtt = RPC_RTO_MIN;
...@@ -65,13 +94,16 @@ rpc_update_rtt(struct rpc_rtt *rt, int timer, long m) ...@@ -65,13 +94,16 @@ rpc_update_rtt(struct rpc_rtt *rt, int timer, long m)
*/ */
unsigned long unsigned long
rpc_calc_rto(struct rpc_rtt *rt, int timer) rpc_calc_rto(struct rpc_rtt *rt, unsigned timer)
{ {
unsigned long res; unsigned long res;
if (timer-- == 0) if (timer-- == 0)
return rt->timeo; return rt->timeo;
res = (rt->srtt[timer] >> 3) + rt->sdrtt[timer]; res = (rt->srtt[timer] >> 3) + rt->sdrtt[timer];
if (res > RPC_RTO_MAX) if (res > RPC_RTO_MAX)
res = RPC_RTO_MAX; res = RPC_RTO_MAX;
return res; return res;
} }
...@@ -584,9 +584,11 @@ xprt_complete_rqst(struct rpc_xprt *xprt, struct rpc_rqst *req, int copied) ...@@ -584,9 +584,11 @@ xprt_complete_rqst(struct rpc_xprt *xprt, struct rpc_rqst *req, int copied)
xprt_adjust_cwnd(xprt, copied); xprt_adjust_cwnd(xprt, copied);
__xprt_put_cong(xprt, req); __xprt_put_cong(xprt, req);
if (!req->rq_nresend) { 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) 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); rpc_clear_timeo(&clnt->cl_rtt);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment